FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Networking_Exploit_Script/nmap_script_domain.py at main · adriank31/Networking_Exploit_Script · GitHub
adriank31
/
Networking_Exploit_Script
Public
Notifications
You must be signed in to change notification settings
Fork
1
Star
1
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Networking_Exploit_Script
/
nmap_script_domain.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
102 lines (88 loc) · 3.86 KB
Breadcrumbs
Networking_Exploit_Script
/
nmap_script_domain.py
Copy path
File metadata and controls
102 lines (88 loc) · 3.86 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import
nmap
import
json
import
socket
def
resolve_domain
(
domain
):
try
:
return
socket
.
gethostbyname
(
domain
)
except
socket
.
gaierror
:
return
None
def
scan_service_version
(
target_ip
,
output_file
):
scanner
=
nmap
.
PortScanner
()
print
(
f"Scanning
{
target_ip
}
for service/version detection..."
)
scanner
.
scan
(
target_ip
,
arguments
=
'-sV -O --script vuln'
)
with
open
(
output_file
,
'w'
)
as
f
:
for
host
in
scanner
.
all_hosts
():
f
.
write
(
f"
\n
Host:
{
host
}
(
{
scanner
[
host
].
hostname
()
}
)
\n
"
)
f
.
write
(
f"State:
{
scanner
[
host
].
state
()
}
\n
"
)
for
protocol
in
scanner
[
host
].
all_protocols
():
f
.
write
(
f"
\n
Protocol:
{
protocol
}
\n
"
)
ports
=
scanner
[
host
][
protocol
].
keys
()
for
port
in
ports
:
port_info
=
scanner
[
host
][
protocol
][
port
]
f
.
write
(
f"Port:
{
port
}
\t
State:
{
port_info
[
'state'
]
}
\t
Service:
{
port_info
[
'name'
]
}
\n
"
)
if
'product'
in
port_info
:
f
.
write
(
f"Service version:
{
port_info
[
'product'
]
}
{
port_info
[
'version'
]
}
\n
"
)
if
'osmatch'
in
scanner
[
host
]:
for
osmatch
in
scanner
[
host
][
'osmatch'
]:
f
.
write
(
f"OS:
{
osmatch
[
'name'
]
}
(
{
osmatch
[
'accuracy'
]
}
% accuracy)
\n
"
)
for
protocol
in
scanner
[
host
].
all_protocols
():
ports
=
scanner
[
host
][
protocol
].
keys
()
for
port
in
ports
:
port_info
=
scanner
[
host
][
protocol
][
port
]
if
'script'
in
port_info
:
for
script
,
output
in
port_info
[
'script'
].
items
():
f
.
write
(
f"[
{
script
}
] =>
{
output
}
\n
"
)
print
(
f"Results saved to
{
output_file
}
"
)
print_important_info
(
scanner
,
target_ip
)
def
print_important_info
(
scanner
,
target_ip
):
host_data
=
{
"IP"
:
target_ip
,
"State"
:
scanner
[
target_ip
].
state
(),
"OS"
: {},
"Ports"
: []
}
if
'osmatch'
in
scanner
[
target_ip
]:
os_match
=
scanner
[
target_ip
][
'osmatch'
][
0
]
host_data
[
"OS"
]
=
{
"Name"
:
os_match
[
'name'
],
"Version"
:
os_match
[
'osclass'
][
0
][
'osgen'
],
"Accuracy"
:
f"
{
os_match
[
'accuracy'
]
}
%"
}
for
protocol
in
scanner
[
target_ip
].
all_protocols
():
ports
=
scanner
[
target_ip
][
protocol
].
keys
()
for
port
in
ports
:
port_info
=
scanner
[
target_ip
][
protocol
][
port
]
port_data
=
{
"Port"
:
port
,
"Protocol"
:
protocol
,
"State"
:
port_info
[
'state'
],
"Service"
:
port_info
[
'name'
],
"Service Version"
:
f"
{
port_info
.
get
(
'product'
,
''
)
}
{
port_info
.
get
(
'version'
,
''
)
}
"
.
strip
(),
"Vulnerabilities"
: []
}
if
'script'
in
port_info
:
for
script
,
output
in
port_info
[
'script'
].
items
():
if
script
==
'vulners'
:
vulns
=
parse_vulners_output
(
output
)
port_data
[
"Vulnerabilities"
]
=
vulns
host_data
[
"Ports"
].
append
(
port_data
)
print
(
json
.
dumps
(
host_data
,
indent
=
2
))
def
parse_vulners_output
(
output
):
vulnerabilities
=
[]
for
line
in
output
.
split
(
'
\n
'
):
if
line
.
strip
()
and
not
line
.
startswith
(
'cpe:'
):
parts
=
line
.
split
()
if
len
(
parts
)
>=
3
and
parts
[
1
].
replace
(
'.'
,
''
).
isdigit
():
vuln
=
{
"CVE"
:
parts
[
0
],
"Severity"
:
float
(
parts
[
1
]),
"URL"
:
parts
[
2
]
}
if
float
(
vuln
[
"Severity"
])
>
0.0
:
vulnerabilities
.
append
(
vuln
)
return
vulnerabilities
if
__name__
==
"__main__"
:
target_website
=
input
(
"Enter the Domain to scan for service/version detection: "
)
target_ip
=
resolve_domain
(
target_website
)
output_file
=
"nmap_scan_results.txt"
scan_service_version
(
target_ip
,
output_file
)
Back
|
FazBrowse Home
|
New Git URL