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 here. Uh, so what I do is, uh, application penetration testing, uh, mostly Web3 applications. And I also do, uh, smart contract audits and security research. Uh, my past talk at DEF CON are in the, uh, blockchain village, which I talk about, uh, exploiting crypto wallets and, uh, DeFi scam and rob pools. So I talk outside of, like, words. I'm, like, a DeFi apes. I'm, like, a mincoin, uh, traders. Blockchain and the apps. So since the first, uh, DeFi summer in 2020, uh, the, uh, the blockchain ecosystem has exceptional growth. There's a lot of things being built. And one way to catalyze them is, like, applications, developer tools, uh, infrastructure, and protocols, which is the blockchain itself. So we're at the AppSite village, and let's talk about applications. Uh, so the most common AppSite-heavy Web3 products are the following. The first one is centralized exchanges, such as, like, Coinbase, uh, Binance, which you guys are probably familiar with. Uh, and then data platform. So the raw data for, uh, blockchain transactions are extremely hard for people to read. So, uh, there's, like, application like Etherscan that help, uh, people to, like, read data, read transaction data. And there's a wallet. Uh, so wallet is a type of application that holds the private key and performs the signing request, uh, when requested. The most popular wallet probably is the, uh, wallet MetaMask. And then there's, uh, Dapps. So I def- uh, the definition I give Dapp is a wide range of applications that include the functionality that implements through the, uh, on-chain smart contract. So all four type of applications play a very important role in the, uh, application space in blockchain. And they all have their own, uh, unique type of services. Today I will talk about the one for the app. So throughout this presentation, I will be talking about a lot of blockchain technologies. So I want to start by explaining them in web 2 terms. So first, smart contract. Smart contract, you can think of, it's a backend API server and a bunch of, uh, private functions. So inside smart contract, there's a lot of functions. Some functions can only be called by, say, admin or owner address. Those functions typically, uh, actions, operations, contract. Um, and then there are transactions. Transactions, you can think of, it's like, uh, a bundle of POST requests that's sent to the smart contract. Transaction hash is a unique identifier for each transaction. Where you can, uh, uh, pull the, pull the transaction information out by using the transaction hash. Uh, so guess, so imagine, uh, a web server that charges a certain amount of fee for each POST request. That's like, uh, so each, each, uh, blockchain transaction will charge, uh, some sort of, like, uh, crypto assets. And when there's a lot of people sending these, like, POST requests to a smart contract, the more you pay, the faster your transaction, uh, will be executed. Uh, so blockchain is formed by, like, a block by block. And each block, you can think of, it contains, uh, multiple, like, POST requests. Uh, and then each block has, like, set amount of time in between. You can think of, like, 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 exposed by, like, blockchain nodes. So the outside can, an entity can talk to the, uh, blockchain. And NFT is type of, like, uh, uh, digital assets that inform an image with ownership information for blockchain and image data and metadata for blockchain. So this is, like, a general workflow for, uh, the app. The app you see there is Uniswap, probably most popular and most well, uh, most used app. Uh, so, uh, you go to a website, there's, like, a connect button, and you click that. That will trigger a connection request, uh, pop up from the wallet. And if you trust the application, you can click next, so that your wallet is going to connect with the app. And after connection is established, you can start using the app. In this example, I exchanged 0.01 Ether to 24 USDT, and I can, 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 execute. And then that transaction will get executed, and the token will be swapped. Uh, next I'll talk about the app architecture. So this is, uh, standard web, web 2 applications, where you have, like, client-side, uh, app. And then you have, like, server-side components, like web server API database. I'm sure everyone is familiar with that. And then, yes, I put into three categories. The first one is API-less, yeah. Uh, what it means is the app on the server-side, there's no API. It's just static HTML, JS file. And the main logic is inside the, uh, smart contract. So, uh, for example, the, uh, example I gave, uh, Uniswap, the early day version of Uniswap is, uh, like, API-less, the app. Uh, where the, like, token exchange information is covered by a smart contract. And the front-end just, uh, help with, like, user interactions. So this type of the app, the attack surface of the application site is quite limited. Uh, so, and this type of the app typically built with the React 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 complete the whole site by, say, using, like, DNS hijacking. The application site, uh, the attack surface is very limited. And typically when this kind of application is exported, it's often the vulnerability from the smart contract. Uh, now the second one is API-enabled app. Uh, so compared to the last one, this one has, on the servers, it has, uh, service APIs. And one example is the, uh, NFT creation app. So it, uh, the server has API allow users to download images or, like, NFT metadata JSON to the back-end. Uh, and then the back-end is going to return, like, a URL. So you can use the URL to talk to the smart contract. Uh, the attack surface for this type of app does increase, but the vulnerability on the application site is mostly, like, Web2 related. And now move to the full-scale Dapps. So full-scale Dapps, uh, the back-end is going to talk to the smart contract, like, read data or send transactions. Uh, so oftentimes in the full-scale Dapp, the smart, the, uh, smart contract will have privilege functions. And the account that can call those privilege functions is private key or stored in the back-end server. So if you have a way to, say, for example, compromise the server or have triggers on, like, an arrow, you're likely, you're likely able to, say, uh, obtain that key from the server and completely transfer out all the money from the smart contract for, uh, all the damages. So the majority of Dapps in 2024 are, like, a full-scale Dapp, uh, compared to, like, 2020. By summer, there's about, like, 80 less Dapps. One example of, like, a full-scale Dapp is cross-chain bridge. So cross-chain bridge allows, uh, users to transfer to cross-chain bridge tokens from one company to another. For example, to, uh, use tokens from, like, Polygon. Uh , because blockchain, the smart contract blockchain cannot talk to, uh, each other, uh, with cross-blockchain. So this type of application must require, uh, a blockchain component. So how bridge should work is, uh, on the source chain, users deposit tokens to the source chain smart contract, and the back-end monitors that deposit event and processes it. And if everything looks good, you will call the privileged functions in the destination . Let's talk about Dapps thread modeling. So from a thread modeling perspective, most smart contract assets in Web3 are, like, public key or private key. First one is, uh, private key. If you can get those, you can have control over the, uh, assets in the address. Or you can, uh, uh, you know, like, create a function for the smart contract. Second one is, uh, signatures. So for certain types of tokens, if you can, uh, certain type of tokens allows, uh, if you can have the, uh, special message signed by the, uh, and there's, there's a lot of, uh, signing those type of message, and then, uh, The last one is API keys. So this API keys is for those, like, such as, like, centralized exchanges. Once you get those API keys, you can... I talk about, like, I, uh, I will start to talk about, uh, client-side attack by mentioning a term called already, uh, connected. So in the, uh, dApp workflow session, I talk about, like, uh, 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 the dApp want the user to sign. So any vulnerability that 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 from a client-side attack perspective, there are, like, three things attackers will do. One is malicious transactions. How that can happen is the attacker can, um, basically modify the JavaScript code of the, uh, website. For example, to, like, cross-site security, hijacking. Um, it's possible to have those malicious JavaScript and initialize, uh, the malicious transaction to take out. And if JavaScript is not possible, and if, like, hijacking is possible, another option is to deceive the user to do something else. The last one is, uh, the user to actually sign. And for, uh, already connected wallet website, um, everything that can initial, uh, will have critical vulnerability. So as it says, right, in Web 2, even if you have, like, account takeover, most of the time it's, like, high. It's maybe, like, a low critical. But in Web 3, it's definitely going to be, um... So let's talk about server-side. So from a server-side perspective, um, there's, like, sort of, like, four things the attacker will want to do. The first one is stealing the keys from the server. Um, basically, if you're stealing the key, you probably can't do it without the, uh, the message from the project. And this is sort of another way that they can potentially do that. And the second one is stealing crypto assets from other users' accounts or, like, admins' accounts. They will probably buy, like, uh, broken access control, um, or you can spend, uh, assets, uh, more than your actual balance. That can probably happen, like, business logic error or risk condition. And for NFTs, as I mentioned, those, like, images are stored, like, all the time. And if those images are broken down, there's a value going to drop, like, dramatically. And that's what can happen when, like, uh, NFTs die. So Web3, anything that can touch this money, it goes super low and has a critical severity. In the last session, I talked about how Web2 attack better and have higher severity in Web3. In the next sessions, I will talk about, um, kind of, like, unique, better attack services. So , I think due to the time constraint, I cannot go over, like, each sub-item one by one. In short , incorrectly processed transactions, and it's possible to initial attack against backend components. And if the application handles, uh, the logic to handle different assets costs is incorrect, uh, it can also... So the first case I want to talk about is, uh, wasted crypto. Yes, we are unregistered APIs. So, this application is, uh, that require users to register for participation. How the registration workflow is, user can provide their own check address, uh, and then, uh, backend is called... Yeah, so the finding here is that, well, that's amazing, uh, is, 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 the smart contract, and as I talk about, each transaction can cost gas. Gas is, like, uh, you can think of as money. So the way to exploit this is, like, I can generate a bunch of, like, random assumed address and keep calling the API to let the admin wallet keep sending transaction to smart contract, and eventually consume all the users in the admin's wallet. So this not only consume all the users, but allow, like, and prevent, like, other users to register. Uh, so this is, like, the, uh, transaction log when I do the testing. So this is in the test net, so there's no actual, like, uh, assets lost. Um, so I write a script to generate a bunch of address and put the request into, like, burp repeater, and then just send it. And then when I, uh, go to user scan, and I see the, those, like, records. Uh, the second one is poor transaction time head-only lead to denied service attack. So this can actually happens 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, uh, execution results. So the, uh, the example code snippet is, I generate using, like, CGVTs. So it's basically, uh, API call deposit. Uh, and when user call this API, it's gonna trigger the, uh, 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 mainnet, the block time is 12 seconds, which means the HTTP connection will be, remain open for at least 12 seconds. If the chain is congested, it can, uh, the, the time can be much longer. So, uh, to exploit this, uh, APIs, uh, only, like, only one single machine is required to send out a bunch of, like, API requests, and to, uh, occupy all the connection slots, and the server is not going to handle any, like, more requests. Um, the next one is poor transaction time handling lead to risk conditions. So this is, uh, gaming, like a Gamefy dApp that allow user to purchase, like, in-game items using crypto assets. Um, so deposit workflow by, uh, user deposit crypto assets into the game smart contract, and then backend, uh, retrieve those deposit information from the smart contract to increase the user's, uh, in-game balance. And what's the interesting part is the withdraw crypto workflow, is, uh, the withdraw workflow work by user submit a withdraw API request to the backend, and the backend verify user's balance, and call the, uh, privilege function withdraw in a smart contract, and after the transaction finish, uh, the token will arrive in user's on-chain wallet, and the backend is gonna update the user balance to zero. So what's the problem here is that, um, the backend, uh, update the user balance only after the, after the transaction successfully executed, and it doesn't log the transaction balance, uh, when it sends the on-chain transactions. So in the, so for example in Serum, like, 12-second block time, user have 12-second window to spend their, like, in-game, like, currencies. Uh, so they can basically in those, uh, time period they can buy a hundred worth of, like, uh, uh, in-game items, and then wait for the transaction to finish, and those token will be arrived in their wallet. Uh, this way user can basically purchase all the in-game item for free. Um, and a race condition can also happens in, like, Web2, but, uh, the, uh, the time window for that in Web2 is much smaller, but in Web3 the time window in this case is at least 12 seconds, so it's, uh, much easier to pull off. Um, the next one is, uh, bridge contract, bridge backend, lack of smart contract address validations. So, uh, I, I talk about, like, how bridge work briefly, uh, 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 submit the transaction hash to the backend through APIs, and the backend fetch the, uh, information with the transaction hash, uh, to validate the deposit, and if anything goes correctly, the bridge backend really is gonna call the privilege function in the smart contract destination chain and release the fund to the user. Um , so for this kind of bridge, the backend actually need to validate, uh, tons of stuff, and in that particular application, it need to validate, for example, the transaction status is successful, and, uh, it need to take, uh, 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 operate by the, uh, by the project. Um, so to exploit this vulnerability that Teflo will be, uh, I am going to deploy a malicious smart contract on the blockchain that basically share 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 , uh, and wait for the bridge backend to process the hash, and because I'm missing the address validation , so if you think the address is correct, and then it's going to release the tokens, uh, to the, to the, uh, users on the destination chain, and when that happens, um, and , and after that, the user can withdraw his, uh, like, tokens sent to the fake contract, because that's, he had full control of that. And if this vulnerability get exploited, like, all the tokens in the destination chain smart contract can be stolen. Alright, so the last case. So this is like a lightweight crypto trading applications, where user can deposit assets and perform, like, token swap. Uh, the backend use, like, Fireblock as custodian services. Uh, how the deposit work is, user request, uh, uh , like, a deposit address through APIs, and then the backend gonna get one from Fireblock, and then the user gonna deposit crypto asset to the address. And then the backend periodically query the Fireblock.getTransaction API, and if it sees the deposit transactions, it gonna, uh, give the user the in-app balance. So we are, when we are doing the testing, so we deposit, like, 0.1 metatoken to deposit address, and the, and the balance increase by 1.1. And we are so confused, because this is not, like , double or ten times, it just, it's, like , increased by 1. So we go to the on-chain, the, uh, Polygon scan, and see there's only, like, 0.1 metatoken arrive in the address. Um, however, we found a record of, like, a scammed NFT airdropped into that address. So it's quite common for scammers to airdrop, like, NFTs, uh, with, like, phishing site link in the token information to a newly added address within the blockchain. Newly added address is, like, a, like, a crypto with value for the first time. So the backend treat that value list NFT as a valid, like, a magic deposit. Uh, so this is a whiteboard testing, and we found out the root cause is that the backend just, uh, uh, doesn't, doesn't, what, when it parsed the information returned by Fireblock, it failed to check the token type. So to exploit this issue, we, we deploy a URC -1155 NFT and make 99 NFT with no value to the address, and which caused our, uh, account to increase, like, 99 magic. Uh, 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, uh, Web, uh, Web2 vulnerability in Web3 application often has, like, increased severity because it can touch monies. Um, and unlike smart contracts where, where it's, like, publicly viewable, the exploitation of the backend might have less exposure because no one can see it, uh, but it can still happen. So to secure a DApp, especially a DApp with, like, heavy backend components, it is, like, as important to get, uh, penetration testing compared, uh, as, like, getting, uh, like, audits for your smart contract. Um, this is the last slide. So, if you want to get into DApp hacking, uh, I would suggest, like, you, you be, first be decent at Web2 application hacking because at the end of the day, there's tons of Web2 components and you need to be familiar with different type, 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, uh, probably going to waste in gas is going to be enough. And to understand, like, basic, uh, concept of blockchain, include those, like, Web2 terminology, you don't really need to understand how blockchain work. And then you learn the smart con- solidity smart contract language so you can understand smart 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 smart contract. That's a completely different topic. Uh, and go find a DApp and hack it legally, and start, like, and, so I believe, like, starting hacking in DApp is probably one of the best way for, like, Web2 website hackers that pivot into Web3 security. And, uh, well, if you want to ask me, like, why, like, Web3 security, I mean, like, uh, look at this bounty, like $10 million. Uh, well, I don't think this can ever happen in Web2. So, uh, so, yeah, uh, I guess people love money. Uh , alright, so that's my talk. I hope you guys enjoy and learn something about Web3 security. Thank you. Thank you.