Skip to content

Commit

Permalink
Merge pull request codingo#112 from tonydelanuez/replace-text-with-un…
Browse files Browse the repository at this point in the history
…iversal-newlines

Fix python 3.6 compat issue with subprocess.Popen keyword arguments && creating helper function 'run_scan' to create a subprocess, moving subprocess logic to helper.
  • Loading branch information
codingo authored Aug 26, 2019
2 parents 5badb59 + 927d5bf commit 8f1c4ef
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 19 deletions.
5 changes: 2 additions & 3 deletions Reconnoitre/lib/find_dns.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import subprocess

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):
Expand All @@ -27,7 +26,7 @@ def find_dns(target_hosts, output_directory, quiet):

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

for line in lines:
Expand Down
4 changes: 2 additions & 2 deletions Reconnoitre/lib/hostname_scan.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import subprocess

from Reconnoitre.lib.file_helper import check_directory
from Reconnoitre.lib.subprocess_helper import run_scan


def hostname_scan(target_hosts, output_directory, quiet):
Expand All @@ -18,7 +18,7 @@ def hostname_scan(target_hosts, output_directory, quiet):
else:
SWEEP = "nbtscan -q %s" % (target_hosts)

results = subprocess.check_output(SWEEP, shell=True,text=True)
results = run_scan(SWEEP)
lines = results.split("\n")

for line in lines:
Expand Down
6 changes: 3 additions & 3 deletions Reconnoitre/lib/ping_sweeper.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import subprocess

from Reconnoitre.lib.file_helper import check_directory
from Reconnoitre.lib.subprocess_helper import run_scan


def ping_sweeper(target_hosts, output_directory, quiet):
Expand All @@ -23,7 +22,8 @@ def ping_sweeper(target_hosts, output_directory, quiet):
def call_nmap_sweep(target_hosts):
SWEEP = "nmap -n -sP %s" % (target_hosts)

results = subprocess.check_output(SWEEP, shell=True, text=True)
results = run_scan(SWEEP)
lines = str(results).encode("utf-8").split("\n")
return lines


Expand Down
10 changes: 4 additions & 6 deletions Reconnoitre/lib/service_scan.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import multiprocessing
import socket
import subprocess

from Reconnoitre.lib.file_helper import check_directory
from Reconnoitre.lib.file_helper import create_dir_structure
from Reconnoitre.lib.file_helper import load_targets
from Reconnoitre.lib.file_helper import write_recommendations
from Reconnoitre.lib.subprocess_helper import run_scan


def nmap_scan(
Expand All @@ -19,8 +19,7 @@ def nmap_scan(
print("[+] Starting quick nmap scan for %s" % (ip_address))
QUICKSCAN = "nmap -sC -sV -Pn --disable-arp-ping %s -oA '%s/%s.quick'" % (
ip_address, output_directory, ip_address)
quickresults = subprocess.check_output(
QUICKSCAN, shell=True,text=True)
quickresults = run_scan(QUICKSCAN)

write_recommendations(quickresults, ip_address, output_directory)
print("[*] TCP quick scans completed for %s" % ip_address)
Expand Down Expand Up @@ -69,9 +68,8 @@ def nmap_scan(
UDPSCAN = "nmap -sC -sV -sU -Pn --disable-arp-ping %s -oA '%s/%s-udp'" % (
ip_address, output_directory, ip_address)

udpresult = "" if no_udp_service_scan is True else subprocess.check_output(
UDPSCAN, shell=True, text=True)
tcpresults = subprocess.check_output(TCPSCAN, shell=True, text=True)
udpresult = "" if no_udp_service_scan is True else run_scan(UDPSCAN)
tcpresults = run_scan(TCPSCAN)

write_recommendations(tcpresults + udpresult, ip_address, output_directory)
print("[*] TCP%s scans completed for %s" %
Expand Down
7 changes: 2 additions & 5 deletions Reconnoitre/lib/snmp_walk.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import subprocess

from Reconnoitre.lib.file_helper import check_directory, load_targets
from Reconnoitre.lib.subprocess_helper import run_scan


def valid_ip(address):
Expand Down Expand Up @@ -73,11 +74,7 @@ def snmp_scans(ip_address, output_directory):
ip_address, output_directory, ip_address))

try:
subprocess.check_output(
SCAN,
stderr=subprocess.STDOUT,
shell=True,
text=True)
run_scan(SCAN, stderr=subprocess.STDOUT)
except Exception:
print("[+] No Response from %s" % ip_address)
except subprocess.CalledProcessError:
Expand Down
8 changes: 8 additions & 0 deletions Reconnoitre/lib/subprocess_helper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import subprocess


def run_scan(scan, stderr=None):
"""Helper method to perform a scan using a subprocess and return results.
We use the same configuration options for each call to check_output, this
can be bunched into one helper function to keep config constant."""
return subprocess.check_output(scan, shell=True, stderr=stderr, universal_newlines=True)

0 comments on commit 8f1c4ef

Please sign in to comment.