Skip to content

Commit c37f4e6

Browse files
committed
TeamCity: Prevent endless recursion and stack explosions in try_login
1 parent ed1a5d9 commit c37f4e6

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

lib/metasploit/framework/login_scanner/teamcity.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ class Teamcity < HTTP
2525
LOCKED_OUT = ::Metasploit::Model::Login::Status::LOCKED_OUT
2626
INCORRECT = ::Metasploit::Model::Login::Status::INCORRECT
2727

28+
class TeamCityError < StandardError; end
29+
class StackLevelTooDeepError < TeamCityError; end
30+
2831
# Send a GET request to the server and return a response.
2932
# @param [Hash] opts A hash with options that will take precedence over default values used to make the HTTP request.
3033
# @return [Hash] A hash with a status and an error or the response from the login page.
@@ -85,7 +88,9 @@ def create_login_request(username, password, public_key)
8588
# @param [String] password The user's password.
8689
# @param [String] public_key The public key used to encrypt the password.
8790
# @return [Hash] A hash with the status and an error or the response.
88-
def try_login(username, password, public_key)
91+
def try_login(username, password, public_key, retry_counter = 0)
92+
raise StackLevelTooDeepError, 'try_login stack level too deep!' if retry_counter >= 2
93+
8994
login_request = create_login_request(username, password, public_key)
9095

9196
begin
@@ -106,7 +111,7 @@ def try_login(username, password, public_key)
106111
if timeout
107112
framework_module.print_status "User '#{username}' locked out for #{timeout} seconds. Sleeping, and retrying..."
108113
sleep(timeout + 1) # + 1 as TeamCity is off-by-one when reporting the lockout timer.
109-
result = try_login(username, password, public_key)
114+
result = try_login(username, password, public_key, retry_counter + 1)
110115
return result
111116
end
112117

0 commit comments

Comments
 (0)