예제 #1
0
    def _action(self):
        try:
            data = json.loads(request.data.decode())

            if data["action"] == "start":
                Hashcat.sessions[data["session"]].start()
            if data["action"] == "update":
                Hashcat.sessions[data["session"]].update()
            if data["action"] == "pause":
                Hashcat.sessions[data["session"]].pause()
            if data["action"] == "resume":
                Hashcat.sessions[data["session"]].resume()
            if data["action"] == "quit":
                Hashcat.sessions[data["session"]].quit()
            if data["action"] == "remove":
                Hashcat.remove_session(data["session"])

            res = {"response": "ok"}

            return json.dumps(res)
        except Exception as e:
            traceback.print_exc()

            return json.dumps({
                "response": "error",
                "message": str(e),
            })
예제 #2
0
파일: httpapi.py 프로젝트: opt9/WebHashcat
    def _createSession(self):
        try:
            data = json.loads(request.data.decode())

            random_name = ''.join(
                random.choice(string.ascii_uppercase + string.digits)
                for _ in range(12))
            hash_file = os.path.join(
                self.hash_directory,
                data["name"] + "_" + random_name + ".list")

            f = open(hash_file, "w")
            f.write(data["hashes"])
            f.close()

            Hashcat.create_session(
                data["name"], data["crack_type"], hash_file,
                int(data["hash_mode_id"]),
                data["wordlist"] if "wordlist" in data else None,
                data["rule"] if "rule" in data else None,
                data["mask"] if "mask" in data else None,
                data["username_included"])

            res = {"response": "ok"}

            return json.dumps(res)
        except Exception as e:
            traceback.print_exc()

            return json.dumps({
                "response": "error",
                "message": str(e),
            })
예제 #3
0
    def _createSession(self):
        try:
            data = json.loads(request.form.get('json'))

            random_name = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(12))
            hash_file = os.path.join(self.hash_directory, data["name"]+"_"+random_name+".list")

            file = request.files['file']
            file.save(hash_file)

            Hashcat.create_session(
                data["name"],
                data["crack_type"],
                hash_file,
                int(data["hash_mode_id"]),
                data["wordlist"] if "wordlist" in data else None,
                data["rule"] if "rule" in data else None,
                data["mask"] if "mask" in data else None,
                data["username_included"],
                int(data["device_type"]),
                int(data["brain_mode"]),
                int(data["end_timestamp"]) if data["end_timestamp"] != None else None,
                data["hashcat_debug_file"],
            )

            res = {"response": "ok"}

            return json.dumps(res)
        except Exception as e:
            traceback.print_exc()

            return json.dumps({
                "response": "error",
                "message": str(e),
            })
예제 #4
0
파일: httpapi.py 프로젝트: opt9/WebHashcat
    def _removeSession(self, session_name):
        try:
            Hashcat.remove_session(session_name)

            res = {"response": "ok"}

            return json.dumps(res)
        except Exception as e:
            traceback.print_exc()

            return json.dumps({
                "response": "error",
                "message": str(e),
            })
예제 #5
0
	def __init__(self, token):
		self.chats = {}
		self.bot = telepot.Bot(token)
		self.hashcat = Hashcat()
		print('Hashbot.__init__(): hashcat.update()')
		self.admins_file = 'admins.txt'
		self.admins = []
		try:
			file = open(self.admins_file, 'r')
			print('opened admins_file')
			lines = file.readlines()
			self.admins = [int(line.strip()) for line in lines]
			file.close()
		except:
			open(self.admins_file, 'w')
예제 #6
0
파일: httpapi.py 프로젝트: opt9/WebHashcat
    def _upload_wordlist(self):
        try:
            data = json.loads(request.data.decode())

            Hashcat.upload_wordlist(data["name"], data["wordlists"])

            res = {"response": "ok"}

            return json.dumps(res)
        except Exception as e:
            traceback.print_exc()

            return json.dumps({
                "response": "error",
                "message": str(e),
            })
예제 #7
0
    def _upload_mask(self):
        try:
            data = json.loads(request.data.decode())

            Hashcat.upload_mask(data["name"], base64.b64decode(data["masks"]))

            res = {"response": "ok"}

            return json.dumps(res)
        except Exception as e:
            traceback.print_exc()

            return json.dumps({
                "response": "error",
                "message": str(e),
            })
