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,20 @@ def run
95
94
sql += "CLOSE table_cursor "
96
95
sql += "DEALLOCATE table_cursor "
97
96
97
+ begin
98
+ if mssql_login_datastore
99
+ result = mssql_query ( sql , false )
100
+ column_data = result [ :rows ]
101
+ else
102
+ print_error ( 'Login failed' )
103
+ return
104
+ end
105
+ rescue Rex ::ConnectionRefused => e
106
+ print_error ( "Connection failed: #{ e } " )
107
+ return
108
+ end
98
109
99
- # Add error handling here
100
- result = mssql_query ( sql , false ) if mssql_login_datastore
101
110
column_data = result [ :rows ]
102
-
103
111
widths = [ 0 , 0 , 0 , 0 , 0 , 9 ]
104
112
total_width = 0
105
113
@@ -113,25 +121,24 @@ def run
113
121
total_width += a
114
122
}
115
123
116
- print_line ( "" )
124
+ print_line
117
125
118
126
buffer = ""
119
127
headings . each { |row |
120
128
0 . upto ( 5 ) { |col |
121
129
buffer += row [ col ] . ljust ( widths [ col ] + 1 )
122
130
}
123
131
print_line ( buffer )
124
- print_line ( "" )
132
+ print_line
125
133
buffer = ""
126
134
127
135
0 . upto ( 5 ) { |col |
128
136
buffer += print "=" * widths [ col ] + " "
129
137
}
130
138
print_line ( buffer )
131
- print_line ( "" )
139
+ print_line
132
140
}
133
141
134
- table_data_sql = { }
135
142
column_data . each { |row |
136
143
count_sql = "SELECT COUNT(*) AS count FROM "
137
144
@@ -153,73 +160,11 @@ def run
153
160
154
161
buffer += row_count . to_s
155
162
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
163
+ print_line
179
164
}
180
165
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
166
+ print_line
223
167
disconnect
224
168
end
169
+
225
170
end
0 commit comments