Ejemplo n.º 1
0
    def __init__(self, module_name, have_items):
        self.module_name = module_name
        logs_dir = "{0}/logs/{1}".format(Registry().get('wr_path'),
                                         module_name)
        curdate = t("%Y-%m-%d")
        curtime = t("%H_%M_%S")

        if not os.path.exists(logs_dir):
            raise WSException(
                "LOGGER ERROR: Path {0} for module {1} not exists!".format(
                    logs_dir, module_name))

        if not os.path.exists("{0}/{1}".format(logs_dir, curdate)):
            os.mkdir("{0}/{1}".format(logs_dir, curdate))

        if not os.path.exists("{0}/{1}/{2}".format(logs_dir, curdate,
                                                   curtime)):
            os.mkdir("{0}/{1}/{2}".format(logs_dir, curdate, curtime))

        if have_items:
            self.items_dir = "{0}/{1}/{2}/items".format(
                logs_dir, curdate, curtime)
            os.mkdir(self.items_dir)

        self.logs_dir = "{0}/{1}/{2}".format(logs_dir, curdate, curtime)

        self.log_fh = open("{0}/run.log".format(self.logs_dir), "w")
Ejemplo n.º 2
0
    def __init__(self, module_name, have_items):
        self.module_name = module_name
        logs_dir = "{0}/logs/{1}".format(Registry().get('wr_path'),
                                         module_name)
        curdate = t("%Y-%m-%d")
        curtime = t("%H_%M_%S")

        if not os.path.exists(logs_dir):
            os.mkdir(logs_dir)

        log_date_path = "{0}/{1}".format(logs_dir, curdate)
        if not os.path.exists(log_date_path):
            os.mkdir(log_date_path)

        logs_time_path = "{0}/{1}".format(log_date_path, curtime)
        if not os.path.exists(logs_time_path):
            try:
                os.mkdir(logs_time_path)
            except OSError:
                logs_time_path += "_" + str(random.randint(100, 900))
                os.mkdir(logs_time_path)

        if have_items:
            self.items_dir = "{0}/items".format(logs_time_path)
            if not os.path.exists(self.items_dir):
                os.mkdir(self.items_dir)
            else:
                self.log(
                    "!!! Concurrency bug, logs/items content may be shuffled with other ws process !!!"
                )

        self.logs_dir = "{0}/{1}/{2}".format(logs_dir, curdate, curtime)

        self.log_fh = open("{0}/run.log".format(self.logs_dir), "w")
Ejemplo n.º 3
0
    def _logger(self, content=True, good_items=None, bad_items=None, in_output=None):
        """
        Check logger work
        :param content: We check content?
        :param good_items: This items was found
        :param bad_items: This items was not found
        :param in_output: check this phrases in output
        :return:
        """
        good_items = good_items or []
        bad_items = bad_items or []
        in_output = in_output or []

        logs_path = "{0}/logs/dafs/{1}/".format(wrpath, t("%Y-%m-%d"))
        time_dir = sorted(os.listdir(logs_path))[-1]

        run_log_data = file_get_contents("{0}/{1}/run.log".format(logs_path, time_dir))

        assert "Loaded {0} words from source".format(self._how_many_variants()) in run_log_data
        for item in in_output:
            assert item in run_log_data

        for item in bad_items:
            assert os.path.exists("{0}/{1}/items/{2}.txt".format(logs_path, time_dir, item))
            if self.check_method != 'head':
                assert ('<h1>Not Found</h1>' if content else '') in \
                       file_get_contents("{0}/{1}/items/{2}.txt".format(logs_path, time_dir, item))

        for item in good_items:
            assert os.path.exists("{0}/{1}/items/{2}.txt".format(logs_path, time_dir, item))
            if self.check_method != 'head':
                assert '<h1>Not Found</h1>' not in \
                       file_get_contents("{0}/{1}/items/{2}.txt".format(logs_path, time_dir, item))
