start	end	text
660	4980	Yeah, I hope my talk can give you guys a taste of Web3 security.
5420	8480	So, my name is Pei-Yu Wang. I'm a security engineer.
8820	13960	So, what I do is application penetration testing, mostly Web3 applications,
13960	20000	like apps and wallets. And I also do small contract audits and security research.
20000	26340	My past talks at DEF CON are in Blockchain Village, which I talk about exploiting crypto
26340	32860	and DeFi scammer outposts. So, outside of like words, I'm like a DeFi apes. I'm like a mincoin
32860	40720	traders. Blockchain and the apps. So, since the first DeFi summer in 2020,
40720	46440	the blockchain ecosystem has exceptional growth. There's a lot of things being built,
46440	52180	and one way to catalyze them is like applications, develop tools, infrastructure, and protocols,
52180	56400	which is the blockchain itself. So, we're here at AppStack Village,
56400	60200	and let's talk about applications. So, the most common AppStack-heavy
60200	64560	Web3 products are the following. The first one is centralized exchanges,
64560	69960	such as Coinbase, Binance, which you guys are probably familiar with, and then data platform.
69960	75200	So, the raw data for blockchain transactions are extremely hard for people to read.
75200	81580	So, there's an application like Etherscan that helps people to read data, read transaction data.
81580	86940	And there's a wallet. So, wallet is a type of application that holds the private key and
86940	92340	performs the signing request when requested. The most popular wallet probably is the wallet
92340	98700	MetaMask. And then there's Dapps. So, the definition I give Dapp is a wide range of
98700	104960	applications that include the functionality that implements through the on-chain smart contract.
105180	110660	So, all four types of applications play a very important role in the application space in
110660	117080	blockchains. And they all have their own unique type of services. Today, I will talk about the
117080	123860	one in PDF. So, throughout this presentation, I will be talking about a lot of Web2 terms.
123880	129320	So, I want to start by explaining the Web2 terms. So, first, smart contract.
129320	133860	Smart contract, you can think of it's a backend API server that runs on blockchains.
134120	138700	Privileged functions. So, inside smart contracts, there's a lot of functions. And some functions
138700	144440	can only be called by, say, admin or owner address. Those functions, typically,
145300	150960	actions, operations, contracts. And then there are transactions. Transactions, you can think of
150960	157640	it's like a bundle of post requests that's sent to the smart contract. Transaction hash is a
157640	164960	unique identifier for each transaction where you can pull the transaction information out by using
164960	172480	hash. So, imagine a web server that charges a certain amount of fee for each post request.
172640	179560	That's like... so, each transaction will charge some sort of, like, crypto assets.
179800	184040	And when there's a lot of people sending this, like, post request to a smart contract,
184040	187780	the more you pay, the faster your transaction will be executed.
188660	193160	So, blockchain is formed by, like, a block by block. And each block, you can think of it
193160	201120	multiple post requests. And each block has, like, set amount of time in between. You can think of
201120	206140	the batch of post requests get executed, like, block by block. And there's a certain time in
206140	212680	between. So, blockchain RPC is the communication channel that's exposed by, like, blockchain nodes.
212680	219580	So, the outside entity can talk to the blockchains. And NFT is type of, like,
219580	224440	digital assets in the form of an image with ownership information from the blockchain.
224900	233220	So, this is, like, a general workflow for the app. The app you see there is Uniswap,
233220	240660	probably the most popular and most used app. So, you go to a website, there's, like,
240780	247900	a connect button, and you click that. That triggers a connection request pop up from the wallet.
247900	253680	If you trust the application, you can click X so that your wallet is going to connect with the app.
254460	258960	And after the connection is established, you can start using the app. In this example,
258960	267220	I exchanged 0.01 Ether to 24 USDT, and I can click the swap. And that transaction gets sent
267220	272140	to the extension wallet. And once you click the confirm, which means you sign the transaction,
272140	275560	and that transaction will be sent to the blockchain and executed. And then that
275560	279500	transaction will get executed, and the token will be swapped.
279880	285640	Next, I'll talk about DApp architecture. So, this is standard Web 2.0 applications,
285640	291620	where you have, like, client-side app, and then you have, like, server-side components,
291620	295300	like web server API database. I'm sure everyone is familiar with that.
296100	303760	And DApps, I put into three categories. The first one is API-less DApp. What it means
303760	313960	is that on the server-side, there's no API. And the main logic is inside the small contracts.
315040	322900	So, for example, the example I gave Uniswap, the early version of Uniswap is API-less DApp,
322900	327840	where the token exchange information is inside a small contract, and the front-end just
327840	333500	help with, like, user interactions. So, this type of DApp, the attack surface,
333500	338800	application side is quite limited. So, and this type of DApp typically deal with the
338800	343700	app framework, and React has sort of, like, SSS building protection there. So, it's hard to find
343700	348460	SSS there. And then unless you have, like, you can completely take over the site by, say, using,
348460	353420	like, DNS hijacking, the application side, the attack surface is very limited. And typically,
353420	358300	when this kind of application gets exported, it's often the vulnerability from the small contract.
359160	365020	Now, the second one is API-enabled DApp. So, compared to the last one, this one on the
365020	373100	servers has service APIs. And one example is, say, NFT creation DApp. So, if the server has API,
373100	378540	allow users to upload images or, like, NFT metadata JSON to the back-end, and then the
378540	383260	back-end is going to return, like, a URL. So, you can use a URL to talk to a small contract.
384220	389160	The attack surface for this type of app is increased, but the vulnerability on the
389160	395340	application side is mostly, like, Web2 related. And now, move to the full-scale DApps. So,
395340	402160	full-scale DApps, the back-end is going to talk, like, read data or send transactions.
402440	409840	So, oftentimes, in the full-scale DApp, the small contract will have privileged functions,
409840	415260	and the account that can call those functions, those private keys are stored in the back-end
415260	420680	server. So, if you have a way to, say, for example, compromise a server or have triggers on,
420680	427740	like, an arrow, you're likely able to, say, obtain that key from the server and completely
427740	433360	transfer out all the money from the small contract for, like, very big damages. So,
433360	438620	the advantages of DApps in 2024 are, like, a full-scale DApp compared to, like, 2020,
438620	445900	by some mergers of, like, APS, APLS DApp. One example of, like, a full-scale DApp is
445900	451300	cross-chain bridge. So, cross-chain bridge allows a user to transfer to...
453700	455760	other, for example, to...
459340	464900	because blockchain, the small contract blockchain cannot talk to each other.
465600	472460	It's cross-blockchain. So, this type of application must require a blockchain component.
472460	480500	So, how bridge works is, on a source chain, the back-end monitors that deposit event and
480500	485120	processes it. And if everything looks good, all the privileged functions can be
485120	486960	transferred out.
489980	495000	So, let's talk about DApps threat modeling. So, from a threat modeling perspective,
495000	504600	the most popular assets in Web3 are the private key. If you can get those, you can have full
504600	512420	control over the assets in the address, or you can invoke, like, privileged functions as well.
512420	520820	Second one is signatures. So, for certain type of tokens, it allows...
523700	528020	if you can have the special message signed by the...
530560	532620	and there's a lot of...
532620	536300	you could sign in those type of messages, and then...
538000	542500	the last one is API keys. So, API keys is for those, like,
543780	545900	such as, like, centralized exchanges...
547800	549880	get those API keys, you can take...
554690	560750	I talk about, like, I will start to talk about client-side attack by mentioning a term
560750	568810	called already-connected wallet. So, in the DApp workflow session, I talk about, like,
568810	574990	if a user wants to use a DApp, the DApp must connect to their wallet. And there's a best
574990	581490	practice in Web3 that users should only connect their wallet to the DApp they trust. And then
581490	588010	once... and when users trust the DApp, they just sign whatever, like, things that the DApp wants
588010	594270	the user to sign. So, if any vulnerability exists in client-side vulnerability inside the DApp that
594270	599330	has a lot of user-connected wallet, and it's very popular, the severity is going to increase,
599330	606150	like, dramatically. So, client-side attack perspective, there are, like, three things
606150	611350	attackers will most likely want to do. The first one is initial malicious transactions.
611350	619170	How that can happen is when the attacker can modify the JavaScript code of the website,
619170	625970	for example, through, like, cross-site security, hijacking, it's possible to have those malicious
625970	632690	jobs initialize the transaction to take out all the security. And if, in general, JavaScript is
632690	640710	not possible, and if, like, checking is possible, another option is to deceive the user.
641210	653490	The last one is... and for already connected website, everything that can initial...
654810	659690	will have critical vulnerability. So, as it says, right, in Web 2.0, even if you have, like,
659690	665450	can't take over, it's, like, high, it's maybe, like, a low critical, but Web 3.0, it's definitely...
668830	673270	So, let's talk about server-side. So, from a server-side perspective, there's, like,
673270	677630	sort of, like, four things the attacker will want to do. The first one is stealing the keys.
679410	684570	Basically, if you're stealing the key, you probably can't think about the asset as part of the project,
684570	689490	and it's just sort of a lot of ways you can pretend to do that. And the second one is stealing
689490	694910	crypto assets from other users' accounts or admins' accounts. They will probably buy, like,
694990	704670	a broken access control, or you can spend assets more than your actual balance. That can probably
704670	709350	happen, like, business knowledge error or risk condition. And for NFTs, as I mentioned, those,
709350	713810	like, images are, like, fault-free. And if those images are down,
713810	718470	this NFT value is going to go down, like, dramatically, and that's what can happen when,
718470	723430	like, an NFT is attacked. So, actually, anything that can touch somebody
724750	739940	has a critical severity. So, in the last session, I talked about how Web 2.0 attack
739940	746640	has higher severity in Web 3.0. In the next sessions, I will talk about what kind of, like,
746640	754680	unique better attack service that can be enabled in Web 3.0. So, I think due to Comcast free,
754680	760760	I cannot go over, like, each sub-item one by one. In short, deep applications that
762900	768000	incorrectly process transactions, they can come in more quickly. And it's possible to
768000	773940	initial attack against backend components through smart contract. And if the application
773940	782340	allows you to handle different SS class, it can also, yeah.
782980	790100	So, the first case I want to talk about is race control in gas via unregistered APIs.
790100	797140	So, this application is a program that requires users to register for participation. So,
797140	805580	the registration is based on APIs, which users can provide their own chain address.
806680	813630	And then backend is part of the registration. The function can only be called, like,
813630	824390	an identity. So, what's that instrument? I'm giving you a different mic.
840980	842780	Hello. Wow.
846220	853660	Great. So, well, the case study just started. So, you didn't miss anything. Okay. Yeah. So,
853660	860440	the finding here is that, wow, that's amazing. So, the APIs accept any assumed address as long
860440	865580	as the address data is in the correct format. So, each time the API is called, the backend
865580	870700	is going to send a transaction to a smart contract. And as I talk about, each transaction can cost
870700	877020	gas. Gas is, like, you can think of as money. So, the way to exploit this is, like, I can generate
877220	882780	a bunch of, like, a random assumed address and keep calling the API to let the admin want to
882780	887540	keep sending transactions to smart contracts and eventually consume all the ethers in the
887540	892760	admin's wallet. So, this not only consumes all the ethers, but allow, like, and prevent, like,
892760	899120	other users to register. So, this is, like, the transaction log when I do the testing. So,
899120	905180	this is in the test net. So, there's no actual, like, assets lost. So, I write a script to generate
905320	910860	a bunch of address and put the request into, like, a repeater and just send it. And when I
910860	919900	go to etherscan, I see those, like, records. The second one is poor transaction time. So,
919900	925640	this can actually happen in any Dapp that have API to trigger the backend to send a transaction
925640	932760	and keep the connection open while waiting for the on-chain transaction execution results. So,
932760	938720	the example code snippet is I generate using, like, ChagVTs. So, it's basically an API called
938720	945560	deposit. And when user call this API, it's going to trigger the backend to send a deposit
945560	951380	transaction to the smart contract. And the code will wait for the transaction executed and then
951380	957300	send HTTP response to the users. So, what's the problem here is that, for example, on a certain
957300	964060	main net, the block time is 12 seconds, which means the HTTP connection will remain open for
964060	971520	at least 12 seconds. If the chain is congested, it can the time can be much longer. So,
971520	977440	to exploit these APIs, like, only one single machine is required to send a bunch of, like,
977440	983480	API requests and to occupy all the connection slots and the server is not going to handle any,
983480	989160	like, more requests. The next one is poor transaction time handling leads to risk
989160	994760	conditions. So, this is gaming, like, a game-fied app that allows users to purchase, like, in-game
994760	1002560	items using crypto assets. So, deposit workflow by user deposit crypto assets into the game smart
1002560	1008220	contract and then backend retrieve those deposit informations from the smart contract to increase
1008220	1013260	the user's in-game balance. And what's the interesting part is the withdrawal crypto
1013260	1018600	workflow is the withdrawal workflow work by users submit a withdrawal API request to the backend
1018600	1024740	and the backend verify the user's balance and call the privilege function withdraw in a smart
1024740	1030600	contract. And after the transaction is finished, the token will arrive in user's on-chain wallet
1030600	1037020	and the backend is going to update the user balance to zero. So, what's the problem here is that
1037880	1045500	the backend update the user balance only after the transaction successfully executed and it
1045500	1051740	doesn't lock the transaction balance when they send the on-chain transactions. So, for example,
1051740	1057540	in serum, like, 12-second block time, user have 12-second window to spend their, like, in-game
1057540	1064180	currencies. So, they can basically, in those time periods, they can buy 100 words of, like,
1064180	1069360	in-game items and then wait for the transaction to finish and those tokens will be arrived in their
1069360	1074340	wallets. This way, the user can basically purchase all the in-game items for free.
1074340	1081020	And a race condition can also happen in, like, Web 2.0, but the time window for that in Web 2.0 is
1081020	1085960	much smaller. But in Web 3.0, the time window in this case is at least 12 seconds. So, it's much
1085960	1093300	easier to pull off. The next one is bridge contract, bridge backend, lack of smart contract
1093300	1099520	address validations. So, I talk about how bridge work briefly, previous slide. So, for this
1099520	1104920	particular bridge, the workflow is, like, user deposit tokens into smart contract on the source
1104920	1110220	chain and obtain a transaction hash. And then the user submits the transaction hash to the backend
1110220	1117620	through APIs, and the backend fetches the information with the transaction hash to validate
1117620	1123220	the deposit. And if anything goes correctly, the bridge backend is going to call the privilege
1123220	1126990	function in the smart contract and the destination chain and release the fund to the user.
1127850	1133410	So, for this kind of bridge, the backend actually needs to validate tons of stuff.
1133630	1138130	And in that particular application, it needs to validate, for example, the transaction status is
1138130	1145710	successful, and it needs to get the information of the deposit amount, the sender receiver address.
1146510	1151490	And if anything is not validated correctly, it can cause the bridge to become vulnerable.
1151490	1157410	And in this case, the backend does not verify the smart contract that received the token
1157410	1165250	is the one operated by the project. So, to exploit this vulnerability,
1165250	1172030	I am going to deploy a malicious smart contract on the blockchain that basically shares the same
1172030	1177170	functionality as the legitimate smart contract. And I make a token deposit into that fake bridge
1177170	1181850	contract and obtain a transaction hash. And I submit a transaction hash to the bridge backend
1181850	1187690	through APIs and wait for the bridge backend to process the hash. And because I'm missing
1187690	1194730	the address validations, he thinks the address is correct. And then it's going to release the
1194730	1202330	tokens to the users on the destination chain. And when that happens, and after that, the user
1202330	1207950	can withdraw his tokens sent to the fake contract because he had full control of that.
1208010	1212990	And if this vulnerability gets exploited, all the tokens in the destination chain smart contract can
1212990	1219290	be stolen. So, the last case. So, this is a lightweight crypto trading application where
1219290	1225730	users can deposit assets and perform token swap. The backend uses Fireblock as custodian services.
1225730	1232050	The deposit work is user requests a deposit address through APIs. And then the backend
1232050	1236390	is going to get one from Fireblock. And then the user is going to deposit a crypto asset to the
1236390	1243030	address. And then the backend periodically curates the Fireblock.getTransaction API.
1243090	1248430	And if it sees the deposit transactions, it's going to give the user the in-app balance.
1248990	1254270	So, when we are doing the testing, we deposit like 0.1 metatoken to the deposit address.
1254270	1259550	And the balance increased by 1.1. And we were so confused because this is not like double or
1259550	1265410	10 times. It just, it's like increased by one. So, we go to the Polygon scam and see there's
1265410	1272730	only like 0.1 metatoken arrived in the address. However, we found a record of like a scam NFT
1272730	1277830	airdropped into that address. So, it's quite common for scammers to airdrop like NFTs
1278430	1282950	with like phishing site link in the token information to a newly added address within
1282950	1290290	the blockchain. Newly added address means the address like received like a crypto with value
1290290	1297590	for the first time. So, the backend treat that value list NFT as a valid like a magic deposit.
1297990	1302410	So, this is a whiteboard testing and we found out the root cause is that the backend just
1304750	1310510	doesn't, when it parses the information returned by Fireblock, it failed to check the token type.
1310510	1317470	To exploit these issues, we deployed a ERC-1155 NFT and make 99 NFT with no value to the address
1317470	1324350	which caused our account to increase like 99 metatoken. So, to summarize the state of like
1324350	1329070	dApp security. So, right now, with the advance of like blockchain ecosystem, dApp becomes like
1329070	1334130	more and more complex and some of them start integrating heavy Web2 components. And often
1334130	1338650	vulnerability are introduced in dApp because a lot of developers either lack of Web3 security
1338650	1345690	knowledge or Web2 security knowledge. And Web2 vulnerability in Web3 application often has like
1345690	1352430	increased severity because it can touch monies. And unlike small contracts where it's like
1352430	1357630	public viewable, the exploitation of the backend might have less exposure because no one can see
1357630	1363990	it, but it can still happen. So, to secure dApp, especially dApp with like heavy backend components,
1363990	1370190	it is like as important to get pension testing compared as like getting like audits for your
1370190	1377810	small contract. This is the last slide. So, if you want to get into dApp hacking, I would
1377810	1381810	suggest like you first be decent at Web2 application hacking because at the end of
1381810	1386590	day there's tons of Web2 components and you need to be familiar with the architecture of
1386590	1391090	different type of dApps. That way you will know what the attack services are for this app. And
1391090	1395830	the best way to do it is play around with dApp to experiment then. An investment of like $100
1395830	1402350	of crypto, probably going to waste gas, is going to be enough. And to understand like basic concept
1402350	1406630	of blockchain, include those like Web2 technology, you don't really need to understand how blockchain
1406630	1411450	works. And then you learn the solidity of small contract language so you can understand small
1411450	1415970	contract. And sometimes you can find some like hidden attack services. And it's not necessarily
1415970	1420490	require you to know like how to do a secure audit of small contract. That's a completely different
1420490	1426650	topic. And go find a dApp and hack it, I forget legally, and start like... So I believe like
1426650	1431110	starting hacking dApp is probably one of the best way to look for like Web2 website hackers that
1431110	1437270	pivot into Web3 security. And well, if you want to ask me like why like Web3 security, I mean like
1437270	1443870	look at this bounty, like $10 million. Well, I don't think this can ever happen in Web2. So yeah,
1443870	1450470	I guess people love money. All right. So that's my talk. I hope you guys enjoy and learn something
1450470	1452310	about Web3 security. Thank you.
