コード例 #1
0
ファイル: run_server.py プロジェクト: josephrexme/canari
def run(args):
    opts = parse_args(args)

    fix_pypath()

    if opts.port == -1:
        opts.port = 443 if not opts.disable_ssl else 80

    if os.name == 'posix' and os.geteuid() and (opts.port <= 1024
                                                or opts.enable_privileged):
        print('You must run this server as root to continue...')
        os.execvp('sudo', ['sudo'] + sys.argv)

    fix_binpath(config['default/path'])

    transforms = {}

    print('Loading transform packages...')

    try:
        for pkg_name in opts.packages:

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

            print('Loading transform package %s' % pkg_name)

            transform_package = import_package(pkg_name)

            for transform_name in transform_package.__all__:

                transform_name = ('%s.%s' % (pkg_name, transform_name))
                transform_module = import_transform(transform_name)

                if not hasattr(transform_module, 'dotransform'):
                    continue

                if os.name == 'posix' and hasattr(transform_module.dotransform, 'privileged') and \
                        (os.geteuid() or not opts.enable_privileged):
                    continue

                if hasattr(transform_module.dotransform,
                           'remote') and transform_module.dotransform.remote:
                    print('Loading %s at /%s...' %
                          (transform_name, transform_name))
                    inputs = []
                    if hasattr(transform_module.dotransform, 'inputs'):
                        for category, entity_type in transform_module.dotransform.inputs:
                            inputs.append(entity_type.type)
                            inputs.append(entity_type._v2type_)
                    transforms['/%s' %
                               transform_name] = (transform_module.dotransform,
                                                  inputs)

    except Exception, e:
        print(str(e))
        print('Failed to load transforms... exiting')
        exit(-1)
コード例 #2
0
ファイル: run_server.py プロジェクト: digital4rensics/canari
def run(args):

    opts = parser.parse_args(args)

    fix_pypath()

    if opts.port == -1:
        opts.port = 443 if not opts.disable_ssl else 80

    if name == "posix" and geteuid() and (opts.port <= 1024 or opts.enable_privileged):
        print("You must run this server as root to continue...")
        execvp("sudo", ["sudo"] + list(argv))

    fix_binpath(config["default/path"])

    transforms = {}

    print("Loading transform packages...")

    try:
        for p in opts.packages:

            if not p.endswith(".transforms"):
                p = "%s.transforms" % p

            print("Loading transform package %s" % p)

            m = import_package(p)

            for t in m.__all__:

                t = "%s.%s" % (p, t)
                m2 = import_transform(t)

                if not hasattr(m2, "dotransform"):
                    continue

                if (
                    name == "posix"
                    and hasattr(m2.dotransform, "privileged")
                    and (geteuid() or not opts.enable_privileged)
                ):
                    continue

                if hasattr(m2.dotransform, "remote") and m2.dotransform.remote:
                    print("Loading %s at /%s..." % (t, t))
                    if hasattr(m2.dotransform, "inputs"):
                        inputs = [e[1]("").type for e in m2.dotransform.inputs]
                        inputs = inputs + [i.split(".")[-1] for i in inputs]
                        transforms["/%s" % t] = (m2.dotransform, inputs)
                    else:
                        transforms["/%s" % t] = (m2.dotransform, [])

    except Exception, e:
        print(str(e))
        print("Failed to load transforms... exiting")
        exit(-1)
コード例 #3
0
ファイル: run_server.py プロジェクト: delawaredfir/canari
def run(args):

    opts = parse_args(args)

    fix_pypath()

    if opts.port == -1:
        opts.port = 443 if not opts.disable_ssl else 80

    if os.name == 'posix' and os.geteuid() and (opts.port <= 1024 or opts.enable_privileged):
        print ('You must run this server as root to continue...')
        os.execvp('sudo', ['sudo'] + sys.argv)

    fix_binpath(config['default/path'])


    transforms = {}

    print ('Loading transform packages...')

    try:
        for p in opts.packages:

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

            print ('Loading transform package %s' % p)

            m = import_package(p)

            for t in m.__all__:

                t = ('%s.%s' % (p, t))
                m2 = import_transform(t)

                if not hasattr(m2, 'dotransform'):
                    continue

                if os.name == 'posix' and hasattr(m2.dotransform, 'privileged') and (os.geteuid() or not opts.enable_privileged):
                    continue

                if hasattr(m2.dotransform, 'remote') and m2.dotransform.remote:
                    print ('Loading %s at /%s...' % (t, t))
                    if hasattr(m2.dotransform, 'inputs'):
                        inputs = [e[1]('').type for e in m2.dotransform.inputs]
                        inputs = inputs + [i.split('.')[-1] for i in inputs]
                        transforms['/%s' % t] = (m2.dotransform, inputs)
                    else:
                        transforms['/%s' % t] = (m2.dotransform, [])

    except Exception, e:
        print (str(e))
        print ('Failed to load transforms... exiting')
        exit(-1)
