def post(self, *args, **kwargs): ''' Creates a new weapon system, and yes the form validation is shit ''' form = Form( name="Please enter a name", ssh_user="******", ssh_key="Please enter an ssh key", ip_address="Please enter a ip address", ssh_port="Please enter an ssh port", service_port="Please enter a service port", ) if form.validate(self.request.arguments): if WeaponSystem.by_name(self.get_argument('name')) is not None: self.render("admin/weaponsystem/create.html", errors=['That name already exists'] ) elif WeaponSystem.by_ip_address(self.get_argument('ip_address')) is not None: self.render("admin/weaponsystem/create.html", errors=['IP Address already in use'] ) else: try: if not 1 <= int(self.get_argument('ssh_port', -1)) < 65535: raise ValueError("SSh port not in range") if not 1 <= int(self.get_argument('service_port', -1)) < 65535: raise ValueError("Service port not in range") weapon_system = self.create_weapon() self.render("admin/weaponsystem/created.html", errors=None) except ValueError: self.render("admin/weaponsystem/create.html", errors=["Invalid port number; must be 1-65535"] ) else: self.render("admin/weaponsystem/create.html", errors=form.errors)
def post(self, *args, **kwargs): ''' Creates a new weapon system, and yes the form validation is shit ''' form = Form( name="Please enter a name", ssh_user="******", ssh_key="Please enter an ssh key", ip_address="Please enter a ip address", ssh_port="Please enter an ssh port", service_port="Please enter a service port", ) if form.validate(self.request.arguments): if WeaponSystem.by_name(self.get_argument('name')) is not None: self.render("admin/weaponsystem/create.html", errors=['That name already exists']) elif WeaponSystem.by_ip_address( self.get_argument('ip_address')) is not None: self.render("admin/weaponsystem/create.html", errors=['IP Address already in use']) else: try: if not 1 <= int(self.get_argument('ssh_port', -1)) < 65535: raise ValueError("SSh port not in range") if not 1 <= int(self.get_argument('service_port', -1)) < 65535: raise ValueError("Service port not in range") weapon_system = self.create_weapon() self.render("admin/weaponsystem/created.html", errors=None) except ValueError: self.render( "admin/weaponsystem/create.html", errors=["Invalid port number; must be 1-65535"]) else: self.render("admin/weaponsystem/create.html", errors=form.errors)
def validate_form(self): ''' Shitty form validation ''' # Name try: self.name = self.filter_string(self.get_argument("name")) if WeaponSystem.by_name(self.name) != None: raise ValueError("Name already exits") except: self.render( "admin/create_weaponsystem.html", message="Invalid Name") return False # IP Address try: self.ip_address = self.filter_string( self.get_argument("ipaddress"), extra_chars=".") if WeaponSystem.by_ip_address(self.ip_address) != None: raise ValueError("IP Address already in use") except: self.render("admin/create_weaponsystem.html", message="Missing IP Address") return False # Service Port try: self.listen_port = int(self.get_argument("srvport")) if not 1 < self.listen_port < 65535: raise ValueError("Invalid port range, or not a number") except: self.render("admin/create_weaponsystem.html", message="Invalid Listen Port") return False # SSH User try: self.ssh_user = self.filter_string(self.get_argument("sshuser")) if self.ssh_user.lower() == 'root': raise ValueError("SSH User cannot be 'root'") except: self.render("admin/create_weaponsystem.html", message="Missing SSH User") return False # SSH Key try: self.ssh_key = self.filter_string( self.get_argument("sshkey"), extra_chars="+/=- \n") except: self.render("admin/create_weaponsystem.html", message="Missing SSH Private Key") return False # SSH Port try: self.ssh_port = int(self.get_argument("sshport")) if not 1 < self.ssh_port < 65535: raise ValueError("Invalid port range, or not a number") except: self.render("admin/create_weaponsystem.html", message="Missing SSH Port") return False return True
def post(self, *args, **kwargs): ''' Creates a new weapon system, and yes the form validation is shit ''' if self.validate_form(): weapon_system = WeaponSystem( name=unicode(self.name), ssh_user=unicode(self.ssh_user), ssh_key=unicode(self.ssh_key), ip_address=unicode(self.ip_address), ssh_port=self.ssh_port, service_port=self.listen_port, ) dbsession.add(weapon_system) dbsession.flush() weapon_system.initialize() self.render("admin/created_weaponsystem.html")
def __queue__(self): ''' Starts a job or leaves it in the queue (thread safe) ''' logging.debug("Attempting to acquire queue mutex ...") self.mutex.acquire() logging.debug("Successfully acquired queue mutex.") queue = list(Job.queue()) # Create a copy of the queue for job in queue: logging.info("Dispatching job: %s" % job.job_name) if len(job) == 0: job.status = u"COMPLETED" dbsession.add(job) dbsession.flush() else: algo = Algorithm.by_id(job.algorithm_id) weapon_systems = WeaponSystem.system_ready(algo) if weapon_systems is not None and 0 < len(weapon_systems): logging.info("Weapon systems available: %d" % ( len(weapon_systems), )) thread.start_new_thread( self.__crack__, (job, weapon_systems[0],) ) else: logging.info("No available weapon systems at this time.") self.mutex.release()
def __queue__(self): ''' Starts a job or leaves it in the queue (thread safe) ''' logging.debug("Attempting to acquire queue mutex ...") self.mutex.acquire() logging.debug("Successfully acquired queue mutex.") queue = list(Job.queue()) # Create a copy of the queue for job in queue: logging.info("Dispatching job: %s" % job.job_name) if len(job) == 0: job.status = u"COMPLETED" dbsession.add(job) dbsession.flush() else: algo = Algorithm.by_id(job.algorithm_id) weapon_systems = WeaponSystem.system_ready(algo) if weapon_systems is not None and 0 < len(weapon_systems): logging.info("Weapon systems available: %d" % (len(weapon_systems), )) thread.start_new_thread(self.__crack__, ( job, weapon_systems[0], )) else: logging.info("No available weapon systems at this time.") self.mutex.release()
def get(self, *args, **kwargs): ''' Display the default user page ''' user = User.by_username(self.session.data['username']) dispatch = Dispatch.Instance() self.render('user/home.html', user=user, all_weapons=WeaponSystem.get_all(), )
def get(self, *args, **kwargs): try: weapon_system = WeaponSystem.by_uuid(self.get_argument('uuid')) success = weapon_system.initialize() except: self.render("admin/initialize_failure.html") return if success: self.render("admin/initialize_success.html") else: self.render("admin/initialize_failure.html")
def create_weapon(self): ''' Adds parameters to the database ''' weapon_system = WeaponSystem( name=unicode(self.get_argument('name')), ssh_user=unicode(self.get_argument('ssh_user')), ssh_key=unicode(self.get_argument('ssh_key')), ip_address=unicode(self.get_argument('ip_address')), ssh_port=int(self.get_argument('ssh_port')), service_port=int(self.get_argument('service_port')), ) dbsession.add(weapon_system) dbsession.flush() return weapon_system
def get(self, *args, **kwargs): success = False try: weapon_system = WeaponSystem.by_uuid(self.get_argument('uuid', '')) if weapon_system is not None: self.init_weapon_system(weapon_system) success = True else: raise ValueError("WeaponSystem uuid does not exist") except Exception as error: self.output += "\n[!] Error: " + str(error) logging.exception("Error while initializing weapon system.") finally: weapon_system.initialized = success dbsession.add(weapon_system) dbsession.flush() self.render("admin/weaponsystem/initialize.html", success=success, output=self.output)
def get(self, *args, **kwargs): ''' Renders the detail weapon system page ''' uuid = self.get_argument('uuid', '') weapon_system = WeaponSystem.by_uuid(uuid) self.render("admin/weaponsystem/details.html", wsys=weapon_system)
def get(self, *args, **kwargs): ''' Renders the create weapon system page ''' self.render("admin/edit_weaponsystem.html", uninit_systems=WeaponSystem.get_uninitialized(), weapon_systems=WeaponSystem.get_all())