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. rust 神奇的特质

    pub trait Summary { fn summarize_author(&self) -> String; fn summarize(&self) -> Strin ...

  2. CSV文件导入到数据库中读取数据详解(接着上个帖子)

    一.controller层 二.SERVICE层 @Overridepublic Result importJinjiangAssessResult(MultipartFile file) throw ...

  3. 一小时彻底搞懂RabbitMQ

    windows上面安装rabbitmq-server-3.7.4.exe 首先需要安装otp_win64_20.3.exe 步骤1:安装Erlang RabbitMQ 它依赖于Erlang,需要先安装 ...

  4. elasticsearch中query和filter的区别

    参考博客来自: https://mp.weixin.qq.com/s/tiiveCW3W-oDIgxvlwsmXA?utm_medium=hao.caibaojian.com&utm_sour ...

  5. java 中对hashmap进行排序

    public class HashMapSort { public static void main(String[] args) { HashMap<Integer, Student> ...

  6. 用Creator实现一个擀面的效果

    先上几张效果图 怎么实现的呢? 节点介绍 1是背景图,可以忽略:2 是准备好的面团:3 是擀好的面饼先隐藏:4 是需要绘制的节点:5 是擀面杖. 制作开始 首先在view上挂一个mask,并且设置为模 ...

  7. 什么才是市场急需的前端工程师?要价1.8W,HR不敢还嘴!

    据统计,国外的前端开发人员和后端开发人员比例约1:1,但是在国内比例却在1:3以下, Web前端开发职位人才缺口巨大.前端工程师的发展之路十分有“钱”景. 每天,HR 群都有人在吐槽招不到前端工程师. ...

  8. JasperReport报表中输出Excel时,部分列不显示的问题

    JasperReport开源报表功能强大,是我们WEB系统中做报表开发的一个强有力的工具,上手也比较简单.我碰到的问题是进行报表输出时,在html网页中显示正常,但如果导出为Excel时,部分列不显示 ...

  9. RSS阅读器推荐

    http://www.feeddemon.com/ Windows,Free (完)

  10. node.js/npm升级正确操作(windows和linux均有)

    原文地址:https://www.wjcms.net/archives/nodejsnpm升级正确操作windows和linux均有 今天我们总结一下node.js以及npm升级的正确操作方法. 小编 ...