Пример #1
0
    def _eval_option(self, one):
        batch_words = []
        if os.path.exists(one.strip()):
            gprint("load file form : %s" % one)
            with open(one.strip()) as fp:
                for l in fp:
                    o = l.strip()
                    batch_words.append(o)
        else:
            try:
                if '[[' in one and ']]' in one:
                    # gprint("detect file in code")
                    tone = one
                    for d in self._get_c(tone):
                        # gprint("patch %s" % d)
                        one = self._replace_c(one, d)

                gprint("try parse from python code:\n %s" %
                       colored(one, 'blue'))
                w = eval(one)
                if isinstance(w, list):
                    batch_words = w
            except Exception as e:
                rprint(str(e))
                gprint("only as words")
                batch_words = one.split()
        return batch_words
Пример #2
0
 def do_add(self, args):
     target = None
     passwd = 'chopper'
     encoding = 'UTF-8'
     type = None
     All = args.split()
     if len(All) < 3:
         rprint(
             "at least [target] [passwd] | like  http://localhost/1.php chopper "
         )
         return
     for w in All:
         if w.startswith("http"):
             target = w
             if target.endswith(".php"):
                 type = 'php'
             elif target.endswith(".jsp"):
                 type = 'jsp'
             elif target.endswith(".asp"):
                 type = 'asp'
         elif w.lower() in ['utf-8', 'gbk']:
             encoding = w
         elif w in ['php', 'jsp', 'asp', 'aspx']:
             type = w
         else:
             passwd = w
     checken = Checken(target=target,
                       passwd=passwd,
                       encoding=encoding,
                       type=type)
     with use_db() as db:
         checken.save(db)
     gprint(type, target, passwd, encoding)
Пример #3
0
 def callback_out(future, url=''):
     try:
         r = future.result(timeout=timeout)
         result_zusammen[url] = r
         callback(r)
     except futures.TimeoutError:
         rprint('timeout:', url)
Пример #4
0
    def search(self, *key):
        gprint(key[-1])
        if not self.cookies:
            self.load_session()

        res = requests.get("https://github.com/{}/product".format(self.user))
        self.cookies = res.cookies.get_dict()
        gprint(str(self.cookies))
        url = "https://github.com/search?q={}&type=code".format("+".join(key))
        self.sess.driver.get(url)
        res = self.sess.driver.page_source
        b = BeautifulSoup(res, 'lxml')

        codes = b.select(".code-list-item")
        if len(codes) > 0:
            gprint("Found : %d" % len(codes))
        else:
            gprint("Not found:")
            rprint(b.text.replace("\n", ""))
            # for i in b.select("a"):
            # gprint(str(i))
        ss = {}
        for code in codes:

            k = code.select(".text-bold")[0].text
            v = {
                colored(str(n), 'green'): i.text.replace("\n", "")
                for n, i in enumerate(code.select("td.blob-code"))
            }
            gprint(colored(k, "blue"))
            Tprint(v)
Пример #5
0
 def load_session(self):
     gprint(" load cookies from")
     cookies = pickle.load(open(self.LOGIN_INFO_SESSION, "rb"))
     self.flow.go(self.main_url)
     self.flow.screenshot("beforelogin")
     for cookie in cookies:
         gprint(str(cookie))
         try:
             self.flow.phantom.add_cookie(cookie)
         except Exception as e:
             rprint("load cookie failed. try --login")
Пример #6
0
    def do_load(self, path):
        if path == 'last':
            fs = sorted(os.listdir(BP_SESSION_DIR))
            if len(fs) > 0:
                path = os.path.join(BP_SESSION_DIR, fs[-1])

        if os.path.exists(path):
            with open(path, 'rb') as fp:
                Bp._brute_req = fp.read()
            gprint("Load ok")
        else:
            rprint("Not found : %s" % path)
Пример #7
0
def load_and_run_test(prepare_test_info, *module_names, **test_options):
    """
        thread: int (only use for plugin set)
    """
    if not len(prepare_test_info) > 0:
        rprint("No targets")
        return

    for name in module_names:
        Obj = load(name)
        if not Obj: continue
        for info in prepare_test_info:
            t = TestBase(info)
        TestBase.run(Obj)
Пример #8
0
    def selector(self, x, time=0):
        try:
            r = self.waiter.until(
                EC.presence_of_element_located((By.CSS_SELECTOR, x)))
            if r:
                return r
        except TimeoutException as e:
            if isinstance(time, int) and time > 3:
                rprint("not found : %s , you can see error page in " % x +
                       colored("/tmp/TimeoutException.png ", 'red'))

                self.flow.screenshot("TimeoutException")
                with open("/tmp/TimeoutException.html", "w") as fp:
                    fp.write(self.flow.html())
                # raise TimeoutException("time out not found : %s" %x)
                sys.exit(0)
            return self.selector(x, time + 1)
Пример #9
0
 def do_summary(self, args):
     if not args:
         t = [[i] + n for i, n in enumerate(self._res)]
         t.insert(0, ['id'] + ['args'
                               for i in range(len(t[0]) - 2)] + ['lens'])
         print(tabulate(t, headers='firstrow'))
         urgly = t[0]
         tc = Counter([i[-1] for i in t])
         v = min(tc, key=lambda x: tc[x])
         for i in t:
             if i[-1] == v:
                 if i != urgly:
                     gprint("---- focus on ---- ")
                     print(tabulate([urgly]))
                     break
     else:
         try:
             w = self._res_detail[int(args)]
             gprint(BS(w, 'lxml').text)
         except Exception as e:
             rprint(str(e))
             gprint("Must int ")
Пример #10
0
 def summary(self, futu):
     res, args = futu.result()
     if isinstance(res, Exception):
         rprint(str(res))
         rprint(str(args))
     else:
         w = len(res.content)
         self._res.append(args + [w])
         self._res_detail.append(res.text)
     self.finish_count += 1
     if len(self.futures) == self.finish_count:
         # os.system("tput sc")
         # os.system("tput cup 0 0")
         print("\r%s" % colored(self.prompt, 'red'), end='')
         # os.system("tput rc")
     else:
         # os.system("tput sc")
         # os.system("tput cup 0 0")
         if int(self.finish_count % 20) == 0:
             print("\r%d/%d%s" % (self.finish_count, len(
                 self.futures), colored(self.prompt, 'red')),
                   end='')
Пример #11
0
    def search(self, key, page=0):
        search_input = self.selector("input#q")
        search_input.send_keys("{}\n".format(key))
        self.flow.screenshot("mod")
        check_if_found = self.selector(".list_jg")
        check_if_found = check_if_found.get_attribute('outerHTML')
        num = 0
        try:
            num = re.findall(r'Total\ results:\s(\d+)', check_if_found)[0]
            gprint("found result in :%s = %s" % (key, num))
            num = int(num)
            if num == 0:
                return
        except IndexError:
            self.flow.screenshot("error.png")
            rprint("page load error !! see /tmp/error.png ")
            return
        self.selector(".list_mod")
        res = self.flow.html()
        iis = []
        iis += self.parse(res)
        gprint("Done %d" % len(iis))
        if len(iis) >= num:
            return iis

        gprint(" page 1")
        if page and isinstance(page, int):
            for i in range(page):
                next_page = self.selector("a.next_page")
                next_page.click()
                self.selector(".list_mod")
                res = self.flow.html()
                gprint(" page " + str(i + 2))
                iis += self.parse(res)

        return iis
Пример #12
0
 def try_run(*args, **kargs):
     try:
         return Obj.test(*args, **kargs)
     except Exception as e:
         rprint(e)
         print_exception(e)