コード例 #4
0
ファイル: shell.py プロジェクト: andreoli/canari
def run(args):

    opts = parser.parse_args(args)

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

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

    mtgsh = MtgConsole(opts.package)
    mtgsh.interact(highlight('Welcome to Canari.', 'green', True))
コード例 #5
0
ファイル: run_server.py プロジェクト: andreoli/canari
def run(args):
    opts = parse_args(args)

    fix_pypath()

    if opts.port == -1:
        opts.port = 443 if not opts.disable_ssl else 80

    if os.name == 'posix' and os.geteuid() and (opts.port <= 1024 or opts.enable_privileged):
        print ('You must run this server as root to continue...')
        os.execvp('sudo', ['sudo'] + sys.argv)

    fix_binpath(config['default/path'])

    transforms = {}

    print ('Loading transform packages...')

    try:
        for pkg_name in opts.packages:

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

            print ('Loading transform package %s' % pkg_name)

            transform_package = import_package(pkg_name)

            for transform_name in transform_package.__all__:

                transform_name = ('%s.%s' % (pkg_name, transform_name))
                transform_module = import_transform(transform_name)

                if not hasattr(transform_module, 'dotransform'):
                    continue

                if os.name == 'posix' and hasattr(transform_module.dotransform, 'privileged') and \
                        (os.geteuid() or not opts.enable_privileged):
                    continue

                if hasattr(transform_module.dotransform, 'remote') and transform_module.dotransform.remote:
                    print ('Loading %s at /%s...' % (transform_name, transform_name))
                    inputs = []
                    if hasattr(transform_module.dotransform, 'inputs'):
                        for category, entity_type in transform_module.dotransform.inputs:
                            inputs.append(entity_type.type)
                            inputs.append(entity_type._v2type_)
                    transforms['/%s' % transform_name] = (transform_module.dotransform, inputs)

    except Exception, e:
        print (str(e))
        print ('Failed to load transforms... exiting')
        exit(-1)
コード例 #6
0
def run(args):

    opts = parser.parse_args(args)

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

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

    mtgsh = MtgConsole(opts.package)
    mtgsh.interact(highlight('Welcome to Canari.', 'green', True))
コード例 #7
0
ファイル: run_transform.py プロジェクト: josephrexme/canari
def run(args):

    [transform, params, value,
     fields] = parseargs(['canari %s' % cmd_name(__name__)] + args)

    transform_module = None

    fix_binpath(config['default/path'])
    try:
        transform_module = import_transform(transform)

        if os.name == 'posix' and hasattr(transform_module.dotransform,
                                          'privileged') and os.geteuid():
            rc = sudo(sys.argv)
            if rc == 1:
                message(MaltegoTransformResponseMessage() +
                        UIMessage('User cancelled transform.'))
            elif rc == 2:
                message(MaltegoTransformResponseMessage() +
                        UIMessage('Too many incorrect password attempts.'))
            elif rc:
                message(MaltegoTransformResponseMessage() +
                        UIMessage('Unknown error occurred.'))
            exit(0)

        if hasattr(transform_module, 'onterminate'):
            onterminate(transform_module.onterminate)
        else:
            transform_module.__setattr__('onterminate', lambda *args: exit(-1))

        input_entity = to_entity(guess_entity_type(transform_module, fields),
                                 value, fields)

        msg = transform_module.dotransform(
            MaltegoTransformRequestMessage(value, fields, params,
                                           input_entity),
            MaltegoTransformResponseMessage()) if get_transform_version(
                transform_module.dotransform
            ) == 2 else transform_module.dotransform(
                MaltegoTransformRequestMessage(value, fields, params,
                                               input_entity),
                MaltegoTransformResponseMessage(), config)

        if isinstance(msg, MaltegoTransformResponseMessage):
            message(msg)
        elif isinstance(msg, basestring):
            raise MaltegoException(msg)
        else:
            raise MaltegoException(
                'Could not resolve message type returned by transform.')
    except MaltegoException, me:
        croak(str(me))