Ejemplo n.º 4
0
    def _logger(self, first_stop=False):
        """
        Check logger work
        :param first_stop:
        :param selenium:
        :return:
        """
        logs_path = "{0}/logs/form-bruter/{1}/".format(wrpath, t("%Y-%m-%d"))
        time_dir = sorted(os.listdir(logs_path))[-1]

        run_log_data = file_get_contents("{0}/{1}/run.log".format(logs_path, time_dir))
        assert "Loaded 4 words from source" in run_log_data
        assert "qwerty" in run_log_data

        assert os.path.exists("{0}/{1}/items/123.txt".format(logs_path, time_dir))
        assert os.path.exists("{0}/{1}/items/test.txt".format(logs_path, time_dir))
        assert os.path.exists("{0}/{1}/items/qwerty.txt".format(logs_path, time_dir))
        assert os.path.exists("{0}/{1}/items/abcde.txt".format(logs_path, time_dir)) == (not first_stop)

        assert '<input type="password" name="password" />' \
               in file_get_contents("{0}/{1}/items/123.txt".format(logs_path, time_dir))
        assert '<input type="password" name="password" />' \
               in file_get_contents("{0}/{1}/items/test.txt".format(logs_path, time_dir))
        assert '<input type="password" name="password" />' \
               not in file_get_contents("{0}/{1}/items/qwerty.txt".format(logs_path, time_dir))
        assert 'Success!' in file_get_contents("{0}/{1}/items/qwerty.txt".format(logs_path, time_dir))
Ejemplo n.º 5
0
 def log(self, _str, new_str=True, _print=True):
     """ Write string in log and print it if need """
     self.log_fh.write((t("[%H:%M:%S] ") if new_str else '') + _str +
                       ('\n' if new_str else ''))
     self.log_fh.flush()
     if _print:
         if new_str:
             print _str
         else:
             print _str,
     sys.stdout.flush()
Ejemplo n.º 6
0
    def _check_logger(self):
        """Check logger work"""
        logs_path = "{0}/logs/cms/{1}/".format(wrpath, t("%Y-%m-%d"))
        time_dir = sorted(os.listdir(logs_path))[-1]

        run_log_data = file_get_contents("{0}/{1}/run.log".format(logs_path, time_dir))
        assert "Loaded {0} variants".format(self._how_many_variants()) in run_log_data
        if not self.selenium:
            for item in self.found_items:
                if self.check_method is not 'head':
                    assert item['sum'] == md5sum("{0}/{1}/items/{2}".format(logs_path, time_dir, item['log']))
Ejemplo n.º 7
0
 def log(self, _str, new_str=True, _print=True):
     """ Write string in log and print it if need """
     self.log_fh.write(
         (t("[%H:%M:%S] ") if new_str else '') + _str + ('\n' if new_str else '')
     )
     self.log_fh.flush()
     if _print:
         if new_str:
             print _str
         else:
             print _str,
     sys.stdout.flush()
Ejemplo n.º 8
0
    def __init__(self, module_name, have_items):
        self.module_name = module_name
        logs_dir = "{0}/logs/{1}".format(Registry().get('wr_path'), module_name)
        curdate = t("%Y-%m-%d")
        curtime = t("%H_%M_%S")

        if not os.path.exists(logs_dir):
            raise WSException("LOGGER ERROR: Path {0} for module {1} not exists!".format(logs_dir, module_name))

        if not os.path.exists("{0}/{1}".format(logs_dir, curdate)):
            os.mkdir("{0}/{1}".format(logs_dir, curdate))

        if not os.path.exists("{0}/{1}/{2}".format(logs_dir, curdate, curtime)):
            os.mkdir("{0}/{1}/{2}".format(logs_dir, curdate, curtime))

        if have_items:
            self.items_dir = "{0}/{1}/{2}/items".format(logs_dir, curdate, curtime)
            os.mkdir(self.items_dir)

        self.logs_dir = "{0}/{1}/{2}".format(logs_dir, curdate, curtime)

        self.log_fh = open("{0}/run.log".format(self.logs_dir), "w")
Ejemplo n.º 9
0
        for tmp in os.listdir(Registry().get('wr_path') + "/classes/modules/"):
            if tmp.count("Modules") or tmp.count(".pyc") or tmp.count(
                    "__init__") or tmp == "params":
                continue
            modules_list.append(tmp.replace(".py", ""))
        modules_list.sort()
        for module_name in modules_list:
            print("\t" + module_name)
    exit(1)

if module.logger_enable:
    Registry().set('logger',
                   Logger(module.logger_name, module.logger_have_items))

if module.time_count:
    print("Started module work at " + t("%Y-%m-%d %H:%M:%S"))
    start_time = int(time.time())

Registry().set('module', module)

parser = argparse.ArgumentParser(description="",
                                 prog="{0} {1}".format(sys.argv[0],
                                                       sys.argv[1]))
for option in module.options:
    parser.add_argument(*module.options[option].flags,
                        required=module.options[option].required,
                        help=module.options[option].description,
                        dest=module.options[option].name)

args = vars(parser.parse_args(sys.argv[2:]))
for option in args.keys():