예제 #8
0
class HashBot:

	def __init__(self, token):
		self.chats = {}
		self.bot = telepot.Bot(token)
		self.hashcat = Hashcat()
		print('Hashbot.__init__(): hashcat.update()')
		self.admins_file = 'admins.txt'
		self.admins = []
		try:
			file = open(self.admins_file, 'r')
			print('opened admins_file')
			lines = file.readlines()
			self.admins = [int(line.strip()) for line in lines]
			file.close()
		except:
			open(self.admins_file, 'w')

	def handle_message(self, msg):
		content_type, chat_type, chat_id = telepot.glance(msg)
		if chat_id not in self.chats:
			self.chats[chat_id] = Chat(chat_id, self.bot, self.hashcat)
		if chat_id in self.admins:
			self.chats[chat_id].on_message_received(msg)
		else:
			self.deny_permission(chat_id)

	def handle_callback(self, msg):
		content_type, chat_type, chat_id = telepot.glance(msg['message'])
		if chat_id not in self.chats:
			self.chats[chat_id] = Chat(chat_id, self.bot, self.hashcat)
		if chat_id in self.admins:
			self.chats[chat_id].on_callback_received(msg)
		else:
			self.deny_permission(chat_id)

	def deny_permission(self, chat_id):
		print('admins:', self.admins)
		self.bot.sendMessage(chat_id, "You are not authorized to use this bot. Your chat id is: <code>" + \
			str(chat_id) + "</code> add it to <code>$bot$/admins.txt</code>", parse_mode='HTML')

	def start(self):
		MessageLoop(self.bot, {'chat': self.handle_message, 'callback_query': self.handle_callback}).run_as_thread()
		while 1:
			self.hashcat.update()
			time.sleep(0.1)
예제 #9
0
def main():

    # Config

    config = configparser.ConfigParser()

    current_dir = os.path.dirname(__file__)

    config.read(current_dir + os.sep + 'settings.ini')

    loglevel_str = config["General"]["loglevel"]

    bind_address = config["Server"]["bind"]
    bind_port = config["Server"]["port"]
    username = config["Server"]["username"]
    password = config["Server"]["password"]

    binary = config["Hashcat"]["binary"]
    hashes_dir = config["Hashcat"]["hashes_dir"]
    rules_dir = config["Hashcat"]["rule_dir"]
    mask_dir = config["Hashcat"]["mask_dir"]
    wordlist_dir = config["Hashcat"]["wordlist_dir"]

    # Logging

    loglevel_dict = {
        "debug": logging.DEBUG,
        "info": logging.INFO,
        "warning": logging.WARNING,
        "error": logging.ERROR,
        "critical": logging.CRITICAL,
    }

    logfile = os.path.dirname(__file__) + os.sep + 'hashcatnode.log'

    logging.basicConfig(filename=logfile,
                        format='%(asctime)s\t%(levelname)s\t%(message)s',
                        level=loglevel_dict[loglevel_str])

    # Startup

    logging.info("Hashcat node starting")

    Hashcat.binary = binary
    Hashcat.rules_dir = rules_dir
    Hashcat.wordlist_dir = wordlist_dir
    Hashcat.mask_dir = mask_dir

    Hashcat.parse_version()
    Hashcat.parse_help()
    Hashcat.parse_rules()
    Hashcat.parse_masks()
    Hashcat.parse_wordlists()

    Hashcat.reload_sessions()

    httpsServer = Server(bind_address, bind_port, username, password,
                         hashes_dir)
    httpsServer.start_server()
예제 #10
0
def main(run_server=True):

    # Config

    config = configparser.ConfigParser()

    current_dir = os.path.dirname(os.path.abspath(__file__))

    config.read(current_dir + os.sep + 'settings.ini')

    loglevel_str = config["General"]["loglevel"]

    bind_address = config["Server"]["bind"]
    bind_port = config["Server"]["port"]
    # Docker support
    username = config["Server"]["username"]
    username_hash = config["Server"]["sha256hash"]
    if username == 'DOCKER_ENV':
        username = os.environ.get("HASHCATNODE_USERNAME")
        if username == None:
            raise Exception(
                'HASHCATNODE_USERNAME environment variable not defined')
    if username_hash == 'DOCKER_ENV':
        username_hash = os.environ.get("HASHCATNODE_HASH")
        if username_hash == None:
            raise Exception(
                'HASHCATNODE_HASH environment variable not defined')

    binary = config["Hashcat"]["binary"]
    hashes_dir = config["Hashcat"]["hashes_dir"]
    rules_dir = config["Hashcat"]["rule_dir"]
    mask_dir = config["Hashcat"]["mask_dir"]
    wordlist_dir = config["Hashcat"]["wordlist_dir"]
    workload_profile = config["Hashcat"]["workload_profile"]

    # Logging

    loglevel_dict = {
        "debug": logging.DEBUG,
        "info": logging.INFO,
        "warning": logging.WARNING,
        "error": logging.ERROR,
        "critical": logging.CRITICAL,
    }

    logfile = os.path.dirname(
        os.path.abspath(__file__)) + os.sep + 'hashcatnode.log'

    logging.basicConfig(filename=logfile,
                        format='%(asctime)s\t%(levelname)s\t%(message)s',
                        level=loglevel_dict[loglevel_str])

    # Startup

    logging.info("Hashcat node starting")

    Hashcat.binary = binary
    Hashcat.rules_dir = rules_dir
    Hashcat.wordlist_dir = wordlist_dir
    Hashcat.mask_dir = mask_dir
    Hashcat.workload_profile = workload_profile

    Hashcat.parse_version()
    Hashcat.parse_help()
    Hashcat.parse_rules()
    Hashcat.parse_masks()
    Hashcat.parse_wordlists()

    Hashcat.reload_sessions()

    if run_server:
        httpsServer = Server(bind_address, bind_port, username, username_hash,
                             hashes_dir)
        httpsServer.start_server()

    return Hashcat