Yeah, I hope my talk can give you guys a taste of Web3 security. So, my name is Pei-Yu Wang. I'm a security engineer. So, what I do is application penetration testing, mostly Web3 applications, like apps and wallets. And I also do small contract audits and security research. My past talks at DEF CON are in Blockchain Village, which I talk about exploiting crypto and DeFi scammer outposts. So, outside of like words, I'm like a DeFi apes. I'm like a mincoin traders. Blockchain and the apps. So, since the first DeFi summer in 2020, the blockchain ecosystem has exceptional growth. There's a lot of things being built, and one way to catalyze them is like applications, develop tools, infrastructure, and protocols, which is the blockchain itself. So, we're here at AppStack Village, and let's talk about applications. So, the most common AppStack-heavy Web3 products are the following. The first one is centralized exchanges, such as Coinbase, Binance, which you guys are probably familiar with, and then data platform. So, the raw data for blockchain transactions are extremely hard for people to read. So, there's an application like Etherscan that helps people to read data, read transaction data. And there's a wallet. So, wallet is a type of application that holds the private key and performs the signing request when requested. The most popular wallet probably is the wallet MetaMask. And then there's Dapps. So, the definition I give Dapp is a wide range of applications that include the functionality that implements through the on-chain smart contract. So, all four types of applications play a very important role in the application space in blockchains. And they all have their own unique type of services. Today, I will talk about the one in PDF. So, throughout this presentation, I will be talking about a lot of Web2 terms. So, I want to start by explaining the Web2 terms. So, first, smart contract. Smart contract, you can think of it's a backend API server that runs on blockchains. Privileged functions. So, inside smart contracts, there's a lot of functions. And some functions can only be called by, say, admin or owner address. Those functions, typically, actions, operations, contracts. And then there are transactions. Transactions, you can think of it's like a bundle of post requests that's sent to the smart contract. Transaction hash is a unique identifier for each transaction where you can pull the transaction information out by using hash. So, imagine a web server that charges a certain amount of fee for each post request. That's like... so, each transaction will charge some sort of, like, crypto assets. And when there's a lot of people sending this, like, post request to a smart contract, the more you pay, the faster your transaction will be executed. So, blockchain is formed by, like, a block by block. And each block, you can think of it multiple post requests. And each block has, like, set amount of time in between. You can think of the batch of post requests get executed, like, block by block. And there's a certain time in between. So, blockchain RPC is the communication channel that's exposed by, like, blockchain nodes. So, the outside entity can talk to the blockchains. And NFT is type of, like, digital assets in the form of an image with ownership information from the blockchain. So, this is, like, a general workflow for the app. The app you see there is Uniswap, probably the most popular and most used app. So, you go to a website, there's, like, a connect button, and you click that. That triggers a connection request pop up from the wallet. If you trust the application, you can click X so that your wallet is going to connect with the app. And after the connection is established, you can start using the app. In this example, I exchanged 0.01 Ether to 24 USDT, and I can click the swap. And that transaction gets sent to the extension wallet. And once you click the confirm, which means you sign the transaction, and that transaction will be sent to the blockchain and executed. And then that transaction will get executed, and the token will be swapped. Next, I'll talk about DApp architecture. So, this is standard Web 2.0 applications, where you have, like, client-side app, and then you have, like, server-side components, like web server API database. I'm sure everyone is familiar with that. And DApps, I put into three categories. The first one is API-less DApp. What it means is that on the server-side, there's no API. And the main logic is inside the small contracts. So, for example, the example I gave Uniswap, the early version of Uniswap is API-less DApp, where the token exchange information is inside a small contract, and the front-end just help with, like, user interactions. So, this type of DApp, the attack surface, application side is quite limited. So, and this type of DApp typically deal with the app framework, and React has sort of, like, SSS building protection there. So, it's hard to find SSS there. And then unless you have, like, you can completely take over the site by, say, using, like, DNS hijacking, the application side, the attack surface is very limited. And typically, when this kind of application gets exported, it's often the vulnerability from the small contract. Now, the second one is API-enabled DApp. So, compared to the last one, this one on the servers has service APIs. And one example is, say, NFT creation DApp. So, if the server has API, allow users to upload images or, like, NFT metadata JSON to the back-end, and then the back-end is going to return, like, a URL. So, you can use a URL to talk to a small contract. The attack surface for this type of app is increased, but the vulnerability on the application side is mostly, like, Web2 related. And now, move to the full-scale DApps. So, full-scale DApps, the back-end is going to talk, like, read data or send transactions. So, oftentimes, in the full-scale DApp, the small contract will have privileged functions, and the account that can call those functions, those private keys are stored in the back-end server. So, if you have a way to, say, for example, compromise a server or have triggers on, like, an arrow, you're likely able to, say, obtain that key from the server and completely transfer out all the money from the small contract for, like, very big damages. So, the advantages of DApps in 2024 are, like, a full-scale DApp compared to, like, 2020, by some mergers of, like, APS, APLS DApp. One example of, like, a full-scale DApp is cross-chain bridge. So, cross-chain bridge allows a user to transfer to... other, for example, to... because blockchain, the small contract blockchain cannot talk to each other. It's cross-blockchain. So, this type of application must require a blockchain component. So, how bridge works is, on a source chain, the back-end monitors that deposit event and processes it. And if everything looks good, all the privileged functions can be transferred out. So, let's talk about DApps threat modeling. So, from a threat modeling perspective, the most popular assets in Web3 are the private key. If you can get those, you can have full control over the assets in the address, or you can invoke, like, privileged functions as well. Second one is signatures. So, for certain type of tokens, it allows... if you can have the special message signed by the... and there's a lot of... you could sign in those type of messages, and then... the last one is API keys. So, API keys is for those, like, such as, like, centralized exchanges... get those API keys, you can take... I talk about, like, I will start to talk about client-side attack by mentioning a term called already-connected wallet. So, in the DApp workflow session, I talk about, like, if a user wants to use a DApp, the DApp must connect to their wallet. And there's a best practice in Web3 that users should only connect their wallet to the DApp they trust. And then once... and when users trust the DApp, they just sign whatever, like, things that the DApp wants the user to sign. So, if any vulnerability exists in client-side vulnerability inside the DApp that has a lot of user-connected wallet, and it's very popular, the severity is going to increase, like, dramatically. So, client-side attack perspective, there are, like, three things attackers will most likely want to do. The first one is initial malicious transactions. How that can happen is when the attacker can modify the JavaScript code of the website, for example, through, like, cross-site security, hijacking, it's possible to have those malicious jobs initialize the transaction to take out all the security. And if, in general, JavaScript is not possible, and if, like, checking is possible, another option is to deceive the user. The last one is... and for already connected website, everything that can initial... will have critical vulnerability. So, as it says, right, in Web 2.0, even if you have, like, can't take over, it's, like, high, it's maybe, like, a low critical, but Web 3.0, it's definitely... So, let's talk about server-side. So, from a server-side perspective, there's, like, sort of, like, four things the attacker will want to do. The first one is stealing the keys. Basically, if you're stealing the key, you probably can't think about the asset as part of the project, and it's just sort of a lot of ways you can pretend to do that. And the second one is stealing crypto assets from other users' accounts or admins' accounts. They will probably buy, like, a broken access control, or you can spend assets more than your actual balance. That can probably happen, like, business knowledge error or risk condition. And for NFTs, as I mentioned, those, like, images are, like, fault-free. And if those images are down, this NFT value is going to go down, like, dramatically, and that's what can happen when, like, an NFT is attacked. So, actually, anything that can touch somebody has a critical severity. So, in the last session, I talked about how Web 2.0 attack has higher severity in Web 3.0. In the next sessions, I will talk about what kind of, like, unique better attack service that can be enabled in Web 3.0. So, I think due to Comcast free, I cannot go over, like, each sub-item one by one. In short, deep applications that incorrectly process transactions, they can come in more quickly. And it's possible to initial attack against backend components through smart contract. And if the application allows you to handle different SS class, it can also, yeah. So, the first case I want to talk about is race control in gas via unregistered APIs. So, this application is a program that requires users to register for participation. So, the registration is based on APIs, which users can provide their own chain address. And then backend is part of the registration. The function can only be called, like, an identity. So, what's that instrument? I'm giving you a different mic. Hello. Wow. Great. So, well, the case study just started. So, you didn't miss anything. Okay. Yeah. So, the finding here is that, wow, that's amazing. So, the APIs accept any assumed address as long as the address data is in the correct format. So, each time the API is called, the backend is going to send a transaction to a smart contract. And as I talk about, each transaction can cost gas. Gas is, like, you can think of as money. So, the way to exploit this is, like, I can generate a bunch of, like, a random assumed address and keep calling the API to let the admin want to keep sending transactions to smart contracts and eventually consume all the ethers in the admin's wallet. So, this not only consumes all the ethers, but allow, like, and prevent, like, other users to register. So, this is, like, the transaction log when I do the testing. So, this is in the test net. So, there's no actual, like, assets lost. So, I write a script to generate a bunch of address and put the request into, like, a repeater and just send it. And when I go to etherscan, I see those, like, records. The second one is poor transaction time. So, this can actually happen in any Dapp that have API to trigger the backend to send a transaction and keep the connection open while waiting for the on-chain transaction execution results. So, the example code snippet is I generate using, like, ChagVTs. So, it's basically an API called deposit. And when user call this API, it's going to trigger the backend to send a deposit transaction to the smart contract. And the code will wait for the transaction executed and then send HTTP response to the users. So, what's the problem here is that, for example, on a certain main net, the block time is 12 seconds, which means the HTTP connection will remain open for at least 12 seconds. If the chain is congested, it can the time can be much longer. So, to exploit these APIs, like, only one single machine is required to send a bunch of, like, API requests and to occupy all the connection slots and the server is not going to handle any, like, more requests. The next one is poor transaction time handling leads to risk conditions. So, this is gaming, like, a game-fied app that allows users to purchase, like, in-game items using crypto assets. So, deposit workflow by user deposit crypto assets into the game smart contract and then backend retrieve those deposit informations from the smart contract to increase the user's in-game balance. And what's the interesting part is the withdrawal crypto workflow is the withdrawal workflow work by users submit a withdrawal API request to the backend and the backend verify the user's balance and call the privilege function withdraw in a smart contract. And after the transaction is finished, the token will arrive in user's on-chain wallet and the backend is going to update the user balance to zero. So, what's the problem here is that the backend update the user balance only after the transaction successfully executed and it doesn't lock the transaction balance when they send the on-chain transactions. So, for example, in serum, like, 12-second block time, user have 12-second window to spend their, like, in-game currencies. So, they can basically, in those time periods, they can buy 100 words of, like, in-game items and then wait for the transaction to finish and those tokens will be arrived in their wallets. This way, the user can basically purchase all the in-game items for free. And a race condition can also happen in, like, Web 2.0, but the time window for that in Web 2.0 is much smaller. But in Web 3.0, the time window in this case is at least 12 seconds. So, it's much easier to pull off. The next one is bridge contract, bridge backend, lack of smart contract address validations. So, I talk about how bridge work briefly, previous slide. So, for this particular bridge, the workflow is, like, user deposit tokens into smart contract on the source chain and obtain a transaction hash. And then the user submits the transaction hash to the backend through APIs, and the backend fetches the information with the transaction hash to validate the deposit. And if anything goes correctly, the bridge backend is going to call the privilege function in the smart contract and the destination chain and release the fund to the user. So, for this kind of bridge, the backend actually needs to validate tons of stuff. And in that particular application, it needs to validate, for example, the transaction status is successful, and it needs to get the information of the deposit amount, the sender receiver address. And if anything is not validated correctly, it can cause the bridge to become vulnerable. And in this case, the backend does not verify the smart contract that received the token is the one operated by the project. So, to exploit this vulnerability, I am going to deploy a malicious smart contract on the blockchain that basically shares the same functionality as the legitimate smart contract. And I make a token deposit into that fake bridge contract and obtain a transaction hash. And I submit a transaction hash to the bridge backend through APIs and wait for the bridge backend to process the hash. And because I'm missing the address validations, he thinks the address is correct. And then it's going to release the tokens to the users on the destination chain. And when that happens, and after that, the user can withdraw his tokens sent to the fake contract because he had full control of that. And if this vulnerability gets exploited, all the tokens in the destination chain smart contract can be stolen. So, the last case. So, this is a lightweight crypto trading application where users can deposit assets and perform token swap. The backend uses Fireblock as custodian services. The deposit work is user requests a deposit address through APIs. And then the backend is going to get one from Fireblock. And then the user is going to deposit a crypto asset to the address. And then the backend periodically curates the Fireblock.getTransaction API. And if it sees the deposit transactions, it's going to give the user the in-app balance. So, when we are doing the testing, we deposit like 0.1 metatoken to the deposit address. And the balance increased by 1.1. And we were so confused because this is not like double or 10 times. It just, it's like increased by one. So, we go to the Polygon scam and see there's only like 0.1 metatoken arrived in the address. However, we found a record of like a scam NFT airdropped into that address. So, it's quite common for scammers to airdrop like NFTs with like phishing site link in the token information to a newly added address within the blockchain. Newly added address means the address like received like a crypto with value for the first time. So, the backend treat that value list NFT as a valid like a magic deposit. So, this is a whiteboard testing and we found out the root cause is that the backend just doesn't, when it parses the information returned by Fireblock, it failed to check the token type. To exploit these issues, we deployed a ERC-1155 NFT and make 99 NFT with no value to the address which caused our account to increase like 99 metatoken. So, to summarize the state of like dApp security. So, right now, with the advance of like blockchain ecosystem, dApp becomes like more and more complex and some of them start integrating heavy Web2 components. And often vulnerability are introduced in dApp because a lot of developers either lack of Web3 security knowledge or Web2 security knowledge. And Web2 vulnerability in Web3 application often has like increased severity because it can touch monies. And unlike small contracts where it's like public viewable, the exploitation of the backend might have less exposure because no one can see it, but it can still happen. So, to secure dApp, especially dApp with like heavy backend components, it is like as important to get pension testing compared as like getting like audits for your small contract. This is the last slide. So, if you want to get into dApp hacking, I would suggest like you first be decent at Web2 application hacking because at the end of day there's tons of Web2 components and you need to be familiar with the architecture of different type of dApps. That way you will know what the attack services are for this app. And the best way to do it is play around with dApp to experiment then. An investment of like $100 of crypto, probably going to waste gas, is going to be enough. And to understand like basic concept of blockchain, include those like Web2 technology, you don't really need to understand how blockchain works. And then you learn the solidity of small contract language so you can understand small contract. And sometimes you can find some like hidden attack services. And it's not necessarily require you to know like how to do a secure audit of small contract. That's a completely different topic. And go find a dApp and hack it, I forget legally, and start like... So I believe like starting hacking dApp is probably one of the best way to look for like Web2 website hackers that pivot into Web3 security. And well, if you want to ask me like why like Web3 security, I mean like look at this bounty, like $10 million. Well, I don't think this can ever happen in Web2. So yeah, I guess people love money. All right. So that's my talk. I hope you guys enjoy and learn something about Web3 security. Thank you.