Automatically Discovering Vulnerabilities Using the Vulnerability Scanner

1. Modify the run_scanner method in the scanner class.

#!/usr/bin/env python

import requests
import re
from bs4 import BeautifulSoup
from urllib.parse import urljoin class Scanner:
def __init__(self, url, ignore_links):
self.session = requests.Session()
self.target_url = url
self.target_links = []
self.links_to_ignore = ignore_links def extract_links_from(self, url):
response = self.session.get(url)
return re.findall('(?:href=")(.*?)"', response.content.decode(errors='ignore')) def crawl(self, url=None):
if url == None:
url = self.target_url
href_links = self.extract_links_from(url)
for link in href_links:
link = urljoin(url, link) if "#" in link:
link = link.split("#")[0] if self.target_url in link and link not in self.target_links and link not in self.links_to_ignore:
self.target_links.append(link)
print(link)
self.crawl(link) def extract_forms(self, url):
response = self.session.get(url)
parsed_html = BeautifulSoup(response.content, features="lxml")
return parsed_html.findAll("form") def submit_form(self, form, value, url):
action = form.get("action")
post_url = urljoin(url, action)
method = form.get("method") inputs_list = form.findAll("input")
post_data = {}
for input in inputs_list:
input_name = input.get("name")
input_type = input.get("type")
input_value = input.get("value")
if input_type == "text":
input_value = value post_data[input_name] = input_value
if method == "post":
return requests.post(post_url, data=post_data)
return self.session.get(post_url, params=post_data) def run_scanner(self):
for link in self.target_links:
forms = self.extract_forms(link)
for form in forms:
print("[+] Testing form in " + link)
is_vulnerable_to_xss = self.test_xss_in_form(form, link)
if is_vulnerable_to_xss:
print("\n\n[***] XSS discovered in " + link + " in the following from")
print(form) if "=" in link:
print("\n\n[+] Testing " + link)
is_vulnerable_to_xss = self.test_xss_in_link(link)
if is_vulnerable_to_xss:
print("[***] Discovered XSS in " + link) def test_xss_in_link(self, url):
xss_test_script = "<sCript>alert('test')</scriPt>"
url = url.replace("=", "=" + xss_test_script)
response = self.session.get(url)
return xss_test_script in response.content.decode() def test_xss_in_form(self, form, url):
xss_test_script = "<sCript>alert('test')</scriPt>"
response = self.submit_form(form, xss_test_script, url)
return xss_test_script in response.content.decode()

2. Test this new automatically vulnerability scanner.

#!/usr/bin/env python

import scanner

target_url = "http://10.0.0.45/dvwa/"
links_to_ignore = "http://10.0.0.45/dvwa/logout.php" data_dict = {"username": "admin", "password": "password", "Login": "submit"} vuln_scanner = scanner.Scanner(target_url, links_to_ignore)
vuln_scanner.session.post("http://10.0.0.45/dvwa/login.php", data=data_dict) vuln_scanner.crawl()
vuln_scanner.run_scanner()

Following is the full test result.

root@kali:~/PycharmProjects/vulnerability_scanner# python3 vulnerability_scanner.py
http://10.0.0.45/dvwa/dvwa/css/main.css
http://10.0.0.45/dvwa/favicon.ico
http://10.0.0.45/dvwa/instructions.php
http://10.0.0.45/dvwa/setup.php
http://10.0.0.45/dvwa/vulnerabilities/brute/
http://10.0.0.45/dvwa/vulnerabilities/exec/
http://10.0.0.45/dvwa/vulnerabilities/csrf/
http://10.0.0.45/dvwa/vulnerabilities/fi/?page=include.php
http://10.0.0.45/dvwa/vulnerabilities/sqli/
http://10.0.0.45/dvwa/vulnerabilities/sqli_blind/
http://10.0.0.45/dvwa/vulnerabilities/upload/
http://10.0.0.45/dvwa/vulnerabilities/xss_r/
http://10.0.0.45/dvwa/vulnerabilities/xss_s/
http://10.0.0.45/dvwa/security.php
http://10.0.0.45/dvwa/phpinfo.php
http://10.0.0.45/dvwa/phpinfo.php?=PHPB8B5F2A0-3C92-11d3-A3A9-4C7B08C10000
http://10.0.0.45/dvwa/about.php
http://10.0.0.45/dvwa/instructions.php?doc=PHPIDS-license
http://10.0.0.45/dvwa/instructions.php?doc=readme
http://10.0.0.45/dvwa/instructions.php?doc=changelog
http://10.0.0.45/dvwa/instructions.php?doc=copying
http://10.0.0.45/dvwa/security.php?phpids=on
http://10.0.0.45/dvwa/security.php?phpids=off
http://10.0.0.45/dvwa/security.php?test=%22><script>eval(window.name)</script>
http://10.0.0.45/dvwa/ids_log.php
[+] Testing form in http://10.0.0.45/dvwa/setup.php
[+] Testing form in http://10.0.0.45/dvwa/vulnerabilities/brute/
[+] Testing form in http://10.0.0.45/dvwa/vulnerabilities/exec/
[+] Testing form in http://10.0.0.45/dvwa/vulnerabilities/csrf/ [+] Testing http://10.0.0.45/dvwa/vulnerabilities/fi/?page=include.php
[+] Testing form in http://10.0.0.45/dvwa/vulnerabilities/sqli/
[+] Testing form in http://10.0.0.45/dvwa/vulnerabilities/sqli_blind/
[+] Testing form in http://10.0.0.45/dvwa/vulnerabilities/upload/
[+] Testing form in http://10.0.0.45/dvwa/vulnerabilities/xss_r/ [***] XSS discovered in http://10.0.0.45/dvwa/vulnerabilities/xss_r/ in the following from
<form action="#" method="GET" name="XSS">
<p>What's your name?</p>
<input name="name" type="text"/>
<input type="submit" value="Submit"/>
</form>
[+] Testing form in http://10.0.0.45/dvwa/vulnerabilities/xss_s/
[+] Testing form in http://10.0.0.45/dvwa/security.php [+] Testing http://10.0.0.45/dvwa/phpinfo.php?=PHPB8B5F2A0-3C92-11d3-A3A9-4C7B08C10000 [+] Testing http://10.0.0.45/dvwa/instructions.php?doc=PHPIDS-license [+] Testing http://10.0.0.45/dvwa/instructions.php?doc=readme [+] Testing http://10.0.0.45/dvwa/instructions.php?doc=changelog [+] Testing http://10.0.0.45/dvwa/instructions.php?doc=copying
[+] Testing form in http://10.0.0.45/dvwa/security.php?phpids=on [+] Testing http://10.0.0.45/dvwa/security.php?phpids=on
[+] Testing form in http://10.0.0.45/dvwa/security.php?phpids=off [+] Testing http://10.0.0.45/dvwa/security.php?phpids=off
[+] Testing form in http://10.0.0.45/dvwa/security.php?test=%22><script>eval(window.name)</script> [+] Testing http://10.0.0.45/dvwa/security.php?test=%22><script>eval(window.name)</script>
[+] Testing form in http://10.0.0.45/dvwa/ids_log.php

