Example #1
0
def index(request):
    '''
    Dashboard controller
    :param request:
    :return:
    '''
    if request.method == 'GET':
        #check for existing incomplete session
        session = Sandbox_Session()
        try:
            current_session = Sandbox_Session.objects.get(status=Sandbox_Session.CONFIGURING)
            create_new_session = False

        except Sandbox_Session.DoesNotExist:
            session.save()
            current_session = Sandbox_Session.objects.get(status=Sandbox_Session.CONFIGURING)
            create_new_session = True


        session_config = None
        try:
            session_config = ast.literal_eval(current_session.configuration)
            #retrieve any existing configurations in database
        except SyntaxError:
            pass

        devices = adb.devices()
        if len(devices) == 1:
            for device, status in devices.iteritems():
                current_session.device_serial = device
                current_session.save()
                current_session = Sandbox_Session.objects.get(id=current_session.id)

        profileModules = profileManager.modules_info()
        monitorModules = monitorsManager.modules_info()
        monitor_total = monitorsManager.count_modules()

        sessions = Sandbox_Session.objects.all()
        params = {
            "selected_device":current_session.device_serial,
            "profileModules":profileModules,
            "monitorModules":monitorModules,
            "create_new_session":create_new_session,
            "current_session":current_session,
            "module_total":monitor_total,
            "session_config":session_config,
            "sessions":sessions,
            "devices":devices,
        }
        return render_to_response("dashboard/index.html",params ,context_instance=RequestContext(request))
Example #2
0
def handle_upload_file(files, id):
    """
    Save uploaded apk to droidpot apk folder and save apk paths to session database
    :param files: uploaded file[s] in POST form
    :param id: session id
    :return: bool
    """
    current_session = Sandbox_Session.objects.get(id=id)

    total_samples = len(files)
    if total_samples > 1:
        #create holding sessions
        for i in range(0, total_samples-1, 1):
            session = Sandbox_Session()
            session.status = Sandbox_Session.HOLD
            session.configuration = current_session.configuration
            session.analysis_duration = current_session.analysis_duration
            session.device_serial = current_session.device_serial
            session.save()


    count = 0
    first_id = current_session.id
    for file in files:
        sample_path = {}
        file_name = file.__str__()

        temp_file_path = os.path.join(APK_BASE_DIR, file_name)

        with open(temp_file_path, 'wb+') as destination:
            for chunk in file.chunks():
                destination.write(chunk)

        file_md5 = hashlib.md5(open(temp_file_path).read()).hexdigest()

        new_file_name = file_md5 + "_" + file_name
        new_file_path = os.path.join(APK_BASE_DIR, new_file_name)
        sample_path[new_file_name] = new_file_path


        if not os.path.exists(new_file_path):
            os.rename(temp_file_path, new_file_path)
            log.info("New sample uploaded")

        else:
            log.info("Identical sample found.")
            os.remove(temp_file_path)

        each_session = Sandbox_Session.objects.get(id=first_id+count)
        each_session.apk_paths = sample_path
        each_session.save()
        count +=1

    return True