Esempio n. 1
0
class ResolveDomains():
    IP_FILENAME = "ips.txt"
    DOMAIN_IP_FILENAME = "domains_ips.csv"
    UNRESOLVED_FILENAME = "unresolved.txt"


    def __init__(self, input_file, output_path, verbose):
        self.input_file = input_file
        self.output_path = output_path

        self.log = Lumberjack(False, verbose)

        if not os.path.exists(self.output_path):
            self.log.error("Folder {} not found".format(self.output_path))
            sys.exit(1)

        self.domains = {
            "resolved": {},
            "unresolved": []
        }

        self.log.info("Starting resolving domains...")


    def main(self):
        with open(self.input_file, "r") as domain_file:
            for domain in domain_file:
                self.check_domain(domain.strip())

        self.log.debug(self.domains)

        self.create_files()


    def check_domain(self, domain):
        resolver = dns.resolver.Resolver()
        resolver.nameservers = ["4.2.2.1", "8.8.8.8"]

        try:
            ips = resolver.resolve(domain, "A")
            if ips:

                self.log.info("Resolved " + domain)
                self.domains["resolved"][domain] = [ips[0].to_text()]
                self.log.debug("%s: %s" % (domain, ips[0].to_text()))
                for index, ip in enumerate(ips):
                    if index != 0:
                        self.domains["resolved"][domain] += [ip.to_text()]
                        self.log.debug("%s: %s" % (domain, ip.to_text()))
                # Remove duplicates
                self.domains["resolved"][domain] = list(set(self.domains["resolved"][domain]))
            else:
                self.domains["unresolved"] += [domain]
                self.log.warning("Could not resolve " + domain)

        except:
            self.domains["unresolved"] += [domain]
            self.log.warning("Could not resolve " + domain)


    def create_files(self):
        with open(os.path.join(self.output_path, self.IP_FILENAME), "w") as ip_file:
            all_ips = []
            for domain, ips in self.domains["resolved"].items():
                for ip in ips:
                    if ip not in all_ips:
                        all_ips += [ip]
            all_ips = sorted(all_ips, key=ipaddress.IPv4Address)
            for ip in all_ips:
                ip_file.write(ip + "\n")

        with open(os.path.join(self.output_path, self.DOMAIN_IP_FILENAME), "w") as domain_ip_file:
            for domain, ips in self.domains["resolved"].items():
                domain_ip_file.write("{},{}\n".format(domain, "/".join(ips)))

        with open(os.path.join(self.output_path, self.UNRESOLVED_FILENAME), "w") as unresolved_file:
            for domain in self.domains["unresolved"]:
                unresolved_file.write(domain + "\n")
Esempio n. 2
0
class B_FRAME():
    def __init__(self, ip, port, username, password, debug=True):
        self.debug = debug
        self.log = Lumberjack("brute.log", self.debug)

        # True - x3270; False - s3270
        self.emulator = WrappedEmulator(True)

        self.ip = ip
        self.port = port
        self.username = username
        self.password = password

        time.sleep(2)

        self.connect()

        self.login()

        if self.debug:
            self.print_screen()

    def connect(self):
        self.log.info("Connecting to {}:{}".format(self.ip, self.port))

        self.emulator.connect("{}:{}".format(self.ip, self.port))
        self.emulator.send_enter()

        if not self.emulator.is_connected():
            self.log.error("Failed to connect")
            sys.exit(1)

        self.log.info("Connected successfully")

    def login(self):
        self.log.info("Loggin as " + self.username)

        self.emulator.move_to(0, 0)
        self.emulator.send_string(self.username)
        self.emulator.move_to(1, 1)
        self.emulator.send_string(self.password)

        self.emulator.send_enter()

        time.sleep(2)

    def get_screen_data(self):
        return self.emulator.exec_command(b'ASCII').data

    def print_screen(self):
        screen_data = self.get_screen_data()

        for line in screen_data:
            self.log.debug(line.decode())

    def disconnect(self):
        self.log.info("Disconnecting...")

        self.emulator.exec_command(b'DISCONNECT')

    def create_html(self, filename):
        self.log.debug("Creating HTML file")

        full_filename = "./html/{}/{}.html".format(self.username, filename)

        if os.path.isfile(full_filename):
            os.remove(full_filename)

        self.emulator.exec_command(
            "PRINTTEXT(HTML, file, {})".format(full_filename).encode())

    def test_command(self, command):
        if self.debug:
            self.log.debug("Testing command: " + command)

        self.emulator.move_to(10, 10)
        self.emulator.send_string(command)

        if self.debug:
            self.print_screen()

        self.emulator.send_enter()

        if self.debug:
            self.print_screen()

    def go_home(self):
        self.emulator.send_pf3()

        screen_data = self.get_screen_data()

        if b'SOME TEXT' not in screen_data[0]:
            self.log.warning("Filed to exit menu")

            self.disconnect()

            time.sleep(2)

            self.connect()
            time.sleep(2)

            self.login()
