Example #1
0
def create_profile(args):

    set_canari_mode(CanariMode.Local)

    opts = parse_args(args)
    current_dir = os.getcwd()
    try:
        with PushDir(opts.working_dir or current_dir):
            transform_package = TransformDistribution(opts.package)
            transform_package.create_profile(opts.working_dir, current_dir)
    except ValueError, e:
        print(str(e))
        exit(-1)
Example #2
0
def create_profile(args):

    set_canari_mode(CanariMode.Local)

    opts = parse_args(args)
    current_dir = os.getcwd()
    try:
        with PushDir(opts.working_dir or current_dir):
            transform_package = TransformDistribution(opts.package)
            transform_package.create_profile(opts.working_dir, current_dir)
    except ValueError as e:
        print(str(e), file=sys.stderr)
        exit(-1)
Example #3
0
def remote_transform(host, transform, input, entity_field, transform_parameter, raw_output, 
                     ssl, base_path, soft_limit, hard_limit, verbose):
    if verbose:
        set_canari_mode(CanariMode.LocalDebug)

    entity_type, entity_value = split_validate(input, 'entity')
    fields = {}
    params = []

    for f in entity_field:
        name, value = split_validate(f, 'entity field')
        fields[name] = Field(name=name, value=value)

    for p in transform_parameter:
        name, value = split_validate(p, 'transform parameter')
        params.append(Field(name=name, value=value))

    try:
        r = remote_canari_transform_runner(
            host,
            base_path,
            transform,
            [_Entity(type=entity_type, value=entity_value, fields=fields)],
            params,
            Limits(soft=soft_limit, hard=hard_limit),
            ssl
        )

        if r.status == 200:
            data = r.read().decode('utf8')
            if raw_output:
                click.echo(data, err=True)
                exit(0)
            else:
                console_writer(MaltegoMessage.parse(data))
                exit(0)

        click.echo('ERROR: Received status %d for %s://%s/%s. Are you sure you got the right server?' % (
            r.status,
            'https' if ssl else 'http',
            host,
            transform
        ), err=True)
        
        if verbose:
            click.echo(r.read(), err=True)
    except Exception as e:
        click.echo('ERROR: %s' % e, err=True)
        if verbose:
            traceback.print_exc()
    exit(-1)
Example #4
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)
Example #5
0
def remote_transform(args):
    if args.verbose:
        set_canari_mode(CanariMode.LocalDebug)

    entity_type, entity_value = split_validate(args.input, 'entity')
    fields = {}
    params = []

    for f in args.entity_field:
        name, value = split_validate(f, 'entity field')
        fields[name] = Field(name=name, value=value)

    for p in args.transform_parameter:
        name, value = split_validate(p, 'transform parameter')
        params.append(Field(name=name, value=value))

    try:
        r = remote_canari_transform_runner(
            args.host,
            args.base_path,
            args.transform,
            [_Entity(type=entity_type, value=entity_value, fields=fields)],
            params,
            Limits(soft=args.soft_limit, hard=args.hard_limit),
            args.ssl
        )

        if r.status == 200:
            data = r.read()
            if args.raw_output:
                print data
                exit(0)
            else:
                console_writer(MaltegoMessage.parse(data))
                exit(0)

        print 'ERROR: Received status %d for %s://%s/%s. Are you sure you got the right server?' % (
            r.status,
            'https' if args.ssl else 'http',
            args.host,
            args.transform
        )
    except Exception, e:
        print 'ERROR: %s' % e
Example #6
0
def run_transform(opts):
    set_canari_mode(CanariMode.LocalDispatch)
    with PushDir(CanariProject().src_dir):
        local_transform_runner(opts.transform, opts.value, opts.fields, opts.params, load_config(), message)
Example #7
0
def debug_transform(opts):
    set_canari_mode(CanariMode.LocalDebug)
    with PushDir(CanariProject().src_dir):
        local_transform_runner(opts.transform, opts.value, opts.fields,
                               opts.params, load_config(), console_writer)
Example #8
0
def run_transform(opts):
    set_canari_mode(CanariMode.LocalDispatch)
    with PushDir(CanariProject().src_dir):
        local_transform_runner(opts.transform, opts.value, opts.fields,
                               opts.params, load_config(), message)
Example #9
0
 def mode(self, value):
     return set_canari_mode(value)
Example #10
0
from canari.pkgutils.transform import TransformDistribution

__author__ = 'Nadeem Douba'
__copyright__ = 'Copyright 2015, Canari Project'
__credits__ = []

__license__ = 'GPL'
__version__ = '0.5'
__maintainer__ = 'Nadeem Douba'
__email__ = '*****@*****.**'
__status__ = 'Development'

__all__ = ['application']

# Initialize Canari modes and bin path
set_canari_mode(CanariMode.RemotePlumeDispatch)
fix_binpath(load_config()[OPTION_REMOTE_PATH])
fix_pypath()


def get_image_path(i):
    return os.path.join('static', md5(i).hexdigest())


def get_image_url(i):
    return '%s/static/%s' % (request.host_url, md5(i).hexdigest())


# Monkey patch our resource lib to automatically rewrite icon urls
_icon_resource = canari.resource.icon_resource
canari.resource.icon_resource = lambda name, pkg=None: get_image_url(
Example #11
0
__author__ = 'Nadeem Douba'
__copyright__ = 'Copyright 2015, Canari Project'
__credits__ = []

__license__ = 'GPL'
__version__ = '0.5'
__maintainer__ = 'Nadeem Douba'
__email__ = '*****@*****.**'
__status__ = 'Development'

__all__ = [
    'application'
]

# Initialize Canari modes and bin path
set_canari_mode(CanariMode.RemotePlumeDispatch)
fix_binpath(load_config()[OPTION_REMOTE_PATH])
fix_pypath()


def get_image_path(i):
    return os.path.join('static', md5(i).hexdigest())


def get_image_url(i):
    return '%s/static/%s' % (request.host_url, md5(i).hexdigest())


# Monkey patch our resource lib to automatically rewrite icon urls
_icon_resource = canari.resource.icon_resource
canari.resource.icon_resource = lambda name, pkg=None: get_image_url(_icon_resource(name, pkg))
Example #12
0
def debug_transform(opts):
    set_canari_mode(CanariMode.LocalDebug)
    with PushDir(CanariProject().src_dir):
        local_transform_runner(opts.transform, opts.value, opts.fields, opts.params, load_config(), console_writer)
Example #13
0
def dispatcher():
    set_canari_mode(CanariMode.LocalDispatch)
    run_transform.run_transform.parser.prog = 'dispatcher'
    opts = run_transform.run_transform.parser.parse_args()
    run_transform.run_transform(opts)
Example #14
0
def main():
    try:
        set_canari_mode(CanariMode.LocalUnknown)
        canari_main()
    except KeyboardInterrupt:
        print('exiting...', file=sys.stderr)