Esempio n. 1
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)
Esempio n. 2
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
Esempio n. 3
0
    def do_cmd(self):
        local_server = 'server'
        self.show()
        while 1:
            self.prompt = colored("(%s)" % local_server, 'blue') + colored(
                self.pwd, 'red', attrs=['underline'])
            os.system('tput cup %d 0' % self.SIZE[0])
            res = input(self.prompt).strip()

            if res == 'exit':
                return True
            elif res == 'local':
                local_server = 'local'
                self.flush()
                continue
            elif res == 'server':
                local_server = 'server'
                self.flush()
                continue
            elif res.startswith("upload"):
                files = res.split()[1:]
                for file in files:
                    if os.path.exists(file):
                        self.upload(file)
                self.flush()
                self.ls(self.pwd)
                self.show()
                continue

            self.flush()
            if local_server == 'local':
                try:
                    res = os.popen(res).read()
                    err = ''
                except Exception as e:
                    err = str(e)
            else:
                res, err = self.cmd(res)

            if err:
                self.cmd_result = err
            else:
                self.cmd_result = res
            self.show()
Esempio n. 4
0
 def __init__(self, *args, **kargs):
     super().__init__(*args, **kargs)
     self.prompt = colored("(Bp)", 'red')
     self.thread = 10
     BPData.add_target("Unknow")
     self._exe = None
     self._res = []
     self._res_detail = []
     self.proxy = 'socks5://127.0.0.1:1080'
     self.futures = []
     self.finish_count = 0
Esempio n. 5
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='')
Esempio n. 6
0
 def __init__(self):
     super().__init__()
     self.prompt = colored('(Dolch)', 'red')
Esempio n. 7
0
    def run(cls, Obj):
        TestBase.process_now = 0

        def try_run(*args, **kargs):
            try:
                return Obj.test(*args, **kargs)
            except Exception as e:
                rprint(e)
                print_exception(e)

        test_if_same = set()
        result_zusammen = dict()
        hs = []
        for i in cls.ins:
            if (i.target.ip + i.target.ports) in test_if_same: continue
            if '/' in i.target.ports:
                i.target.port = i.target.ports.split("/")[0].strip()
            else:
                i.target.port = i.target.ports.strip()
            test_if_same.add(i.target.ip + i.target.ports)
            hs.append(i.target)
        #hs = [i.target for i in cls.ins]
        process_len = len(hs)
        if hasattr(Obj, '__name__'):
            cls.log("use :", Obj.__name__)
        if hasattr(Obj, "mode"):
            if Obj.mode == "thread":
                thread = 7
                if hasattr(Obj, 'thread'):
                    thread = int(Obj.thread)
                if hasattr(Obj, 'timeout'):
                    timeout = Obj.timeout
                else:
                    timeout = 12
                gprint("set mode : %s" % Obj.mode)
                gprint("set thread : %d" % thread)
                gprint("set timeout : %d" % timeout)
                with ThreadPoolExecutor(max_workers=thread) as exe:
                    if not hasattr(Obj, 'callback'):
                        if hasattr(Obj, 'log') and Obj.log == 'simple':

                            callback = lambda x: gprint(
                                x, "\nfinish done | %s" % colored(
                                    "-" * 5 + '\n', 'blue'))
                        else:
                            callback = lambda x: TestBase.process_add(
                                process_len)
                    else:
                        callback = Obj.callback

                    def callback_out(future, url=''):
                        try:
                            r = future.result(timeout=timeout)
                            result_zusammen[url] = r
                            callback(r)
                        except futures.TimeoutError:
                            rprint('timeout:', url)

                    for h in hs:
                        future = exe.submit(try_run, h)
                        future.add_done_callback(
                            partial(callback_out, url=h.ip))

                if 'has' in Obj.__name__ or 'if' in Obj.__name__:
                    Tprint(result_zusammen, color='green', attrs=['bold'])
        else:
            res = try_run(hs)
            if res:
                cls.log(res)
Esempio n. 8
0
 def log(cls, *args, label='green', **kwargs):
     """
     l,g,bg
     """
     head = colored("[+]", 'red', attrs=['bold'])
     print(head, *args, **kwargs)
Esempio n. 9
0
from DrMoriaty.utils.log import lprint, gprint, rprint, colored, cprint, Tprint
from DrMoriaty.datas.data import Cache, Info
from DrMoriaty.setting import DB_FOFA

from functools import partial
from concurrent import futures
from concurrent.futures.thread import ThreadPoolExecutor
from .test import load, ls_mod
from traceback import print_exception

C = lambda x, y: colored(' ' + x + ' ', on_color='on_' + y) if x.strip(
) else ''


def search_in_db(key=None, *show_options):
    prepare_test_info = []
    DB_Handle = Cache(DB_FOFA)
    if not key:
        for i in DB_Handle.query(Info):
            lprint(title=i.title,
                   os=i.os,
                   ip=i.ip,
                   ports=i.ports,
                   time=i.ctime,
                   geo=i.geo,
                   body=i.body)
    else:

        if not show_options:

            def printer(i):
Esempio n. 10
0
    def __init__(self, target):

        self.prompt = colored(">")