From a34b85c5d51aa180c45aa9d794ab145185a4b9e6 Mon Sep 17 00:00:00 2001 From: Seth Art Date: Thu, 22 Aug 2019 23:41:40 -0400 Subject: [PATCH] Build 217 - Can get banner with python3 and no errors! #112 --- celerystalk | 2 +- lib/administrative.py | 2 +- lib/config_parser.py | 10 +++++----- lib/csimport.py | 6 +++--- lib/interactive.py | 2 +- lib/nmap.py | 8 ++++---- lib/query.py | 2 +- lib/report.py | 10 +++++----- lib/scan.py | 4 ++-- lib/screenshot.py | 2 +- lib/utils.py | 12 ++++++------ lib/workspace.py | 6 +++--- parsers/generic_urlextract.py | 2 +- setup/install.sh | 6 +++--- setup/requirements.txt | 3 ++- 15 files changed, 39 insertions(+), 38 deletions(-) diff --git a/celerystalk b/celerystalk index 8c71b24..e90ad06 100755 --- a/celerystalk +++ b/celerystalk @@ -89,7 +89,7 @@ import csv from lib.nmap import nmapcommand -build=str(216) +build=str(217) def print_banner(): diff --git a/lib/administrative.py b/lib/administrative.py index 16e7b22..0923778 100644 --- a/lib/administrative.py +++ b/lib/administrative.py @@ -23,7 +23,7 @@ def restore_all_workspaces(restore_file): workspaces = lib.db.get_all_workspaces() if workspaces: print("[!] There is already a current workspace. This will backup the currnt DB and OVERWRITE it with the new one.") - answer = raw_input("Are you sure you want to continue? (y\N): ") + answer = input("Are you sure you want to continue? (y|N): ") print("") if (answer == "Y") or (answer == "y"): backup_all_workspaces() diff --git a/lib/config_parser.py b/lib/config_parser.py index f1a3c30..ce9d5a9 100644 --- a/lib/config_parser.py +++ b/lib/config_parser.py @@ -1,5 +1,5 @@ from collections import OrderedDict -from ConfigParser import ConfigParser +import configparser class MultiOrderedDict(OrderedDict): @@ -13,7 +13,7 @@ def __setitem__(self, key, value): def read_config_ini(config_file=None): - config = ConfigParser() + config = configparser.ConfigParser() config.read([config_file]) supported_services = [] for (key,val) in config.items("nmap-service-names"): @@ -46,7 +46,7 @@ def get_user_config(config_file): def extract_bb_nmap_options(config_file=None): - config = ConfigParser(allow_no_value=True) + config = configparser.ConfigParser(allow_no_value=True) config.read([config_file]) for (key, val) in config.items("nmap-commands"): @@ -56,7 +56,7 @@ def extract_bb_nmap_options(config_file=None): return options def extract_udp_scan_nmap_options(config_file=None): - config = ConfigParser(allow_no_value=True) + config = configparser.ConfigParser(allow_no_value=True) config.read([config_file]) for (key, val) in config.items("nmap-commands"): @@ -66,7 +66,7 @@ def extract_udp_scan_nmap_options(config_file=None): return options def read_bb_scope_ini(bb_scope_file): - bb_config = ConfigParser(allow_no_value=True) + bb_config = configparser.ConfigParser(allow_no_value=True) bb_config.read([bb_scope_file]) in_scope_domains = [] diff --git a/lib/csimport.py b/lib/csimport.py index d5d4418..e822f07 100644 --- a/lib/csimport.py +++ b/lib/csimport.py @@ -5,7 +5,7 @@ import lib.db import lib.utils from lib import db -import urlparse +from urllib import parse as urlparse import os import csv @@ -85,7 +85,7 @@ def import_scope(scope_file,workspace): else: db_vhost = (ip, ip, 1, 0, 0, workspace) # add it to the vhosts db and mark as in scope lib.db.create_vhost(db_vhost) - except Exception, e: + except Exception as e: # Putting this try/except here because i have a feeling that at some point we will see # something like 192.168.0.0-192.168.200.255 or something like that. Not handling that # right now. @@ -185,7 +185,7 @@ def import_url(url,workspace,output_base_dir): vhost_explicitly_out_of_scope = lib.db.is_vhost_explicitly_out_of_scope(vhost, workspace) if not vhost_explicitly_out_of_scope: # and if the vhost is not explicitly out of scope if in_scope == 0: - answer = raw_input( + answer = input( "[+] {0} is not in scope. Would you like to to add {1}/{0} to the list of in scope hosts?".format(vhost, ip)) if (answer == "Y") or (answer == "y") or (answer == ""): diff --git a/lib/interactive.py b/lib/interactive.py index ef35c2f..cab5ecc 100644 --- a/lib/interactive.py +++ b/lib/interactive.py @@ -15,7 +15,7 @@ def help_db(self): def do_quit(self, args): """Quits the program.""" - print "Quitting." + print("Quitting.") raise SystemExit def do_db(self,args): diff --git a/lib/nmap.py b/lib/nmap.py index dd82fda..beffa93 100644 --- a/lib/nmap.py +++ b/lib/nmap.py @@ -1,19 +1,19 @@ import sys -from ConfigParser import ConfigParser +import configparser from celery import chain from kombu import uuid - import lib.utils import tasks -from lib import config_parser, utils import lib.db +import lib.config_parser +import lib.utils import os def nmap_scan_subdomain_host(vhost,workspace,simulation,output_base_dir,config_file=None): celery_path = sys.path[0] config_nmap_options = config_parser.extract_bb_nmap_options(config_file=config_file) - config = ConfigParser(allow_no_value=True) + config = configparser.ConfigParser(allow_no_value=True) config.read(['config.ini']) vhost_explicitly_out_of_scope = lib.db.is_vhost_explicitly_out_of_scope(vhost, workspace) diff --git a/lib/query.py b/lib/query.py index 6e0c7f4..cc6e963 100644 --- a/lib/query.py +++ b/lib/query.py @@ -1,5 +1,5 @@ import time -import db +import lib.db import os from lib.utils import get_terminal_width diff --git a/lib/report.py b/lib/report.py index 734fff0..497d99f 100644 --- a/lib/report.py +++ b/lib/report.py @@ -926,7 +926,7 @@ def populate_report_data(report_file,vhost,workspace): report_file.write("Output File:\t" + normalized_output_file + '\n') report_file.write("Status:\t\t" + status + '\n') report_file.write('-' * 50 + '\n\n') - except OSError, e: + except OSError: report_file.write('\n') report_file.write('-' * 50 + '\n') report_file.write("Command Name:\t" + command_name+ '\n') @@ -947,7 +947,7 @@ def populate_report_data(report_file,vhost,workspace): if linecount > 300: report_file.write("\nSnip... Only displaying first 300 of the total " + str( linecount) + " lines...\n") - except IOError, e: + except IOError: #dont tell the user at the concole that file didnt exist. pass @@ -1015,7 +1015,7 @@ def get_command_header_and_info(vhost,normalized_output_file,command_name,comman command_header_html_string = command_header_html_string + "Status:" + status + ' [No Output Data]\n' else: command_header_html_string = command_header_html_string + "Status:" + status + '\n' - except OSError, e: + except OSError: command_header_html_string = command_header_html_string + "Command:" + command + '\n' command_header_html_string = command_header_html_string + "\nError!: No such file or directory: " + normalized_output_file + "\n" # command_header_html_string = command_header_html_string + "{0} did not produce any data\n".format(command_name)) @@ -1046,7 +1046,7 @@ def convert_file_contents_to_html(normalized_output_file): if linecount > 300: file_html_string = file_html_string + "\nSnip... Only displaying first 300 of the total " + str( linecount) + " lines...\n" - except IOError, e: + except IOError: # dont tell the user at the concole that file didnt exist. pass file_html_string = file_html_string + " " @@ -1064,4 +1064,4 @@ def convert_file_contents_to_html2(normalized_output_file): def command_footer_html(tasks_for_output_file): for task in tasks_for_output_file: - print {} \ No newline at end of file + print(task) \ No newline at end of file diff --git a/lib/scan.py b/lib/scan.py index 0d2dca8..c2e0c64 100644 --- a/lib/scan.py +++ b/lib/scan.py @@ -7,7 +7,7 @@ from celery import chain import socket import re -import urlparse +from urllib import parse as urlparse import lib.db from random import shuffle @@ -108,7 +108,7 @@ def aquatone_host(urls_to_screenshot,vhost,workspace,simulation,scan_output_base populated_command = replace_user_config_options(config_file,populated_command) #print(populated_command) - except Exception, e: + except Exception as e: print(e) print("[!] Error: In the config file, there needs to be one (and only one) enabled aquatone command.") exit() diff --git a/lib/screenshot.py b/lib/screenshot.py index 2d16839..ad2180f 100644 --- a/lib/screenshot.py +++ b/lib/screenshot.py @@ -88,7 +88,7 @@ def aquatone_all_paths(workspace,simulation=None,config_file=None): if cmd_name == "aquatone": populated_command = celery_path + "/celerystalk db paths_only limit | " + cmd.replace("[OUTPUT]", outdir) #print(populated_command) - except Exception, e: + except Exception as e: print(e) print("[!] Error: In the config file, there needs to be one (and only one) enabled aquatone command.") exit() diff --git a/lib/utils.py b/lib/utils.py index 597b8a0..f6ec7c3 100644 --- a/lib/utils.py +++ b/lib/utils.py @@ -6,11 +6,11 @@ from libnessus.parser import NessusParser from netaddr import IPAddress, IPRange, IPNetwork import socket -import db +from lib import db +from lib import config_parser import os import re -import lib.db -import lib.config_parser + def task_splitter(id): @@ -147,7 +147,7 @@ def start_celery_worker(config_file): popen_string = "celery -A tasks worker --concurrency=%s -Ofair -q --pidfile ./%%n.pid --logfile ./log/celeryWorker.log > /dev/null 2>&1" % (str(concurrent_tasks)) p = Popen(popen_string, shell=True) - except Exception, e: + except Exception as e: #print(e) p = Popen( "celery -A tasks worker -Ofair -q --pidfile ./%n.pid --logfile ./log/celeryWorker.log > /dev/null 2>&1", @@ -223,7 +223,7 @@ def target_splitter(target_networks): # Putting this try/except here because i have a feeling that at some point we will see # something like 192.168.0.0-192.168.200.255 or something like that. Not handling that # right now. - print(error) + print("error") else: # If there is no "-" in the line, we can deal with it as a simple network or IPAddress. Luckily # IPNetwork automatically converts an IP without a CIDR into /32 CIDR, and it works just like @@ -275,7 +275,7 @@ def check_for_new_default_config(): if user_config_age < default_config_age: print("[!] [config_default.ini] pulled from git is newer than the the current [config.ini] file.") print("[!] This is most likely because a new tool or possibly a new feature has been added.\n") - answer = raw_input("[+] Would you like backup your current config and replace [config.ini] with the new version? (y\N)") + answer = input("[+] Would you like backup your current config and replace [config.ini] with the new version? (y|N)") print("") if (answer == "Y") or (answer == "y"): from shutil import copyfile diff --git a/lib/workspace.py b/lib/workspace.py index 9ceb3e5..729ff8c 100644 --- a/lib/workspace.py +++ b/lib/workspace.py @@ -21,8 +21,8 @@ def create_workspace(workspace,arguments): if arguments["-o"]: #and the user specified a workspace arg_output_dir = os.path.join(arguments["-o"], '') if arg_output_dir != output_dir: # if the user specified output dir is not the same as the db output_dir, ask the user whether they want to update it or ignore the command line output_dir - output_dir_answer = raw_input( - "[!] The DB shows that the output directory for the [{0}] workspace is [{1}].\n[+] Do you want to update the output directory to [{2}]? (y\N)".format( + output_dir_answer = input( + "[!] The DB shows that the output directory for the [{0}] workspace is [{1}].\n[+] Do you want to update the output directory to [{2}]? (y|N)".format( workspace, output_dir, arg_output_dir)) print("") if (output_dir_answer == "Y") or ( @@ -46,7 +46,7 @@ def create_workspace(workspace,arguments): print("[+] Workspace: " + workspace + " already exists and is the current workspace: " + workspace + "\n") else: print("[+] Workspace: " + workspace + " already exists but it is not the current workspace\n") - answer = raw_input("[+] Would you like to switch to this workspace? [Y\\n] ") + answer = input("[+] Would you like to switch to this workspace? [Y\\n] ") if (answer == "Y") or (answer == "y") or (answer == ""): lib.db.update_current_workspace(workspace) diff --git a/parsers/generic_urlextract.py b/parsers/generic_urlextract.py index 363ecfc..07afdfe 100644 --- a/parsers/generic_urlextract.py +++ b/parsers/generic_urlextract.py @@ -2,7 +2,7 @@ import re import lib.db import lib.utils -import urlparse +from urllib import parse as urlparse #TODO: Add this when i move project to python3 diff --git a/setup/install.sh b/setup/install.sh index 8876ff3..04b2e3e 100755 --- a/setup/install.sh +++ b/setup/install.sh @@ -54,7 +54,7 @@ elif [ "$DISTRO" == "ubuntu" ]; then curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" -y apt-get update -y - apt-get install docker-ce docker-ce-cli containerd.io python-pip python3-pip unzip redis-server chromium jq -y + apt-get install docker-ce docker-ce-cli containerd.io python-pip python3-pip unzip redis-server chromium jq python3-pip -y fi @@ -76,7 +76,7 @@ echo "******************************************" echo "* Installing python requirements via pip *" echo "******************************************" echo "" -pip install -r requirements.txt --upgrade +pip3 install -r requirements.txt --upgrade echo "" @@ -89,7 +89,7 @@ if [ ! -f /opt/python-libnessus/python_libnessus.egg-info ]; then cd /opt/ git clone https://github.com/bmx0r/python-libnessus.git cd python-libnessus - python setup.py install + python3 setup.py install fi diff --git a/setup/requirements.txt b/setup/requirements.txt index faec88b..50335a5 100644 --- a/setup/requirements.txt +++ b/setup/requirements.txt @@ -11,4 +11,5 @@ bleach selenium prettytable pyvirtualdisplay -ansi2html \ No newline at end of file +ansi2html +configparser==3.7.4 \ No newline at end of file