def main(): parser = argparse.ArgumentParser(description="Attack agent") parser.add_argument('-f', '--filename', help='database filename', dest='db_file') parser.add_argument('-p', '--port', help='Listener port number (default port is 10000)', type=int, default=10000) parser.add_argument('-ip', help='Listener ip address', type=str) args = parser.parse_args() if args.db_file is not None: database_records = read_records_from_json(args.db_file) manager = AttackManager(database_records) manager.update() print(manager) # assumed_target_state = {"protocol": "ip", "address": "127.0.0.1"} goal = Condition() goal.add(("shell", "EQ PERMANENT")) goal.add(("privilege", "EQ 0")) print(goal) else: print('invalid DB file')
def main(): """ The entry point of red agent """ listener_port = constant.DEFAULT_LISTENER_PORT #TODO: Command line arguments should be handled elegantly. if len(sys.argv) > 1: listener_port = sys.argv[1] AttackDB().update() Listener().work(constant.DEFAULT_LISTENER_IP, int(listener_port)) assumed_state = { constant.STATE_KEY_PROTOCOL: constant.STATE_VALUE_PROTOCOL_IP, constant.STATE_KEY_ADDRESS: constant.DEFAULT_TARGET_IP } goal = Condition() goal.add((constant.STATE_KEY_SHELL, constant.CONDITION_OPERATOR_EQUAL, constant.STATE_VALUE_SHELL_PERMANENT)) goal.add((constant.STATE_KEY_PRIVILEGE, constant.CONDITION_OPERATOR_EQUAL, constant.STATE_VALUE_PRIVILEGE_ROOT)) planner = Planner(assumed_state, goal) try: planner.make_plan() print(planner) planner.run() except Exception as e: traceback.print_exc() Listener().stop() raise e Listener().stop() sys.exit(0)
def update(self): """ Storing each attack records into __records in an instance of this class. An attack record is stored in there as an instance of RT class. """ global DB_RECORDS for e in DB_RECORDS: keys = list(e.keys()) if not "Name" in keys or not "Preconditions" in keys \ or not "Postconditions" in keys or not "Command" in keys: print("INVALID RECORD :\n" + str(e) + "\n") continue name = e["Name"] cond = Condition() for pre in e["Preconditions"]: cond.add(pre) post = e["Postconditions"] cmd = e["Command"] self.__records.append(RT(name, cond, post, cmd))
def update(self): """ Storing each attack record into __records as an instance of this class. An attack record is stored in there as an instance of AttackRecord class. """ for record in self.records_from_db: keys = list(record.keys()) if not ("Name" in keys) or \ not ("Preconditions" in keys) or \ not ("Postconditions" in keys) or \ not ("Command" in keys): print("INVALID RECORD :\n" + str(record) + "\n") continue name = record["Name"] pre_conditions = Condition() for pre_condition in record["Preconditions"]: pre_conditions.add(pre_condition) post_conditions = record["Postconditions"] command = record["Command"] self.__records.append( AttackRecord(name, pre_conditions, post_conditions, command))