Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RStudio Weak Credentials Plugin #362

Merged
merged 9 commits into from
May 13, 2024

Conversation

leonardo-doyensec
Copy link
Collaborator

The following PR adds the weak credential tester for RStudio Server.

Some notes on the current version of the rstudio server credential tester.

  • does a custom fingerprint in the canAccept() method since rstudio is not correctly recognized from nmap
  • tests the credentials using RSA encryption, which is the default in rstudio
  • since RSA is used the plugin is a bit slow, due to the fact that rstudio takes some time to verify the credentials

@tooryx tooryx added the Contributor main The main issue a contributor is working on (top of the contribution queue). label Feb 1, 2024
@tooryx tooryx linked an issue Feb 1, 2024 that may be closed by this pull request
Comment on lines +126 to +133
canAcceptByCustomFingerprint =
response.status().isSuccess()
&& response.headers().get(SERVER_HEADER).isPresent()
&& response.headers().get(SERVER_HEADER).get().equals(RSTUDIO_HEADER)
&& response
.bodyString()
.map(RStudioCredentialTester::bodyContainsRStudioElements)
.orElse(false);
Copy link
Collaborator

@maoning maoning Apr 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we can have a dedicated web fingerpirnt for rstudio. The web fingerprinter is triggered on all the http services detected by nmap. Feel free to open a new fingerprint request for rstudio.

This is fine for now, no action needed.

ret.append(B64PAD);
return ret.toString();
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't done this in Java, did a quick google search, does the one-liner mentioned here work?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

During the plugin development i was looking for some shortcut to perform the conversion. Back then this was not working, but right now it is. Maybe it was related to other issues in the code. I've fixed this

@leonardo-doyensec
Copy link
Collaborator Author

Hi @maoning,
besides the changes that you have requested i've added also the rstudio username to the common list of usernames

public ImmutableList<TestCredential> testValidCredentials(
NetworkService networkService, List<TestCredential> credentials) {

return credentials.stream()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that this tester takes a long time to complete, can we make it return once it finds a valid credential?

Similar to

return credentials.stream()
.filter(cred -> isJenkinsAccessible(networkService, cred))
.findFirst()
.map(ImmutableList::of)
.orElseGet(ImmutableList::of);

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test takes a long time since the default configuration of RStudio uses RSA, which takes time to decrypt and verify. I've implemented the required change.

@@ -55,6 +55,12 @@ service_default_credentials {
default_usernames: "admin"
default_passwords: "admin"
}
service_default_credentials {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add another default credential rstudio/rstudio? Creds declared here are being tested first, hopefully short-circuit the plugin more often.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've implemented the required change. However, since nmap doesn't recognize the service, the standard flow will be followed. This means that the credentials will be bruteforced in the regular way.

@leonardo-doyensec
Copy link
Collaborator Author

Hi @maoning ,
I've fixed what you have requested. I've also upgraded gradle to version 7, since otherwise the plugin will not build.
Let me know if i need to fix something else, i know that the plugin is slow, but that is an issue with how RStudio handles the credentials.

@maoning
Copy link
Collaborator

maoning commented May 8, 2024

Hi @maoning , I've fixed what you have requested. I've also upgraded gradle to version 7, since otherwise the plugin will not build. Let me know if i need to fix something else, i know that the plugin is slow, but that is an issue with how RStudio handles the credentials.

@leonardo-doyensec could you do a rebase of your branch to resolve the merge conflict?

@leonardo-doyensec
Copy link
Collaborator Author

Hi @maoning, i've fixed the merge conflict. I've also fixed a non working test after the recent commits

@copybara-service copybara-service bot merged commit 5c1aadb into google:master May 13, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Contributor main The main issue a contributor is working on (top of the contribution queue).
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PRP: RStudio Weak Credentials
3 participants