コード例 #8
0
def run(args):

    [transform, params, value, fields] = parseargs(['canari %s' % cmd_name(__name__)] + args)

    m = None
    pysudo = path.join(get_bin_dir(), 'pysudo')

    fix_binpath(config['default/path'])
    try:
        m = import_transform(transform)

        if name == 'posix' and hasattr(m.dotransform, 'privileged') and geteuid():
# Keep it for another day
#            if platform == 'darwin':
#                execvp(
#                    'osascript',
#                    ['osascript', '-e', 'do shell script "%s" with administrator privileges' % ' '.join(sys.argv)]
#                )
#            if sys.platform.startswith('linux') and path.exists("/usr/bin/gksudo"):
#                execvp('/usr/bin/gksudo', ['/usr/bin/gksudo'] + list(sys.argv))
#            else:
            execvp(pysudo, [pysudo] + list(argv))
            exit(-1)

        if hasattr(m, 'onterminate'):
            onterminate(m.onterminate)
        else:
            m.__setattr__('onterminate', lambda *args: exit(-1))

        msg = m.dotransform(
            type(
                'MaltegoTransformRequestMessage',
                (object,),
                    {
                    'value' : value,
                    'fields' : fields,
                    'params' : params
                }
            )(),
            MaltegoTransformResponseMessage()
        )

        if isinstance(msg, MaltegoTransformResponseMessage):
            message(msg)
        elif isinstance(msg, basestring):
            raise MaltegoException(msg)
        else:
            raise MaltegoException('Could not resolve message type returned by transform.')
    except MaltegoException, me:
        croak(str(me))
コード例 #9
0
ファイル: shell.py プロジェクト: liorvh/canari
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)
コード例 #10
0
def run(args):

    [transform, params, value, fields] = parseargs(['canari %s' % cmd_name(__name__)] + args)

    m = None

    fix_binpath(config['default/path'])
    try:
        m = import_transform(transform)

        if os.name == 'posix' and hasattr(m.dotransform, 'privileged') and os.geteuid():
            rc = sudo(sys.argv)
            if rc == 1:
                message(MaltegoTransformResponseMessage() + UIMessage('User cancelled transform.'))
            elif rc == 2:
                message(MaltegoTransformResponseMessage() + UIMessage('Too many incorrect password attempts.'))
            elif rc:
                message(MaltegoTransformResponseMessage() + UIMessage('Unknown error occurred.'))
            exit(0)

        if hasattr(m, 'onterminate'):
            onterminate(m.onterminate)
        else:
            m.__setattr__('onterminate', lambda *args: exit(-1))

        msg = m.dotransform(
            type(
                'MaltegoTransformRequestMessage',
                (object,),
                    {
                    'value' : value,
                    'fields' : fields,
                    'params' : params
                }
            )(),
            MaltegoTransformResponseMessage()
        )

        if isinstance(msg, MaltegoTransformResponseMessage):
            message(msg)
        elif isinstance(msg, basestring):
            raise MaltegoException(msg)
        else:
            raise MaltegoException('Could not resolve message type returned by transform.')
    except MaltegoException, me:
        croak(str(me))
