-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdemo_4.py
executable file
·77 lines (59 loc) · 2.17 KB
/
demo_4.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env python3
"""Command-line interface to perform several security tests."""
import json
import subprocess
import warnings
from lxml import html
import nmap3
import requests
import whois
import typer
from Wappalyzer import Wappalyzer, WebPage
app = typer.Typer()
# Workaround for https://github.com/chorsley/python-Wappalyzer/issues/40
warnings.simplefilter("ignore")
def get_page(url: str, proxy: str = None):
"""Perform a GET request and return response object."""
proxies = None
if proxy:
proxies = {"http": f"http://{proxy}"}
response = requests.get(url, proxies=proxies)
return response
@app.command()
def analyze(url: str, proxy: str = None):
"""Analyze page and display framework and versions."""
response = get_page(url, proxy)
webpage = WebPage.new_from_response(response)
wappalyzer = Wappalyzer.latest()
results = wappalyzer.analyze_with_versions_and_categories(webpage)
print(json.dumps(results, indent=2))
@app.command()
def discover(url: str, wordlist: str = "/dev/null"):
"""Brute-force file and directory names."""
subprocess.run(["gobuster", "-u", url, "-w", wordlist], check=True)
@app.command()
def forms(url: str, proxy: str = None):
"""Find a form in a page, and print form details."""
response = get_page(url, proxy)
tree = html.fromstring(response.content)
for form in tree.xpath("//form"):
print(f"Found a {form.method} form for {form.action}")
for field in form.fields:
print(f"Contains input field {field}")
@app.command()
def domain(name: str):
"""Print the domain registrant's name and organization."""
results = whois.whois(name)
print(f"{name} is registered by {results.name} - {results.org}")
@app.command()
def portscan(target: str, top: int = 10):
"""Perform a portscan against a target on the top TOP ports,
and print the open ports and services."""
nmap = nmap3.Nmap()
results = nmap.scan_top_ports(target, default=top)
ip, *_unused = results.keys()
for port in results[ip]["ports"]:
if "open" in port["state"]:
print(f"{port['portid']} {port['service']['name']}")
if __name__ == "__main__":
app()