Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rapid7
GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/auxiliary/parser/unattend.rb
19758 views
1
##
2
# This module requires Metasploit: https://metasploit.com/download
3
# Current source: https://github.com/rapid7/metasploit-framework
4
##
5
6
class MetasploitModule < Msf::Auxiliary
7
8
def initialize(info = {})
9
super(
10
update_info(
11
info,
12
'Name' => 'Auxiliary Parser Windows Unattend Passwords',
13
'Description' => %q{
14
This module parses Windows answer files (Unattend files) in the target directory.
15
16
See also: post/windows/gather/enum_unattend
17
},
18
'License' => MSF_LICENSE,
19
'Author' => [
20
'Ben Campbell',
21
],
22
'References' => [
23
['URL', 'https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-8.1-and-8/ff715801(v=win.10)'],
24
['URL', 'https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-vista/cc749415(v=ws.10)'],
25
['URL', 'https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2008-R2-and-2008/cc732280(v=ws.10)'],
26
['URL', 'https://learn.microsoft.com/en-us/windows-hardware/manufacture/desktop/update-windows-settings-and-scripts-create-your-own-answer-file-sxs?view=windows-11'],
27
],
28
'Notes' => {
29
'Stability' => [CRASH_SAFE],
30
'SideEffects' => [],
31
'Reliability' => []
32
}
33
)
34
)
35
36
register_options([
37
OptPath.new('PATH', [true, 'Directory or file to parse.']),
38
OptBool.new('RECURSIVE', [true, 'Recursively check for files', false]),
39
])
40
end
41
42
def run
43
if datastore['RECURSIVE']
44
ext = '**/*.xml'
45
else
46
ext = '/*.xml'
47
end
48
49
if datastore['PATH'].ends_with?('.xml')
50
filepath = datastore['PATH']
51
else
52
filepath = File.join(datastore['PATH'], ext)
53
end
54
55
Dir.glob(filepath) do |item|
56
print_status "Processing #{item}"
57
file = File.read(item)
58
begin
59
xml = REXML::Document.new(file)
60
rescue REXML::ParseException => e
61
print_error("#{item} invalid xml format.")
62
vprint_line(e.message)
63
next
64
end
65
66
results = Rex::Parser::Unattend.parse(xml)
67
table = Rex::Parser::Unattend.create_table(results)
68
print_line table.to_s unless table.nil?
69
print_line
70
end
71
end
72
end
73
74