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

Triton Inference Server Rce Detector #451

Merged
merged 18 commits into from
May 20, 2024

Conversation

secureness
Copy link
Contributor

@secureness secureness commented Apr 4, 2024

@leonardo-doyensec leonardo-doyensec self-assigned this Apr 12, 2024
Copy link
Collaborator

@leonardo-doyensec leonardo-doyensec left a comment

Choose a reason for hiding this comment

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

Hi @secureness,
Thank you for your contribution! I did a review of your plugin, and i've found that is not properly working. Below you can find a list of things to address, some of them are minor stylistic issues but there are some important things to change (for example the issue at line 168).

Feel free to reach out.

~ Leonardo (Doyensec)

* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.tsunami.plugins.detectors.rce;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please add a space from the line above

import com.google.common.collect.ImmutableList;
import com.google.common.flogger.GoogleLogger;
import com.google.common.util.concurrent.Uninterruptibles;
import com.google.gson.*;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Avoid using wildcard imports. Import only needed packages

import com.google.tsunami.plugin.annotations.PluginInfo;
import com.google.tsunami.plugin.payload.Payload;
import com.google.tsunami.plugin.payload.PayloadGenerator;
import com.google.tsunami.proto.*;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Avoid using wildcard imports. Import only needed packages

if (modelNames.bodyString().isEmpty()) {
return false;
}
JsonArray modelNamesJO =
Copy link
Collaborator

Choose a reason for hiding this comment

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

Methods and non-static variables should be named in lowerCamelCase, with acronyms treated as words. Please consider changing variable name to modelNamesJo

}
JsonArray modelNamesJO =
JsonParser.parseString(modelNames.bodyString().get()).getAsJsonArray();
if (modelNamesJO.isEmpty()) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This statement creates some problem during the run. Running on my side it will result in a crash during the Tsunami scan. Please fix this by replacing with modelNamesJO.isJsonNull()

