Exemple #1
0
    def __call__(self, value, *args, **kwargs):
        if os.name == 'posix' and hasattr(self.mod.dotransform, 'privileged') and os.geteuid():
            print highlight("Need to be root to run this transform... sudo'ing...", 'green', True)
            os.execvp('sudo', self.sudoargs)
            return

        local_transform_runner(self.mod, value, kwargs, list(args), config, message_writer=console_message)
Exemple #2
0
def list_transforms(opts):

    try:
        with PushDir(opts.working_dir or CanariProject().src_dir):
            transform_package = TransformDistribution(opts.package)
            for transform_class in transform_package.transforms:
                transform = transform_class()
                print('`- %s: %s' % (highlight(transform.name, 'green', True), transform.description))
                print(highlight('  `- Maltego identifiers:', 'black', True))
                print('    `- %s applies to %s in set %s' % (
                    highlight(transform.name, 'red', False),
                    highlight(transform.input_type._type_, 'red', False),
                    highlight(transform.transform_set, 'red', False)
                ))
                print('')
    except ValueError, e:
        print(e)
        exit(-1)
Exemple #3
0
def console_writer(msg, tab=-1):
    """
    Internal API: Returns a prettified tree-based output of an XML message for debugging purposes. This helper function
    is used by the debug-transform command.
    """
    tab += 1

    if isinstance(msg, Model):
        msg = fromstring(msg.render(fragment=True))

    print('%s`- %s: %s %s' % (
        '  ' * tab,
        highlight(msg.tag, None, True),
        highlight(msg.text, 'red', False) if msg.text is not None else '',
        highlight(msg.attrib, 'green', True) if msg.attrib.keys() else ''
    ))
    for c in msg.getchildren():
        print('  %s`- %s: %s %s' % (
            '  ' * tab,
            highlight(c.tag, None, True),
            highlight(c.text, 'red', False) if c.text is not None else '',
            highlight(c.attrib, 'green', True) if c.attrib.keys() else ''
        ))
        for sc in c.getchildren():
            tab += 1
            console_writer(sc, tab)
            tab -= 1
Exemple #4
0
def list_transforms(args):

    opts = parse_args(args)

    try:
        with pushd(opts.working_dir or os.getcwd()):
            transform_package = TransformDistribution(opts.package)
            for t in transform_package.transforms:
                print('`- %s: %s' % (highlight(
                    t.__name__, 'green', True), t.dotransform.description))
                print(highlight('  `- Maltego identifiers:', 'black', True))
                for uuid, (input_set,
                           input_type) in zip(t.dotransform.uuids,
                                              t.dotransform.inputs):
                    print '    `- %s applies to %s in set %s' % (
                        highlight(uuid, 'red', False),
                        highlight(input_type._type_, 'red',
                                  False), highlight(input_set, 'red', False))
                print ''
    except ValueError, e:
        print str(e)
        exit(-1)
Exemple #5
0
def shell(opts):

    set_canari_mode(CanariMode.LocalShellDebug)

    if not opts.package.endswith('transforms'):
        opts.package = '%s.transforms' % opts.package

    try:
        transform_package = TransformDistribution(opts.package)
        with PushDir(opts.working_dir or transform_package.default_prefix):
            mtg_console = MtgConsole(transform_package.transforms, auto_sudo=opts.sudo)
            mtg_console.interact(highlight('Welcome to Canari %s.' % canari.__version__, 'green', True))
    except ValueError, e:
        print str(e)
        exit(-1)
Exemple #6
0
def shell(opts):

    fix_binpath(config['default/path'])
    fix_pypath()

    if not opts.package.endswith('transforms'):
        opts.package = '%s.transforms' % opts.package

    try:
        t = TransformDistribution(opts.package)
        with pushd(opts.working_dir or t.default_prefix):
            mtg_console = MtgConsole(opts.package)
            mtg_console.interact(highlight('Welcome to Canari %s.' % canari.__version__, 'green', True))
    except ValueError, e:
        print str(e)
        exit(-1)
Exemple #7
0
def console_writer(msg, tab=-1):
    """
    Internal API: Returns a prettified tree-based output of an XML message for debugging purposes. This helper function
    is used by the debug-transform command.
    """
    tab += 1

    if isinstance(msg, Model):
        msg = fromstring(msg.render(fragment=True))

    print('%s`- %s: %s %s' %
          ('  ' * tab, highlight(msg.tag, None, True),
           highlight(msg.text, 'red', False) if msg.text is not None else '',
           highlight(msg.attrib, 'green', True) if msg.attrib.keys() else ''))
    for c in msg.getchildren():
        print('  %s`- %s: %s %s' %
              ('  ' * tab, highlight(c.tag, None, True),
               highlight(c.text, 'red', False) if c.text is not None else '',
               highlight(c.attrib, 'green', True) if c.attrib.keys() else ''))
        for sc in c.getchildren():
            tab += 1
            console_writer(sc, tab)
            tab -= 1
Exemple #8
0
def sudo():
    print highlight("Need to be root to run this transform... sudo'ing...", 'green', True)
    sys.argv.insert(0, 'sudo')
    os.execvp(sys.argv[0], sys.argv)
Exemple #9
0
def list_commands(opts):
    cmds = canari_main.subparsers.choices
    for name, cmd in sorted(cmds.iteritems()):
        print('%s - %s' % (highlight(name, 'green', True), cmd.description))
Exemple #10
0
def list_commands(opts):
    cmds = canari_main.subparsers.choices
    for name, cmd in sorted(cmds.iteritems()):
        print ('%s - %s' % (highlight(name, 'green', True), cmd.description))
Exemple #11
0
def list_commands(opts):
    cmds = canari_main.subparsers.choices
    k = cmds.keys()
    k.sort()
    for i in k:
        print('%s - %s' % (highlight(i, 'green', True), cmds[i].description))
Exemple #12
0
def list_commands(opts):
    cmds = canari_main.subparsers.choices
    k = cmds.keys()
    k.sort()
    for i in k:
        print ('%s - %s' % (highlight(i, 'green', True), cmds[i].description))