Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code for Issue --> Refactoring for classes #4 #126

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
Binary file added Reconnoitre/lib/.DS_Store
Binary file not shown.
169 changes: 0 additions & 169 deletions Reconnoitre/lib/file_helper.py

This file was deleted.

109 changes: 58 additions & 51 deletions Reconnoitre/lib/find_dns.py
Original file line number Diff line number Diff line change
@@ -1,51 +1,58 @@
from Reconnoitre.lib.file_helper import check_directory
from Reconnoitre.lib.file_helper import load_targets
from Reconnoitre.lib.subprocess_helper import run_scan


def find_dns(target_hosts, output_directory, quiet):
check_directory(output_directory)
dns_server_list = []
results = 0
hostcount = 0
dnscount = 0

output_file = open(output_directory + "/DNS-Detailed.txt", 'w')
output_targets = open(output_directory + "/DNS-targets.txt", 'w')

targets = load_targets(target_hosts, output_directory, quiet)
target_file = open(targets, 'r')

print("[*] Loaded targets from: %s" % targets)
print("[+] Enumerating TCP port 53 over targets to find dns servers")

for ip_address in target_file:
hostcount += 1
ip_address = ip_address.strip()
ip_address = ip_address.rstrip()

print(" [>] Testing %s for DNS" % ip_address)
DNSSCAN = "nmap -n -sV -Pn -vv -p53 %s" % (ip_address)
results = run_scan(DNSSCAN)
lines = results.split("\n")

for line in lines:
line = line.strip()
line = line.rstrip()
if (("53/tcp" in line) and ("open" in line)
and ("Discovered" not in line)):
print(
" [=] Found DNS service running on: %s" %
(ip_address))
output_file.write(
"[*] Found DNS service running on: %s\n" %
(ip_address))
output_file.write(" [>] %s\n" % (line))
output_targets.write("%s\n" % (ip_address))
dns_server_list.append(ip_address)
dnscount += 1
print("[*] Found %s DNS servers within %s hosts" %
(str(dnscount), str(hostcount)))
output_file.close()
output_targets.close()
return '' if len(dns_server_list) == 0 else ','.join(dns_server_list)
from lib.utility import Utility

class FindDNS:
def __init__(self, target_hosts, output_directory, quiet) -> None:
# Function args
self.target_hosts = target_hosts
self.output_directory = output_directory
self.quiet = quiet
# Algorithm setup
self.output_file = "{}/DNS-Detailed.txt".format(self.output_directory)
self.output_targets = "{}/DNS-targets.txt".format(self.output_directory)
self.dns_server_list = []
self.results = 0
self.hostcount = 0
self.dnscount = 0

def find_dns(self):
Utility.check_directory(self.output_directory)

output_file = open(self.output_directory + "/DNS-Detailed.txt", 'w')
output_targets = open(self.output_directory + "/DNS-targets.txt", 'w')

targets = Utility.load_targets(self.target_hosts, self.output_directory, self.quiet)
target_file = open(targets, 'r')

print("[*] Loaded targets from: %s" % targets)
print("[+] Enumerating TCP port 53 over targets to find dns servers")

for ip_address in target_file:
self.hostcount += 1
ip_address = ip_address.strip()
ip_address = ip_address.rstrip()

print(" [>] Testing %s for DNS" % ip_address)
DNSSCAN = "nmap -n -sV -Pn -vv -p53 %s" % (ip_address)
results = Utility.run_scan(DNSSCAN)
lines = results.split("\n")

for line in lines:
line = line.strip()
line = line.rstrip()
if (("53/tcp" in line) and ("open" in line)
and ("Discovered" not in line)):
print(
" [=] Found DNS service running on: %s" %
(ip_address))
output_file.write(
"[*] Found DNS service running on: %s\n" %
(ip_address))
output_file.write(" [>] %s\n" % (line))
output_targets.write("%s\n" % (ip_address))
self.dns_server_list.append(ip_address)
self.dnscount += 1
print("[*] Found %s DNS servers within %s hosts" %
(str(self.dnscount), str(self.hostcount)))
output_file.close()
output_targets.close()
return '' if len(self.dns_server_list) == 0 else ','.join(self.dns_server_list)
73 changes: 38 additions & 35 deletions Reconnoitre/lib/hostname_scan.py
Original file line number Diff line number Diff line change
@@ -1,48 +1,51 @@
import os
from lib.utility import Utility

from Reconnoitre.lib.file_helper import check_directory
from Reconnoitre.lib.subprocess_helper import run_scan
class HostNameScan():
def __init__(self, target_hosts, output_directory, quiet):
self.target_hosts = target_hosts
self.output_directory = output_directory
self.quiet = quiet
self.hostnames = 0
self.output_file = "{}/hostnames.txt".format(self.output_directory)

def hostname_scan(self, target_hosts, output_directory, quiet):
Utility.check_directory(output_directory)
f = open(self.output_file, 'w')
print("[+] Writing hostnames to: %s" % self.output_file)

def hostname_scan(target_hosts, output_directory, quiet):
check_directory(output_directory)
output_file = output_directory + "/hostnames.txt"
f = open(output_file, 'w')
print("[+] Writing hostnames to: %s" % output_file)
SWEEP = ''

hostnames = 0
SWEEP = ''
if (os.path.isfile(target_hosts)):
SWEEP = "nbtscan -q -f %s" % (target_hosts)
else:
SWEEP = "nbtscan -q %s" % (target_hosts)

if (os.path.isfile(target_hosts)):
SWEEP = "nbtscan -q -f %s" % (target_hosts)
else:
SWEEP = "nbtscan -q %s" % (target_hosts)
results = Utility.run_scan(SWEEP)
lines = results.split("\n")

results = run_scan(SWEEP)
lines = results.split("\n")
for line in lines:
line = line.strip()
line = line.rstrip()

for line in lines:
line = line.strip()
line = line.rstrip()
# Final line is blank which causes list index issues if we don't
# continue past it.
if " " not in line:
continue

# Final line is blank which causes list index issues if we don't
# continue past it.
if " " not in line:
continue
while " " in line:
line = line.replace(" ", " ")

while " " in line:
line = line.replace(" ", " ")
ip_address = line.split(" ")[0]
host = line.split(" ")[1]

ip_address = line.split(" ")[0]
host = line.split(" ")[1]
if (self.hostnames > 0):
f.write('\n')

if (hostnames > 0):
f.write('\n')
print(" [>] Discovered hostname: %s (%s)" % (host, ip_address))
f.write("%s - %s" % (host, ip_address))
self.hostnames += 1

print(" [>] Discovered hostname: %s (%s)" % (host, ip_address))
f.write("%s - %s" % (host, ip_address))
hostnames += 1

print("[*] Found %s hostnames." % (hostnames))
print("[*] Created hostname list %s" % (output_file))
f.close()
print("[*] Found %s hostnames." % (self.hostnames))
print("[*] Created hostname list %s" % (self.output_file))
f.close()
Loading