You can add new methods in the scanner class to find more vulnerabilities.

Python Ethical Hacking - VULNERABILITY SCANNER(9)的更多相关文章

  1. Python Ethical Hacking - VULNERABILITY SCANNER(7)

    VULNERABILITY_SCANNER How to discover a vulnerability in a web application? 1. Go into every possibl ...

  2. Python Ethical Hacking - VULNERABILITY SCANNER(4)

    Extracting & Submitting Forms Automatically Target website:http://10.0.0.45/dvwa/vulnerabilities ...

  3. Python Ethical Hacking - VULNERABILITY SCANNER(2)

    VULNERABILITY_SCANNER How to discover a vulnerability in a web application? 1. Go into every possibl ...

  4. Python Ethical Hacking - VULNERABILITY SCANNER(8)

    Implementing Code To Discover XSS in Parameters 1. Watch the URL of the XSS reflected page carefully ...

  5. Python Ethical Hacking - VULNERABILITY SCANNER(3)

    Polish the Python code using sending requests in a session Class Scanner. #!/usr/bin/env python impo ...

  6. Python Ethical Hacking - VULNERABILITY SCANNER(1)

    HTTP REQUESTS BASIC INFORMATION FLOW The user clicks on a link. HTML website generates a request(cli ...

  7. Python Ethical Hacking - VULNERABILITY SCANNER(6)

    EXPLOITATION - XSS VULNS EXPLOITING XSS Run any javascript code. Beef framework can be used to hook ...

  8. Python Ethical Hacking - VULNERABILITY SCANNER(5)

    EXPLOITATION - XSS VULNS XSS - CROSS SITE SCRIPTING VULNS Allow an attacker to inject javascript cod ...

  9. Python Ethical Hacking - BACKDOORS(8)

    Cross-platform hacking All programs we wrote are pure python programs They do not rely on OS-specifi ...

随机推荐

  1. 机器学习——打开集成方法的大门,手把手带你实现AdaBoost模型

    本文始发于个人公众号:TechFlow,原创不易,求个关注 今天是机器学习专题的第25篇文章,我们一起来聊聊AdaBoost. 我们目前为止已经学过了好几个模型,光决策树的生成算法就有三种.但是我们每 ...

  2. mac安装powerdesigner

    安装Wine $brew install wine $wine --version 安装PowerDesigner cd PowerDesigner15.1 wine PowerDesigner15_ ...

  3. Maven的pom文件依赖提示 ojdbc6 Missing artifact,需要手动下载并导入maven参考

    eg: 需要 ojdbc6.jar 的下载地址 https://www.oracle.com/database/technologies/jdbcdriver-ucp-downloads.html c ...

  4. Redis自带压测工具(redis-benchmark.exe)

    redis做压测: 可以用自带的redis-benchmark工具,使用简单 压测命令:redis-benchmark -h 127.0.0.1 -p 6379 -c 50 -n 10000 压测需要 ...

  5. JDK8--02:为什么要使用lambda

    lambda是一个匿名函数,我们可以把lambda理解为一个可以传递的代码(将代码像数据一样传递),可以写出更简洁更灵活的代码.首先看一下原来的匿名内部类实现方式(以比较器为例) //原来的匿名内部类 ...

  6. Layer 3.0

    https://jeesite.gitee.io/front/layer/3.0/layer.layui.com/index.html

  7. 注解式HTTP请求Feign (F版)

    Spring Cloud 为开发者提供了在分布式系统中的一些常用的组件(例如配置管理,服务发现,断路器,智能路由,微代理,控制总线,一次性令牌,全局锁定,决策竞选,分布式会话集群状态).使用Sprin ...

  8. jQurey Validation 1.16

    https://jeesite.gitee.io/front/jquery-validation/1.16/demo/index.html

  9. Swoole 中 TCP、UDP 和长连接、短连接

    TCP 服务 swoole 文档 - TCP 服务 tcp 服务端 <?php // 1. 创建 swoole 默认创建的是一个同步的阻塞tcp服务 $host = "0.0.0.0& ...

  10. node解压压缩包以及压缩图片

    node解压压缩包以及压缩图片 首先保证电脑安装node环境,下载地址:http://nodejs.cn //可以打开一个dos窗口输入node -v进行确认是否安装成功 C:\ > node ...