Skip to content

Commit 55895c6

Browse files
committed
Fix nil bug in mssql_idf
1 parent c967b60 commit 55895c6

File tree

1 file changed

+12
-73
lines changed

1 file changed

+12
-73
lines changed

modules/auxiliary/admin/mssql/mssql_idf.rb

Lines changed: 12 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
require 'msf/core'
1616

17-
1817
class Metasploit3 < Msf::Auxiliary
1918

2019
include Msf::Exploit::Remote::MSSQL
@@ -95,11 +94,14 @@ def run
9594
sql += "CLOSE table_cursor "
9695
sql += "DEALLOCATE table_cursor "
9796

97+
if mssql_login_datastore
98+
result = mssql_query(sql, false)
99+
else
100+
print_error('Login failed')
101+
return
102+
end
98103

99-
# Add error handling here
100-
result = mssql_query(sql, false) if mssql_login_datastore
101104
column_data = result[:rows]
102-
103105
widths = [0, 0, 0, 0, 0, 9]
104106
total_width = 0
105107

@@ -113,25 +115,24 @@ def run
113115
total_width += a
114116
}
115117

116-
print_line("")
118+
print_line
117119

118120
buffer = ""
119121
headings.each { |row|
120122
0.upto(5) { |col|
121123
buffer += row[col].ljust(widths[col] + 1)
122124
}
123125
print_line(buffer)
124-
print_line("")
126+
print_line
125127
buffer = ""
126128

127129
0.upto(5) { |col|
128130
buffer += print "=" * widths[col] + " "
129131
}
130132
print_line(buffer)
131-
print_line("")
133+
print_line
132134
}
133135

134-
table_data_sql = {}
135136
column_data.each { |row|
136137
count_sql = "SELECT COUNT(*) AS count FROM "
137138

@@ -153,73 +154,11 @@ def run
153154

154155
buffer += row_count.to_s
155156
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
179158
}
180159

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
223161
disconnect
224162
end
163+
225164
end

0 commit comments

Comments
 (0)