Skip to content

Update OS Command Injection Plugin to Include All Test Cases#77

Open
shayancha wants to merge 5 commits into
mainfrom
shayancha/update-os_command_injection-plugin
Open

Update OS Command Injection Plugin to Include All Test Cases#77
shayancha wants to merge 5 commits into
mainfrom
shayancha/update-os_command_injection-plugin

Conversation

@shayancha
Copy link
Copy Markdown
Collaborator

Went through all OS command injection test cases and added patched sources to the taintmonkey() fixture.

All test cases execute predictably when only the necessary sink function is included in the SINKS list.

However, there is a bug for the use case where multiple sink functions are included in SINKS and the last element is not the appropriate sink function for the test case being executed.

@bliutech
Copy link
Copy Markdown
Owner

However, there is a bug for the use case where multiple sink functions are included in SINKS and the last element is not the appropriate sink function for the test case being executed.

Can you elaborate on this bug a bit more? Would it occur for something like this?

SINKS = [
   "os.popen",
   "os.system"
]

With only os.system being patched? I suspect this may be due to some issues with cache invalidation in taintmonkey.patch.import_module.

Comment thread plugins/cwe_78_os_command_injection/__init__.py Outdated
Copy link
Copy Markdown
Owner

@bliutech bliutech left a comment

Choose a reason for hiding this comment

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

Looks like a good start. I think we need to also add harnesses for each test case to this plugin as well.

@shayancha
Copy link
Copy Markdown
Collaborator Author

However, there is a bug for the use case where multiple sink functions are included in SINKS and the last element is not the appropriate sink function for the test case being executed.

Can you elaborate on this bug a bit more? Would it occur for something like this?

SINKS = [
   "os.popen",
   "os.system"
]

With only os.system being patched? I suspect this may be due to some issues with cache invalidation in taintmonkey.patch.import_module.

Yes, exactly!

@bliutech
Copy link
Copy Markdown
Owner

Got it. I think we need to tie the lifetime of the import cache directly to the TaintMonkey object. This way we don't need to invalidate the cache on every import and can just do it at the destruction of the instance. We probably want to implement a similar approach to pytest with how they have a MonkeyPatch.undo() interface. https://github.com/pytest-dev/pytest/blob/main/src/_pytest/monkeypatch.py#L57

@bliutech bliutech self-requested a review August 1, 2025 15:03
Copy link
Copy Markdown
Owner

@bliutech bliutech left a comment

Choose a reason for hiding this comment

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

Good progress so far!

@shayancha shayancha requested a review from bliutech August 2, 2025 01:27
@shayancha
Copy link
Copy Markdown
Collaborator Author

I adjusted open_file_command so that it acts as a propagator, not a source.

However, is_safe_path does not seem to properly sanitize the input, even after I try to monkey patch it manually. I noticed that if I even try to do something like

@tm.patch.function(
        "dataset.cwe_78_os_command_injection.secure_novalidation.app.is_safe_path"
    )
    def patched_is_safe_path(path):
        return original_function(path)

I get different behavior than if I don't monkey patch, which shouldn't be the case. When I monkey patch, is_safe_path isn't actually blocking any inputs from continuing to a sink.

Copy link
Copy Markdown
Collaborator

@SeabassMarket SeabassMarket left a comment

Choose a reason for hiding this comment

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

We are going to rewrite plugins soon to follow the new streamlined format. Just clean it up a bit, and then we'll merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants