CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/spec/lib/rex/parser/group_policy_preferences_spec.rb
Views: 11655
1
# encoding: binary
2
3
xml_group = '
4
<?xml version="1.0" encoding="utf-8"?>
5
<Groups clsid="{3125E937-EB16-4b4c-9934-544FC6D24D26}"><User clsid="{DF5F1855-51E5-4d24-8B1A-D9BDE98BA1D1}" name="SuperSecretBackdoor" image="0" changed="2013-04-25 18:36:07" uid="{B5EDB865-34F5-4BD7-9C59-3AEB1C7A68C3}"><Properties action="C" fullName="" description="" cpassword="VBQUNbDhuVti3/GHTGHPvcno2vH3y8e8m1qALVO1H3T0rdkr2rub1smfTtqRBRI3" changeLogon="0" noChange="0" neverExpires="1" acctDisabled="0" userName="SuperSecretBackdoor"/></User>
6
</Groups>
7
'
8
9
xml_datasrc = '
10
<?xml version="1.0" encoding="utf-8"?>
11
<DataSources clsid="{380F820F-F21B-41ac-A3CC-24D4F80F067B}"><DataSource clsid="{5C209626-D820-4d69-8D50-1FACD6214488}" userContext="1" name="test" image="0" changed="2013-04-25 20:39:08" uid="{3513F923-9661-4819-9995-91A63C7D7A65}"><Properties action="C" userDSN="0" dsn="test" driver="test" description="" username="test" cpassword="eYbbv1GZI4DZEgTXPUDspw"><Attributes><Attribute name="test" value="test"/><Attribute name="test2" value="test2"/></Attributes></Properties></DataSource>
12
</DataSources>
13
'
14
15
xml_drive = '
16
<?xml version="1.0" encoding="utf-8"?>
17
<Drives clsid="{8FDDCC1A-0C3C-43cd-A6B4-71A6DF20DA8C}"><Drive clsid="{935D1B74-9CB8-4e3c-9914-7DD559B7A417}" name="E:" status="E:" image="0" changed="2013-04-25 20:33:02" uid="{016E2095-EAB5-43C0-8BCF-4C2655F709F5}"><Properties action="C" thisDrive="NOCHANGE" allDrives="NOCHANGE" userName="drivemap" path="drivemap" label="" persistent="0" useLetter="1" letter="E" cpassword="Lj3fkZ8E3AFAJPTSoBitKw"/></Drive>
18
</Drives>
19
'
20
21
xml_schd = '
22
<?xml version="1.0" encoding="utf-8"?>
23
<ScheduledTasks clsid="{CC63F200-7309-4ba0-B154-A71CD118DBCC}"><Task clsid="{2DEECB1C-261F-4e13-9B21-16FB83BC03BD}" name="test1" image="2" changed="2013-04-25 20:30:13" uid="{41059D76-C7B4-4D05-9679-AE7510247B1F}"><Properties action="U" name="test1" appName="notepad.exe" args="" startIn="" comment="" runAs="test1" cpassword="DdGgLn/bpUNU/QjjcNvn4A" enabled="0"><Triggers><Trigger type="DAILY" startHour="8" startMinutes="0" beginYear="2013" beginMonth="4" beginDay="25" hasEndDate="0" repeatTask="0" interval="1"/></Triggers></Properties></Task>
24
</ScheduledTasks>
25
'
26
27
xml_serv = '
28
<?xml version="1.0" encoding="utf-8"?>
29
<NTServices clsid="{2CFB484A-4E96-4b5d-A0B6-093D2F91E6AE}"><NTService clsid="{AB6F0B67-341F-4e51-92F9-005FBFBA1A43}" name="Blah" image="0" changed="2013-04-25 20:29:49" uid="{C6AE4201-9F99-46AB-93C2-9D734D87D343}"><Properties startupType="NOCHANGE" serviceName="Blah" timeout="30" accountName="bob" cpassword="OQWR9sf5FTlGgh8SJX31ug"/></NTService>
30
</NTServices>
31
'
32
33
xml_ms = '
34
<?xml version="1.0" encoding="utf-8"?>
35
<Groups clsid="{3125E937-EB16-4b4c-9934-544FC6D24D26}"
36
disabled="1">
37
<User clsid="{DF5F1855-51E5-4d24-8B1A-D9BDE98BA1D1}"
38
name="DbAdmin"
39
image="2"
40
changed="2007-07-06 20:45:20"
41
uid="{253F4D90-150A-4EFB-BCC8-6E894A9105F7}">
42
<Properties
43
action="U"
44
newName=""
45
fullName="Database Admin"
46
description="Local Database Admin"
47
cpassword="demo"
48
changeLogon="0"
49
noChange="0"
50
neverExpires="0"
51
acctDisabled="1"
52
userName="DbAdmin"/>
53
</User>
54
<Group clsid="{6D4A79E4-529C-4481-ABD0-F5BD7EA93BA7}"
55
name="Database Admins"
56
image="2"
57
changed="2007-07-06 20:46:21"
58
uid="{C5FB3901-508A-4A9E-9171-60D4FC2B404B}">
59
<Properties
60
action="U"
61
newName=""
62
description="Local Database Admins"
63
userAction="REMOVE"
64
deleteAllUsers="1"
65
deleteAllGroups="1"
66
removeAccounts="0"
67
groupName="Database Admins">
68
<Members>
69
<Member
70
name="domain\sampleuser"
71
action="ADD"
72
sid=""/>
73
</Members>
74
</Properties>
75
</Group>
76
</Groups>
77
'
78
79
# Win2k8 appears to append some junk padding in some cases
80
cpassword_win2k8 = []
81
# Win2k8R2 - EqWFlA4kn2T6PHvGi09M7seHuqCYK/slkJWIl7mK+wEMON8tIIslS6707RU1F7Bh
82
cpassword_win2k8 << ['EqWFlA4kn2T6PHvGi09M7seHuqCYK/slkJWIl7mK+wEMON8tIIslS6707RU1F7BhTµkp', 'N3v3rGunnaG!veYo']
83
cpassword_win2k8 << ['EqWFlA4kn2T6PHvGi09M7seHuqCYK/slkJWIl7mK+wGSwOI7Be//GJdxd5YYXUQHTµkp', 'N3v3rGunnaG!veYou']
84
# Win2k8R2 - EqWFlA4kn2T6PHvGi09M7seHuqCYK/slkJWIl7mK+wFSuDccBEp/4l5EuKnwF0WS
85
cpassword_win2k8 << ['EqWFlA4kn2T6PHvGi09M7seHuqCYK/slkJWIl7mK+wFSuDccBEp/4l5EuKnwF0WS»YÂVAA', 'N3v3rGunnaG!veYouUp']
86
cpassword_normal = "j1Uyj3Vx8TY9LtLZil2uAuZkFQA/4latT76ZwgdHdhw"
87
cpassword_bad = "blah"
88
89
RSpec.describe Rex::Parser::GPP do
90
GPP = Rex::Parser::GPP
91
92
##
93
# Decrypt
94
##
95
it "Decrypt returns Local*P4ssword! for normal cpassword" do
96
result = GPP.decrypt(cpassword_normal)
97
expect(result).to eq("Local*P4ssword!")
98
end
99
100
it "Decrypt returns blank for bad cpassword" do
101
result = GPP.decrypt(cpassword_bad)
102
expect(result).to eq("")
103
end
104
105
it "Decrypt returns blank for nil cpassword" do
106
result = GPP.decrypt(nil)
107
expect(result).to eq("")
108
end
109
110
it 'Decrypts a cpassword containing junk padding' do
111
cpassword_win2k8.each do |encrypted, expected|
112
result = GPP.decrypt(encrypted)
113
expect(result).to eq(expected)
114
end
115
end
116
117
##
118
# Parse
119
##
120
121
it "Parse returns empty [] for nil" do
122
expect(GPP.parse(nil)).to be_empty
123
end
124
125
it "Parse returns results for xml_ms and password is empty" do
126
results = GPP.parse(xml_ms)
127
expect(results).not_to be_empty
128
expect(results[0][:PASS]).to be_empty
129
end
130
131
it "Parse returns results for xml_datasrc, and attributes, and password is test1" do
132
results = GPP.parse(xml_datasrc)
133
expect(results).not_to be_empty
134
expect(results[0].include?(:ATTRIBUTES)).to be_truthy
135
expect(results[0][:ATTRIBUTES]).not_to be_empty
136
expect(results[0][:PASS]).to eq("test")
137
end
138
139
xmls = []
140
xmls << xml_group
141
xmls << xml_drive
142
xmls << xml_schd
143
xmls << xml_serv
144
xmls << xml_datasrc
145
146
it "Parse returns results for all good xmls and passwords" do
147
xmls.each do |xml|
148
results = GPP.parse(xml)
149
expect(results).not_to be_empty
150
expect(results[0][:PASS]).not_to be_empty
151
end
152
end
153
154
##
155
# Create_Tables
156
##
157
it "Create_tables returns tables for all good xmls" do
158
xmls.each do |xml|
159
results = GPP.parse(xml)
160
tables = GPP.create_tables(results, "test")
161
expect(tables).not_to be_empty
162
end
163
end
164
end
165
166