Blame view

modules/winreg.py 2.69 KB
Imanol-Mikel Barba Sabariego authored
1
import os
2
3
4

import logger
import tomb
5
import winver
6
from modules.module import Module
7
from mount import mount,umount
8
from runcmd import runProcess
root authored
9
import time
10
Imanol-Mikel Barba Sabariego authored
11
12
13
14
15
16
17
18
19

def getInstance():
    return RegistryModule()

class RegistryModule(Module):

    def __init__(self):
        self.name = "winreg"
        self.description = "Extracts Windows Registry files"
20
        self.requiredVars = ["winvol"]
Imanol-Mikel Barba Sabariego authored
21
22
        self.vars = {}
Imanol-Mikel Barba Sabariego authored
23
    def execute(self):
Imanol-Mikel Barba Sabariego authored
24
        path = tomb.getPath() + self.name + "/"
25
26
        if(not os.path.exists(path)):
            os.mkdir(path)
27
        logger.msgLog("Extracting Windows registry from volumes: " + repr(self.vars['winvol'].value), "winreg", logger.TYPE_INFO)
28
29
        for vol in self.vars['winvol'].value:
            mntpoint = "/mnt/"
30
31
32
33
            try:
                mntid = mount("/dev/" + vol)
            except:
                raise
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
            mntpoint += mntid
            files = []
            windir = winver.getWindowsDirectory(mntpoint)
            if windir == None:
                raise Exception("No Windows installation present")
            version = winver.getWindowsVersion(mntpoint)
            profiles = winver.getUserProfiles(mntpoint)
            if version <= winver._WIN_ME:
                #9x
                files = [windir + "USER.DAT",windir + "SYSTEM.DAT"]
                if(len(profiles) > 0):
                    for profile in profiles:
                        if(os.path.isfile(profile + "USER.DAT")):
                            files += [profile + "USER.DAT"]
                if version == winver._WIN_ME:
                    #ME
                    files += [windir + "CLASSES.DAT"]

            elif version > winver._WIN_ME:
                    #NT
                    files += [windir + "/System32/config/SAM" ]
                    files += [windir + "/System32/config/SECURITY"]
                    files += [windir + "/System32/config/SOFTWARE"]
                    files += [windir + "/System32/config/SYSTEM"]
                    files += [windir + "/System32/config/DEFAULT"]
                    for profile in profiles:
                        files += [profile + "/NTUSER.DAT"]
                        if version > winver._WIN_NT and version < winver._WIN_VISTA:
                            #2k XP 2k3
                            files += [profile + "/Local Settings/Application Data/Microsoft/Windows/UsrClass.dat"]
                        else:
                            #Vista+
                            files += [profile + "/AppData/Local/Microsoft/Windows/UsrClass.dat"]
Imanol-Mikel Barba Sabariego authored
67
root authored
68
            runProcess(["tar","-czvf",path + "winreg_" + vol + "-" + str(int(time.time())) + ".tar.gz"] + files)
69
70
71
72
            try:
                umount(mntid)
            except:
                raise