From b23984a210cb5195c787eb49f4f88e4e1ac6d67f Mon Sep 17 00:00:00 2001 From: linqining Date: Sun, 22 Dec 2024 11:25:37 +0800 Subject: [PATCH] feat:task8 --- mover/linqining/code/task8/call.sh | 2 + .../linqining/code/task8/challenge/Move.toml | 37 ++++++++ .../task8/challenge/sources/challenge.move | 90 +++++++++++++++++++ .../challenge/tests/challenge_tests.move | 2 + mover/linqining/code/task8/miner/go.mod | 8 ++ mover/linqining/code/task8/miner/main.go | 56 ++++++++++++ mover/linqining/readme.md | 4 +- 7 files changed, 197 insertions(+), 2 deletions(-) create mode 100644 mover/linqining/code/task8/call.sh create mode 100644 mover/linqining/code/task8/challenge/Move.toml create mode 100644 mover/linqining/code/task8/challenge/sources/challenge.move create mode 100644 mover/linqining/code/task8/challenge/tests/challenge_tests.move create mode 100644 mover/linqining/code/task8/miner/go.mod create mode 100644 mover/linqining/code/task8/miner/main.go diff --git a/mover/linqining/code/task8/call.sh b/mover/linqining/code/task8/call.sh new file mode 100644 index 000000000..f61d43497 --- /dev/null +++ b/mover/linqining/code/task8/call.sh @@ -0,0 +1,2 @@ +sui client call --package 0x097a3833b6b5c62ca6ad10f0509dffdadff7ce31e1d86e63e884a14860cedc0f --module lets_move --function get_flag \ +--args "SnyLUIXawx" linqining 0x19e76ca504c5a5fa5e214a45fca6c058171ba333f6da897b82731094504d5ab9 0x8 --gas-budget 3000000 \ No newline at end of file diff --git a/mover/linqining/code/task8/challenge/Move.toml b/mover/linqining/code/task8/challenge/Move.toml new file mode 100644 index 000000000..b2a5ed0c2 --- /dev/null +++ b/mover/linqining/code/task8/challenge/Move.toml @@ -0,0 +1,37 @@ +[package] +name = "challenge" +edition = "2024.beta" # edition = "legacy" to use legacy (pre-2024) Move +# license = "" # e.g., "MIT", "GPL", "Apache 2.0" +# authors = ["..."] # e.g., ["Joe Smith (joesmith@noemail.com)", "John Snow (johnsnow@noemail.com)"] + +[dependencies] +Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "framework/testnet" } + +# For remote import, use the `{ git = "...", subdir = "...", rev = "..." }`. +# Revision can be a branch, a tag, and a commit hash. +# MyRemotePackage = { git = "https://some.remote/host.git", subdir = "remote/path", rev = "main" } + +# For local dependencies use `local = path`. Path is relative to the package root +# Local = { local = "../path/to" } + +# To resolve a version conflict and force a specific version for dependency +# override use `override = true` +# Override = { local = "../conflicting/version", override = true } + +[addresses] +challenge = "0x0" + +# Named addresses will be accessible in Move as `@name`. They're also exported: +# for example, `std = "0x1"` is exported by the Standard Library. +# alice = "0xA11CE" + +[dev-dependencies] +# The dev-dependencies section allows overriding dependencies for `--test` and +# `--dev` modes. You can introduce test-only dependencies here. +# Local = { local = "../path/to/dev-build" } + +[dev-addresses] +# The dev-addresses section allows overwriting named addresses for the `--test` +# and `--dev` modes. +# alice = "0xB0B" + diff --git a/mover/linqining/code/task8/challenge/sources/challenge.move b/mover/linqining/code/task8/challenge/sources/challenge.move new file mode 100644 index 000000000..ea8b90f91 --- /dev/null +++ b/mover/linqining/code/task8/challenge/sources/challenge.move @@ -0,0 +1,90 @@ + +/// Module: challenge +module challenge::challenge; + +use std::ascii::{String, string}; +use std::hash; +use sui::event; +use sui::bcs; +use sui::random; +use sui::random::Random; +use sui::transfer::share_object; +use std::debug::print; +use sui::address; + + +public struct Challenge has drop { + id:ID, + str: String, + difficulity: u64, + ture_num: u64 +} + + + + +#[test] +fun test_challenge_fail() { + let challenge:Challenge = Challenge{ + id: object::id_from_address(@0x19e76ca504c5a5fa5e214a45fca6c058171ba333f6da897b82731094504d5ab9), + str:std::ascii::string(b"M9[fZ#glu@qF5J8zd:m)*V87>C*\\Y"), + difficulity: 3, + ture_num: 108, + }; + // let cbyte = bcs::to_bytes(&challenge); + // print(&cbyte.to_string()); + let mut prefix_sum: u32 = 1; + let name = std::ascii::string(b"proof"); + let borrowname = std::ascii::string(b"getproof"); + let mut proof = b"1234567892"; + let mut strlen:u8 =30; + let call_addr = @0xc1f4704452819f75c258fe3a01e54d6561899e3478f818625ee8be716fbdd007; + print(&call_addr.to_bytes()); + while (prefix_sum!=0){ + strlen = strlen+1; + let mut proof = b"SnyLUIXawx"; + let mut full_proof: vector = vector::empty(); + vector::append(&mut full_proof, proof); + vector::append(&mut full_proof, call_addr.to_bytes()); + vector::append(&mut full_proof, bcs::to_bytes(&challenge)); + + let hash: vector = hash::sha3_256(full_proof); + // print(&name); + print(&proof); + prefix_sum = 0; + let mut i: u64 = 0; + while (i < challenge.difficulity) { + let borrorval = (*vector::borrow(&hash, i) as u32); + + prefix_sum = prefix_sum + borrorval; + i = i + 1; + }; + + print(&prefix_sum); + if (prefix_sum==0){ + print(&borrowname); + print(&proof); + break + } + }; + return + +} + +fun getRandomString(laststr:vector,strLen:u8): String { + let mut gen = sui::random::new_generator_from_seed_for_testing(laststr); + + let mut str_len = strLen; + + let mut rand: vector = b""; + while (str_len != 0) { + let rand_num = random::generate_u8_in_range(&mut gen, 34, 126); + vector::push_back(&mut rand, rand_num); + str_len = str_len - 1; + }; + + string(rand) +} + + + diff --git a/mover/linqining/code/task8/challenge/tests/challenge_tests.move b/mover/linqining/code/task8/challenge/tests/challenge_tests.move new file mode 100644 index 000000000..c8e6954ff --- /dev/null +++ b/mover/linqining/code/task8/challenge/tests/challenge_tests.move @@ -0,0 +1,2 @@ + +module challenge::challenge_tests; diff --git a/mover/linqining/code/task8/miner/go.mod b/mover/linqining/code/task8/miner/go.mod new file mode 100644 index 000000000..ec8447aa9 --- /dev/null +++ b/mover/linqining/code/task8/miner/go.mod @@ -0,0 +1,8 @@ +module example.com/m/v2 + +go 1.23.0 + +require ( + golang.org/x/crypto v0.31.0 // indirect + golang.org/x/sys v0.28.0 // indirect +) diff --git a/mover/linqining/code/task8/miner/main.go b/mover/linqining/code/task8/miner/main.go new file mode 100644 index 000000000..c43db7db5 --- /dev/null +++ b/mover/linqining/code/task8/miner/main.go @@ -0,0 +1,56 @@ +package main + +import ( + "encoding/hex" + "fmt" + "golang.org/x/crypto/sha3" + "math/rand" + "time" +) + +func main() { + preFixSum := 1 + + addrByte := bytesFromHex("c1f4704452819f75c258fe3a01e54d6561899e3478f818625ee8be716fbdd007") + fmt.Println(addrByte) + objByte := bytesFromHex("19e76ca504c5a5fa5e214a45fca6c058171ba333f6da897b82731094504d5ab91d4d395b665a23676c75407146354a387a643a6d292a5638373e432a5c5903000000000000006c00000000000000") + fmt.Println(objByte) + + // Create a new hash & write input string + for preFixSum != 0 { + proof := getRandomString(10) + hash := sha3.New256() + _, _ = hash.Write([]byte(proof)) + hash.Write(addrByte) + hash.Write(objByte) + sha3 := hash.Sum(nil) + + preFixSum = 0 + for i := 0; i < 3; i++ { + preFixSum = preFixSum + int(sha3[i]) + } + fmt.Println(preFixSum) + if preFixSum == 0 { + fmt.Println("getproof") + fmt.Println(proof) + break + } + } + return +} + +func getRandomString(n int) string { + const letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" + rand.Seed(time.Now().UnixNano()) + b := make([]byte, n) + for i := range b { + b[i] = letters[rand.Intn(len(letters))] + } + return string(b) +} + +func bytesFromHex(hexstr string) []byte { + bytes, err := hex.DecodeString(hexstr) + fmt.Println(err) + return bytes +} diff --git a/mover/linqining/readme.md b/mover/linqining/readme.md index ff44c49c3..23586b109 100644 --- a/mover/linqining/readme.md +++ b/mover/linqining/readme.md @@ -54,5 +54,5 @@ - [x] flag hash : 7SW1NGXYLjPuLLbxrHe4ceDwDe1xjcuvEBCjub11GMYG ## 08 Move CTF Lets Move -- [] proof : -- [] flag hash : +- [x] proof : SnyLUIXawx +- [x] flag hash : FT2f1fkHGHz7Wj9Hq6KvSZXpbRJkK5QiBLdNyLsMCJKY