{"id":9441,"date":"2022-10-27T10:50:58","date_gmt":"2022-10-27T10:50:58","guid":{"rendered":"https:\/\/www.trustrecipe.in\/?p=9441"},"modified":"2023-11-07T23:08:25","modified_gmt":"2023-11-07T23:08:25","slug":"team-finance-exploit-oct-27-2022-detailed-analysis","status":"publish","type":"post","link":"https:\/\/immunebytes.com\/blog\/team-finance-exploit-oct-27-2022-detailed-analysis\/","title":{"rendered":"Team Finance Exploit &#8211; Oct 27, 2022 &#8211; Detailed Analysis"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\">&nbsp;Introduction<\/h3>\n\n\n\n<p>This report details a significant exploit incident targeting Team Finance on the Ethereum blockchain, which occurred on October 27, 2022, for ~$14.5 million.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Incident Overview<\/h3>\n\n\n\n<p>The hacking incident took place when Team Finance was executing a migration from Uniswap v2 to v3.<\/p>\n\n\n\n<p>An attacker exploited vulnerabilities in the LockToken contract, leading to the unauthorized transfer of tokens from the V2 liquidity pool to the V3 liquidity pool, namely WTH, CAW, USDC, and TSUKA. <\/p>\n\n\n\n<p>The attacker manipulated the Initialize price of the V3 liquidity pool using `sqrtPriceX96` to secure significant refund arbitrage.&nbsp;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Key Data Related to the Attack<\/h3>\n\n\n\n<p><strong>Attack Transaction:<\/strong> 0xb2e3ea72d353da43a2ac9a8f1670fd16463ab370e563b9b5b26119b2601277ce]<\/p>\n\n\n\n<p><strong>Attacker\u00e2\u20ac\u2122s Addresses:<\/strong>&nbsp;<br>0x161cebB807Ac181d5303A4cCec2FC580CC5899Fd<br>0xBa399a2580785A2dEd740F5e30EC89Fb3E617e6E<\/p>\n\n\n\n<p><strong>Contracts Involved&nbsp;<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>Attack Contract:<\/strong> 0xCFF07C4e6aa9E2fEc04DAaF5f41d1b10f3adAdF4&nbsp;&nbsp;<\/li><li><strong>Victim Contract:<\/strong> 0xE2fE530C047f2d85298b07D9333C05737f1435fB<\/li><li><strong>Token A:<\/strong> 0x2d4abfdcd1385951df4317f9f3463fb11b9a31df<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Vulnerability Analysis<\/h3>\n\n\n\n<p>The core of the exploit lies in the LockToken contract&#8217;s <strong>&#8216;migrate&#8217;<\/strong> function. The checks and validations in this function were weak, enabling the attacker to bypass them with ease and manipulate prices during the migration phase.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"686\" src=\"https:\/\/www.trustrecipe.in\/wp-content\/uploads\/2023\/10\/Team-Finance-Exploit-Oct-2022-1-1024x686.png\" alt=\"\" class=\"wp-image-9442\" srcset=\"https:\/\/immunebytes.com\/blog\/wp-content\/uploads\/2023\/10\/Team-Finance-Exploit-Oct-2022-1-1024x686.png 1024w, https:\/\/immunebytes.com\/blog\/wp-content\/uploads\/2023\/10\/Team-Finance-Exploit-Oct-2022-1-300x201.png 300w, https:\/\/immunebytes.com\/blog\/wp-content\/uploads\/2023\/10\/Team-Finance-Exploit-Oct-2022-1-768x514.png 768w, https:\/\/immunebytes.com\/blog\/wp-content\/uploads\/2023\/10\/Team-Finance-Exploit-Oct-2022-1-1536x1029.png 1536w, https:\/\/immunebytes.com\/blog\/wp-content\/uploads\/2023\/10\/Team-Finance-Exploit-Oct-2022-1-1170x784.png 1170w, https:\/\/immunebytes.com\/blog\/wp-content\/uploads\/2023\/10\/Team-Finance-Exploit-Oct-2022-1-585x392.png 585w, https:\/\/immunebytes.com\/blog\/wp-content\/uploads\/2023\/10\/Team-Finance-Exploit-Oct-2022-1-263x175.png 263w, https:\/\/immunebytes.com\/blog\/wp-content\/uploads\/2023\/10\/Team-Finance-Exploit-Oct-2022-1.png 1920w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><br><br>The migrate function within the compromised LockToken contract facilitates the transition of specific liquidity from Uniswap-V2 to Uniswap-V3 for users. Post-migration, users receive a portion of the tokens as a refund, determined by the prevailing price. To invoke this function, parameters such as lock ID, the duration of the lock, and a designated withdrawal address are necessary.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"686\" src=\"https:\/\/www.trustrecipe.in\/wp-content\/uploads\/2023\/10\/Team-Finance-Exploit-Oct-2022-2-1024x686.png\" alt=\"\" class=\"wp-image-9443\" srcset=\"https:\/\/immunebytes.com\/blog\/wp-content\/uploads\/2023\/10\/Team-Finance-Exploit-Oct-2022-2-1024x686.png 1024w, https:\/\/immunebytes.com\/blog\/wp-content\/uploads\/2023\/10\/Team-Finance-Exploit-Oct-2022-2-300x201.png 300w, https:\/\/immunebytes.com\/blog\/wp-content\/uploads\/2023\/10\/Team-Finance-Exploit-Oct-2022-2-768x514.png 768w, https:\/\/immunebytes.com\/blog\/wp-content\/uploads\/2023\/10\/Team-Finance-Exploit-Oct-2022-2-1536x1029.png 1536w, https:\/\/immunebytes.com\/blog\/wp-content\/uploads\/2023\/10\/Team-Finance-Exploit-Oct-2022-2-1170x784.png 1170w, https:\/\/immunebytes.com\/blog\/wp-content\/uploads\/2023\/10\/Team-Finance-Exploit-Oct-2022-2-585x392.png 585w, https:\/\/immunebytes.com\/blog\/wp-content\/uploads\/2023\/10\/Team-Finance-Exploit-Oct-2022-2-263x175.png 263w, https:\/\/immunebytes.com\/blog\/wp-content\/uploads\/2023\/10\/Team-Finance-Exploit-Oct-2022-2.png 1920w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Attack Flow<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Pre-attack Preparations<\/strong><\/h4>\n\n\n\n<p>The attacker deployed the attack contract and also generated &#8220;token A&#8221; through the token contract 0x2d4abfdcd1385951df4317f9f3463fb11b9a31df.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Token Locking<\/strong><\/h4>\n\n\n\n<p>The lockToken function within the LockToken contract allows users to secure their tokens and subsequently generate an NFT serving as a Liquidity Provider (LP) token. <br><br>It provides users the latitude to specify details, including the token type, quantity, withdrawal address, and the duration of the lock. <br><br>In this specific exploit, the attacker leveraged this function to lock &#8216;token A&#8217;, designating the withdrawal to the attack contract&#8217;s address. This action resulted in the creation of four distinct NFTs, bearing the LP ids 15324, 15325, 15326, and 15327.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh7-us.googleusercontent.com\/OZC0iJ7t2SKDOniIHaIrD1EqHTn7U1oQCnREBcNvDbIB-Fzov4abadXZB64JlpmGrpKmwqwWNz5Y-Xw1SJAUemy3ZxtbwOphmZVjWATDktlxcoPEgbxUR2zsgycofZ82SHCXtkA1JJOpELy-FwZ8bQY\" alt=\"\"\/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Locking Time Adjustment<\/strong><\/h4>\n\n\n\n<p>The `extendLockDuration` function in the LockToken contract was used to adjust the locking time for each of the NFT tokens.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh7-us.googleusercontent.com\/bD2BT8JdvIdPFrF3v95rKxGEKVBQ3YHjZouZoOW4QUooYazdxBFhG1Mfo0VzaUoTFWLAPY3b8qIwjLzok3y8QxAZknRPxmKg26FhRefF-mCPLB-1WuYgIDT5526-PjJFatPwVT_o3pDZePJPZQIa5qE\" alt=\"\"\/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Migration Preparations<\/strong><\/h4>\n\n\n\n<p>The attack contract initiated a query to the LockToken contract, aiming to determine the specific number of LP tokens. This data extraction was pivotal as it formed an integral part of the parameters required to execute the attack successfully.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"686\" src=\"https:\/\/www.trustrecipe.in\/wp-content\/uploads\/2023\/10\/Team-Finance-Exploit-Oct-2022-3-1024x686.png\" alt=\"\" class=\"wp-image-9444\" srcset=\"https:\/\/immunebytes.com\/blog\/wp-content\/uploads\/2023\/10\/Team-Finance-Exploit-Oct-2022-3-1024x686.png 1024w, https:\/\/immunebytes.com\/blog\/wp-content\/uploads\/2023\/10\/Team-Finance-Exploit-Oct-2022-3-300x201.png 300w, https:\/\/immunebytes.com\/blog\/wp-content\/uploads\/2023\/10\/Team-Finance-Exploit-Oct-2022-3-768x514.png 768w, https:\/\/immunebytes.com\/blog\/wp-content\/uploads\/2023\/10\/Team-Finance-Exploit-Oct-2022-3-1536x1029.png 1536w, https:\/\/immunebytes.com\/blog\/wp-content\/uploads\/2023\/10\/Team-Finance-Exploit-Oct-2022-3-1170x784.png 1170w, https:\/\/immunebytes.com\/blog\/wp-content\/uploads\/2023\/10\/Team-Finance-Exploit-Oct-2022-3-585x392.png 585w, https:\/\/immunebytes.com\/blog\/wp-content\/uploads\/2023\/10\/Team-Finance-Exploit-Oct-2022-3-263x175.png 263w, https:\/\/immunebytes.com\/blog\/wp-content\/uploads\/2023\/10\/Team-Finance-Exploit-Oct-2022-3.png 1920w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Exploitation Through Migrate Function<\/strong><\/h4>\n\n\n\n<p>Leveraging the NFTs acquired in earlier stages, the attacker invoked the migrate function. This orchestrated action served two malicious purposes:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"686\" src=\"https:\/\/www.trustrecipe.in\/wp-content\/uploads\/2023\/10\/Team-Finance-Exploit-Oct-2022-4-1024x686.png\" alt=\"\" class=\"wp-image-9446\" srcset=\"https:\/\/immunebytes.com\/blog\/wp-content\/uploads\/2023\/10\/Team-Finance-Exploit-Oct-2022-4-1024x686.png 1024w, https:\/\/immunebytes.com\/blog\/wp-content\/uploads\/2023\/10\/Team-Finance-Exploit-Oct-2022-4-300x201.png 300w, https:\/\/immunebytes.com\/blog\/wp-content\/uploads\/2023\/10\/Team-Finance-Exploit-Oct-2022-4-768x514.png 768w, https:\/\/immunebytes.com\/blog\/wp-content\/uploads\/2023\/10\/Team-Finance-Exploit-Oct-2022-4-1536x1029.png 1536w, https:\/\/immunebytes.com\/blog\/wp-content\/uploads\/2023\/10\/Team-Finance-Exploit-Oct-2022-4-1170x784.png 1170w, https:\/\/immunebytes.com\/blog\/wp-content\/uploads\/2023\/10\/Team-Finance-Exploit-Oct-2022-4-585x392.png 585w, https:\/\/immunebytes.com\/blog\/wp-content\/uploads\/2023\/10\/Team-Finance-Exploit-Oct-2022-4-263x175.png 263w, https:\/\/immunebytes.com\/blog\/wp-content\/uploads\/2023\/10\/Team-Finance-Exploit-Oct-2022-4.png 1920w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Bypassing Safeguards<\/strong><\/h4>\n\n\n\n<p>The preparations using the NFTs allowed the attacker to sidestep various validations embedded in the migrate function. Specifically:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>The verification checks tied to the NFT&#8217;s id and its associated lock time.<\/li><li>The requirements associated with the withdrawal address.<\/li><\/ul>\n\n\n\n<p>As a result, the NFT id that was obtained by locking the token A was now primed to engage in the migration of the FEG-WETH token pair. This occurred despite the absence of checks confirming if the user\u00e2\u20ac\u2122s locked token matched the one currently in operation.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"686\" src=\"https:\/\/www.trustrecipe.in\/wp-content\/uploads\/2023\/10\/Team-Finance-Exploit-Oct-2022-5-1024x686.png\" alt=\"\" class=\"wp-image-9448\" srcset=\"https:\/\/immunebytes.com\/blog\/wp-content\/uploads\/2023\/10\/Team-Finance-Exploit-Oct-2022-5-1024x686.png 1024w, https:\/\/immunebytes.com\/blog\/wp-content\/uploads\/2023\/10\/Team-Finance-Exploit-Oct-2022-5-300x201.png 300w, https:\/\/immunebytes.com\/blog\/wp-content\/uploads\/2023\/10\/Team-Finance-Exploit-Oct-2022-5-768x514.png 768w, https:\/\/immunebytes.com\/blog\/wp-content\/uploads\/2023\/10\/Team-Finance-Exploit-Oct-2022-5-1536x1029.png 1536w, https:\/\/immunebytes.com\/blog\/wp-content\/uploads\/2023\/10\/Team-Finance-Exploit-Oct-2022-5-1170x784.png 1170w, https:\/\/immunebytes.com\/blog\/wp-content\/uploads\/2023\/10\/Team-Finance-Exploit-Oct-2022-5-585x392.png 585w, https:\/\/immunebytes.com\/blog\/wp-content\/uploads\/2023\/10\/Team-Finance-Exploit-Oct-2022-5-263x175.png 263w, https:\/\/immunebytes.com\/blog\/wp-content\/uploads\/2023\/10\/Team-Finance-Exploit-Oct-2022-5.png 1920w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Price Manipulation<\/strong><\/h4>\n\n\n\n<p>The attacker had the ability to input the sqrtPriceX96 parameter, which is integral to the price calculation during the UNI-V3 migration. This not only intensified the exploit but also gave the attacker undue advantage over price adjustments.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Funds Transfer<\/h4>\n\n\n\n<p>Post-exploitation, the attacker mobilized the pre-configured NFTs to secure migration refunds for four specific tokens. These were:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>WETH<\/li><li>DAI<\/li><li>CAW<\/li><li>TSUKA<\/li><\/ul>\n\n\n\n<p>These refunded tokens, which were an illicit gain from the exploit, were promptly sent to the address: 0xBa399a2580785A2dEd740F5e30EC89Fb3E617e6E.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Impact Analysis<\/h3>\n\n\n\n<p>The stolen funds of this attack are divided as:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>ETH: 880.258<\/li><li>DAI: 6,429,327.6<\/li><li>CAW: 74,613,657,704.3<\/li><li>TSUKA: 1,183,757.7<\/li><\/ul>\n\n\n\n<p>The combined value of these stolen funds was around $14.5 million.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Post-Incident Update<\/h3>\n\n\n\n<p>Subsequent to the exploit, which totaled a staggering $14.5 million, the attacker returned approximately $7 million in stolen tokens. The attacker identified themselves as a \u00e2\u20ac\u0153whitehat\u00e2\u20ac\u009d within transaction remarks.&nbsp;<\/p>\n\n\n\n<p>Here are the returned amounts:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>DAI: Over $765,000&nbsp;<\/li><li>TSUKA: 11.8 million tokens&nbsp;<\/li><li>ETH to Kondux: 209&nbsp;<\/li><li>ETH to Feg Token: 548<\/li><\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">&nbsp;Conclusion<\/h4>\n\n\n\n<p>The Team Finance exploit underlines the imperative for robust security protocols and continuous vulnerability assessments in the realm of smart contract design and deployment. <\/p>\n\n\n\n<p>The subsequent actions by the attacker, who self-identified as a &#8220;whitehat&#8221;, bring forth the intricate nature of cybersecurity within the blockchain ecosystem.<\/p>\n\n\n\n<p>Therefore, conducting <a href=\"https:\/\/immunebytes.com\/blog\/smart-contract-audit\/\" title=\"\">regular smart contract audits<\/a> is absolutely necessary to uncover the bugs, which could not be identified earlier. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp;Introduction This report details a significant exploit incident targeting Team Finance on the Ethereum blockchain, which occurred on October 27,&hellip;<\/p>\n","protected":false},"author":2,"featured_media":10186,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_lmt_disableupdate":"","_lmt_disable":"","footnotes":""},"categories":[6,679],"tags":[],"class_list":["post-9441","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-crypto-hacks-exploits","category-web3-security"],"_links":{"self":[{"href":"https:\/\/immunebytes.com\/blog\/wp-json\/wp\/v2\/posts\/9441","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/immunebytes.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/immunebytes.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/immunebytes.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/immunebytes.com\/blog\/wp-json\/wp\/v2\/comments?post=9441"}],"version-history":[{"count":3,"href":"https:\/\/immunebytes.com\/blog\/wp-json\/wp\/v2\/posts\/9441\/revisions"}],"predecessor-version":[{"id":10187,"href":"https:\/\/immunebytes.com\/blog\/wp-json\/wp\/v2\/posts\/9441\/revisions\/10187"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/immunebytes.com\/blog\/wp-json\/wp\/v2\/media\/10186"}],"wp:attachment":[{"href":"https:\/\/immunebytes.com\/blog\/wp-json\/wp\/v2\/media?parent=9441"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/immunebytes.com\/blog\/wp-json\/wp\/v2\/categories?post=9441"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/immunebytes.com\/blog\/wp-json\/wp\/v2\/tags?post=9441"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}