本文へ移動

TECHFUND
Media

Hi AUDIT
2024/6/10

NORMIEトークン$881,686のエクスプロイト|ハッキング分析

このブログ記事では、224.98ETH(約881,686ドル相当)の損失をもたらしたNORMIEトークンを含むスマートコントラクトのエクスプロイトを分解します。攻撃者は一連の戦略的スワップ、フラッシュローン、契約のロジックの脆弱性を利用してトークン供給を操作し、大きな利益を得ました。この悪用がどのように実行されたかを理解するために、その手順とコードを分解してみよう。

エクスプロイトのステップごとの内訳

1. 最初のスワップと残高照合

  • 攻撃者は最初にSushi Routerから2 ETHをスワップし、171,955 NORMIEトークンを入手しました。

  • 彼らはおよそ500万NORMIEトークンになるまでトークンをスワップし続けた。500万トークンを蓄積した理由は、デプロイ先のウォレット残高と一致させ、premarketuserチェックを回避するためでした。

2. プレマーケット・ユーザー・リストの操作

  • 攻撃コントラクトのアドレスは、脆弱性のあるgetpremarket_user関数を通じてpremarketuserリストに追加された。この関数は、受信者のアドレスがまだプレマーケットユーザーでないかどうか、そして購入される金額がチームのウォレット残高と一致するかどうかをチェックし、両方の条件が満たされた場合にプレマーケットユーザーのステータスを付与します。

  • チームのウォレットと同じ残高を維持することで、攻撃者はこのリストに追加された。

function _transfer(address sender, address recipient, uint256 amount) private returns (bool) {
  emit inSwapAndLiquifyStatus(inSwapAndLiquify);
  require(sender != address(0), "ERC20: transfer from the zero address");
  require(recipient != address(0), "ERC20: transfer to the zero address");

  if (sender != owner() && recipient != owner()) require(enableTrading, "cannot trade before the market opening");

  if (inSwapAndLiquify) {
    return _basicTransfer(sender, recipient, amount);
  } else {
    if (!isTxLimitExempt[sender] && !isTxLimitExempt[recipient]) {
      require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount.");
    }
    uint256 fAmount = (uint256(keccak256(abi.encodePacked(block.timestamp, block.difficulty))) % 11) + 90;
    uint256 tokensToSwap = _minimumTokensBeforeSwap.mul(fAmount).div(100);
    uint256 contractTokenBalance = balanceOf(address(this));
    bool overMinimumTokenBalance = contractTokenBalance >= tokensToSwap;
    emit stepLiquify(overMinimumTokenBalance, !inSwapAndLiquify, !isMarketPair[sender], swapAndLiquifyEnabled);
    if (isMarketPair[sender] && !isExcludedFromFee[recipient] && premarket_user[recipient]) {
      _balances[address(this)] = _balances[address(this)].add(amount);
    }
    if (overMinimumTokenBalance && !inSwapAndLiquify && !isMarketPair[sender] && swapAndLiquifyEnabled && !isExcludedFromFee[sender]) {
      if (swapAndLiquifyByLimitOnly) contractTokenBalance = tokensToSwap;
      swapAndLiquify(contractTokenBalance);
    }
    _balances[sender] = _balances[sender].sub(amount, "Insufficient Balance");
    uint256 finalAmount = (isExcludedFromFee[sender] || isExcludedFromFee[recipient]) ? amount : takeFee(sender, recipient, amount);
    if (checkWalletLimit && !isWalletLimitExempt[recipient]) require(balanceOf(recipient).add(finalAmount) <= _walletMax);
    _balances[recipient] = _balances[recipient].add(finalAmount);
    _get_premarket_user(recipient, amount);
    emit Transfer(sender, recipient, finalAmount);
    return true;
  }
}

3. フラッシュ・ローンとトークン・スワップ

  • premarketuserになった後、攻撃者は11,333,141 NORMIEトークンのフラッシュローンを行った。

  • 彼らはこのうち9,066,513トークンを65.97ETHと交換し、トークンの供給を大幅に操作した。

  • 残りの2,266,628 NORMIEトークンはUniswap V2ペアに提供された。

4. スワップとリキファイメカニズムの悪用

  • Uniswapファクトリーのskim機能を使用して、攻撃者は操作された資産を引き出しました。

  • 攻撃者の契約はプレマーケットユーザーとして認識され、新しいNORMIEトークンの鋳造をトリガーしました。

5. 最終スワップと利益抽出

  • 攻撃者は0.5ETHを操作後の安い価格で約11,040,494 NORMIEトークンとスワップしました。

  • 彼らは借りたNORMIEトークンを返済し、トークン供給量を当初の10億から6500億NORMIEトークンに膨れ上がらせました。

  • - 利益の合計は224.98ETHで、約881,686ドルに相当します。

swapAndLiquify関数

function swapAndLiquify(uint256 tAmount) private lockTheSwap {

uint256 tokensForLP = tAmount.mul(liquidityShare).div(totalDistributionShares).div(2);

uint256 tokensForSwap = tAmount.sub(tokensForLP);

swapTokensForEth(tokensForSwap);

uint256 amountReceived = address(this).balance;

emit eventSwapAndLiquify(amountReceived);

uint256 totalBNBFee = totalDistributionShares.sub(liquidityShare.div(2));

uint256 amountBNBLiquidity = amountReceived.mul(_liquidityShare).div(totalBNBFee).div(2);

uint256 amountBNBTeam = amountReceived.mul(_teamShare).div(totalBNBFee);

uint256 amountBNBMarketing = amountReceived.sub(amountBNBLiquidity).sub(amountBNBTeam);

emit teamGetBnb(amountBNBTeam);

emit marketingGetBnb(amountBNBMarketing);

emit liquidityGetBnb(amountBNBLiquidity);

if (amountBNBMarketing > 0) transferToAddressETH(teamWalletAddress, amountBNBMarketing);

if (amountBNBTeam > 0) transferToAddressETH(devWalletAddress, amountBNBTeam);

if (amountBNBLiquidity > 0 && tokensForLP > 0) addLiquidity(tokensForLP, amountBNBLiquidity);

}

結論

この悪用は、スマートコントラクトのコードを徹底的に監査して脆弱性を特定し、緩和することの重要性を浮き彫りにしました。攻撃者が市場前のユーザーリストを操作し、流動性チェックを回避した結果、NORMIEトークンプロジェクトは多大な金銭的損失を被りました。強固なセキュリティの実践と定期的な監査は、将来的にこのような悪用を防ぐのに役立ちます。

続けて読むTsuru 41万ドルのエクスプロイト|ハッキング分析  

著者 Piyush shukla

Hi AUDIT

Hi AUDITは、ハイスピード・ハイクオリティ・ベストプライスのセキュリティ監査サービスです。WEB3スタートアップ向けの自動監査SaaSとコンサルティングを提供しています。
View More