14
14
15
15
require 'msf/core'
16
16
17
-
18
17
class Metasploit3 < Msf ::Auxiliary
19
18
20
19
include Msf ::Exploit ::Remote ::MSSQL
@@ -95,11 +94,14 @@ def run
95
94
sql += "CLOSE table_cursor "
96
95
sql += "DEALLOCATE table_cursor "
97
96
97
+ if mssql_login_datastore
98
+ result = mssql_query ( sql , false )
99
+ else
100
+ print_error ( 'Login failed' )
101
+ return
102
+ end
98
103
99
- # Add error handling here
100
- result = mssql_query ( sql , false ) if mssql_login_datastore
101
104
column_data = result [ :rows ]
102
-
103
105
widths = [ 0 , 0 , 0 , 0 , 0 , 9 ]
104
106
total_width = 0
105
107
@@ -113,25 +115,24 @@ def run
113
115
total_width += a
114
116
}
115
117
116
- print_line ( "" )
118
+ print_line
117
119
118
120
buffer = ""
119
121
headings . each { |row |
120
122
0 . upto ( 5 ) { |col |
121
123
buffer += row [ col ] . ljust ( widths [ col ] + 1 )
122
124
}
123
125
print_line ( buffer )
124
- print_line ( "" )
126
+ print_line
125
127
buffer = ""
126
128
127
129
0 . upto ( 5 ) { |col |
128
130
buffer += print "=" * widths [ col ] + " "
129
131
}
130
132
print_line ( buffer )
131
- print_line ( "" )
133
+ print_line
132
134
}
133
135
134
- table_data_sql = { }
135
136
column_data . each { |row |
136
137
count_sql = "SELECT COUNT(*) AS count FROM "
137
138
@@ -153,73 +154,11 @@ def run
153
154
154
155
buffer += row_count . to_s
155
156
print_line ( buffer )
156
- print_line ( "" )
157
-
158
- # if row_count == 0
159
- # data_sql = nil
160
- # table_data_sql[full_table + "." + column_name] = nil
161
- # elsif row_count < 4
162
- # data_sql = "SELECT * from " + full_table
163
- # table_data_sql[full_table + "." + column_name] = data_sql
164
- # else
165
- # data_sql = "SELECT TOP 3 * from " + full_table
166
- #
167
- # # or this will get top, middle and last rows
168
- #
169
- # data_sql = "
170
- # with tmp as (select *,ROW_NUMBER() over (order by " + column_name + ") as rownumber from " + full_table + " )
171
- # select * from tmp where rownumber between 1 and 1;
172
- # with tmp as (select *,ROW_NUMBER() over (order by " + column_name + ") as rownumber from " + full_table + " )
173
- # select * from tmp where rownumber between " + (row_count / 2).to_s + " and " + (row_count / 2).to_s + ";
174
- # with tmp as (select *,ROW_NUMBER() over (order by " + column_name + ") as rownumber from " + full_table + " )
175
- # select * from tmp where rownumber between " + row_count.to_s + " and " + row_count.to_s + ";
176
- # "
177
- # table_data_sql[full_table + "." + column_name] = data_sql
178
- # end
157
+ print_line
179
158
}
180
159
181
- print_line ( "" )
182
-
183
- # The code from this point on is for dumping out some sample data however the MSSQL parser isn't working
184
- # correctly so the output is messed up. I'll finish implementing this once the bug is fixed.
185
-
186
- # print_line("")
187
- # print_with_underline("Sample Data")
188
- # print_line("")
189
- # table_data_sql.each_pair { |table, sql|
190
- # if !sql.nil?
191
- # print_with_underline table
192
- # result = mssql_query(sql, true) if mssql_login_datastore
193
- # #print_line result.inspect
194
- # result[:colnames].each { |row|
195
- # print row.ljust(20)
196
- # }
197
- # end
198
- # }
199
- #
200
- # if !data_sql.nil?
201
- # result = mssql_query(data_sql, false) if mssql_login_datastore
202
- # # print_line "INSPECT"
203
- # # print_line result.keys.inspect
204
- # # print_line result[:colnames].inspect
205
- # result[:colnames].each { |row|
206
- # print row.ljust(20)
207
- # }
208
- # print_line("")
209
- # result[:colnames].each { |row|
210
- # print "=" * 20 + " "
211
- # }
212
- # print_line("")
213
- #
214
- # if !result[:rows].nil?
215
- ## print_line data_sql
216
- # result[:rows].each { |acol|
217
- # acol.each { |aval|
218
- # # print_line aval
219
- # }
220
- # }
221
- # end
222
- # end
160
+ print_line
223
161
disconnect
224
162
end
163
+
225
164
end
0 commit comments