Skip to content

Commit 26f28ae

Browse files
committed
Minor cleaup
1 parent 2349ee7 commit 26f28ae

File tree

1 file changed

+36
-50
lines changed

1 file changed

+36
-50
lines changed

modules/post/windows/gather/enum_prefetch.rb

Lines changed: 36 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -44,49 +44,29 @@ def prefetch_key_value()
4444
reg_key.close
4545
end
4646

47-
def timezone_key_value(sysnfo)
48-
49-
if sysnfo =~/(Windows 7)/
50-
reg_key = session.sys.registry.open_key(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Control\\TimeZoneInformation", KEY_READ)
51-
key_value = reg_key.query_value("TimeZoneKeyName").data
52-
if key_value.empty? or key_value.nil?
53-
print_line("Couldn't find key/value for timezone from registry.")
54-
else
55-
print_good("Remote: Timezone is %s" % key_value)
56-
end
57-
58-
elsif sysnfo =~/(Windows XP)/
59-
reg_key = session.sys.registry.open_key(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Control\\TimeZoneInformation", KEY_READ)
60-
key_value = reg_key.query_value("StandardName").data
61-
if key_value.empty? or key_value.nil?
47+
def timezone_key_values(key_value)
48+
# Looks for timezone from registry
49+
timezone_key = session.sys.registry.open_key(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Control\\TimeZoneInformation", KEY_READ)
50+
if timezone_key.nil?
6251
print_line("Couldn't find key/value for timezone from registry.")
6352
else
64-
print_good("Remote: Timezone is %s" % key_value)
65-
end
66-
else
67-
print_error("Unknown system. Can't find timezone value from registry.")
68-
end
69-
reg_key.close
70-
end
71-
72-
73-
def timezone_bias()
74-
# Looks for the timezone difference in minutes from registry
75-
reg_key = session.sys.registry.open_key(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Control\\TimeZoneInformation", KEY_READ)
76-
key_value = reg_key.query_value("Bias").data
77-
if key_value.nil?
78-
print_error("Couldn't find bias from registry")
79-
else
80-
if key_value < 0xfff
81-
bias = key_value
82-
print_good("Remote: localtime bias to UTC: -%s minutes." % bias)
83-
else
84-
offset = 0xffffffff
85-
bias = offset - key_value
86-
print_good("Remote: localtime bias to UTC: +%s minutes." % bias)
53+
timezone = timezone_key.query_value(key_value).data
54+
tzbias = timezone_key.query_value("Bias").data
55+
if timezone.nil? or tzbias.nil?
56+
print_error("Couldn't find timezone information from registry.")
57+
else
58+
print_good("Remote: Timezone is %s." % timezone)
59+
if tzbias < 0xfff
60+
bias = tzbias
61+
print_good("Remote: Localtime bias to UTC: -%s minutes." % bias)
62+
else
63+
offset = 0xffffffff
64+
bias = offset - tzbias
65+
print_good("Remote: Localtime bias to UTC: +%s minutes." % bias)
66+
end
67+
end
8768
end
88-
end
89-
reg_key.close
69+
timezone_key.close
9070
end
9171

9272

@@ -113,19 +93,19 @@ def gather_prefetch_info(name_offset, hash_offset, lastrun_offset, runcount_offs
11393
prun = count['lpBuffer'].unpack('L*')[0]
11494

11595
# Finds the hash.
116-
client.railgun.kernel32.SetFilePointer(handle, hash_offset, 0, 0)
96+
client.railgun.kernel32.SetFilePointer(handle, hash_offset, 0, nil)
11797
hh = client.railgun.kernel32.ReadFile(handle, 4, 4, 4, nil)
11898
phash = hh['lpBuffer'].unpack('h*')[0].reverse
11999

120100
# Finds the LastModified timestamp (MACE)
121101
lm = client.priv.fs.get_file_mace(filename)
122-
lmod = lm['Modified'].utc.to_s
102+
lmod = lm['Modified'].utc
123103

124104
# Finds the Creation timestamp (MACE)
125105
cr = client.priv.fs.get_file_mace(filename)
126-
creat = cr['Created'].utc.to_s
106+
creat = cr['Created'].utc
127107

128-
# Prints the results and closes the file handle
108+
# Saves the results to the table and closes the file handle
129109
if name.nil? or count.nil? or hh.nil? or lm.nil? or cr.nil?
130110
print_error("Could not access file: %s." % filename)
131111
else
@@ -136,7 +116,6 @@ def gather_prefetch_info(name_offset, hash_offset, lastrun_offset, runcount_offs
136116
end
137117

138118

139-
140119
def run
141120

142121
print_status("Prefetch Gathering started.")
@@ -157,19 +136,26 @@ def run
157136

158137
sysnfo = client.sys.config.sysinfo['OS']
159138

160-
if sysnfo =~/(Windows XP)/ # Offsets for WinXP
139+
if sysnfo =~/(Windows XP)/
140+
# Offsets for WinXP
161141
print_good("Detected Windows XP (max 128 entries)")
162142
name_offset = 0x10
163143
hash_offset = 0x4C
164144
lastrun_offset = 0x78
165145
runcount_offset = 0x90
146+
# Registry key for timezone
147+
key_value = "StandardName"
166148

167-
elsif sysnfo =~/(Windows 7)/ # Offsets for Win7
149+
elsif sysnfo =~/(Windows 7)/
150+
# Offsets for Win7
168151
print_good("Detected Windows 7 (max 128 entries)")
169152
name_offset = 0x10
170153
hash_offset = 0x4C
171154
lastrun_offset = 0x80
172155
runcount_offset = 0x98
156+
# Registry key for timezone
157+
key_value = "TimeZoneKeyName"
158+
173159
else
174160
print_error("No offsets for the target Windows version. Currently works only on WinXP and Win7.")
175161
return nil
@@ -191,10 +177,9 @@ def run
191177

192178
prefetch_key_value
193179

194-
print_status("Searching for TimeZone Registry Values.")
180+
print_status("\nSearching for TimeZone Registry Values.")
195181

196-
timezone_key_value(sysnfo)
197-
timezone_bias
182+
timezone_key_values(key_value)
198183

199184
print_good("Current UTC Time: %s" % Time.now.utc)
200185

@@ -216,6 +201,7 @@ def run
216201
end
217202
end
218203

204+
# Stores and prints out results
219205
results = table.to_s
220206
loot = store_loot("prefetch_info", "text/plain", session, results, nil, "Prefetch Information")
221207
print_line("\n" + results + "\n")

0 commit comments

Comments
 (0)