.setRequestBody(
ByteString.copyFromUtf8(
String.format(
"{\"parameters\":{\"config\" : \"{}\", \"file:config.pbtxt\" :\"%s\" }}",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please consider declaring this as a constant

.setRequestBody(
ByteString.copyFromUtf8(
String.format(
"{\"parameters\":{\"config\" : \"{}\", \"file:1/model.py\" : \"%s\" }}",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please consider declaring this as a constant

Comment on lines 142 to 144
if (!payloadGenerator.isCallbackServerEnabled()) {
return false;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

The isCallbackServerEnabled() method return false when all config fields are empty so that improper config (e.g., missing certain fields) can be exposed.
In case where the correct config file is used, but if the callback server is not run, the plugin will crash.

Consider changing the business logic in order to catch this case

* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.tsunami.plugins.detectors.rce;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please add a space from the line above

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi, I didn't understand about this part of the review, unfortunately.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be changed in order to be compliant with Google's Java Format. You can find more information here https://google.github.io/styleguide/javaguide.html#s3-source-file-structure

@leonardo-doyensec
Copy link
Collaborator

leonardo-doyensec commented Apr 12, 2024

I've also noticed that the issue that this PR is referring to is incorrect. I think this plugin is linked to #433

@secureness
Copy link
Contributor Author

I've also noticed that the issue that this PR is referring to is incorrect. I think this plugin is linked to #433

Yes you are right, sorry about this :))

@leonardo-doyensec
Copy link
Collaborator

Hi @secureness,
I'm noticing that after your changes the plugin still not working properly. I think that the root cause is the modelNamesJo.isEmpty() method. Please remove it.

~ Leonardo (Doyensec)

@maoning
Copy link
Collaborator

maoning commented Apr 25, 2024

@secureness could you check if the proposed change works? I would like to merge in this PR asap to unblock you from picking up the hive weak cred plugin.

@secureness
Copy link
Contributor Author

@maoning @leonardo-doyensec I'm sorry if it took too long to fix the review suggestion.

@leonardo-doyensec
Copy link
Collaborator

Hi @secureness ,
thank you for your changes. However after the last commits, the plugin no longer builds.
This is an issue related to gradlew. Please upgrade it to version 7. You can take a look at the solution adopted here 251cdd2

~ Leonardo (Doyensec)

@secureness
Copy link
Contributor Author

@leonardo-doyensec thanks for the help. I just wanted to let you know that it is done now.

Copy link
Collaborator

@leonardo-doyensec leonardo-doyensec left a comment

Choose a reason for hiding this comment

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

Hi @secureness ,
thank you for your changes. I've added some comment on the code. I'm also noticing that when the plugin is running, and the callback server receives the request (so that the vulnerability is confirmed) the amount of vulnerability detected is not updated. This means that in Tsunami's final log the vulnerability count is zero.
Can you please fix also that?

~ Leonardo (Doyensec)

package com.google.tsunami.plugins.detectors.rce;

import static com.google.common.truth.extensions.proto.ProtoTruth.assertThat;
import static com.google.tsunami.common.data.NetworkEndpointUtils.*;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please, import only needed packages and remove star imports.

Comment on lines 102 to 109
public void detect_whenVulnerable_returnsVulnerability() throws IOException {
mockWebServer.enqueue(
new MockResponse().setResponseCode(200).setBody("[{\"name\":\"metasploit\"}]"));
mockWebServer.enqueue(new MockResponse().setResponseCode(200));
mockWebServer.enqueue(new MockResponse().setResponseCode(200));
mockWebServer.enqueue(new MockResponse().setResponseCode(200));
mockWebServer.enqueue(new MockResponse().setResponseCode(200));
mockCallbackServer.enqueue(PayloadTestHelper.generateMockSuccessfulCallbackResponse());
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ideally would be better to implement more reliable tests. Keep in mind that tests should mimic the vulnerable service as close as possible.

@secureness
Copy link
Contributor Author

@leonardo-doyensec I made some changes according to the official Google(the google/ directory) tsunami plugins. I have the # of detected vulnerability: 1. message after the scan results.
Also, I updated the testbed google/security-testbeds#51.

@leonardo-doyensec
Copy link
Collaborator

leonardo-doyensec commented May 9, 2024

LGTM - Approved
@maoning you can merge it. We also need to merge the security testbed google/security-testbeds#51

Reviewer: Leonardo, Doyensec

Plugin: Triton Inference Server Model Overwrite lead to RCE
Feedback: The overall quality is below standard. The plugin was not working at first and several interactions were required to make it work properly. Furthermore, some elements of formatting were missing, which further hindered the review of the plugin. The security testbed was easy to deploy
Drawbacks: None

@vsutedjo vsutedjo self-requested a review May 17, 2024 09:44
@vsutedjo vsutedjo self-assigned this May 17, 2024
@vsutedjo vsutedjo added the Contributor main The main issue a contributor is working on (top of the contribution queue). label May 17, 2024
copybara-service bot pushed a commit that referenced this pull request May 17, 2024
--
959e027 by secureness <nosecureness@gmail.com>:

v1

--
a0fece5 by secureness <nosecureness@gmail.com>:

chore

--
86fc686 by secureness <nosecureness@gmail.com>:

first review round

--
1a91386 by secureness <nosecureness@gmail.com>:

better callback control flow, I found out it from cve202348022 detector

--
b810477 by secureness <nosecureness@gmail.com>:

remove modelNamesJo.isEmpty()

--
cddb281 by secureness <nosecureness@gmail.com>:

test upgrade

--
0483886 by secureness <nosecureness@gmail.com>:

remove unused imports

--
a4e0990 by secureness <nosecureness@gmail.com>:

general improvement

--
e897bdf by secureness <nosecureness@gmail.com>:

fix the callback server message:)

--
610d7a5 by Viviana Sutedjo <37225049+vsutedjo@users.noreply.github.com>:

Update TritonInferenceServerRceDetectorBootstrapModule.java
--
c2c28b9 by Viviana Sutedjo <37225049+vsutedjo@users.noreply.github.com>:

Update TritonInferenceServerRceVulnDetector.java
--
3666842 by Viviana Sutedjo <37225049+vsutedjo@users.noreply.github.com>:

Update TritonInferenceServerRceVulnDetectorTest.java
--
d061471 by Viviana Sutedjo <37225049+vsutedjo@users.noreply.github.com>:

Update TritonInferenceServerRceVulnDetector.java

COPYBARA_INTEGRATE_REVIEW=#451 from secureness:triton-all-version d061471
PiperOrigin-RevId: 634763499
Change-Id: I949987a9081ddb196d4bd867c138c6d91a51a3ef
@tooryx
Copy link
Member

tooryx commented May 20, 2024

Hi @secureness,

Your PR has been merged. This usually means a reward will be granted. Google will start the internal QC process and the reward amount will be determined based on the quality of the detector report. Please be patient and allow up to a week for the QC process to finish. You'll be notified once the decision is made.

Thanks!

@tooryx tooryx merged commit 40430c4 into google:master May 20, 2024
1 check passed
@secureness
Copy link
Contributor Author

@tooryx After 27 days I didn't get any response yet. Is there anything wrong with this submission?

@tooryx
Copy link
Member

tooryx commented Jun 10, 2024

Hi @secureness,

I will check with the team and get back to you this week.

Cheers,
~tooryx

@tooryx
Copy link
Member

tooryx commented Jun 10, 2024

You will receive an update on the tracking bug soon. Sorry for the delay!

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.

None yet

5 participants