章节3:外部侦查
目标站点与子域名
目标站点与子域名
在红队行动中,目标站点往往是提供的有限信息之一,例如 raven-med.local,而我们需要从这个点入手。有了目标站点,我们可以进一步枚举其子域名,得到其面向公网的IT资产。考虑到raven-med.local是一个虚构的制造公司,并且该域名尚未被注册,此处我们以SmartBear公司 (https://smartbear.com)作为教学案例。
目标站点
对于目标站点本身,我们也是有诸多内容可以做的。需要提醒的是,在当前阶段无需进行主动侦查,例如使用扫描器对目标站点进行目录爆破等,这至少在我们充分进行了被动侦查之后再做。我们发现,该公司是一家计算机软件开发公司,并且我们从图片中可以看到有多个导航栏,例如产品、解决方案、资源、职业生涯等。这些都值得我们手动浏览一遍。这些对于我们有什么意义呢?例如通过了解产品,我们可以得知该公司的产业线。通过了解职业生涯信息,我们可以了解到该公司目前哪些岗位可能有空缺,以及从岗位描述中提取有效信息等等。
尽管我们没有使用主动扫描器,但我们依旧可以了解到该站点的一些信息,例如使用 shodan 搜索引擎。
此外,我们还可以查询该站点的DNS信息,但需要注意的是,不同的DNS服务器可能返回不同结果。
└─# nslookup smartbear.com
Server: 8.8.8.8
Address: 8.8.8.8#53
Non-authoritative answer:
Name: smartbear.com
Address: 65.8.20.55
Name: smartbear.com
Address: 65.8.20.33
Name: smartbear.com
Address: 65.8.20.8
Name: smartbear.com
Address: 65.8.20.128
(谷歌DNS返回的结果)
PS C:\Users\ntsystem> nslookup smartbear.com
Server: cdns02.comcast.net
Address: 2001:558:feed::2
Non-authoritative answer:
Name: smartbear.com
Addresses: 13.225.223.61
13.225.223.46
13.225.223.4
13.225.223.25
(Comcast运营商返回的结果)
(亚马逊 Route 53 返回的结果)
以及 Whois 查询。
└─# whois smartbear.com
Domain Name: SMARTBEAR.COM
Registry Domain ID: 100038507_DOMAIN_COM-VRSN
Registrar WHOIS Server: whois.godaddy.com
Registrar URL: http://www.godaddy.com
Updated Date: 2022-09-04T07:44:21Z
Creation Date: 2003-07-03T18:16:08Z
Registry Expiry Date: 2025-07-03T18:16:08Z
Registrar: GoDaddy.com, LLC
Registrar IANA ID: 146
Registrar Abuse Contact Email: abuse@godaddy.com
Registrar Abuse Contact Phone: 480-624-2505
Domain Status: clientDeleteProhibited https://icann.org/epp#clientDeleteProhibited
Domain Status: clientRenewProhibited https://icann.org/epp#clientRenewProhibited
Domain Status: clientTransferProhibited https://icann.org/epp#clientTransferProhibited
Domain Status: clientUpdateProhibited https://icann.org/epp#clientUpdateProhibited
Name Server: NS-1416.AWSDNS-49.ORG
Name Server: NS-1701.AWSDNS-20.CO.UK
Name Server: NS-431.AWSDNS-53.COM
Name Server: NS-917.AWSDNS-50.NET
DNSSEC: unsigned
URL of the ICANN Whois Inaccuracy Complaint Form: https://www.icann.org/wicf/
>>> Last update of whois database: 2023-01-06T23:05:28Z <<<
For more information on Whois status codes, please visit https://icann.org/epp
NOTICE: The expiration date displayed in this record is the date the
registrar's sponsorship of the domain name registration in the registry is
currently set to expire. This date does not necessarily reflect the expiration
date of the domain name registrant's agreement with the sponsoring
registrar. Users may consult the sponsoring registrar's Whois database to
view the registrar's reported date of expiration for this registration.
TERMS OF USE: You are not authorized to access or query our Whois
database through the use of electronic processes that are high-volume and
automated except as reasonably necessary to register domain names or
modify existing registrations; the Data in VeriSign Global Registry
Services' ("VeriSign") Whois database is provided by VeriSign for
information purposes only, and to assist persons in obtaining information
about or related to a domain name registration record. VeriSign does not
guarantee its accuracy. By submitting a Whois query, you agree to abide
by the following terms of use: You agree that you may use this Data only
for lawful purposes and that under no circumstances will you use this Data
to: (1) allow, enable, or otherwise support the transmission of mass
unsolicited, commercial advertising or solicitations via e-mail, telephone,
or facsimile; or (2) enable high volume, automated, electronic processes
that apply to VeriSign (or its computer systems). The compilation,
repackaging, dissemination or other use of this Data is expressly
prohibited without the prior written consent of VeriSign. You agree not to
use electronic processes that are automated and high-volume to access or
query the Whois database except as reasonably necessary to register
domain names or modify existing registrations. VeriSign reserves the right
to restrict your access to the Whois database in its sole discretion to ensure
operational stability. VeriSign may restrict or terminate your access to the
Whois database for failure to abide by these terms of use. VeriSign
reserves the right to modify these terms at any time.
The Registry database contains ONLY .COM, .NET, .EDU domains and
Registrars.
Domain Name: SMARTBEAR.COM
Registry Domain ID: 100038507_DOMAIN_COM-VRSN
Registrar WHOIS Server: whois.godaddy.com
Registrar URL: https://www.godaddy.com
Updated Date: 2016-07-04T05:51:05Z
Creation Date: 2003-07-03T13:16:08Z
Registrar Registration Expiration Date: 2025-07-03T13:16:08Z
Registrar: GoDaddy.com, LLC
Registrar IANA ID: 146
Registrar Abuse Contact Email: abuse@godaddy.com
Registrar Abuse Contact Phone: +1.4806242505
Domain Status: clientTransferProhibited https://icann.org/epp#clientTransferProhibited
Domain Status: clientUpdateProhibited https://icann.org/epp#clientUpdateProhibited
Domain Status: clientRenewProhibited https://icann.org/epp#clientRenewProhibited
Domain Status: clientDeleteProhibited https://icann.org/epp#clientDeleteProhibited
Registry Registrant ID: Not Available From Registry
Registrant Name: Registration Private
Registrant Organization: Domains By Proxy, LLC
Registrant Street: DomainsByProxy.com
Registrant Street: 2155 E Warner Rd
Registrant City: Tempe
Registrant State/Province: Arizona
Registrant Postal Code: 85284
Registrant Country: US
Registrant Phone: +1.4806242599
Registrant Phone Ext:
Registrant Fax: +1.4806242598
Registrant Fax Ext:
Registrant Email: Select Contact Domain Holder link at https://www.godaddy.com/whois/results.aspx?domain=SMARTBEAR.COM
Registry Admin ID: Not Available From Registry
Admin Name: Registration Private
Admin Organization: Domains By Proxy, LLC
Admin Street: DomainsByProxy.com
Admin Street: 2155 E Warner Rd
Admin City: Tempe
Admin State/Province: Arizona
Admin Postal Code: 85284
Admin Country: US
Admin Phone: +1.4806242599
Admin Phone Ext:
Admin Fax: +1.4806242598
Admin Fax Ext:
Admin Email: Select Contact Domain Holder link at https://www.godaddy.com/whois/results.aspx?domain=SMARTBEAR.COM
Registry Tech ID: Not Available From Registry
Tech Name: Registration Private
Tech Organization: Domains By Proxy, LLC
Tech Street: DomainsByProxy.com
Tech Street: 2155 E Warner Rd
Tech City: Tempe
Tech State/Province: Arizona
Tech Postal Code: 85284
Tech Country: US
Tech Phone: +1.4806242599
Tech Phone Ext:
Tech Fax: +1.4806242598
Tech Fax Ext:
Tech Email: Select Contact Domain Holder link at https://www.godaddy.com/whois/results.aspx?domain=SMARTBEAR.COM
Name Server: NS-431.AWSDNS-53.COM
Name Server: NS-1701.AWSDNS-20.CO.UK
Name Server: NS-1416.AWSDNS-49.ORG
Name Server: NS-917.AWSDNS-50.NET
DNSSEC: unsigned
URL of the ICANN WHOIS Data Problem Reporting System: http://wdprs.internic.net/
>>> Last update of WHOIS database: 2023-01-06T23:05:44Z <<<
For more information on Whois status codes, please visit https://icann.org/epp
TERMS OF USE: The data contained in this registrar's Whois database, while believed by the
registrar to be reliable, is provided "as is" with no guarantee or warranties regarding its
accuracy. This information is provided for the sole purpose of assisting you in obtaining
information about domain name registration records. Any use of this data for any other purpose
is expressly forbidden without the prior written permission of this registrar. By submitting
an inquiry, you agree to these terms and limitations of warranty. In particular, you agree not
to use this data to allow, enable, or otherwise support the dissemination or collection of this
data, in part or in its entirety, for any purpose, such as transmission by e-mail, telephone,
postal mail, facsimile or other means of mass unsolicited, commercial advertising or solicitations
of any kind, including spam. You further agree not to use this data to enable high volume, automated
or robotic electronic processes designed to collect or compile this data for any purpose, including
mining this data for your own personal or commercial purposes. Failure to comply with these terms
may result in termination of access to the Whois database. These terms may be subject to modification
子域名
除了提供的站点外,我们还可以去枚举目标的子域名。因为子域名的数量往往比较庞大,对于企业来说,他们自己可能都不清楚自己有多少子域名,对于那些不常被关照的子域名,往往可能就是最脆弱的地方。对于主域名以及常用的子域名,公司往往即使更新公开服务的版本、修复漏洞,对于那些可能被遗忘的,情况则恰恰相反。枚举子域名的方法既有主动搜集,也有被动搜集。主动搜集例如使用字典来爆破枚举,被动搜集则利用了庞大的OSINT信息。接下来笔者来推荐2款子域名枚举的工具。
Sublist3r
这是一款老牌子域名枚举工具,经典且可靠。使用方法也很简单,执行命令sublist3r -d [域名] 即可。如果我们用其来枚举SmartBear公司的子域名,是这样的:
在这些结果中,我们可以找到该公司的VPN域名站点、Staging站点等。
OneForAll
地址:https://github.com/shmilylty/OneForAll
这款国产的工具也是很好用的,使用方法也是很简单。在安装完之后,执行命令 python3 oneforall.py --target [域名] 即可。
└─# python3 oneforall.py --target smartbear.com --fmt json run
OneForAll is a powerful subdomain integration tool
___ _ _
___ ___ ___| _|___ ___ ___| | | {v0.4.5 #dev}
| . | | -_| _| . | _| .'| | |
|___|_|_|___|_| |___|_| |__,|_|_| git.io/fjHT1
OneForAll is under development, please update before each use!
[*] Starting OneForAll @ 2023-01-06 14:58:25
14:58:25,352 [INFOR] utils:523 - Checking dependent environment
14:58:25,353 [INFOR] utils:535 - Checking network environment
14:58:25,519 [INFOR] utils:546 - Checking for the latest version
14:58:25,634 [INFOR] utils:570 - The current version v0.4.5 is already the latest version
14:58:25,635 [INFOR] oneforall:243 - Start running OneForAll
14:58:25,636 [INFOR] oneforall:248 - Got 1 domains
14:58:25,648 [INFOR] wildcard:108 - Detecting smartbear.com use wildcard dns record or not
14:58:25,757 [ALERT] wildcard:123 - The domain smartbear.com disables wildcard
14:58:25,758 [INFOR] collect:44 - Start collecting subdomains of smartbear.com
14:58:25,805 [INFOR] module:63 - QueryMX module took 0.0 seconds found 0 subdomains
14:58:25,830 [INFOR] module:63 - NSECCheck module took 0.1 seconds found 0 subdomains
14:58:25,844 [INFOR] module:63 - QueryNS module took 0.0 seconds found 0 subdomains
14:58:25,846 [INFOR] module:63 - QuerySPF module took 0.0 seconds found 0 subdomains
14:58:25,869 [INFOR] module:63 - QuerySOA module took 0.1 seconds found 0 subdomains
14:58:25,875 [INFOR] module:63 - AXFRCheck module took 0.1 seconds found 0 subdomains
14:58:25,966 [INFOR] module:63 - CertInfo module took 0.2 seconds found 1 subdomains
14:58:25,983 [INFOR] module:63 - SiteDossierQuery module took 0.2 seconds found 11 subdomains
14:58:26,041 [INFOR] module:63 - QueryTXT module took 0.2 seconds found 0 subdomains
14:58:26,090 [ALERT] utils:273 - GET https://transparencyreport.google.com/transparencyreport/api/v3/httpsreport/ct/certsearch?include_expired=true&include_subdomains=true&domain=smartbear.com 404 - Not Found 1611
14:58:26,090 [INFOR] module:63 - GoogleQuery module took 0.3 seconds found 0 subdomains
14:58:26,096 [ALERT] utils:273 - GET https://fullhunt.io/api/v1/domain/smartbear.com/subdomains 401 - Unauthorized 50
14:58:26,096 [ALERT] utils:282 - {'message': 'Unauthorized access', 'success': False}
14:58:26,097 [INFOR] module:63 - FullHuntAPIQuery module took 0.3 seconds found 0 subdomains
14:58:26,099 [ALERT] utils:273 - GET https://jldc.me/anubis/subdomains/smartbear.com 300 - Multiple Choices 2
14:58:26,099 [ALERT] utils:282 - []
14:58:26,102 [INFOR] module:63 - AnubisQuery module took 0.3 seconds found 0 subdomains
14:58:26,122 [ALERT] utils:273 - GET https://www.virustotal.com/ui/domains/smartbear.com/subdomains?limit=40&cursor= 429 - Too Many Requests 181
14:58:26,122 [ALERT] utils:282 - {'error': {'message': 'Please re-send request with a valid reCAPTCHA response in the "x-recaptcha-response" header', 'code': 'RecaptchaRequiredError'}}
14:58:26,125 [INFOR] module:63 - VirusTotalQuery module took 0.3 seconds found 0 subdomains
14:58:26,154 [ALERT] utils:273 - GET https://api.threatminer.org/v2/domain.php?q=smartbear.com&rt=5 500 - Internal Server Error 0
14:58:26,155 [INFOR] module:63 - ThreatMinerQuery module took 0.3 seconds found 0 subdomains
14:58:26,231 [INFOR] module:63 - RiddlerQuery module took 0.4 seconds found 11 subdomains
14:58:26,234 [INFOR] module:63 - RapidDNSQuery module took 0.4 seconds found 144 subdomains
14:58:26,412 [INFOR] module:63 - HackerTargetQuery module took 0.6 seconds found 59 subdomains
14:58:26,438 [INFOR] module:63 - CSPCheck module took 0.7 seconds found 0 subdomains
14:58:26,837 [INFOR] module:63 - IP138Query module took 1.0 seconds found 5 subdomains
14:58:27,004 [ALERT] utils:273 - GET https://searchdns.netcraft.com/?restriction=site+contains&position=limited&host=%2A.smartbear.com&from=1 403 - Forbidden 9000
14:58:27,005 [INFOR] module:63 - NetCraftQuery module took 1.2 seconds found 0 subdomains
14:58:27,195 [INFOR] module:63 - SitemapCheck module took 1.4 seconds found 1 subdomains
14:58:27,268 [INFOR] module:63 - DNSDumpsterQuery module took 1.5 seconds found 58 subdomains
14:58:27,479 [INFOR] module:63 - BingSearch module took 1.6 seconds found 1 subdomains
14:58:27,568 [INFOR] module:63 - CertSpotterQuery module took 1.8 seconds found 68 subdomains
14:58:27,684 [INFOR] module:63 - SogouSearch module took 1.8 seconds found 1 subdomains
14:58:27,998 [INFOR] module:63 - ChinazQuery module took 2.2 seconds found 6 subdomains
14:58:28,049 [INFOR] module:63 - RobotsCheck module took 2.3 seconds found 0 subdomains
14:58:28,124 [INFOR] module:63 - CrossDomainCheck module took 2.3 seconds found 0 subdomains
14:58:28,380 [INFOR] module:63 - GiteeSearch module took 2.5 seconds found 0 subdomains
14:58:28,642 [INFOR] module:63 - CeBaiduQuery module took 2.8 seconds found 0 subdomains
14:58:28,749 [INFOR] module:63 - YahooSearch module took 2.9 seconds found 3 subdomains
14:58:28,965 [ALERT] utils:273 - GET https://api.sublist3r.com/search.php?domain=smartbear.com 523 - 7140
14:58:28,967 [INFOR] module:63 - Sublist3rQuery module took 3.2 seconds found 0 subdomains
14:58:29,026 [INFOR] module:63 - BaiduSearch module took 3.2 seconds found 0 subdomains
14:58:29,066 [INFOR] module:63 - SoSearch module took 3.2 seconds found 1 subdomains
14:58:29,302 [INFOR] module:63 - AlienVaultQuery module took 3.5 seconds found 56 subdomains
14:58:29,347 [INFOR] module:63 - AskSearch module took 3.5 seconds found 2 subdomains
14:58:30,856 [INFOR] module:63 - CrtshQuery module took 5.1 seconds found 155 subdomains
14:58:32,591 [INFOR] module:63 - YandexSearch module took 6.7 seconds found 0 subdomains
14:58:34,317 [INFOR] module:63 - RobtexQuery module took 8.5 seconds found 3 subdomains
14:58:38,971 [INFOR] module:63 - GoogleSearch module took 13.1 seconds found 5 subdomains
14:58:39,419 [ERROR] module:159 - HTTPSConnectionPool(host='www.dnsscan.cn', port=443): Read timed out. (read timeout=13)
14:58:39,419 [INFOR] module:63 - QianXunQuery module took 13.6 seconds found 0 subdomains
14:58:39,678 [INFOR] module:63 - BruteSRV module took 0.3 seconds found 0 subdomains
14:58:39,683 [INFOR] brute:461 - Start running Brute module
14:58:39,684 [INFOR] brute:411 - Blasting smartbear.com
14:58:39,684 [INFOR] brute:119 - Querying NS records of smartbear.com
14:58:39,714 [INFOR] brute:129 - smartbear.com's authoritative name server is ['ns-1416.awsdns-49.org.', 'ns-1701.awsdns-20.co.uk.', 'ns-431.awsdns-53.com.', 'ns-917.awsdns-50.net.']
14:58:39,714 [INFOR] brute:99 - Querying A record from authoritative name server: ['ns-1416.awsdns-49.org.', 'ns-1701.awsdns-20.co.uk.', 'ns-431.awsdns-53.com.', 'ns-917.awsdns-50.net.']
14:58:39,823 [INFOR] brute:114 - Authoritative name server A record result: ['205.251.197.136', '205.251.198.165', '205.251.193.175', '205.251.195.149']
14:58:39,824 [INFOR] brute:348 - Generating dictionary for smartbear.com
14:58:39,913 [ALERT] utils:686 - Please check whether pirat.smartbear.com is correct or not
14:58:39,916 [INFOR] brute:366 - Dictionary size: 95247
14:58:39,957 [INFOR] brute:442 - Running massdns to brute subdomains
14:59:16,330 [INFOR] brute:197 - Counting IP cname appear times
14:59:16,332 [INFOR] brute:238 - Processing result
14:59:16,335 [ALERT] brute:452 - Brute module takes 36.7 seconds, found 71 subdomains of smartbear.com
14:59:16,341 [INFOR] brute:492 - Finished Brute module to brute smartbear.com
14:59:16,354 [INFOR] resolve:143 - Start resolving subdomains of smartbear.com
14:59:16,375 [INFOR] resolve:166 - Running massdns to resolve subdomains
14:59:19,421 [INFOR] resolve:104 - Processing resolved results
14:59:19,437 [INFOR] resolve:172 - Finished resolve subdomains of smartbear.com
14:59:19,438 [INFOR] resolve:61 - Saving resolved results
14:59:19,452 [INFOR] request:258 - Start requesting subdomains of smartbear.com
14:59:19,453 [INFOR] request:39 - Port range:[80, 443]
14:59:19,456 [INFOR] request:56 - Generating request urls
14:59:19,456 [INFOR] request:217 - Requesting urls in bulk
Request Progress: 319it [01:20, 3.94it/s]
15:00:40,386 [INFOR] request:264 - Found that smartbear.com has 197 alive subdomains
15:00:40,387 [INFOR] finder:23 - Start Finder module
0it [00:00, ?it/s]15:00:40,664 [INFOR] request:217 - Requesting urls in bulk
Request Progress: 148it [00:04, 34.65it/s]
0it [00:00, ?it/s]15:00:45,140 [INFOR] module:63 - Finder module took 4.8 seconds found 0 subdomains
15:00:45,140 [INFOR] module:63 - Finder module took 4.8 seconds found 0 subdomains
15:00:45,141 [INFOR] resolve:143 - Start resolving subdomains of smartbear.com
15:00:45,141 [INFOR] request:258 - Start requesting subdomains of smartbear.com
15:00:45,142 [INFOR] request:39 - Port range:[80, 443]
15:00:45,142 [INFOR] request:56 - Generating request urls
15:00:45,142 [INFOR] request:217 - Requesting urls in bulk
Request Progress: 1it [00:00, 294.67it/s]
15:00:45,147 [INFOR] request:264 - Found that smartbear.com has 197 alive subdomains
15:00:45,148 [INFOR] altdns:203 - Start altdns module
15:00:45,620 [INFOR] altdns:210 - The altdns module generated 167 new subdomains
15:00:45,621 [INFOR] resolve:143 - Start resolving subdomains of smartbear.com
15:00:45,664 [INFOR] resolve:166 - Running massdns to resolve subdomains
15:00:47,222 [INFOR] resolve:104 - Processing resolved results
15:00:47,240 [INFOR] resolve:172 - Finished resolve subdomains of smartbear.com
15:00:47,251 [INFOR] request:258 - Start requesting subdomains of smartbear.com
15:00:47,251 [INFOR] request:39 - Port range:[80, 443]
0it [00:00, ?it/s]15:00:47,253 [INFOR] request:56 - Generating request urls
15:00:47,254 [INFOR] request:217 - Requesting urls in bulk
Request Progress: 97it [01:23, 1.16it/s]
15:02:10,733 [INFOR] request:264 - Found that smartbear.com has 219 alive subdomains
15:02:12,255 [ALERT] export:64 - The subdomain result for smartbear.com: /opt/OneForAll/results/smartbear.com.json
15:02:12,257 [INFOR] oneforall:257 - Finished OneForAll
最终,枚举结果会自动保存到 csv 或者 json文件之中。
└─# cat results/smartbear.com.json
[{"id": 137, "alive": 1, "request": 1, "resolve": 1, "url": "http://academy.smartbear.com", "subdomain": "academy.smartbear.com", "level": 1, "cname": "lu-elb-prod02-ssl-1936357760.eu-west-1.elb.amazonaws.com,lu-elb-prod02-ssl-1936357760.eu-west-1.elb.amazonaws.com,lu-elb-prod02-ssl-1936357760.eu-west-1.elb.amazonaws.com", "ip": "54.155.72.54,34.240.41.94,18.202.131.230", "public": "1,1,1", "cdn": 1, "port": 80, "status": 200, "reason": "OK", "title": "SmartBear Academy", "banner": "nginx", "cidr": "54.155.0.0/16,34.240.0.0/13,18.202.0.0/15", "asn": "AS16509,AS16509,AS16509", "org": "AMAZON-02,AMAZON-02,AMAZON-02", "addr": "\u7f8e\u56fd\u5f17\u5409\u5c3c\u4e9a\u963f\u4ec0\u672c,\u7231\u5c14\u5170Dublin,\u7231\u5c14\u5170Dublin", "isp": "\u4e9a\u9a6c\u900a,\u4e9a\u9a6c\u900a,\u4e9a\u9a6c\u900a", "source": "RapidDNSQuery"}, {"id": 138, "alive": 1, "request": 1, "resolve": 1, "url": "https://academy.smartbear.com", "subdomain": "academy.smartbear.com", "level": 1, "cname": "lu-elb-prod02-ssl-1936357760.eu-west-1.elb.amazonaws.com,lu-elb-prod02-ssl-1936357760.eu-west-1.elb.amazonaws.com,lu-elb-prod02-ssl-1936357760.eu-west-1.elb.amazonaws.com", "ip": "54.155.72.54,34.240.41.94,18.202.131.230", "public": "1,1,1", "cdn": 1, "port": 443, "status": 200, "reason": "OK", "title": "SmartBear Academy", "banner": "nginx", "cidr": "54.155.0.0/16,34.240.0.0/13,18.202.0.0/15", "asn": "AS16509,AS16509,AS16509", "org": "AMAZON-02,AMAZON-02,AMAZON-02", "addr": "\u7f8e\u56fd\u5f17\u5409\u5c3c\u4e9a\u963f\u4ec0\u672c,\u7231\u5c14\u5170Dublin,\u7231\u5c14\u5170Dublin", "isp": "\u4e9a\u9a6c\u900a,\u4e9a\u9a6c\u900a,\u4e9a\u9a6c\u900a", "source": "RapidDNSQuery"}, {"id": 265, "alive": 0, "request": 0, "resolve": 1, "url": "http://accounts.ftr.smartbear.c
公开服务
公开服务
公开服务,顾名思义,即目标对互联网开放的端口上运行的服务。几乎所有公司都拥有Web服务,我们在上一篇也看到了。除此之外,邮件服务器、VPN门户等往往也是作为公开的服务,虽然很常见,但绝对值得我们一看。如果运气好,就能遇到可以利用的漏洞或者不当配置,例如开启Open Relay的邮件服务器、可能存在绕过认证的VPN登陆界面。
此外,除了上述提到的Web服务、邮件服务器、VPN门户等公开服务,也有一些服务是由于内部人员疏忽而开放的。例如对外开放3389端口,也就是RDP服务的工作站。虽然说暴露 3389 不代表一定会被入侵者们成功利用,但绝对是增加了不必要的攻击面。在Shodan搜索引擎上查看面向公网开放3389端口的服务器,结果多达103W。
而我们案例中的 SmartBear 也将 RDP 暴露在了公网
除了RDP,如果将SMB、WinRM、VNC等、以及一些内部使用的App暴露在互联网上,也都是很危险的。但对于攻击者来说,则是很大的机会。
而在我们的 Lab 中,已知有这些公开服务
raven-medicine.org
Port 21: vsftpd 3.0.3
把 FTP 暴露在公网,是比较危险的。
Port 80: Apache 2.4.41
我们可以看到,这是一个搭建在 Apache 2.4.41 的自定义 Web 应用,是企业的首页。
Port 3000: Node.js
这是一个 Node.js 应用,使用了 Express 框架,看起来是一个内部聊天应用,不应当暴露于公网上,而是在局域网内部访问。
Port 8090 未成功识别
这是 Confluence 应用,主要用于企业内部的 wiki 和文档管理。不应当被暴露在公网,而是通过企业内部网络访问。
white-bird.org
Port 8090 IIS 10.0
这是一个 .Net 的自定义 Web 应用,使用的是 .Net 框架,看起来无须认证即可进行一些操作,这是很危险的。
OSINT信息搜集
OSINT信息搜集
其实在前两篇,我们已经在做一些 OSINT 的信息搜集了,因此笔者刻意放缓了一些节奏,将重点和更有趣的部分在这里讲述。开源情报 (OSINT) 收集是红队、社会工程学攻击和物理渗透的早期关键行动。 OSINT 包括任何公开可用的内容,并且可以在不引起蓝队过度关注的情况下访问。许多人认为使用搜索引擎就足以找到他们所需要的数据,但实际上大多数互联网都没有被搜索引擎索引。 OSINT 的其他常用来源的示例包括:
公司网站
产品信息
组织信息
联系信息
社交媒体
员工关系
员工信息
招聘信息
公司基础设施的信息
职位空缺
公共数据库
dehashed.com:历史泄露数据的数据库
Wayback Machine:来自公司网站的历史信息
ICANN:IP地址、域名注册等信息
Google Dorks:使用先进的 Google 搜索引擎技术来提取信息
Shodan:Shodan 是一个互联网连接设备的搜索引擎
接下来,我们以几个具体的例子来展示 OSINT 信息能给我们带来哪些有用的情报,以下这些还不是一个穷尽的可能,我们用作抛砖引玉。
我们从官网注意到,该公司的IT部门主管是CISO,即首席安全官。虽然这不代表该公司的安全程度就真的滴水不漏,但有一定程度的安全控制措施、流程、策略被部署是可以预见的.
查看公司的 Contact Info, 即联系信息, 我们找到了一些地址, 电话, 邮箱等. 在网站上列举联系方式并不是一个错误配置, 几乎所有公司都会在门户房展上展示, 但同时也给我们提供了一定的信息, 以及社会工程学攻击的入口点.
查看公司的 Career 板块, IT部门有个开放岗位 Atlassian Administrator,说明该公司有在使用 Atlassian 的产品,例如 JIRA、Confluence,并且从职责描述中也得到了证实。因此, 如果我们能找到面向公网开放的 Atlassian 应用, 可以用近期的 0 day漏洞尝试攻击, 例如 CVE-2022-26134 Confluence RCE: https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2022-26134.
此外, 我们还能获得这些信息:
Operating System: Windows 10, Linux, Mac OS X
Active Directory: Microsoft Active Directory
Production Software: Tomcat, Jenkins
Email: Outlook
Video Conferencing: Zoom, Polycom
Office Suite: MS Office, OneDrive, Office 365
Issue and Project Tracking: Atlassian Jira
Wiki: Atlanssian Confluence
我们在泄漏库网站 https://dehashed.com 上搜集 smartbear.com 的域名,得到了一些员工的详细个人信息甚至密码, 虽然大概率这些密码已经得到了修改, 但运气好的话, 也许会有少数并没有及时被修改, 甚至在后来得到了重用.
我们通过一两个员工邮箱的案例, 我们得知该公司对于员工邮箱的命名格式为 [名].[姓]@smartbear.com, 或者是 [部门]@smartbear.com, 以及 [产品]@smartbear.com. 因此, 在得知员工列表后, 我们几乎可以列举出所有员工的工作邮箱. 此外, 我们可以在领英上查看特定员工的职位以及所在地区 (办公室), 从而推断出员工关系, 例如他的上级, 下属, 同事. 针对人事的攻击, 高价值目标能带来更多的价值, 例如部门领导, 总监, 执行官等, 以下是一些实例:
Head of G&A Department: Bryce Chicoyne - bryce.chiocyne@smartbear.com
Head of Product & Dev Department : Dan Faulkner - dan.faulkner@smartbear.com
Head of Sales Department : Lou DiFruscio - lou.difruscio@smartbear.com
Head of Marketing Department: Cynthia Gumbert - cynthia.gumbert@smartbear.com
Head of HR Department: Veronica Curran - veronicac.urran@smartbear.com
Head of IT Department: Christine Whichard - christine.whichard@smartbear.com
Head of Legal Department: Lance Levy - lance.levy@smartbear.com
Director, Product Security: Matthew Runkle - matthew.runkle@smartbear.com
Director of Information Security: Adam FairhallView - adam.fairhallView@smartbear.com
Senior Director Of Engineering: Patrick Day - patrick.dayv@smartbear.com
工具 theHarvester 也可以用于寻找目标域名的有趣信息, 例如员工邮件地址, 网址, 存活IP和主机等.
公开的 IP 或主机显着扩大了目标公司的攻击面, 如果部署在这些 IP/主机上的任何服务或应用程序被利用,攻击者就有可能在内部网络中获得一个立足点。以下, 是 Smartbear 公司的一些存活主机或 IP.
* 10.110.1.67,10.110.4.134,10.110.2.49,10.110.3.129
* 10.110.3.129,10.110.1.67,10.110.4.134,10.110.2.49
* 10.110.4.134,10.110.1.67,10.110.3.129,10.110.2.49
* 10.50.22.103,10.50.21.64
* 10.81.21.164,10.81.22.83
* 10.81.22.174,10.81.21.136
* 10.92.10.229,10.92.30.136
* 104.130.174.23
* 104.16.242.229,104.16.243.229
* 104.17.71.206,104.17.70.206,104.17.72.206,104.17.74.206,104.17.73.206
* 104.17.72.206,104.17.73.206,104.17.70.206,104.17.71.206,104.17.74.206
* 104.44.133.165
* 104.44.134.177
* ............
* 104.47.59.138,104.47.55.138
* 54.208.93.159,34.196.253.122
* 54.209.140.167,18.211.47.137,3.224.145.90,54.82.45.42
* 54.237.159.170,52.7.153.190
* 64.78.230.178
* 65.8.20.112,65.8.20.45,65.8.20.85,65.8.20.13
* 78.31.213.98
* 79.142.246.130
* 79.142.246.131
* 79.142.246.132
* 87.244.55.186
* 89.107.198.52
* 99.84.191.126,99.84.191.57,99.84.191.23,99.84.191.43
* 99.84.191.23,99.84.191.57,99.84.191.126,99.84.191.43
通过枚举这些存活的 IP, 我们找到了一批应用的登陆页面. 对于攻击者来说, 他们会尝试使用弱口令, 默认凭证, 甚至暴力破解攻击来获得访问. 并且, 如果这些登陆门户没有实施 SSO 的话, 攻击者可以克隆网站并钓鱼获得员工的凭证,.
https://my.smartbear.com/login.asp?returnUrl=/index.asp
https://accounts.smartbear.com/accounts/login?next=/
https://app1.qacomplete.smartbear.com/Common/login.html?redirect=app%3DagSP
https://app2.qacomplete.smartbear.com/Common/login.html?redirect=app%3DagSP
https://login.slm.manage.smartbear.com/
https://se-sydney-vpn.smartbear.com/?src=connect
https://vpn-de.smartbear.com
https://vpn-dr.smartbear.com
https://vpn-fl.smartbear.com
https://vpn-ire.smartbear.com
https://vpn-mem.smartbear.com
https://vpn-mum.smartbear.com
https://vpn-swe.smartbear.com
https://vpn-uk.smartbear.com
https://vpn.smartbear.com
https://vpn-bos.smartbear.com
............
https://id.smartbear.com/login
https://smartbear-cc.force.com/portal/SupPortalLogin
https://staging.smartbear.com/
此外, 我们可以用 Google Dorking 技术找到了 SmartBear 的 2 个可以展开的文件夹. 虽然可以展开的文件夹不总是能带来安全风险的, 但绝对不是一个建议的配置.
https://eclipse.smartbear.com/8.0/8_5_8502/
https://eclipse.smartbear.com/8.0/8_4_8406/
https://eclipse.smartbear.com/8.0/8_5_8502/
根据 https://jira-app.ze.smartbear.com/ 站点, 我们得知 SmartBear 在 Azure 上部署服务, 即我们得知了 Azure 是 SmartBear 所采用的云设施之一.
我们还在 Shodan 上发现了 SmartBear 的一台开启了 RDP 的服务器, 从证书来看, 是 QA 部门的. 对公网开启 RDP 协议, 会导致攻击者进行密码攻击, 以及使用历史 RDP 的 CVE 漏洞, 例如 BlueKeep 进行攻击.
在 Fofa 上, 我们还找到了 SmartBear 公司暴露在公网上的 RabbitMQ 服务:
然后, 我们研究一下 SmartBear 的母公司, 子公司, 以及合作伙伴. 我们可以用这个网站 https://www.crunchbase.com/organization/smart-bear-software 来查询目标的子母公司.
经过汇总, 如下:
Subsidiaries
Pactflow
Bugsnug
TM4J
Swagger
Bitbar
Cucumber
Zephyr
Hiptest
CrossbrowserTesting.com
lucierna
AlertSite
SoapUI
Francisco Partners
Vista Equity Partners
Insight Partners
我们通过查询历史新闻, 证实了我们的发现:
从官网 https://smartbear.com/partners/find-a-partner/, 我们得知了 SmartBear 的合作伙伴:
另外, 开源工具 SpiderFoot 能够使用爬虫帮我们爬到海量的OSINT信息。
地址:https://github.com/smicallef/spiderfoot
以上是个抛砖引玉,我们既要擅长手动搜集OSINT信息,也可以适当借助好用的工具协助我们提高效率。有了这些丰富的信息后,可以对目标有个更深的了解,更是为后续的社会工程学攻击做准备。
子域名接管
子域名接管漏洞可以被攻击者用来创建可信的钓鱼方案、恶意软件分发、CSP 绕过、读取父域 Cookie 等。对于企业来说,子域名有更高的可能性直接绕过邮件过滤器,因此钓鱼攻击的成功率大大增加。
子域名接管意思是攻击者对目标域的一个子域有了完全的控制权,通常在以下情况出现
1:在 DNS 记录中,一个子域 (www.azuresky.live) 的 CNAME 所指向另一个域 (dlersec.azureedge.net),但是 dlersec.azureedge.net 在某个时间点过期了并且重新开放给任何人注册。此时,www.azuresky.live 的这条CNAME尚未移除。
2:在 DNS 记录中,一个子域 ( blog.raven-medicine.com) 的 CNAME 所指向一个虚拟主机,比如可以是某个主机提供商上部署的(blog.bestwebsites.net),但这个时候这个虚拟主机还没有被部署或者已经移除了。那么攻击者可以在该平台注册名为 blog 的虚拟主机
一个简单的验证方法如下:
┌──(root㉿kali)-[~/Desktop]
└─# host -t cname app-cloud.dev.example.com
app-cloud.dev.example.com is an alias for app-cloud-dev-eus.azurewebsites.net.
┌──(root㉿kali)-[~/Desktop]
└─# host app-cloud-dev-eus.azurewebsites.net
Host app-cloud-dev-eus.azurewebsites.net not found: 3(NXDOMAIN)
根据此验证方法,我们写一个脚本来批量验证子域名是否可以被接管。
import sys
import dns.resolver
if len(sys.argv)!=2:
print("Usage: python3 subdomain.py target.txt")
file=sys.argv[1]
target=[]
vuln=[]
with open(file,"r") as fp:
for line in fp:
try:
target.append(line.strip())
except:
#print(line)
print('Error')
print("Read "+str(len(target))+" subdomains")
for sub in target:
try:
cname = str(dns.resolver.resolve(sub, 'cname')[0])
cname=cname[0:len(cname)-1]
try:
host=dns.resolver.resolve(cname, 'A')
except:
print(sub+" is vulnerable to subdomain takeover")
vuln.append(sub)
pass
except:
pass
print("\n\nThe following subdomains are vulnerable to subdomain take over")
for i in vuln:
print(i)
但该脚本的判断可能受 DNS 服务器、网络连通性 (获取 CNAME 超时)影响。此外,根据各主机平台的策略,实际接管难度也有所不同。我们可以使用更加专业的工具 https://github.com/EdOverflow/can-i-take-over-xyz 来枚举可接管的子域名。
邮件服务器安全
SMTP 简单邮件传输协议,正如名称所言,简单的实施,无需身份认证,而且发件人地址是可以自己指定的,因此该缺陷可以被利用与伪造和模仿发件人。考虑邮件是社会工程学攻击的重要载体,因此现代企业也配置了如下这些加固邮件服务安全性的措施。从企业角度,他们可以更高效地防范邮件钓鱼攻击、垃圾邮件等,对于网络安全中的进攻方,则增添了社会工程学攻击的难度,我们一起来了解一下。
MX 记录
MX 即 Mail Exchange邮件交换,MX 记录用于标识负责代表域名接收电子邮件的邮件服务器。当有人向与特定域关联的电子邮件地址发送电子邮件时,该电子邮件将被传送到该域的 MX 记录中标识的邮件服务器之一。 MX 记录指定每个邮件服务器的优先级和主机名。 优先级值表示尝试邮件服务器的顺序,值越低表示优先级越高。 如果第一个服务器不可用或无法访问,则尝试下一个具有更高优先级值的服务器,依此类推。MX 记录是电子邮件传递的重要组成部分,有助于确保将邮件可靠地传递给目标收件人。
我们可以通过以下命令来查询目标域的 MX 记录:
┌──(root㉿kali)-[/opt/spoofcheck]
└─# dig MX qq.com +short
20 mx2.qq.com.
30 mx1.qq.com.
10 mx3.qq.com.
┌──(root㉿kali)-[/opt/spoofcheck]
└─# host -t MX qq.com
qq.com mail is handled by 20 mx2.qq.com.
qq.com mail is handled by 30 mx1.qq.com.
qq.com mail is handled by 10 mx3.qq.com.
SPF 记录
SPF 记录,全称为 Sender Policy Framework 发送方策略框架,域名持有者通过使用 DNS 记录来授权哪些邮件服务器可以代替该域名来发送邮件。当该域名收到一份邮件的时候,接收端服务器会检查发件人域的 SPF 记录,以查看发送服务器是否有被授权为该域发送电子邮件。 如果发送服务器未经授权 (IP 地址不匹配),电子邮件可能会被拒绝或标记为垃圾邮件。设置 SPF 不仅可以防止自己的域名被第三方恶意伪造,还有助于维持良好的域名名声 (没有设置 SPF 的话,该域名会被广泛用于伪造和垃圾邮件,久而久之接收方会认为该域名被用于恶意用途,尽管只是被恶意第三方所利用的)。例如,我们可以用该在线网站伪造发件人发送邮件:https://emkei.cz/。
一个比较实际的情景可以是这样的,你在一家公司 A_Company 的 Career 界面申请了一个岗位,提交了所有资料后,你的邮箱收到了一封 noreply@acompany.com 的自动回复邮件,这份邮件实际上是由某职位申请平台 B_Company 发送的。因为 A_Company 与 B_Company 有合作关系,因此 A_Company 的 SPF 记录授权了 B_Company 以域 @acompany 发送邮件给申请者。
一个有效的 SPF 记录可以是这样的:
v=spf1 ip4:209.225.8.0/24 ip4:209.225.28.0/24 ip4:24.196.48.42/32 ip4:24.217.29.16/32 ip4:24.176.92.28/32 ip4:142.136.234.128/27 ip4:142.136.235.128/27 include:et._spf.pardot.com include:spf-c.usa.striata.com include:everbridge.net ~all
这些指定的域名、网段、IP 被授权代替该域名发送邮件,除此之外的所有都 “软拒绝”。对于软拒绝的策略,不同的邮件系统有不同的反应,有的不接受、有的标记、有的接受。
我们可以在在线网站 https://mxtoolbox.com/SuperTool.aspx 上查询目标域名的 SPF 记录并获得解析。
一些常见的配置失误以及绕过
1:SPF 记录的语法错误,导致整个 SPF 记录失效。
例如:v=spf1 ip4:113.110.223.0/24 183.110.226.0/24 183.110.255.0/24 59.110.132.0/24 -all
只有第一个网段有 ip4 的前缀,导致后续的语法错误,让整个记录失效。
2:授权的范围过大,导致有漏网之鱼。例如,SPF 记录授权了一个较大的网段,该网段中任意邮件服务器被入侵了,那么从而实现 SPF 绕过。
3:邮件服务器不支持 SPF 校验
4:内网 DNS 无法解析
5:公司内部的发件人伪造
我们可以通过以下命令来读取目标域的 SPF 记录 (如果配置的话)
┌──(root㉿kali)-[/opt/spoofcheck]
└─# host -t txt xx.com | grep spf
qq.com descriptive text "v=spf1 include:spf.mail.xx.com -all"
┌──(root㉿kali)-[/opt/spoofcheck]
└─# dig TXT +short xx.com
"v=spf1 include:spf.mail.xx.com -all"
DKIM
全称 Domain Keys Identified Mail 域名密钥识别邮件标准。DKIM 是另一种基于 DNS 的身份验证协议,它允许域所有者使用私钥对外发电子邮件进行签名。然后,接收服务器可以使用域的 DNS TXT 记录中发布的公钥来验证签名。 如果签名有效,则可以保证电子邮件在传输过程中未被篡改。由于非对称加密,DKIM 更加难以伪造,除非私钥被攻击者获得。简而言之,DKIM 从垃圾邮件、邮件伪造、钓鱼攻击中保护了邮箱发送者和接受者,是一种邮件认证的形式。
DMARC 记录
全称为 Domain-based Message Authentication, Reporting, and Conformance 基于域名的邮件认证、报告和一致性标准。DMARC 是一个建立在 SPF 和 DKIM 基础上的策略框架,为域所有者提供一种方法来指定接收服务器应如何处理未通过身份验证检查 (SPF 和 DKIM) 的电子邮件。DMARC 策略可以指示接收服务器通过但标记、拒绝、或隔离电子邮件。
例如该 Dmarc 案例:v=DMARC1; p=quarantine; sp=none; aspf=r; adkim=r; pct=100; rua=mailto:dmarcAR@abc.com;
对于任何 (100%) 的邮件消息,如果 SPF 和 DKIM 都没有通过 (这里采取了 relaxed 选项,即部分匹配即可,任何有效的子域名都被接受),那么对其进行隔离。如果是来自子域的消息,不采取行动。DMARC 日志会被发送到 dmarcAR@abc.com 邮箱。因为 DMARC 有有关子域名的设置,因此 DMARC 的配置正确与否,影响着主域名以及子域名。
我们可以通过如下命令来查询目标域的 DMARC 记录
┌──(root㉿kali)-[/opt/spoofcheck]
└─# dig _dmarc.xx.com TXT +short
"v=DMARC1; p=quarantine; rua=mailto:mailauth-reports@xx.com"
┌──(root㉿kali)-[/opt/spoofcheck]
└─# host -t txt _dmarc.xx.com | grep DMARC
_dmarc.xx.com descriptive text "v=DMARC1; p=quarantine; rua=mailto:mailauth-reports@xx.com"
进攻方
SPF,DKIM,和 DMARC 3者共同强化了邮件安全。而对于攻击者而言,将我们的钓鱼邮件服务器配置这 3 项,也会让我们的邮件服务器看起来更加可信,从而减少被目标邮件服务器和网关拦截的概率。
社会工程学信息搜集
社会工程学信息搜集
在之前,我们已经搜集到了一些很有料的信息,那我们来看看如何利用这些搜集到的信息进行社会工程学攻击。我们能想到的场景之一,是借用求职者的身份与公司的HR进行联系,包括但不局限于 LinkedIn 在线私信、电话联系、邮件联系。尤其是邮件联系,我们介绍过现代邮件系统的安全机制了,对于非内部的邮件地址都会进行 banner 标记,甚至比较明显的诈骗邮件、广告邮件直接会被拦截,收件者根本没有机会看到。
我们在之前看到,SmartBear公司具有HE部门,我们可以在LinkedIn上搜索该公司IT部门的员工,虽然不一定所有员工都在用LinkedIn。另外,在OSINT信息收集阶段我们得知该公司的邮件地址方案是 [名].[姓]@smartbear.com,例如 Lindsey.Beaudoin@smartbear.com.
并且我们在之前看到,该公司IT部门有一些岗位是开放的,我们可以声称自己是应聘IT岗位的人员,因为IT人员对公司的基础设施更为了解,如果在询问目标公司的基础设施相关信息的时候,引起怀疑的概率要低一些。例如这么一个语境:“HR你好,作为一个IT系统管理员,我对各家厂商的VPN的配置有一定经验。我可否知道贵公司的VPN供应商?”。如果得到了回答,那么可以查看有关厂商VPN产品的漏洞以及配置不当。
此外,需要注意的是,与HR进行交互,一般分为两种。一种是在求职页面直接填写个人信息、上传简历等。并且我们看到该公司是使用Office工具组的,而允许上传的文件包含word格式,doc格式是支持插入宏的。因此我们可以准备一个插入了宏并且能躲避AV/EDR的doc文档并且上传。但是,通过这种方式上传,对于攻击者来说是没有“回显”的。攻击者甚至不知道HR是否查看了该文件。现在的企业大都有简历过滤系统,会根据关键字进行自动的第一轮筛选。
而另外一种交互方式,则是亲自与HR交谈,例如在LinkedIn上与HR在线交谈、发送邮件表达自己求职意愿并且附上带有宏的doc文档。如果HR回复了,那么很大可能他们将会亲自打开该文档。虽然大家都知道宏是个危险的功能,但因为其拥有一定的用途,在企业里并非完全被禁用。但假如即将打开doc文件的HR的默认设置是禁用宏,那么我们需要额外的话术去诱导该HR先开启宏功能。
那么在技术上如何实现呢?鉴于该章侧重于信息搜集,因此具体攻击手法在下一章讲解。
案例分析 Charter Communication 电信公司
有了先前的知识,我们在这一小节进行一个案例分析,对 Charter Communication 电信公司进行 OSINT 侦查。这一节虽然是案例分析,但并不是把这章节之前的内容生搬硬套就行,而是需要灵活新增侦查手段,创造性地搜集信息。
既然是 OSINT,那么意味着我们与目标的交互需要是被动的,包括但不局限于使用搜索引擎搜索有关目标公司的信息、查看社交媒体、whois 查询等。为了降低一点难度,我们可以与目标进行正常的交互,例如浏览网站。但是以下是不能进行的:nmap扫描、漏洞扫描、对公司员工进行社会工程学攻击、利用漏洞等。
我们目前只有目标企业的名称,即 Charter Communication Inc.。首先,我们要确定 Charter 公司在公网的网段,这个我们可以通过查询 Charter 公司的 ASN 编号。Charter 这样的大型企业,可能拥有多个 ASN (自治域) 编号,并且每个 ASN 编号都有大量的公共网段。至于ASN,是一个全球唯一标识符,它定义了一组一个或多个 IP 前缀,这些前缀由一个或多个网络运营商运行,这些网络运营商维护一个明确定义的路由策略。这些 IP 前缀组称为自治系统。ASN 允许自治系统与其他自治系统交换路由信息,世界各地的网络运营商都需要自治系统编号来控制其网络内的路由以及与其他网络运营商交换路由信息。
我们可以通过一些在线工具根据企业域名或者企业名称来查询 ASN 编号,例如 https://bgp.he.net/search?search%5Bsearch%5D=charter+communication&commit=Search。
但是,单个来源获取到的 ASN 编号肯定是不全甚至不准确的,我们需要从多个来源搜集相对完整的 ASN 编号。此外,有的 ASN 编号也可能不再活跃,即没有网段与之关联。这里,我提供几个有效的 ASN号码:AS12271,AS11427,AS20115,AS33363。
然后,我们根据 ASN 编号得到尽可能完成的网段。比如,我们可以通过在线网站查询 AS12271 的网段 https://asnlookup.com/asn/AS12271/。同样的,我们需要集中多个来源的数据以尽可能减少遗漏,同时,可能一些网站因为更新不及时等原因,会有一些不再属于该 ASN 编号的网段,我们需要注意。在合法的红队行动或者渗透测试中,如果我们确定了错误的范围,那么在后续的过程中可能无意众对非范围内的目标进行攻击,即未授权的行动。所以,相比添加错了的目标,宁愿遗漏一些。当然,最好也不要遗漏。
除了过时的数据,我们还需要注意区别出客户资产!!!考虑到 Charter 是一家很大的电信企业,在有些服务上也充当着运营商或者服务提供商的身份,因此有些资产可能是客户的,并非 Charter 自身的。如何准确区分这些资产,是难以三言两语总结的。我们简单看 2 个例子作为对比。下图是 shodan 搜索的一个结果,我们看到该结果的主机名是 mail.wonsbackgroundchecks.com。
查询一下 wonsbackgroundchecks.com 的 whois 信息,我们没有发现有关 charter.com 的字样,那么有可能是 charter.com 客户的资产。
其网站主页揭露了该公司是从事背景调查的,与电信关系不大,因此,作为子公司或母公司的概率也很小。
查看一下 Charter 的子母公司,也确实没有发现其踪迹。我们发现 Spectrum 是 Charter 收购的一家公司。
那么下图所示的结果,因为其主机名在 spectrum 域之下,很有可能是属于 Charter 的资产了。
查询 spectrum.com 的 whois 信息,也能确认这一点。总之,对于资产的确认,我们务必要十分小心,不然很容易进行未授权操作。
得到了 ASN 以及对应的网段后,尽管我们不可能搜集完整 (甚至企业自己都理不清全部资产),接下来可以搜集顶级域名 TLD 了。顶级域名例如 charter.com,spectrum.com。我们可以优先从字母公司入手,另外一个很快捷的方法是逆向 whois 查询,即我们根据 whois 信息中的某个信息进行逆向查询,有哪些域名包含了特定的关键字。我们可以尝试的逆向查询内容可以是邮箱 (charter.com)、域名服务器 (ns1.charter.com)。便捷的在线网站有 https://viewdns.info/reversewhois/?q=charter.com,https://hackertarget.com/find-shared-dns-servers 等。
我们也是得到了海量的输出,因为 Charter 也是服务供应商,这是可以预期的,我们需要手动筛选。并且在上图中我们可以看到,即便是 charter.com 主站,也有一些变种,例如 charter-business.com 。当我们层层筛选后,可以将 TLD 列表输入给各种子域名枚举工具,这类工具我们之前已经介绍过一些了,这里我再介绍一款 ReconFTW (https://github.com/six2dez/reconftw)。这款工具十分强大,但具体强大之处请自行参考文档以及探索,这里不占用篇幅了。
接下来,是本节最核心的内容,是之前几节难以覆盖到的内容,请系好安全带,让我带你们从 OSINT 到 shell。当搜索引擎与特定的查询相结合的时候,可以辅助我们找到有趣的资产,比较知名的是 Google Dorking。除此之外,还有 Shodan dorking,Github Dorking 等。这些平台的具体侧重点有所不同或略有不同,但背后的宗旨都是一样的,利用现成的语法,组合成特定且精确的搜索语句。比如,在 Github 上,我们可以通过 Dorking 找到包含有明文凭证硬编码的文件,Google 上,我们可以找到开放目录站点,在 Shodan 上,我们可以找到 RDP 暴露于公网的主机。虽然这些 Dorking 都有一定的用途且都很有趣,为了能对我们的红队行动帮助最大,我们主要借助于 Shodan,Fofa,Quake 这 3 款搜索引擎。这 3 款搜素引擎功能是一致的,在具体能力上各有高低,此外,并且还存在着其他同类型的搜索引擎。
简述一下这 3 款搜索引擎的特点和优缺点
Shodan
Fofa
1000 元即可终身会员
能识别大量的应用和组件
有限的 banner 信息
如果使用 API,一次最多返回 100 条
只要频率控制在 1 秒 2 条请求以内,那就没有额度可言
Quake
1000 元即可终身会员
能识别大量的应用和组件
有限的 banner 信息
有搜索次数和请求次数的额度,但一般够用
在探讨各个搜索引擎的语法以及特别的搜索语句之前,我们需要知道我们搜索的宗旨,我们想要得到的是其他搜索引擎难以提供的 quick win。
1: 高风险 CVE 漏洞
未认证 RCE
目录遍历
任意文件读写
更多
2: 配置不当的服务
可读可写 SMB 共享目录
不需要认证的 rsync
不需要认证的 VNC
不需要认证的 X11
开放目录
暴露在公网的域主机
暴露在公网的域控制器
默认凭证
更多
3: 信息搜集
NetBIOS-SSN
SMB
RDP
MSSQL
WinRM
SNMP
更多
4: 企业中常被利用的应用和组件
Outlook
Tomcat
Jenkins
Fastjson
Log4j
Spring
ManageEngine Products
Weblogic
Vmware Products
Struts2
Gitlab
Nexus
JFog
更多
考虑到我们有特定的目标,即 Charter,那么我们每次搜索的时候都需要把目标带上。幸运的是,这 3 款搜索引擎都帮我们整理好了 Organization 以及 ASN。考虑到 Charter 有多个活跃 ASN,那么我们就以组织名为准好了 (Fofa 对于一些 ASN 识别的结果与其他 2 款搜索引擎不一致,因此组织名也有所不同)。时刻记得判断目标结果是否为 Charter 自身的资产。
接下来,我们就可以构造特定的搜索语句了,我个人建议从精确、quick-win的开始,即找到大概率能提供给我们 shell 的资产。这样的案例可以为具有永恒之蓝 MS17-010 漏洞的主机,目前只有 shodan 能精确查找到,语句为 org:"Charter Communications Inc" vuln:ms17-010。
shodan 找到了 16 台具备条件的资产,但是从下图中的结果的域名来看,有可能是 Charter 客户的,我们往下翻一翻。
我们看到这个结果,域名是 spectrum 的,很有可能是 Charter 自身的资产,即在范围内。但请别过于激动,我们不应当实际进行攻击。并且攻击也可能因为其他原因导致失败,例如安全产品的部署、网络防火墙、补丁和系统加固等。
另外一个例子是 VsFTPd 2.3.4 后门 RCE。在 3 款不同搜索引擎下,语句是这样的:
FOFA: org="CHARTER-20115" && banner="vsFTPd 2.3.4"
Shodan: org:"Charter Communications Inc" vsFTPd 2.3.4
Quake: org: "Charter Communications Inc" AND response:"vsFTPd 2.3.4"
同样的,不是所有结果都是我们合法范围内的,需要甄别。我们可以确认该漏洞 (https://www.exploit-db.com/exploits/49757) 利用难度很低,并不需要提供凭证即可执行远程代码。唯一需要注意的是,如果后续我们在利用的时候,目标主机会被开启一个端口,然后我们正向连接该端口。实际利用的成功与否,需要考虑到防火墙的因素。
在刚才,我们通过 2 个精确定位受 CVE 漏洞影响的资产的案例告诉大家,善于使用这些搜索引擎可以给我们后续的边界突破带来 quick win。更多的案例,我不在此一一枚举,重点是我们需要总结出受特定漏洞影响的资产的特征,可以是版本号,可以是 banner 或者响应中的独特字符串。
接下来,我们讨论能同样给我们 quick-win 的配置不当的网络服务或应用,它们通常并不是漏洞,而是配置不当,例如没有设置认证的 VNC 服务,可以让我们不提供凭证的情况下访问目标的桌面,变相给我们提供了 shell,甚至是更高级的 shell。我们先以传统 VNC 服务器举例,这里的话,想要精确定位到未开启认证的 VNC 服务器,我们需要依赖于 shodan。在之前,Quake 也支持精确定位,但可能由于法律法规和隐私的原因,关闭了。
shodan 语句为 org:"Charter Communications Inc" "authentication disabled" "RFB"。我们得到了 15 个结果,并且前几个结果看起来大都是范围内的。
我们连接其中一个,发现确实可以访问到对方的远程桌面 (我没有进行任何操作并且迅速退出)。
并且该主机所在的域为 Charter 注册,那么大概率是范围内的。
不过,也有一些不太成功的案例,例如目标是 IoT/OT 系统,或者目标主机设置了锁屏,因此即便我们能看到目标的 GUI,但是需要凭证才能进入系统 (但只要被解锁之后我们进入,就没有障碍了)。
(这些命令并非我留下的)
我们再来看 noVnc web 应用 (https://github.com/novnc/noVNC),即在服务器上部署 noVnc 应用后,可以通过浏览器访问。3 款搜索引擎都能进行精确查找:
FOFA: org="CHARTER-20115" && server="WebSockify Python" && title="Directory listing for /"
Shodan: org:"Charter Communications Inc" http.title:"Directory listing" "Server: WebSockify Python"
Quake: org:"Charter Communications Inc" and server: "WebSockify Python" and title: "Directory listing for /"
你们也许发现了我额外地给查询语句添加了开放目录的限制条件。原因在于,我们无法根据响应信息确认noVnc是否开启认证,而如果目标主机的使用者不小心开放了目录,那么说明其不是很具备安全意识或者粗心,更有可能不设置认证。这是一个从行为与心理层面进行的推断,如果因为范围限制地很狭窄导致搜索结果过少,我们也可以适当放宽,例如删去开放目录的限制。如下图所示,如果配置了开放目录,我们会能访问该页面,反之则直接进入连接的页面,然后可能面临认证。
不出意料,粗心到配置了开放目录的人确实没有设置认证,我们可以直接访问到他的桌面。
有些应用是被强制全屏的,如果想要获得代码执行,可能需要使用 kiosk breakout 的技术。虽然这很有趣,但请记住我们不能进行任何未授权攻击尝试。
以及在有的服务器上,我们能执行代码,但 noVnc 是运行在容器内的,获得代码执行的意义也不是特别大。
除了 VNC,类似的协议还有 X11,请自行探索利用方法。
目前为止,我介绍了几种通过 OSINT 就能大概率获得 shell 的方法与思路。接下来,我们也许不能直接获得代码执行,但能很大程度丰富我们掌握的知识和情报,例如未认证情况下访问目标的 SMB 共享目录、FTP 服务器等。
我们来查看一下有哪些资产是允许 FTP 匿名访问的。FTP 服务器中可能存储着敏感文件,尤其是如果包含明文凭证、知识产权、VPN侧写文件等。3 个搜索引擎可以分别用如下语句查询:
FOFA: org="CHARTER-20115" && banner="User logged in"
Shodan: org:"Charter Communications Inc" port:21 "User logged in"
Quake: org:"Charter Communications Inc" and response:"User logged in" AND service: "ftp"
我们看到,还是有不少 FTP 服务器允许匿名登陆的,选择其中一个进行访问尝试,虽然看起来没有什么特别有趣的文件,但考虑到样本较多,我们也许总能找到敏感的文件。
类似的,我们还可以访问部分共享目录没有设置认证的 SMB 服务。实际上,SMB 服务本就不该被暴露在公网上。查询没有设置访问的 SMB 服务器,FOFA 无法做到精确查询,因此展示另外 2 个搜索引擎的语句
Shodan: org:"Charter Communications Inc" "authentication disabled" port:445
Quake: org:"Charter Communications Inc" and response:"authentication disabled" and port:445
选择其中一个,尝试访问,我们发现该目标有多个开放的共享目录。如果我们运气好,也可能在其中能得到敏感文件。
例如该资产,我们甚至能访问用户的 C 盘文件,十分危险。
接下来,我们寻找在公网上开放了 RDP 服务的主机,,虽然 RDP 的认证是强制开启的,但是我们可以搜集到目标主机的一些信息。3 款搜索引擎的语句分别如下:
FOFA: org="CHARTER-20115" && protocol="rdp"
Shodan: org:"Charter Communications Inc" "Remote Desktop Protocol"
Quake: org:"Charter Communications Inc" and service:"rdp"
如下图所示,RDP的响应中,我们能够提取到一些主机信息,虽然该目标显然可能是 Charter 客户的资产。我们还可以搜索 MSSQL,NBT-SSN,WinRM 等服务来得到有关主机、域的一些信息。
最后,我们来搜索一些企业中常用的应用和组件。考虑到这些应用在历年几乎都有 RCE 漏洞。虽然有些漏洞并不新了,但是考虑到企业对于安全的重视程度、合规性、流程等因素,想要从所有应用与组件的 RCE 中幸存下来是有难度的,因为我们想要突破边界,1 个 shell 就够了,而企业却要补丁所有资产上运行的应用与组件。现代企业所用的应用与组件颇多,比较典型的有 Confluence,Outlook,Vmware 产品,JBoss,Weblogic,Tomcat 等。例如,要搜索 Outlook OWA 应用,我们可以用以下的查询语句:
FOFA: org="CHARTER-20115" && title="outlook"
Shodan: org:"Charter Communications Inc" http.title:"Outlook"
Quake: org:"Charter Communications Inc" and title:"Outlook"
我们可以看到有不少的实例,但是请注意甄别客户资产。在确定了范围内的资产后,我们可以用 nuclei (https://github.com/projectdiscovery/nuclei) 或 vulmap (https://github.com/zhzyker/vulmap) 等批量扫描工具进行漏洞验证。但是我们只是对 Charter 进行 OSINT,所以请不要实际对 Charter 做漏洞扫描。并且大面积的漏洞扫描是不太隐蔽的,因此在实际的红队行动中,需要在另一台 VPS 主机上进行扫描工作,以免暴露出我们的大本营。
下图是我之前对其他地区资产进行的扫描与概念验证,严格来说依旧属于未授权,请大家不要效仿。
第3章课后作业
请寻找一家大型企业 (千人以及更大规模),通过 OSINT 以及正常访问等手段,搜集以下信息。请不要使用 nmap,漏洞扫描器等。
练习
1:企业的联系方式、地理位置
2:企业的产品、合作伙伴
3:企业的社交媒体、员工社交媒体、员工联系方式 (邮箱、手机号、地址)
4:企业网段
5:企业子域名
6:企业的子公司以及母公司,得到它们的主站点 (顶级域名)
7:除了 HTTP/HTTPS 外的对公网开放的网络服务,例如 RDP,FTP,SSH等。在这些中,有没有大概率存在严重漏洞的?
8:根据职位信息等来源,了解目标公司的基础设施信息以及所用应用 (例如 AD,Azure,Confluence,Jira,Office 365 等)。
9:类似于7,有没有暴露给公网的常见应用,例如 Tomcat,Nexus,Outlook 等。
拓展
1:参考 Charter Communication 案例,写一个脚本,输入目标企业名称或者 ASN,使用 shodan、fofa 等工具进行全自动查询。查询可以是预设或硬编码的。为了完成该题目,可能需要至少一个网络空间测绘平台的 APIKEY。
2:仅仅使用 OSINT 以及正常流量的浏览,你是否能找到目标企业能让你拿到 shell 的资产?