start	end	text
8520	12820	Yeah, I hope my talk can give you guys a taste of Web3 security.
13300	14920	So my name is Pei-Yu Wang.
14920	16740	I'm a security engineer here.
16820	22040	Uh, so what I do is, uh, application penetration testing, uh, mostly Web3 applications.
23460	27760	And I also do, uh, smart contract audits and security research.
27760	36980	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.
36980	38700	So I talk outside of, like, words.
38700	39900	I'm, like, a DeFi apes.
39900	41980	I'm, like, a mincoin, uh, traders.
43160	45080	Blockchain and the apps.
45180	52640	So since the first, uh, DeFi summer in 2020, uh, the, uh, the blockchain ecosystem has exceptional growth.
52640	54280	There's a lot of things being built.
54280	61660	And one way to catalyze them is, like, applications, developer tools, uh, infrastructure, and protocols, which is the blockchain itself.
61660	66040	So we're at the AppSite village, and let's talk about applications.
66160	70420	Uh, so the most common AppSite-heavy Web3 products are the following.
70420	76080	The first one is centralized exchanges, such as, like, Coinbase, uh, Binance, which you guys are probably familiar with.
76080	77760	Uh, and then data platform.
77760	83120	So the raw data for, uh, blockchain transactions are extremely hard for people to read.
83120	89500	So, uh, there's, like, application like Etherscan that help, uh, people to, like, read data, read transaction data.
89500	90900	And there's a wallet.
90980	97440	Uh, so wallet is a type of application that holds the private key and performs the signing request, uh, when requested.
97440	101200	The most popular wallet probably is the, uh, wallet MetaMask.
101200	102780	And then there's, uh, Dapps.
102780	112640	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.
112640	119220	So all four type of applications play a very important role in the, uh, application space in blockchain.
119220	123700	And they all have their own, uh, unique type of services.
123700	126360	Today I will talk about the one for the app.
127040	132160	So throughout this presentation, I will be talking about a lot of blockchain technologies.
132160	135880	So I want to start by explaining them in web 2 terms.
135880	137220	So first, smart contract.
137220	143480	Smart contract, you can think of, it's a backend API server and a bunch of, uh, private functions.
143480	145840	So inside smart contract, there's a lot of functions.
145840	150740	Some functions can only be called by, say, admin or owner address.
150740	155940	Those functions typically, uh, actions, operations, contract.
155980	157660	Um, and then there are transactions.
157660	164040	Transactions, you can think of, it's like, uh, a bundle of POST requests that's sent to the smart contract.
164040	167720	Transaction hash is a unique identifier for each transaction.
167720	174180	Where you can, uh, uh, pull the, pull the transaction information out by using the transaction hash.
174180	180420	Uh, so guess, so imagine, uh, a web server that charges a certain amount of fee for each POST request.
180420	187620	That's like, uh, so each, each, uh, blockchain transaction will charge, uh, some sort of, like, uh, crypto assets.
187640	195780	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.
196360	199560	Uh, so blockchain is formed by, like, a block by block.
199560	203940	And each block, you can think of, it contains, uh, multiple, like, POST requests.
203940	208420	Uh, and then each block has, like, set amount of time in between.
208420	212980	You can think of, like, batch of POST requests get executed, like, block by block.
212980	214840	And there's a certain time in between.
214840	220860	So blockchain RPC is the communication channel that exposed by, like, blockchain nodes.
220860	225860	So the outside can, an entity can talk to the, uh, blockchain.
225860	234940	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.
235780	239400	So this is, like, a general workflow for, uh, the app.
239400	246260	The app you see there is Uniswap, probably most popular and most well, uh, most used app.
246280	250940	Uh, so, uh, you go to a website, there's, like, a connect button, and you click that.
251380	255700	That will trigger a connection request, uh, pop up from the wallet.
255740	261860	And if you trust the application, you can click next, so that your wallet is going to connect with the app.
262440	265960	And after connection is established, you can start using the app.
265960	273440	In this example, I exchanged 0.01 Ether to 24 USDT, and I can, I can click the swap.
273440	276980	And that transaction gets sent to the extension wallet.
276980	283260	And once you click the confirm, which means you sign the transaction, and that transaction will be sent to the blockchain and execute.
283260	286960	And then that transaction will get executed, and the token will be swapped.
287940	290120	Uh, next I'll talk about the app architecture.
290340	297820	So this is, uh, standard web, web 2 applications, where you have, like, client-side, uh, app.
297820	301640	And then you have, like, server-side components, like web server API database.
301640	303460	I'm sure everyone is familiar with that.
304240	307760	And then, yes, I put into three categories.
307760	311100	The first one is API-less, yeah.
311100	315720	Uh, what it means is the app on the server-side, there's no API.
315720	318000	It's just static HTML, JS file.
318660	322220	And the main logic is inside the, uh, smart contract.
322920	331100	So, uh, for example, the, uh, example I gave, uh, Uniswap, the early day version of Uniswap is, uh, like, API-less, the app.
331100	335220	Uh, where the, like, token exchange information is covered by a smart contract.
335220	338700	And the front-end just, uh, help with, like, user interactions.
338980	344040	So this type of the app, the attack surface of the application site is quite limited.
344180	348020	Uh, so, and this type of the app typically built with the React framework.
348020	351060	And React has, sort of, like, SSS building protection there.
351060	352580	So it's hard to find SSS there.
352600	358020	And then, unless you have, like, you can complete the whole site by, say, using, like, DNS hijacking.
358020	361040	The application site, uh, the attack surface is very limited.
361040	366540	And typically when this kind of application is exported, it's often the vulnerability from the smart contract.
367400	370620	Uh, now the second one is API-enabled app.
370620	375360	Uh, so compared to the last one, this one has, on the servers, it has, uh, service APIs.
375440	378920	And one example is the, uh, NFT creation app.
378920	386140	So it, uh, the server has API allow users to download images or, like, NFT metadata JSON to the back-end.
386140	388660	Uh, and then the back-end is going to return, like, a URL.
388660	391460	So you can use the URL to talk to the smart contract.
392360	400000	Uh, the attack surface for this type of app does increase, but the vulnerability on the application site is mostly, like, Web2 related.
400740	403100	And now move to the full-scale Dapps.
403100	410320	So full-scale Dapps, uh, the back-end is going to talk to the smart contract, like, read data or send transactions.
410320	418100	Uh, so oftentimes in the full-scale Dapp, the smart, the, uh, smart contract will have privilege functions.
418100	424200	And the account that can call those privilege functions is private key or stored in the back-end server.
424200	438640	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,
438640	440780	uh, all the damages.
440940	447040	So the majority of Dapps in 2024 are, like, a full-scale Dapp, uh, compared to, like, 2020.
447040	451160	By summer, there's about, like, 80 less Dapps.
451420	455300	One example of, like, a full-scale Dapp is cross-chain bridge.
455300	462940	So cross-chain bridge allows, uh, users to transfer to cross-chain bridge tokens from one company to another.
462940	467220	For example, to, uh, use tokens from, like, Polygon.
467220	475420	Uh , because blockchain, the smart contract blockchain cannot talk to, uh, each other, uh, with cross-blockchain.
475420	480740	So this type of application must require, uh, a blockchain component.
480740	489800	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.
489800	493840	And if everything looks good, you will call the privileged functions in the destination
498380	498980	.
498980	500680	Let's talk about Dapps thread modeling.
501420	507740	So from a thread modeling perspective, most smart contract assets in Web3 are, like, public key or private key.
507740	510840	First one is, uh, private key.
510840	517020	If you can get those, you can have control over the, uh, assets in the address.
517020	520840	Or you can, uh, uh, you know, like, create a function for the smart contract.
520840	522900	Second one is, uh, signatures.
522900	548510	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.
548510	554970	So this API keys is for those, like, such as, like, centralized exchanges.
554970	558030	Once you get those API keys, you can...
563020	572120	I talk about, like, I, uh, I will start to talk about, uh, client-side attack by mentioning a term called already, uh, connected.
573490	581890	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.
581890	589630	And there's a best practice in Web3 that users should only connect their wallet to the dApp they trust.
589630	597750	And then once, and when users trust the dApp, they just sign whatever, like, things the dApp want the user to sign.
597750	608890	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.
609810	615570	So from a client-side attack perspective, there are, like, three things attackers will do.
615570	619770	One is malicious transactions.
619770	627630	How that can happen is the attacker can, um, basically modify the JavaScript code of the, uh, website.
627630	631510	For example, to, like, cross-site security, hijacking.
631510	638230	Um, it's possible to have those malicious JavaScript and initialize, uh, the malicious transaction to take out.
639000	650290	And if JavaScript is not possible, and if, like, hijacking is possible, another option is to deceive the user to do something else.
650570	654590	The last one is, uh, the user to actually sign.
656370	665590	And for, uh, already connected wallet website, um, everything that can initial, uh, will have critical vulnerability.
665590	671050	So as it says, right, in Web 2, even if you have, like, account takeover, most of the time it's, like, high.
671070	672890	It's maybe, like, a low critical.
672890	675570	But in Web 3, it's definitely going to be, um...
677030	679130	So let's talk about server-side.
679130	684390	So from a server-side perspective, um, there's, like, sort of, like, four things the attacker will want to do.
684390	686870	The first one is stealing the keys from the server.
687010	693150	Um, basically, if you're stealing the key, you probably can't do it without the, uh, the message from the project.
693150	696770	And this is sort of another way that they can potentially do that.
696770	701930	And the second one is stealing crypto assets from other users' accounts or, like, admins' accounts.
701930	712650	They will probably buy, like, uh, broken access control, um, or you can spend, uh, assets, uh, more than your actual balance.
712650	715690	That can probably happen, like, business logic error or risk condition.
715690	720350	And for NFTs, as I mentioned, those, like, images are stored, like, all the time.
720350	725450	And if those images are broken down, there's a value going to drop, like, dramatically.
725530	728870	And that's what can happen when, like, uh, NFTs die.
729490	735050	So Web3, anything that can touch this money, it goes super low and has a critical severity.
735050	735850	In the
745570	751910	last session, I talked about how Web2 attack better and have higher severity in Web3.
751910	757370	In the next sessions, I will talk about, um, kind of, like, unique, better attack services.
757470	757890	So
761280	766940	, I think due to the time constraint, I cannot go over, like, each sub-item one by one.
766940	767080	In short
770650	779890	, incorrectly processed transactions, and it's possible to initial attack against backend components.
781010	789710	And if the application handles, uh, the logic to handle different assets costs is incorrect, uh, it can also...
791660	796020	So the first case I want to talk about is, uh, wasted crypto.
796020	798720	Yes, we are unregistered APIs.
798800	805380	So, this application is, uh, that require users to register for participation.
805600	807860	How the registration workflow is,
811530	817430	user can provide their own check address, uh, and then, uh, backend is called...
817430	827990	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.
827990	836070	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.
836070	838830	Gas is, like, uh, you can think of as money.
838870	853350	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.
853350	859790	So this not only consume all the users, but allow, like, and prevent, like, other users to register.
860570	863910	Uh, so this is, like, the, uh, transaction log when I do the testing.
863910	867930	So this is in the test net, so there's no actual, like, uh, assets lost.
867990	875210	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.
875210	879210	And then when I, uh, go to user scan, and I see the, those, like, records.
880090	884630	Uh, the second one is poor transaction time head-only lead to denied service attack.
884630	897050	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.
897050	901630	So the, uh, the example code snippet is, I generate using, like, CGVTs.
901630	904390	So it's basically, uh, API call deposit.
904890	912550	Uh, and when user call this API, it's gonna trigger the, uh, backend to send a deposit transaction to the smart contract.
912550	918710	And the code will wait for the transaction executed, and then send HTTP response to the users.
919410	930670	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.
930670	935410	If the chain is congested, it can, uh, the, the time can be much longer.
935470	949530	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.
950390	954910	Um, the next one is poor transaction time handling lead to risk conditions.
954910	961670	So this is, uh, gaming, like a Gamefy dApp that allow user to purchase, like, in-game items using crypto assets.
961750	975450	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.
975770	990510	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,
990510	999050	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.
999950	1014810	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.
1014910	1023930	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.
1023950	1035130	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.
1035130	1039310	Uh, this way user can basically purchase all the in-game item for free.
1039310	1052470	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.
1052470	1059910	Um, the next one is, uh, bridge contract, bridge backend, lack of smart contract address validations.
1059910	1063910	So, uh, I, I talk about, like, how bridge work briefly, uh, previous slide.
1063910	1078270	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,
1078270	1092330	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.
1093290	1108730	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,
1108730	1126450	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.
1127390	1143070	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,
1143070	1160490	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,
1160490	1173030	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.
1173370	1178950	And if this vulnerability get exploited, like, all the tokens in the destination chain smart contract can be stolen.
1179510	1181190	Alright, so the last case.
1181190	1187490	So this is like a lightweight crypto trading applications, where user can deposit assets and perform, like, token swap.
1187490	1190830	Uh, the backend use, like, Fireblock as custodian services.
1190830	1202270	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.
1202550	1213610	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.
1213990	1222330	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.
1222330	1227310	And we are so confused, because this is not, like , double or ten times, it just, it's, like , increased by 1.
1227470	1233650	So we go to the on-chain, the, uh, Polygon scan, and see there's only, like, 0.1 metatoken arrive in the address.
1234330	1240110	Um, however, we found a record of, like, a scammed NFT airdropped into that address.
1240110	1249090	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.
1249090	1256850	Newly added address is, like, a, like, a crypto with value for the first time.
1257190	1262970	So the backend treat that value list NFT as a valid, like, a magic deposit.
1262970	1275710	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.
1275710	1286690	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.
1287530	1306110	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.
1306610	1313830	And, uh, Web, uh, Web2 vulnerability in Web3 application often has, like, increased severity because it can touch monies.
1314230	1324770	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.
1324770	1336630	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.
1336630	1339310	Um, this is the last slide.
1339310	1353270	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.
1353270	1359970	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.
1360010	1365270	An investment of, like, $100 of crypto, uh, probably going to waste in gas is going to be enough.
1365270	1372930	And to understand, like, basic, uh, concept of blockchain, include those, like, Web2 terminology, you don't really need to understand how blockchain work.
1373110	1380170	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.
1380170	1385150	And it's not necessarily require you to know, like, how to do a secure audit of smart contract.
1385150	1386490	That's a completely different topic.
1386510	1398290	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.
1398590	1404550	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.
1404550	1408250	Uh, well, I don't think this can ever happen in Web2.
1408250	1411010	So, uh, so, yeah, uh, I guess people love money.
1411010	1413690	Uh , alright, so that's my talk.
1413690	1416990	I hope you guys enjoy and learn something about Web3 security.
1416990	1417710	Thank you.
1423550	1424950	Thank you.
