Exemplo n.º 1
0
def drop_into_layer(image_obj, layer_index):
    """Given the image object and the layer index, mount all the layers
    upto the specified layer index and drop into a shell session"""
    rootfs.set_up()
    if layer_index == 0:
        # mount only one layer
        target = rootfs.mount_base_layer(
            image_obj.layers[layer_index].tar_file)
    else:
        # mount all layers uptil the provided layer index
        target = multi_layer.mount_overlay_fs(image_obj, layer_index)
    mount_path = get_mount_path()
    print("\nWorking directory is: {}\n".format(mount_path))
    # check if there is a shell
    shell = check_shell()
    if shell:
        rootfs.prep_rootfs(target)
        print("\nRun 'cd {} && sudo chroot . {}' to look around".format(
            mount_path, shell))
    else:
        print("\nRun 'cd {}' to look around".format(mount_path))
        print("A shell binary doesn't exist in the filesystem. You're on "
              "your own.")
    print("\nAfter exiting from your session, run 'cd -' to go back "
          "and 'tern debug --recover' to clean up.\n")
    sys.exit(0)
Exemplo n.º 2
0
def setup(image_obj):
    """Setup the image object and anything else for analysis"""
    # Add a Notice object for each layer
    for layer in image_obj.layers:
        origin_str = 'Layer {}'.format(layer.layer_index)
        layer.origins.add_notice_origin(origin_str)
    # Set up working directories and mount points
    rootfs.set_up()
Exemplo n.º 3
0
def prepare_for_analysis(image_obj, dfobj):
    # find the layers that are imported
    if dfobj:
        dhelper.set_imported_layers(image_obj)
    # add notices for each layer if it is imported
    image_setup(image_obj)
    # set up the mount points
    rootfs.set_up()
Exemplo n.º 4
0
def drop_into_layer(image_obj, layer_index):
    """Given the image object and the layer index, mount all the layers
    upto the specified layer index and drop into a shell session"""
    rootfs.set_up()
    if layer_index == 0:
        # mount only one layer
        target = rootfs.mount_base_layer(
            image_obj.layers[layer_index].tar_file)
    else:
        # mount all layers uptil the provided layer index
        target = analyze.mount_overlay_fs(image_obj, layer_index)
    # check if there is a shell
    shell = check_shell()
    if shell:
        rootfs.prep_rootfs(target)
        print("Done. Run 'sudo chroot . {}' to look around.".format(shell))
    else:
        print("A shell binary doesn't exist in the filesystem. You're on "
              "your own.")
    print("Working directory is: {}".format(get_mount_path()))
    sys.exit(0)
Exemplo n.º 5
0
def setup(dockerfile=None, image_tag_string=None):
    '''Any initial setup'''
    # generate random names for image, container, and tag
    general.initialize_names()
    # load the cache
    cache.load()
    # load dockerfile if present
    if dockerfile:
        dhelper.load_docker_commands(dockerfile)
    # check if the docker image is present
    if image_tag_string:
        if not container.check_image(image_tag_string):
            # if no docker image is present, try to pull it
            if not container.pull_image(image_tag_string):
                logger.fatal(
                    errors.cannot_find_image.format(imagetag=image_tag_string))
                sys.exit()
    # create temporary working directory
    if not os.path.exists(constants.temp_folder):
        os.mkdir(constants.temp_folder)
    # set up folders for rootfs operations
    rootfs.set_up()
Exemplo n.º 6
0
                        default='',
                        help='A package name that the command needs to '
                        'execute with. Useful when testing commands in the '
                        'snippet library')
    args = parser.parse_args()

    # do initial setup to analyze docker image
    container.check_docker_setup()
    # set some global variables
    rootfs.set_mount_dir()
    # try to load the image
    image_obj = report.load_full_image(args.image)
    if image_obj.origins.is_empty():
        # image loading was successful
        # proceed mounting diff filesystems
        rootfs.set_up()
        if len(image_obj.layers) == 1:
            # mount only one layer
            target = rootfs.mount_base_layer(image_obj.layers[0].tar_file)
        else:
            target = analyze.mount_overlay_fs(image_obj,
                                              len(image_obj.layers) - 1)
        rootfs.prep_rootfs(target)
        # invoke commands in chroot
        # if we're looking up the snippets library
        # we should see 'snippets' in the keys
        if 'snippets' in args.keys and 'packages' in args.keys:
            # get the package info that corresponds to the package name
            # or get the default
            last = args.keys.pop()
            info_list = look_up_lib(args.keys)