-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdemo_3.py
executable file
·54 lines (41 loc) · 1.45 KB
/
demo_3.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
#!/usr/bin/env python3
"""Command-line interface to perform several security tests."""
from lxml import html
import nmap3
import requests
import whois
import typer
app = typer.Typer()
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 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()