-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Flaws in Cast Downloading Contract Source Code #4896
Closed
1 of 2 tasks
Labels
T-bug
Type: bug
Comments
tysm for this.
This seems like the right fix, so we should remove the |
also could just add a check!if there are some file don't have '.sol' in the end of name! |
i'm @Hellobloc , this is another account! sorry for this. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Component
Cast
Have you ensured that all of these are up to date?
What version of Foundry are you on?
No response
What command(s) is the bug in?
cast etherscan
Operating System
Windows
Describe the bug
Introduction
cast supports downloading contract source code locally via etherscan. cast uses the rs library of
ethers-etherscan
to handle part of the download logic. The path traversal vulnerability is well guarded in theethers-etherscan
library, but the operation of automatically adding the.sol
suffix causes the tool to have a possible new risk.https://github.com/foundry-rs/foundry/blob/master/cast/src/lib.rs#L19
https://sourcegraph.com/crates/ethers-etherscan@9e675141953f88a190ac883ad02841370836d35c/-/blob/src/source_tree.rs?L18-36
Risk
Specifically, we can build two contract files,
Attack
andAttack.sol
, inEtherscan
, which makes it possible for the two files to have the same filename and be overwritten when the source code of etherscan is downloaded locally bycast
. This feature can be used to implement some honeypot contracts, where we can make some backdoor source code content overwritten and not visible through the source code.Attack Case
Here we can try to allow the following command to verify the problem
Here we can easily find that our file directory only has an almost empty
Token.sol
file, but the actualToken.sol
is overwritten. In a real scenario, we can build some honeypot contracts to defraud users by designing the Token.sol contract to be more complex making it difficult to detect the overwriting happening.Recommendation
We recommend removing the appending of filenames (
.sol
) whenever possible, or giving some warning notes and trying to detect such issues and warn about them.The text was updated successfully, but these errors were encountered: