渗透测试-信息收集
努力获取目标相关信息,越多越好,本章内容包括涉及通用渗透测试框架中的:
- 信息收集
- 目标识别
- 服务枚举
- 漏洞映射
2.1 外围信息收集
在划定了测试范围之后,就需要进入信息收集阶段。在这个阶段,渗透人员需要使用各种公开资源尽可能地获取测试目标的相关信息。他们从互联网上搜集信息的渠道主要有:
-
论坛
-
公告板
-
新闻组
-
媒体文章
-
博客
-
社交网络
-
github
-
其他商业或非商业性的网站
此外,他们也可以借助各种搜索引擎中获取相关数据,如谷歌、必应、百度、钟馗之眼、撒旦、佛法等。收集的信息主要包括DNS 服务器、路由关系、whois 数据库、电子邮件地址、电话号码、个人信息以及用户账户。收集的信息越多,渗透测试成功的概率越高。
本课程以www.testfire.net 为目标,testfire.net 是IBM 公司为了演示旗下比较有名的Web 漏洞扫描器AppScan 的强大功能所搭建的模拟银行网站,所以上面会有很多常见的Web 安全漏洞。
2.1.1 DNS 信息
在收集DNS 信息的时候,主要关注域名注册商,管理员联系方式,电话和邮箱,子域名等信息。
whois 查询
whois 是一个集成在Kali 中的小工具,whois 工具可以用来查询域名注册信息。whois 查询域名信息数据库,属于公开渠道,域名信息有时候会进行隐藏。
whois testfire.net
也可以通过站长之家进行whois 查询
除了用whois 查询以外,还可以进行反查,对于这些反查得到的信息,如果数量庞大,说明是服务商的电话。
- 邮箱反查:这个邮箱都注册过哪些域名。
- 注册人反查:这个注册人都注册过哪些域名。
- 电话反查:这个电话都注册过哪些域名。
子域名查询
netcraft
利用搜索引擎
利用HTTPS 证书
域传送漏洞
DNS 区域传送(DNS zone transfer)指的是一台备用服务器使用来自主服务器的数据刷新自己的域(zone)数据库。这为运行中的DNS 服务提供了一定的冗余度,其目的是为了防止主的域名服务器因意外故障变得不可用时影响到整个域名的解析。一般来说,DNS 区域传送操作只在网络里真的有备用域名DNS 服务器时才有必要用到,但许多DNS 服务器却被错误地配置成只要有client 发出请求,就会向对方提供一个zone 数据库的详细信息,所以说允许不受信任的互联网用户执行DNS 区域传送(zone transfer)操作,是最为严重的错误配置之一 。
- 缺乏身份认证
- 只要客户端发出请求,主DNS 服务器就会同步数据库
- 正确的配置是主DNS 服务器指定备份DNS 服务器的IP 地址
- 可以使用dig 工具来检测域传送漏洞,命令如下
sudo apt-get install dnsutils
dig axfr @10.9.65.153 vulhub.org
子域名爆破
子域名爆破原理:字典爆破
- 子域名挖掘机
- ksubdomain
2.1.2 DNS2IP
通过DNS 解析找到IP 地址。
ping
┌──(ajest💋AJESTdeKali)-[~]
└─$ ping www.testfire.net
PING testfire.net (65.61.137.117) 56(84) bytes of data.
64 bytes from 65.61.137.117 (65.61.137.117): icmp_seq=1 ttl=108 time=226 ms
^C
--- testfire.net ping statistics ---
2 packets transmitted, 1 received, 50% packet loss, time 999ms
rtt min/avg/max/mdev = 226.192/226.192/226.192/0.000 ms
┌──(ajest💋AJESTdeKali)-[~]
└─$
nslookup
┌──(ajest💋AJESTdeKali)-[~]
└─$ nslookup www.testfire.net
Server: 202.106.196.115
Address: 202.106.196.115#53
Non-authoritative answer:
www.testfire.net canonical name = testfire.net.
Name: testfire.net
Address: 65.61.137.117
┌──(ajest💋AJESTdeKali)-[~]
└─$
dig
dig 工具安装
sudo apt-get update
sudo apt-get install dnsutils
利用dig 工具解析域名
命令 | 示例 |
---|---|
dig |
dig www.testfire.net |
dig @ |
dig @8.8.8.8 www.testfire.net |
dig +trace |
dig +trace www.testfire.net |
dig axfr @ |
dig axfr @127.0.0.1 vulhub.org |
dnsenum
┌──(ajest💋AJESTdeKali)-[~]
└─$ dnsenum testfire.net
dnsenum VERSION:1.2.6
----- testfire.net -----
Host's addresses:
__________________
testfire.net. 20608 IN A 65.61.137.117
Name Servers:
______________
usc2.akam.net. 33592 IN A 184.26.160.64
usc3.akam.net. 38372 IN A 96.7.50.64
asia3.akam.net. 51383 IN A 23.211.61.64
usw2.akam.net. 46845 IN A 184.26.161.64
eur2.akam.net. 63676 IN A 95.100.173.64
eur5.akam.net. 74470 IN A 23.74.25.64
ns1-99.akam.net. 88688 IN A 193.108.91.99
ns1-206.akam.net. 88688 IN A 193.108.91.206
Mail (MX) Servers:
___________________
Trying Zone Transfers and getting Bind Versions:
_________________________________________________
Trying Zone Transfer for testfire.net on usc2.akam.net ...
AXFR record query failed: Connection timed out
Trying Zone Transfer for testfire.net on usc3.akam.net ...
AXFR record query failed: Connection timed out
Trying Zone Transfer for testfire.net on asia3.akam.net ...
AXFR record query failed: Connection timed out
Trying Zone Transfer for testfire.net on usw2.akam.net ...
AXFR record query failed: Connection timed out
Trying Zone Transfer for testfire.net on eur2.akam.net ...
AXFR record query failed: Connection timed out
Trying Zone Transfer for testfire.net on eur5.akam.net ...
AXFR record query failed: Connection timed out
Trying Zone Transfer for testfire.net on ns1-99.akam.net ...
AXFR record query failed: Connection timed out
Trying Zone Transfer for testfire.net on ns1-206.akam.net ...
AXFR record query failed: Connection timed out
Brute forcing with /usr/share/dnsenum/dns.txt:
_______________________________________________
ftp.testfire.net. 86400 IN CNAME testfire.net.
testfire.net. 84502 IN A 65.61.137.117
www.testfire.net. 86400 IN CNAME testfire.net.
testfire.net. 86400 IN A 65.61.137.117
testfire.net class C netranges:
________________________________
65.61.137.0/24
Performing reverse lookup on 256 ip addresses:
_______________________________________________
0 results out of 256 IP addresses.
testfire.net ip blocks:
________________________
done.
┌──(ajest💋AJESTdeKali)-[~]
└─$
网站工具
CDN 问题
如何绕过CDN 查找网站真实IP 地址?这是一个开放性的话题。思路如下:
- 让目标网站主动来连接我们
- 查询DNS 历史记录
- 子域名
- SSL 证书
- 全网扫描
- 国外线路
- 参考文章
https://www.fujieace.com/penetration-test/cdn-find-ip.html
2.1.3 IP 信息
IP 查询
http://ip.tool.chinaz.com/65.61.137.117
https://www.ip138.com/iplookup.asp?ip=65.61.137.117&action=2
IP whois 查询
http://tool.chinaz.com/ipwhois/?q=65.61.137.117
https://www.abuseipdb.com/whois/65.61.137.117
https://ipinfo.io/65.61.137.117
旁站查询
同IP 网站查询
http://stool.chinaz.com/same?s=65.61.137.117&page=
IP2Location
通过IP 地址查询到物理地址:
- 查询IP 地址经纬度
https://www.maxmind.com/
- GPS 定位
https://www.zoomeye.org
2.1.4 利用搜索引擎搜集信息
搜索引擎是指从互联网搜集信息,经过一定的整理以后,提供给用户进行查询的系统。传统搜索引擎 对我们来说并不陌生,像Google、Baidu 等,每天我们几乎都会用他们搜索信息。与传统搜索引擎相比,网络空间搜索引擎 有很大不同,其搜索目标为全球IP 地址,实时扫描互联网和解析各种设备,对网络中的设备进行探测识别和指纹分析,并将其扫描的目标信息进行分布式存储,供需求者检索使用。
传统搜索引擎(网页信息) | 网络空间搜索引擎(IP 地址和指纹信息) |
---|---|
Googlebaidubing | shodanCensysZoomEyeFofaPunkSPIDERIVRE(Drunk) |
Google Hacking
Google 机器人,自动爬行全世界所有网站(网页)的内容。Google Hacking 就是利用搜索引擎的语法,达到精准搜索信息的目的。如果Google 用不了的,也可以考虑其他搜索引擎。
功能 | Google 语法 |
---|---|
探索网站目录结构 | parent directory site:testfire.netindex of site:testfire.net |
搜索登录页面 | site:testfire.net inurl:loginsite:testfire.net intext:login |
搜索指定的文件类型 | site:testfire.net filetype:pdf |
搜索phpinfo() | intext:PHP Version ext:php intext:apache2handler intext:allow_url_include intext:php.ini |
GHDB
intitle:"Index of" "Apache/2.4.49"
ZoomEye
ZoomEye,又称为“钟馗之眼”,是国内安全厂商知道创宇倾力打造的知名空间搜索引擎,它可以识别网络中的站点组件指纹和主机设备指纹。
ZoomEye 支持公网设备指纹检索和Web 指纹检索。Web 指纹识别包括应用名、版本、前端框架、后端框架、服务端语言、服务器操作系统、网站容器、内容管理系统和数据库等。设备指纹识别包括应用名、版本、开放端口、操作系统、服务名、地理位置等,直接输入关键词即可开始检索。下面列举了ZoomEye 的常见搜索语法,更多信息也可以参考搜索导航
设备指纹检索语法
语法 | 描述 | 示例 |
---|---|---|
app: <组件名> | 组件名称 | app:"Apache httpd" |
ver: <组件版本> | 组件的版本号 | ver:"2.2.16" |
port: <端口号> | 目标系统开放端口 | port:3389 |
os: <操作系统> | 目标操作系统类 | os:linux |
service: <服务名> | 系统运行的服务类型 | service:webcam |
hostname: <主机名> | 目标系统的主机名 | hostname:google.com |
country: <国家或地区代码> | 目标系统地理位置 | country:US |
city: <城市名称> | 目标系统所在城市 | city:"beijing" |
ip: <指定的IP 地址> | 目标系统对应的IP 地址 | ip:8.8.8.8 |
org: <组织机构> | 所属的组织结构 | org:"Vimpelcom" |
asn: <自治系统号> | 自治系统编号 | asn:42893 |
ssl: <SSL 证书> | SSL 证书 | ssl:"corp.google.com" |
Web 指纹检索语法
语法 | 描述 | 示例 |
---|---|---|
app: <组件名> | 组件名称 | app:"Apache httpd" |
ver: <组件版本> | 组件的版本号 | ver:"2.2.16" |
site: <网站域名> | 目标网站域名 | site:google.com |
os:<操作系统> | 目标操作系统类型 | os:linux |
title: <页面标题> | 网站的标题 | title:Nginx |
keywords: <页面关键字> | 网站页面的关键字 | keywords:Nginx |
desc: <页面说明> | 页面描述字段 | desc:Nginx |
headers: <请求头部> | HTTP 请求中的Headers | headers:Server |
country: <国家或地区代码> | 目标系统地理位置 | country:US |
city: <城市名称> | 目标系统所在城市 | city:"beijing" |
ip: <指定的IP 地址> | 目标系统对应的IP 地址 | ip:8.8.8.8 |
org: <组织机构> | 所属的组织结构 | org:"Vimpelcom" |
asn: <自治系统号> | 自治系统编号 | asn:42893 |
app:"Apache httpd" +os:"linux" +country:US +city:"New York City"
site:google.com +os:linux +country:US +city:"New York City"
shodan
Shodan主要获取互联网中设备中的服务、位置、端口、版本等信息,目前比较受欢迎的内容有webcam 、linksys 、cisco 、netgear 、SCADA 等。通过不同的搜索语法可以做到批量搜索漏洞主机、统计中病毒主机、进行弱口令爆破、获取shell 等功能。
shodan 常用语法
语法 | 描述 | 示例 |
---|---|---|
city: <城市名称> | 目标系统所在城市 | city:"beijing" |
country: <国家或地区代码> | 国家的简称 | country:"CN" |
geo: <经纬度> | 经纬度 | geo:"469481,7.4447" |
hostname: <主机名> | 主机名或域名 | hostname:"baidu" |
ip: <IP 地址> | IP 地址 | ip:"11.11.11.11" |
isp: <ISP 供应商> | ISP 供应上 | isp:"China Telecom" |
org: <组织或公司> | 组织或公司 | org:"baidu" |
os: <操作系统> | 操作系统 | os:"Windows 7 or 8" |
port: <端口号> | 端口号 | port:80 |
net: <CIDR 格式的IP 地址> | CIDR 格式的IP 地址 | net:"190.30.40.0/24" |
version: <软件版本号> | 软件版本 | version:"4.4.2" |
vuln: <漏洞编号> | 漏洞CVE 编号 | vuln:CVE-2020-0787 |
http.server: <服务类型> | http 请求返回中的server 的类型 | http.server:apache |
http.status: <请求状态码> | http 请求返回响应码的状态 | http.status:200 |
JAWS/1.1
document.cookie="dvr_camcnt=4";
document.cookie="dvr_usr=admin";
document.cookie="dvr_pwd=123";
view2.html
import shodan
api_key="q6KFmh1xNF1x6ktByycv4cppYcUSEc48"
api = shodan.Shodan(api_key)
results = api.search("JAWS/1.1")
print(f"{results['matches'][0]['ip_str']}:{results['matches'][0]['port']}")
fofa
2.1.5 网站信息
网站报告
技术架构
操作系统+Web 服务器+中间件+数据库
*AMP
*NMP
Windows+IIS+{ASP|.NET(.aspx)}+{ACCESS|MSSQL(SQL Server)}
...
套件
phpStudy
XAMPP
宝塔
...
网站部署方式
前后端分离 | 站库分离 |
---|---|
前端服务器后端服务器数据库服务器文件存储服务器第三方服务器接口(短信验证接口)... | Web 服务器数据库服务器 |
2.2 主动信息收集
2.2.1 Web 应用指纹信息
在Web 应用开发过程中,为了开发的高效性,通常会使用一些现成CMS、框架等。
常见的开发框架和内容管理系统(CMS):
PHP | JAVA | JavaScript |
---|---|---|
wordpress(wp) drupal joomlathinkphp(tp) dedecms(织梦) discuz(dz) metinfo(米拓)... |
struts2 spring springboot JBoss Weblogic... |
vue.js |
Wappalyzer
浏览器插件
whatweb
┌──(ajest💋AJESTdeKali)-[~]
└─$ whatweb http://10.4.7.132
http://10.4.7.132 [200 OK] Apache[2.2.22], Content-Language[en], Country[RESERVED][ZZ], Drupal, HTTPServer[Debian Linux][Apache/2.2.22 (Debian)], IP[10.4.7.132], JQuery, MetaGenerator[Drupal 7 (http://drupal.org)], PHP[5.4.45-0+deb7u14], PasswordField[pass], Script[text/javascript], Title[Welcome to Drupal Site | Drupal Site], UncommonHeaders[x-generator], X-Powered-By[PHP/5.4.45-0+deb7u14]
云悉
利器
2.2.2 敏感信息收集
nikto
┌──(ajest💋AJESTdeKali)-[~]
└─$ nikto -h "http://10.4.7.132"
- Nikto v2.1.6
---------------------------------------------------------------------------
+ Target IP: 10.4.7.132
+ Target Hostname: 10.4.7.132
+ Target Port: 80
+ Start Time: 2021-10-13 06:39:10 (GMT0)
---------------------------------------------------------------------------
+ Server: Apache/2.2.22 (Debian)
+ Retrieved x-powered-by header: PHP/5.4.45-0+deb7u14
+ The anti-clickjacking X-Frame-Options header is not present.
+ The X-XSS-Protection header is not defined. This header can hint to the user agent to protect against some forms of XSS
+ Uncommon header 'x-generator' found, with contents: Drupal 7 (http://drupal.org)
+ The X-Content-Type-Options header is not set. This could allow the user agent to render the content of the site in a different fashion to the MIME type
+ Server may leak inodes via ETags, header found with file /robots.txt, inode: 152289, size: 1561, mtime: Wed Nov 20 20:45:59 2013
+ Entry '/INSTALL.mysql.txt' in robots.txt returned a non-forbidden or redirect HTTP code (200)
+ Entry '/INSTALL.pgsql.txt' in robots.txt returned a non-forbidden or redirect HTTP code (200)
+ Entry '/INSTALL.sqlite.txt' in robots.txt returned a non-forbidden or redirect HTTP code (200)
+ Entry '/install.php' in robots.txt returned a non-forbidden or redirect HTTP code (200)
+ Entry '/LICENSE.txt' in robots.txt returned a non-forbidden or redirect HTTP code (200)
+ Entry '/MAINTAINERS.txt' in robots.txt returned a non-forbidden or redirect HTTP code (200)
+ Entry '/UPGRADE.txt' in robots.txt returned a non-forbidden or redirect HTTP code (200)
+ Entry '/xmlrpc.php' in robots.txt returned a non-forbidden or redirect HTTP code (200)
+ Entry '/filter/tips/' in robots.txt returned a non-forbidden or redirect HTTP code (200)
+ Entry '/user/register/' in robots.txt returned a non-forbidden or redirect HTTP code (200)
+ Entry '/user/password/' in robots.txt returned a non-forbidden or redirect HTTP code (200)
+ Entry '/user/login/' in robots.txt returned a non-forbidden or redirect HTTP code (200)
+ Entry '/?q=filter/tips/' in robots.txt returned a non-forbidden or redirect HTTP code (200)
+ Entry '/?q=user/password/' in robots.txt returned a non-forbidden or redirect HTTP code (200)
+ Entry '/?q=user/register/' in robots.txt returned a non-forbidden or redirect HTTP code (200)
+ Entry '/?q=user/login/' in robots.txt returned a non-forbidden or redirect HTTP code (200)
+ "robots.txt" contains 36 entries which should be manually viewed.
+ OSVDB-39272: /misc/favicon.ico file identifies this app/server as: Drupal 7.x
+ Apache/2.2.22 appears to be outdated (current is at least Apache/2.4.37). Apache 2.2.34 is the EOL for the 2.x branch.
+ Web Server returns a valid response with junk HTTP methods, this may cause false positives.
+ DEBUG HTTP verb may show server debugging information. See http://msdn.microsoft.com/en-us/library/e8z01xdh%28VS.80%29.aspx for details.
+ OSVDB-3092: /web.config: ASP config file is accessible.
+ OSVDB-12184: /?=PHPB8B5F2A0-3C92-11d3-A3A9-4C7B08C10000: PHP reveals potentially sensitive information via certain HTTP requests that contain specific QUERY strings.
+ OSVDB-12184: /?=PHPE9568F36-D428-11d2-A769-00AA001ACF42: PHP reveals potentially sensitive information via certain HTTP requests that contain specific QUERY strings.
+ OSVDB-12184: /?=PHPE9568F34-D428-11d2-A769-00AA001ACF42: PHP reveals potentially sensitive information via certain HTTP requests that contain specific QUERY strings.
+ OSVDB-12184: /?=PHPE9568F35-D428-11d2-A769-00AA001ACF42: PHP reveals potentially sensitive information via certain HTTP requests that contain specific QUERY strings.
+ OSVDB-3092: /user/: This might be interesting...
+ Uncommon header 'tcn' found, with contents: choice
+ OSVDB-3092: /README: README file found.
+ OSVDB-3092: /UPGRADE.txt: Default file found.
+ OSVDB-3092: /install.php: Drupal install.php file found.
+ OSVDB-3092: /install.php: install.php file found.
+ OSVDB-3092: /LICENSE.txt: License file found may identify site software.
+ OSVDB-3092: /xmlrpc.php: xmlrpc.php was found.
+ OSVDB-3233: /INSTALL.mysql.txt: Drupal installation file found.
+ OSVDB-3233: /INSTALL.pgsql.txt: Drupal installation file found.
+ OSVDB-3233: /icons/README: Apache default file found.
+ 9572 requests: 0 error(s) and 43 item(s) reported on remote host
+ End Time: 2021-10-13 06:54:36 (GMT0) (926 seconds)
---------------------------------------------------------------------------
+ 1 host(s) tested
┌──(ajest💋AJESTdeKali)-[~]
└─$
robots.txt
根据此文件的内容,“告诉”搜索引擎的蜘蛛、机器人、爬虫,本网站下哪些目录可以爬行,哪些目录不可以爬行。
┌──(ajest💋AJESTdeKali)-[~]
└─$ curl http://www.baidu.com/robots.txt
User-agent: Baiduspider
Disallow: /baidu
Disallow: /s?
Disallow: /ulink?
Disallow: /link?
Disallow: /home/news/data/
Disallow: /bh
...
网站源代码泄露
Git 泄露
┌──(ajest💋AJESTdeKali)-[~/…/01CTFer/01 - web 入门/01 - 举足轻重的信息搜集/02 - 粗心的小李]
└─$ curl http://127.0.0.1/.git
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>301 Moved Permanently</title>
</head><body>
<h1>Moved Permanently</h1>
<p>The document has moved <a href="http://127.0.0.1/.git/">here</a>.</p>
<hr>
<address>Apache/2.4.38 (Debian) Server at 127.0.0.1 Port 80</address>
</body></html>
┌──(ajest💋AJESTdeKali)-[~/…/01CTFer/01 - web 入门/01 - 举足轻重的信息搜集/02 - 粗心的小李]
└─$
https://github.com/lijiejie/GitHack.git
https://github.com/denny0223/scrabble.git
SVN 泄露
HG 泄露
DS_Store 泄露
https://github.com/lijiejie/ds_store_exp.git
其他敏感信息
HTML 注释
github
phpinfo()
phpinfo.php
l.php
readme.md
物理路径
账密泄露
密码会在Cookie 中
默认账密在新闻中
账密在HTML 注释中
密码策略
入职清单里的默认账密
2.3 扫描技术
在渗透测试的过程中,为了节省时间和人力,通常采用手工和工具相结合的方式。使用工具,就是将一些机械性的操作自动化实现,用以提高渗透测试的效率。例如,寻找内网10.9.67.0/24 所有在线主机,如果一个一个去ping 来测试主机是否存活(在线),显然是不合适的。
扫描技术主要包括:
- 资产扫描(发现、整理)
- 敏感路径扫描
- 漏洞扫描
2.3.1 基础知识
常见端口号
远程连接服务端口
端口号 | 服务 | 风险 |
---|---|---|
22 | SSH 远程连接 | 弱口令爆破、SSH 隧道(内网代理转发)、文件传输 |
23 | Telnet 远程连接 | 弱口令爆破、嗅探 |
3389 | RDP 远程连接 | 弱口令爆破、Shift 后门 |
5900 | VNC | 弱口令爆破 |
Web 应用服务端口
端口号 | 服务 | 风险 |
---|---|---|
80|443|8080 | 常见Web 服务端口 | Web 漏洞攻击、服务组件漏洞 |
7001|7002 | Weblogic 管理控制台 | 反序列化、弱口令爆破 |
8080|8089 | Jboos/Resin/Jetty/Jenkins | 反序列化、弱口令爆破 |
9090 | WebSphere 控制台 | 反序列化、弱口令爆破 |
4848 | GlassFish 控制台 | 弱口令爆破 |
1352 | Lotus Domino 邮件服务 | 弱口令爆破、信息泄露 |
10000 | Webmin-Web 控制面板 | 弱口令爆破 |
数据库服务端口
端口号 | 服务 | 风险 |
---|---|---|
3306 | MySQL | 注入、提权、弱口令爆破 |
1433 | MSSQL | 弱口令爆破、注入、提权 |
1521 | Oracle DB | 弱口令爆破、注入、提权、TNS 漏洞 |
5432 | PostgreSQL | 弱口令爆破、注入、提权 |
27017/27018 | MongoDB | 未授权访问、弱口令爆破 |
6379 | Redis | 未授权访问、弱口令爆破 |
5000 | SysBase/DB2 | 未授权访问、弱口令爆破、注入 |
邮件服务端口
端口号 | 服务 | 风险 |
---|---|---|
25 | SMTP | 邮件伪造 |
110 | POP3 协议 | 破解 |
143 | IMAP 协议 | 破解 |
网络协议端口号
端口号 | 服务 | 风险 |
---|---|---|
53 | DNS | 子域名爆破、DNS 劫持、域传送 |
67/68 | DHCP 服务 | 地址池耗尽、DHCP 欺骗 |
161 | SNMP 协议 | 收集目标内网信息、弱口令爆破 |
特殊服务端口
端口号 | 服务 | 风险 |
---|---|---|
2181 | Zookeeper 服务 | |
8069 | Zabbix 服务 | 远程执行、SQL 注入 |
9200/9300 | Elasticsearch | |
11211 | Memchache 服务 | |
512/513/514 | Linux Rexec 服务 | |
873 | Rsysnc 服务 | |
3690 | SVN 服务 | |
50000 | SAP Management Console |
TCP 包头格式
标志位(0 或1) | 名称 | 含义 |
---|---|---|
URG | 紧急指针 | 数据以“插队”方式,送到上层。 |
ACK | 确认位 | 收到数据或请求后响应时发送ACK。 |
PSH | 推送 | 将数据推送给上层。 |
RST | 重置连接 | 重置连接|断开连接 |
SYN | 同步位 | 请求建立连接 |
FIN | 请求结束 | 关闭连接 |
三次握手
建立连接
A -> B:我想跟你聊天。 (SYN = 1)
B -> A:收到!我也想跟你聊天。 (ACK=1,SYN=1)
A -> B:收到,我们开始聊天吧。 (ACK = 1)
四次挥手
关闭连接
A -> B:我们可以结束聊天了。 (FIN=1,ACK=1)
B -> A:好的! (ACK=1)
B -> A:我也要结束聊天了 (FIN=1,ACK=1)
A -> B:好的! (ACK=1)
wireshark 简单使用
注意事项:
- 选择一块网卡
- 数据包的过滤
http && tcp.port == 80 and ip.addr ==10.10.10.1
Nmap
nmap 被誉为“扫描器之王”:免费,跨平台,速度快。
参数速查
重要常用参数 | 含义 |
---|---|
-sP | ping 扫描(不进行端口扫描) |
-P0 | 无ping 扫描 |
-p | 指定端口扫描 |
-sT | TCP 全连接扫描 |
-sS | SYN 半连接扫描 |
-sF | FIN 扫描 |
-sN | Null 扫描 |
-sX | Xmas 扫描 |
-O | 测探目标主机版本 |
-sV | 显示服务的详细版本 |
-sC | 等价于--script=default使用默认类别的(漏洞)脚本进行扫描,可更换其他类别。 |
-A | 全面扫描 |
-oN | 将扫描结果保存成txt 格式 |
-oX | 将扫描结果保存成xml 格式 |
-T1,-T2,-T3,-T4,-T5 | 扫描速度 |
nmap 的扫描过程:
- 扫描主机是否在线
- 进行端口扫描,TOP 1000。
2.3.2 主机发现
主机发现就是确定主机是否存活:
- 网段内存活的IP 地址
- 根据MAC 地址找到IP 地址
ping 扫描
只进行Ping 测试,不进行端口扫描。
┌──(ajest💋AJESTdeKali)-[~]
└─$ sudo nmap 10.4.7.0/24 -sP
Starting Nmap 7.91 ( https://nmap.org ) at 2021-10-13 03:24 UTC
Nmap scan report for bogon (10.4.7.132)
Host is up (0.00027s latency).
MAC Address: 00:0C:29:74:CB:30 (VMware)
Nmap scan report for bogon (10.4.7.254)
Host is up (0.000052s latency).
MAC Address: 00:50:56:E3:95:FC (VMware)
Nmap scan report for bogon (10.4.7.1)
Host is up.
Nmap done: 256 IP addresses (3 hosts up) scanned in 23.04 seconds
┌──(ajest💋AJESTdeKali)-[~]
└─$
其他扫描方式
Ping 扫描方式 | 命令 | 注 |
---|---|---|
TCP SYN Ping | -PSSYN=1 | |
TCP ACK Ping | -PA | |
UDP Ping | -PU | |
ICMP Ping Types | -PE-PP-PM | |
ARP Ping | sudo nmap -PR -sP 10.10.10.0/24 |
2.3.3 端口扫描
端口扫描就是寻找存活主机所开放的端口,并且确定端口上所运行的服务。甚至可以更进一步确定目标主机操作系统类型以及更加详细的信息。
需要明确的问题:
- 哪些端口开放
- 端口上所运行的服务
端口状态
端口状态一共有六种:
端口状态 | 说明 | 原因 |
---|---|---|
Open | 开放 | |
Closed | 关闭 | |
Filtered | 过滤 | 数据包超时 |
Unfiltered | ||
Open|Filtered | ||
Closed|Filtered |
简单的扫描
简单的扫描:
┌──(ajest💋AJESTdeKali)-[~]
└─$ sudo nmap 10.4.7.132 130 ⨯
Starting Nmap 7.91 ( https://nmap.org ) at 2021-10-13 03:32 UTC
Nmap scan report for localhost (10.4.7.132)
Host is up (0.0012s latency).
Not shown: 997 closed ports
PORT STATE SERVICE
22/tcp open ssh
80/tcp open http
111/tcp open rpcbind
MAC Address: 00:0C:29:74:CB:30 (VMware)
Nmap done: 1 IP address (1 host up) scanned in 9.39 seconds
┌──(ajest💋AJESTdeKali)-[~]
└─$
说明:
- 不指定端口的情况下,会进行端口扫描
- 默认扫描TOP 1000 端口号
端口扫描
指定端口:
nmap 10.10.10.31 -p 80
nmap 10.10.10.31 -p 80,3306,3389
nmap 10.10.10.31 -p 1-100
nmap 10.10.10.31 -p 1-100,3306,3389
nmap 10.10.10.31 -p 1-65535
nmap 10.10.10.31 -p-
端口扫描的方式:
端口扫描方式 | 参数 | 原理 | 优缺点 |
---|---|---|---|
TCP 全链接扫描 | -sT | Nmap 发送一个SYN = 1: 如果目标回ACK=1 ,SYN=1 ,则Nmap 回ACK = 1,此时就会建立完整的三次握手连接,Nmap 判断该端口开放。 如果目标直接回RST=1 ,Nmap 判断该端口关闭。 | 准确留下大量的、密集的日志记录。 |
SYN 半连接扫描 | -sS | Nmap 发送一个SYN = 1: 如果目标直接回ACK=1,SYN=1,Nmap 判断该端口开放,并主动重置连接。 如果目标直接回RST = 1 ,Nmap 判断该端口关闭。 | 快速没有TCP 全连接扫描准确,需要root 权限。 |
其他端口扫描方式:
- FIN 扫描:
-sF
- Null 扫描:
-sN
- Xmas 扫描:
-sX
- UDP 扫描:
-sU
- TCP ACK 扫描:
-sA
- TCP 窗口扫描:
-sW
其他扫描方式
其他扫描方式 | 命令 |
---|---|
获取目标操作系统类型(不是很准确) | sudo nmap -O 192.168.16.113 -p 80 |
获取服务详细版本 | sudo nmap 192.168.16.113 -p 80 -sV |
全面扫描 | sudo nmap -A 192.168.16.113 -p- |
保存结果 | sudo nmap -A 192.168.16.113 -p- -oN 113.A |
终极命令
┌──(ajest💋AJESTdeKali)-[~]
└─$ sudo nmap -Pn -A -sS -p- -sC -T4 10.4.7.132 -oN 132.namp
Host discovery disabled (-Pn). All addresses will be marked 'up' and scan times will be slower.
Starting Nmap 7.91 ( https://nmap.org ) at 2021-10-13 03:51 UTC
Nmap scan report for localhost (10.4.7.132)
Host is up (0.00030s latency).
Not shown: 65531 closed ports
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 6.0p1 Debian 4+deb7u7 (protocol 2.0)
| ssh-hostkey:
| 1024 c4:d6:59:e6:77:4c:22:7a:96:16:60:67:8b:42:48:8f (DSA)
| 2048 11:82:fe:53:4e:dc:5b:32:7f:44:64:82:75:7d:d0:a0 (RSA)
|_ 256 3d:aa:98:5c:87:af:ea:84:b8:23:68:8d:b9:05:5f:d8 (ECDSA)
80/tcp open http Apache httpd 2.2.22 ((Debian))
|_http-generator: Drupal 7 (http://drupal.org)
| http-robots.txt: 36 disallowed entries (15 shown)
| /includes/ /misc/ /modules/ /profiles/ /scripts/
| /themes/ /CHANGELOG.txt /cron.php /INSTALL.mysql.txt
| /INSTALL.pgsql.txt /INSTALL.sqlite.txt /install.php /INSTALL.txt
|_/LICENSE.txt /MAINTAINERS.txt
|_http-server-header: Apache/2.2.22 (Debian)
|_http-title: Welcome to Drupal Site | Drupal Site
111/tcp open rpcbind 2-4 (RPC #100000)
| rpcinfo:
| program version port/proto service
| 100000 2,3,4 111/tcp rpcbind
| 100000 2,3,4 111/udp rpcbind
| 100000 3,4 111/tcp6 rpcbind
| 100000 3,4 111/udp6 rpcbind
| 100024 1 40536/udp6 status
| 100024 1 45864/tcp6 status
| 100024 1 46684/udp status
|_ 100024 1 53867/tcp status
53867/tcp open status 1 (RPC #100024)
MAC Address: 00:0C:29:74:CB:30 (VMware)
Device type: general purpose
Running: Linux 3.X
OS CPE: cpe:/o:linux:linux_kernel:3
OS details: Linux 3.2 - 3.16
Network Distance: 1 hop
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
TRACEROUTE
HOP RTT ADDRESS
1 0.30 ms localhost (10.4.7.132)
OS and Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 25.06 seconds
┌──(ajest💋AJESTdeKali)-[~]
└─$
2.4 敏感路径扫描
主要利用字典扫描网站下的敏感目录和文件。工具不重要,字典比较重要。
2.4.1 通用扫描器
御剑
windows 下工具,界面简洁,操作简单,一般适用于国内网站用。
典型案例:
dirb
字典比较丰富,可以递归方式扫描目录结构国外网站用
用法
dirb http://url/directory/ (Simple Test)
dirb http://url/ -X .html (Test files with '.html' extension)
dirb http://url/ /usr/share/dirb/wordlists/vulns/apache.txt (Test with apache.txt wordlist)
dirb https://secure_url/ (Simple Test with SSL)
案例:
- B2R:BILLU_b0x ./dirb http://10.10.10.129 ./wordlists/big.txt
dirsearch
标签
工具名 | 标签1 | 标签2 |
---|---|---|
dirsearch | 目录遍历 |
获取
https://github.com/maurosoria/dirsearch
使用
参考:https://blog.csdn.net/qq_43936524/article/details/115271837
python3 dirsearch.py -w /to/wordlist -u URL -r
# -r #递归扫描
# -R 3 # 设置递归层数为3
# -w #指定字典
# --proxy 127.0.0.1:30000 # 使用代理
# --proxylist proxyserver.txt # 使用代理集合
# -t 30 #指定线程(不宜过大)
# -m POST --data "username=admin" # 使用post请求
# -e php,heml,js # 指定文件扩展名
# --subdirs # 指定网站子目录
其他扫描器
goBuster
BBscan
2.4.2 专用扫描器
droopescan
一款基于插件的,主要针对durpal 的扫描器。
安装方法
git clone https://github.com/droope/droopescan.git
cd droopescan
pip install -r requirements.txt
./droopescan scan --help
典型案例:
- B2R:DC-1
./droopescan scan drupal -u http://10.9.65.139
wpscan
专门用来扫描WordPress 的扫描器。
简单使用
wpscan --url http://dc-2
wpscan --url http://dc-2 -e vp,u --plugins-detection mixed
wpscan --url http://dc-2/ -U user.dic -P pass.dic
典型案例:
- B2R:DC-2
joomscan
专门扫描Joomla 的扫描器。
安装
git clone https://github.com/rezasp/joomscan.git
cd joomscan
perl joomscan.pl
用法
perl joomscan.pl -u http://target.com/joomla
案例
- B2R:DC-3
2.5 漏洞扫描
漏洞挖掘中自动发现漏洞。
2.5.1 漏洞扫描的原理
漏洞扫描指的是利用一些工具自动化发现网络上各类主机设备的安全漏洞。这些自动化工具通常被称为漏洞扫描器(一体化安全弱点管控平台)。漏洞扫描通常可以为两类:
- 黑盒扫描
- 白盒扫描
黑盒扫描
黑盒扫描一般就是通过远程识别服务的类型和版本,对服务是否存在漏洞进行判定。在一些比较新的漏洞扫描软件中,应用了一些更高级的技术,比如模拟渗透攻击。
黑盒扫描使用漏洞扫描器。漏洞扫描器一般会附带一个用于识别主机漏洞的特征库,并且会定期进行更新。在漏洞扫描的时候,就是利用特征库里的脚本与目标系统的反馈信息进行匹配,如果能够匹配上,就说明存在某一个漏洞。
白盒扫描
白盒扫描就是在具有主机操作权限的情况下进行漏洞扫描。比如微软的补丁更新程序会定期对操作系统进行扫描,查找存在的安全漏洞,并推送相应的补丁更新。
白盒扫描的结果更加准确,但一般来说白盒扫描所识别出的漏洞不应当作为外部渗透测试的最终数据。因为这些漏洞由于防火墙和各类防护软件的原因很可能无法在外部渗透测试中得到利用。同时,一般情况下是黑客攻击是没有机会获得用户名和口令。
注意事项
漏洞扫描器会对目标造成影响。漏洞扫描器在识别漏洞的过程中,会向目标发送大量的数据包,有时候会导致目标系统拒绝服务或被扫描数据包阻塞,扫描行为也会被对方的入侵检测设备发现。
漏洞扫描器扫描出来的结果通常会有很多误报(扫描结果中发现漏洞,但实际漏洞并不存在,瞎叫唤)或者漏报(漏洞实际存在,但扫描结果中没有体现,眼瞎了)。因此,需要对扫描结果进行人工分析,确定哪些漏洞是真实存在的,这个过程叫做漏洞验证。漏洞验证是渗透测试过程中不可缺少的一步,只有验证漏洞存在的真实性,才能对漏洞进行深度利用。
在漏扫之前,一定要得到客户的许可,并且讲清楚可能造成的风险以及产生不良后果的应急预案。使用漏洞扫描器时,一定要注意规避风险,努力将对系统运行可能造成的风险降到最低。尽量避免业务高峰期。
2.5.2 网络漏洞扫描
通过网络漏洞扫描,全面掌握目标服务器存在的安全漏洞。市面上常用的漏洞扫描器有:
-
本课程所使用的网络漏洞扫描器是OpenVAS ,可以用来识别远程主机、Web 应用存在的各种漏洞。Nessus 曾经是业内开源漏洞扫描器的工业标准。在Nessus 商业化之后,在他的原始项目中分支出来OpenVAS 开源项目。经过多年的发展,OpenVAS 已经成为当前最好的开源漏洞扫描器之一,功能十分强大,甚至可以与一些商业的漏洞扫描器相媲美。OpenVAS 使用NVT 脚本对多种远程系统的安全问题进行检测。
OpenVAS 的安装(GSM)
安装详细过程请参考,[环境搭建]Kali 安装OpenVAS。
OpenVAS 管理
命令 | 解释 |
---|---|
sudo gvm-start | 启动OpenVAS |
sudo gvm-feed-update | 更新漏洞库 |
sudo gvm-stop | 停止OpenVAS |
sudo gvm-check-setup | 检查OpenVAS 状态 |
OpenVAS 的使用
步骤 | 内容 |
---|---|
1. 访问OpenVAS | https://127.0.0.1:9392 admin:123456 |
2. 扫描目标 | Configration -> Targets |
3. 扫描策略 | Configration -> Scanners |
4. 扫描任务 | Scans -> Tasks |
使用扫描策略对目标进行漏洞扫描,扫描速度是很慢的,很快速的done
,说明扫描失败。
2.5.3 Web 漏洞扫描
随着互联网以及云计算等技术的发展,使得政府、银行、企业以及各个组织基本上都有自己的门户网站。Web 应用越来越多,同时Web 应用的攻击成本、难度都比较低,Web 应用成为黑客攻击的主要目标。无论黑客出于什么样的目的,Web 应用所面临的挑战都是很大的。
如何及时、快速发现Web 应用安全漏洞,并且修补安全漏洞,减轻或消除Web 安全风险成为安全行业的重要课题。
小型Web 应用几十上百个页面,大型的Web 应用成千上万个页面。如果靠人工的方式去检测每个页面的安全性,显然,这个成本是难以估计的。所以,需要借助于自动化工具,帮助审计员去发现Web 安全漏洞。这些自动化工具就是Web 漏洞扫描器。
市面上Web 漏洞扫描器有很多,其中以IBM 公司的AppScan 和商业化Web 漏洞扫描器AWVS 为优秀。
AWVS
AWVS 的安装:略
AWVS 的管理
sudo systemctl start|stop|restart|disable acunetix.service
AWVS 的使用
步骤 | 内容 |
---|---|
1. 访问AWVS | https://127.0.0.1:3443 ajest@kali.org:abc123!@# |
2. 创建扫描目标 | Targets -> Add Target |
4. 开启扫描任务 | Scan |
5. 导出扫描报告 | Report |
漏洞验证
http://www.testfire.net/index.jsp?content=../WEB-INF/web.xml
慎重使用
2.5.4 被动式Web 漏洞扫描器
2.5.4.1 被动式漏洞扫描器原理
Browser <--> Proxy <--> Server
2.5.4.2 w13scan
安装
git clone https://github.com/w-digital-scanner/w13scan.git
cd w13scan # 进入git目录
pip3 install -r requirements.txt
cd W13SCAN # 进入源码目录
python3 w13scan.py -h
# 可能遇到的问题
sudo pip3 install --ignore-installed pycparser
sudo apt-get install libxml2-dev libxslt1-dev python-dev
用法
python3 w13scan.py -s 0.0.0.0:6666