Esempio n. 3
0
def check_pwns(db_filename, htb_api, discord_token, channel_id):
    log = Lumberjack("log/check_pwns_events.log", True)

    db = SQLWizard(db_filename)

    htb_helper = HTBhelper("", "", htb_api)

    log.info("Getting new PWNs")
    users, roots = htb_helper.get_pwns()

    log.info("Got users: " + str(users))
    log.info("Got roots: " + str(roots))

    notification_list = []

    # TODO: Change this
    for user_pwn in users:
        username = user_pwn[0].strip().lower()
        box_name = user_pwn[1].strip().lower()

        found_user = db.select("*", "names",
                               "htb_name = '{}'".format(username))

        if not found_user:
            log.warning(
                "User {} was not found in the database".format(username))
            continue

        found_box = db.select("*", "boxes", "name = '{}'".format(box_name))

        if not found_box:
            log.warning(
                "Box {} was not found in the database".format(username))
            continue

        # check if already in root
        if username in found_box[0][6]:
            log.warning("User {} has got root {}".format(username, box_name))
            continue

        # check if already in user
        if username in found_box[0][5]:
            log.warning("User {} has got user {}".format(username, box_name))
            continue

        if found_box[0][3]:
            wts = found_box[0][3].replace(username + ",",
                                          "").replace(username, "")
        else:
            wts = "-"
        if found_box[0][4]:
            working = found_box[0][4].replace(username + ",",
                                              "").replace(username, "")
        else:
            working = "-"
        if found_box[0][5]:
            user = found_box[0][5].replace(username + ",",
                                           "").replace(username, "")
        else:
            user = "******"
        if found_box[0][6]:
            root = found_box[0][6].replace(username + ",",
                                           "").replace(username, "")
        else:
            root = "-"

        new_data = {}
        new_data["wts"] = wts if wts else "-"
        new_data["working"] = working if working else "-"
        new_data["user"] = user if user else "-"
        new_data["root"] = root if root else "-"

        if new_data["user"] and new_data["user"] != "-":
            new_data["user"] += "," + username
        else:
            new_data["user"] = username

        db.update(
            "boxes",
            OrderedDict([("wts", new_data["wts"]),
                         ("working", new_data["working"]),
                         ("user", new_data["user"]),
                         ("root", new_data["root"])]),
            "name = '{}'".format(box_name))

        log.info("Parsed {} on {} ({})".format("user", box_name, username))
        notification_list.append([username, "user", box_name])

    for root_pwn in roots:
        username = root_pwn[0].strip().lower()
        box_name = root_pwn[1].strip().lower()

        found_user = db.select("*", "names",
                               "htb_name = '{}'".format(username))

        if not found_user:
            log.warning(
                "User {} was not found in the database".format(username))
            continue

        found_box = db.select("*", "boxes", "name = '{}'".format(box_name))

        if not found_box:
            log.warning(
                "Box {} was not found in the database".format(username))
            continue

        # check if already in root
        if username in found_box[0][6]:
            log.warning("User {} has got root {}".format(username, box_name))
            continue

        if found_box[0][3]:
            wts = found_box[0][3].replace(username + ",",
                                          "").replace(username, "")
        else:
            wts = "-"
        if found_box[0][4]:
            working = found_box[0][4].replace(username + ",",
                                              "").replace(username, "")
        else:
            working = "-"
        if found_box[0][5]:
            user = found_box[0][5].replace(username + ",",
                                           "").replace(username, "")
        else:
            user = "******"
        if found_box[0][6]:
            root = found_box[0][6].replace(username + ",",
                                           "").replace(username, "")
        else:
            root = "-"

        new_data = {}
        new_data["wts"] = wts if wts else "-"
        new_data["working"] = working if working else "-"
        new_data["user"] = user if user else "-"
        new_data["root"] = root if root else "-"

        if new_data["root"] and new_data["root"] != "-":
            new_data["root"] += "," + username
        else:
            new_data["root"] = username

        db.update(
            "boxes",
            OrderedDict([("wts", new_data["wts"]),
                         ("working", new_data["working"]),
                         ("user", new_data["user"]),
                         ("root", new_data["root"])]),
            "name = '{}'".format(box_name))

        log.info("Parsed {} on {} ({})".format("root", box_name, username))
        notification_list.append([username, "root", box_name])

    if notification_list:
        tmp_notification_list = [[channel_id] + x for x in notification_list]
        PWNgress(discord_token, db_filename, tmp_notification_list)