Ejemplo n.º 1
0
def startVm(ctx, mach, type, f, sha):
    """
    Start a virtual machien and run the analysis process
    
    """
    mgr = ctx['mgr']
    vb = ctx['vb']
    session = mgr.perf = ctx['perf']
    session = mgr.getSessionObject(vb)
    uuid = mach.id
    from datetime import datetime
    start_time = datetime.now()
    end_time = datetime.now()
    try:
        snap = mach.currentSnapshot
        if snap.name != "testing":
            raise Exception
        progress = vb.openRemoteSession(session, uuid, type, "")
        with open('/home/zozanh/sharedmal/target.exe', 'wb+') as destination:
            for chunk in f.chunks():
                destination.write(chunk)
        clean_log()
        if progressBar(ctx, progress, 100) and int(progress.resultCode) == 0:

            execInGuest(ctx, session,
                        ["C:\\WINDOWS\\system32\\PrototypeI.exe"], None,
                        "zozanh", "12345", -1)
            pauseGuest(ctx, session)
            end_time = datetime.now()
            time.sleep(1)
            getlog(
                {
                    "SHA1": sha,
                    "End Time": end_time,
                    "Start Time": start_time,
                    "File Name": f.name,
                    "File Size": f.size
                }, sha)
            do_job(sha)
            file = open(
                "/home/zozanh/env/djcode/thesis/static/data/" + sha +
                '/fin.log', "wr+")
            file.close()
            restoreSnapshot(ctx, session, uuid, "testing")
            time.sleep(1)
            session.close()
        else:
            pass
    except Exception:
        return False
    return True
Ejemplo n.º 2
0
def startVm(ctx, mach, type, f, sha):
    mgr = ctx['mgr']
    vb = ctx['vb']
    session = mgr.perf = ctx['perf']
    session = mgr.getSessionObject(vb)
    uuid = mach.id
    from datetime import datetime
    start_time = datetime.now()
    end_time = datetime.now()
    try:
        snap = mach.currentSnapshot
        if snap.name != "testing":
            raise Exception        
        progress = vb.openRemoteSession(session, uuid, type, "")
        with open('/home/zozanh/sharedmal/target.exe', 'wb+') as destination:
            for chunk in f.chunks():
                destination.write(chunk)
        clean_log()
        if progressBar(ctx, progress, 100) and int(progress.resultCode) == 0:

                execInGuest(ctx, session, ["C:\\WINDOWS\\system32\\PrototypeI.exe"], None, "zozanh", "12345", -1)
                pauseGuest(ctx, session)
                end_time = datetime.now()
                time.sleep(1)
                getlog({"SHA1": sha, "End Time": end_time, "Start Time": start_time, "File Name": f.name, "File Size": f.size}, sha)
                do_job(sha)
                file = open("/home/zozanh/env/djcode/thesis/static/data/" + sha + '/fin.log', "wr+")
                file.close()
                restoreSnapshot(ctx, session, uuid, "testing")
                time.sleep(1)
                # we ignore exceptions to allow starting VM even if
                # perf collector cannot be started
    #            if perf:
    #                try:
    #                    perf.setup(['*'], [mach], 10, 15)
    #                except Exception, e:
    #                    printErr(ctx, e)
    #                    if g_verbose:
    #                        traceback.print_exc()
                # if session not opened, close doesn't make sense
                session.close()
        else:
            pass
#            reportError(ctx, progress)
    except Exception:
        return False
    return True
Ejemplo n.º 3
0
def startVm(ctx, mach, type, f, sha):
    """
    Start a virtual machien and run the analysis process
    
    """
    mgr = ctx['mgr']
    vb = ctx['vb']
    session = mgr.perf = ctx['perf']
    session = mgr.getSessionObject(vb)
    uuid = mach.id
    from datetime import datetime
    start_time = datetime.now()
    end_time = datetime.now()
    try:
        snap = mach.currentSnapshot
        if snap.name != "testing":
            raise Exception        
        progress = vb.openRemoteSession(session, uuid, type, "")
        with open('/home/zozanh/sharedmal/target.exe', 'wb+') as destination:
            for chunk in f.chunks():
                destination.write(chunk)
        clean_log()
        if progressBar(ctx, progress, 100) and int(progress.resultCode) == 0:

                execInGuest(ctx, session, ["C:\\WINDOWS\\system32\\PrototypeI.exe"], None, "zozanh", "12345", -1)
                pauseGuest(ctx, session)
                end_time = datetime.now()
                time.sleep(1)
                getlog({"SHA1": sha, "End Time": end_time, "Start Time": start_time, "File Name": f.name, "File Size": f.size}, sha)
                do_job(sha)
                file = open("/home/zozanh/env/djcode/thesis/static/data/" + sha + '/fin.log', "wr+")
                file.close()
                restoreSnapshot(ctx, session, uuid, "testing")
                time.sleep(1)
                session.close()
        else:
            pass
    except Exception:
        return False
    return True