コード例 #11
0
ファイル: shell.py プロジェクト: reenberg/canari
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)
コード例 #12
0
ファイル: run_server.py プロジェクト: Silobreaker/canari
def run_server(args):
    fix_binpath(config["default/path"])
    opts = parse_args(args)

    if opts.port == -1:
        opts.port = 443 if not opts.disable_ssl else 80

    if os.name == "posix" and os.geteuid() and (opts.port <= 1024 or opts.enable_privileged):
        print("You must run this server as root to continue...")
        os.execvp("sudo", ["sudo"] + sys.argv)

    transforms = {}

    print("Loading transform packages...")

    try:
        for pkg_name in opts.packages:

            t = TransformDistribution(pkg_name)

            print("Loading transform package %s" % pkg_name)
            for transform_module in t.remote_transforms:
                transform_name = transform_module.__name__

                if (
                    os.name == "posix"
                    and hasattr(transform_module.dotransform, "privileged")
                    and (os.geteuid() or not opts.enable_privileged)
                ):
                    continue

                if hasattr(transform_module.dotransform, "remote") and transform_module.dotransform.remote:
                    print("Loading %s at /%s..." % (transform_name, transform_name))
                    inputs = []
                    if hasattr(transform_module.dotransform, "inputs"):
                        for category, entity_type in transform_module.dotransform.inputs:
                            inputs.append(entity_type._type_)
                            inputs.append(entity_type._v2type_)
                    transforms["/%s" % transform_name] = (transform_module.dotransform, inputs)

    except Exception, e:
        print(str(e))
        print("Failed to load transforms... exiting")
        exit(-1)
コード例 #13
0
ファイル: run_transform.py プロジェクト: andreoli/canari
def run(args):

    [transform, params, value, fields] = parseargs(['canari %s' % cmd_name(__name__)] + args)

    transform_module = None

    fix_binpath(config['default/path'])
    try:
        transform_module = import_transform(transform)

        if os.name == 'posix' and hasattr(transform_module.dotransform, 'privileged') and os.geteuid():
            rc = sudo(sys.argv)
            if rc == 1:
                message(MaltegoTransformResponseMessage() + UIMessage('User cancelled transform.'))
            elif rc == 2:
                message(MaltegoTransformResponseMessage() + UIMessage('Too many incorrect password attempts.'))
            elif rc:
                message(MaltegoTransformResponseMessage() + UIMessage('Unknown error occurred.'))
            exit(0)

        if hasattr(transform_module, 'onterminate'):
            onterminate(transform_module.onterminate)
        else:
            transform_module.__setattr__('onterminate', lambda *args: exit(-1))

        input_entity = to_entity(guess_entity_type(transform_module, fields), value, fields)

        msg = transform_module.dotransform(
            MaltegoTransformRequestMessage(value, fields, params, input_entity),
            MaltegoTransformResponseMessage()
        ) if get_transform_version(transform_module.dotransform) == 2 else transform_module.dotransform(
            MaltegoTransformRequestMessage(value, fields, params, input_entity),
            MaltegoTransformResponseMessage(),
            config
        )

        if isinstance(msg, MaltegoTransformResponseMessage):
            message(msg)
        elif isinstance(msg, basestring):
            raise MaltegoException(msg)
        else:
            raise MaltegoException('Could not resolve message type returned by transform.')
    except MaltegoException, me:
        croak(str(me))
コード例 #14
0
def run(args):

    [transform, params, value, fields] = parseargs(['canari %s' % cmd_name(__name__)] + args)

    m = None
    fix_binpath(config['default/path'])
    try:
        m = import_transform(transform)

        if name == 'posix' and hasattr(m.dotransform, 'privileged') and geteuid():
            execvp('sudo', ['sudo'] + list(argv))
            exit(-1)

        if hasattr(m, 'onterminate'):
            onterminate(m.onterminate)
        else:
            m.__setattr__('onterminate', lambda *args: exit(-1))

        msg = m.dotransform(
            type(
                'MaltegoTransformRequestMessage',
                (object,),
                    {
                    'value' : value,
                    'fields' : fields,
                    'params' : params
                }
            )(),
            MaltegoTransformResponseMessage()
        )

        if isinstance(msg, MaltegoTransformResponseMessage):
            console_message(msg)
        elif isinstance(msg, basestring):
            raise MaltegoException(msg)
        else:
            raise MaltegoException('Could not resolve message type returned by transform.')
    except MaltegoException, me:
        croak(str(me))
コード例 #15
0
def run_transform(opts):
    fix_binpath(config['default/path'])
    local_transform_runner(opts.transform, opts.value, opts.fields, opts.params, config, message)