WEBVTT

00:00.660 --> 00:04.980
Yeah, I hope my talk can give you guys a taste of Web3 security.

00:05.420 --> 00:07.080
So, my name is Pei-Yu Wang.

00:07.080 --> 00:08.480
I'm a security engineer.

00:08.820 --> 00:16.420
So, what I do is application penetration testing, mostly Web3 applications, like apps and wallets.

00:16.420 --> 00:20.000
And I also do small contract audits and security research.

00:20.000 --> 00:29.180
My past talks at DEF CON are in Blockchain Village, which I talk about exploiting crypto and DeFi scammer outposts.

00:29.180 --> 00:32.040
So, outside of like words, I'm like a DeFi apes.

00:32.040 --> 00:34.320
I'm like a mincoin traders.

00:35.180 --> 00:37.320
Blockchain and the apps.

00:37.340 --> 00:44.780
So, since the first DeFi summer in 2020, the blockchain ecosystem has exceptional growth.

00:44.780 --> 00:53.860
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.

00:54.620 --> 00:58.180
So, we're here at AppStack Village, and let's talk about applications.

00:58.180 --> 01:02.580
So, the most common AppStack-heavy Web3 products are the following.

01:02.580 --> 01:09.960
The first one is centralized exchanges, such as Coinbase, Binance, which you guys are probably familiar with, and then data platform.

01:09.960 --> 01:15.200
So, the raw data for blockchain transactions are extremely hard for people to read.

01:15.200 --> 01:21.580
So, there's an application like Etherscan that helps people to read data, read transaction data.

01:21.580 --> 01:23.040
And there's a wallet.

01:23.040 --> 01:29.540
So, wallet is a type of application that holds the private key and performs the signing request when requested.

01:29.540 --> 01:33.460
The most popular wallet probably is the wallet MetaMask.

01:33.460 --> 01:35.020
And then there's Dapps.

01:35.020 --> 01:44.960
So, the definition I give Dapp is a wide range of applications that include the functionality that implements through the on-chain smart contract.

01:45.180 --> 01:51.520
So, all four types of applications play a very important role in the application space in blockchains.

01:51.520 --> 01:55.760
And they all have their own unique type of services.

01:55.760 --> 01:58.160
Today, I will talk about the one in PDF.

01:59.340 --> 02:03.860
So, throughout this presentation, I will be talking about a lot of Web2 terms.

02:03.880 --> 02:07.960
So, I want to start by explaining the Web2 terms.

02:07.960 --> 02:09.320
So, first, smart contract.

02:09.320 --> 02:13.860
Smart contract, you can think of it's a backend API server that runs on blockchains.

02:14.120 --> 02:15.520
Privileged functions.

02:15.520 --> 02:17.860
So, inside smart contracts, there's a lot of functions.

02:17.860 --> 02:22.740
And some functions can only be called by, say, admin or owner address.

02:22.740 --> 02:28.020
Those functions, typically, actions, operations, contracts.

02:28.100 --> 02:29.680
And then there are transactions.

02:29.680 --> 02:36.120
Transactions, you can think of it's like a bundle of post requests that's sent to the smart contract.

02:36.240 --> 02:45.760
Transaction hash is a unique identifier for each transaction where you can pull the transaction information out by using hash.

02:46.180 --> 02:52.480
So, imagine a web server that charges a certain amount of fee for each post request.

02:52.640 --> 02:59.560
That's like... so, each transaction will charge some sort of, like, crypto assets.

02:59.800 --> 03:07.780
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.

03:08.660 --> 03:11.500
So, blockchain is formed by, like, a block by block.

03:11.500 --> 03:15.940
And each block, you can think of it multiple post requests.

03:16.160 --> 03:20.480
And each block has, like, set amount of time in between.

03:20.480 --> 03:25.040
You can think of the batch of post requests get executed, like, block by block.

03:25.040 --> 03:26.860
And there's a certain time in between.

03:27.000 --> 03:32.680
So, blockchain RPC is the communication channel that's exposed by, like, blockchain nodes.

03:32.680 --> 03:37.880
So, the outside entity can talk to the blockchains.

03:37.880 --> 03:44.440
And NFT is type of, like, digital assets in the form of an image with ownership information from the blockchain.

03:44.900 --> 03:51.380
So, this is, like, a general workflow for the app.

03:51.380 --> 03:58.320
The app you see there is Uniswap, probably the most popular and most used app.

03:58.360 --> 04:03.020
So, you go to a website, there's, like, a connect button, and you click that.

04:03.420 --> 04:07.900
That triggers a connection request pop up from the wallet.

04:07.900 --> 04:13.680
If you trust the application, you can click X so that your wallet is going to connect with the app.

04:14.460 --> 04:17.960
And after the connection is established, you can start using the app.

04:17.960 --> 04:25.380
In this example, I exchanged 0.01 Ether to 24 USDT, and I can click the swap.

04:25.560 --> 04:28.960
And that transaction gets sent to the extension wallet.

04:28.960 --> 04:35.160
And once you click the confirm, which means you sign the transaction, and that transaction will be sent to the blockchain and executed.

04:35.160 --> 04:39.500
And then that transaction will get executed, and the token will be swapped.

04:39.880 --> 04:42.020
Next, I'll talk about DApp architecture.

04:42.340 --> 04:53.480
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.

04:53.480 --> 04:55.300
I'm sure everyone is familiar with that.

04:56.100 --> 04:59.600
And DApps, I put into three categories.

04:59.600 --> 05:03.020
The first one is API-less DApp.

05:03.020 --> 05:07.620
What it means is that on the server-side, there's no API.

05:08.140 --> 05:13.960
And the main logic is inside the small contracts.

05:15.040 --> 05:30.740
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.

05:30.820 --> 05:35.900
So, this type of DApp, the attack surface, application side is quite limited.

05:36.380 --> 05:42.900
So, and this type of DApp typically deal with the app framework, and React has sort of, like, SSS building protection there.

05:42.900 --> 05:44.720
So, it's hard to find SSS there.

05:44.720 --> 05:52.820
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.

05:52.820 --> 05:58.300
And typically, when this kind of application gets exported, it's often the vulnerability from the small contract.

05:59.160 --> 06:02.640
Now, the second one is API-enabled DApp.

06:02.880 --> 06:07.120
So, compared to the last one, this one on the servers has service APIs.

06:07.300 --> 06:10.840
And one example is, say, NFT creation DApp.

06:10.860 --> 06:20.460
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.

06:20.460 --> 06:23.260
So, you can use a URL to talk to a small contract.

06:24.220 --> 06:31.880
The attack surface for this type of app is increased, but the vulnerability on the application side is mostly, like, Web2 related.

06:32.820 --> 06:34.900
And now, move to the full-scale DApps.

06:34.900 --> 06:42.160
So, full-scale DApps, the back-end is going to talk, like, read data or send transactions.

06:42.440 --> 06:56.060
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.

06:56.080 --> 07:12.800
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.

07:13.120 --> 07:22.780
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.

07:23.380 --> 07:27.040
One example of, like, a full-scale DApp is cross-chain bridge.

07:27.040 --> 07:31.300
So, cross-chain bridge allows a user to transfer to...

07:33.700 --> 07:35.760
other, for example, to...

07:39.340 --> 07:44.900
because blockchain, the small contract blockchain cannot talk to each other.

07:45.600 --> 07:47.140
It's cross-blockchain.

07:47.140 --> 07:52.460
So, this type of application must require a blockchain component.

07:52.460 --> 08:01.520
So, how bridge works is, on a source chain, the back-end monitors that deposit event and processes it.

08:01.520 --> 08:06.960
And if everything looks good, all the privileged functions can be transferred out.

08:09.980 --> 08:12.420
So, let's talk about DApps threat modeling.

08:12.940 --> 08:22.500
So, from a threat modeling perspective, the most popular assets in Web3 are the private key.

08:22.500 --> 08:32.420
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.

08:32.420 --> 08:34.640
Second one is signatures.

08:34.640 --> 08:40.820
So, for certain type of tokens, it allows...

08:43.700 --> 08:48.020
if you can have the special message signed by the...

08:50.560 --> 08:52.620
and there's a lot of...

08:52.620 --> 08:56.300
you could sign in those type of messages, and then...

08:58.000 --> 09:00.200
the last one is API keys.

09:00.200 --> 09:05.900
So, API keys is for those, like, such as, like, centralized exchanges...

09:07.800 --> 09:09.880
get those API keys, you can take...

09:14.690 --> 09:25.050
I talk about, like, I will start to talk about client-side attack by mentioning a term called already-connected wallet.

09:25.110 --> 09:33.630
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.

09:33.630 --> 09:41.210
And there's a best practice in Web3 that users should only connect their wallet to the DApp they trust.

09:41.210 --> 09:49.330
And then once... and when users trust the DApp, they just sign whatever, like, things that the DApp wants the user to sign.

09:49.330 --> 10:00.430
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.

10:01.830 --> 10:08.550
So, client-side attack perspective, there are, like, three things attackers will most likely want to do.

10:08.550 --> 10:11.350
The first one is initial malicious transactions.

10:11.350 --> 10:30.650
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.

10:30.790 --> 10:40.710
And if, in general, JavaScript is not possible, and if, like, checking is possible, another option is to deceive the user.

10:41.210 --> 10:53.490
The last one is... and for already connected website, everything that can initial...

10:54.810 --> 10:57.030
will have critical vulnerability.

10:57.150 --> 11:05.450
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...

11:08.830 --> 11:10.630
So, let's talk about server-side.

11:10.630 --> 11:15.950
So, from a server-side perspective, there's, like, sort of, like, four things the attacker will want to do.

11:15.950 --> 11:17.630
The first one is stealing the keys.

11:19.410 --> 11:28.250
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.

11:28.250 --> 11:33.430
And the second one is stealing crypto assets from other users' accounts or admins' accounts.

11:33.430 --> 11:44.130
They will probably buy, like, a broken access control, or you can spend assets more than your actual balance.

11:44.130 --> 11:47.170
That can probably happen, like, business knowledge error or risk condition.

11:47.170 --> 11:51.850
And for NFTs, as I mentioned, those, like , images are, like, fault-free.

11:51.870 --> 12:00.330
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.

12:00.950 --> 12:06.510
So, actually, anything that can touch somebody has a critical severity.

12:10.240 --> 12:23.400
So, in the last session, I talked about how Web 2.0 attack has higher severity in Web 3.0.

12:23.400 --> 12:31.360
In the next sessions, I will talk about what kind of, like, unique better attack service that can be enabled in Web 3.0.

12:32.100 --> 12:38.180
So, I think due to Comcast free, I cannot go over, like, each sub-item one by one.

12:38.180 --> 12:46.620
In short, deep applications that incorrectly process transactions, they can come in more quickly.

12:46.620 --> 12:52.640
And it's possible to initial attack against backend components through smart contract.

12:52.820 --> 13:02.340
And if the application allows you to handle different SS class, it can also, yeah.

13:02.980 --> 13:10.100
So, the first case I want to talk about is race control in gas via unregistered APIs.

13:10.100 --> 13:16.920
So, this application is a program that requires users to register for participation.

13:16.940 --> 13:25.580
So, the registration is based on APIs, which users can provide their own chain address.

13:26.680 --> 13:30.140
And then backend is part of the registration.

13:30.900 --> 13:35.530
The function can only be called, like, an identity.

13:36.970 --> 13:38.890
So, what's that instrument?

13:42.310 --> 13:44.390
I'm giving you a different mic.

14:00.980 --> 14:01.940
Hello.

14:01.940 --> 14:02.780
Wow.

14:06.220 --> 14:07.120
Great.

14:07.120 --> 14:09.420
So, well, the case study just started.

14:09.420 --> 14:11.200
So, you didn't miss anything.

14:11.280 --> 14:12.360
Okay.

14:12.820 --> 14:13.440
Yeah.

14:13.440 --> 14:16.220
So, the finding here is that, wow, that's amazing.

14:16.480 --> 14:23.200
So, the APIs accept any assumed address as long as the address data is in the correct format.

14:23.260 --> 14:28.060
So, each time the API is called, the backend is going to send a transaction to a smart contract.

14:28.260 --> 14:31.240
And as I talk about, each transaction can cost gas.

14:31.240 --> 14:33.960
Gas is, like, you can think of as money.

14:34.040 --> 14:48.500
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.

14:48.500 --> 14:54.940
So, this not only consumes all the ethers, but allow, like, and prevent, like, other users to register.

14:55.800 --> 14:58.980
So, this is, like, the transaction log when I do the testing.

14:58.980 --> 15:00.240
So, this is in the test net.

15:00.240 --> 15:03.080
So, there's no actual, like, assets lost.

15:03.940 --> 15:10.340
So, I write a script to generate a bunch of address and put the request into, like, a repeater and just send it.

15:10.340 --> 15:14.520
And when I go to etherscan, I see those, like, records.

15:15.420 --> 15:18.000
The second one is poor transaction time.

15:18.000 --> 15:32.540
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.

15:32.540 --> 15:36.840
So, the example code snippet is I generate using, like, ChagVTs.

15:36.840 --> 15:39.620
So, it's basically an API called deposit.

15:40.280 --> 15:47.640
And when user call this API, it's going to trigger the backend to send a deposit transaction to the smart contract.

15:47.760 --> 15:53.780
And the code will wait for the transaction executed and then send HTTP response to the users.

15:54.240 --> 16:05.820
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.

16:05.820 --> 16:10.800
If the chain is congested, it can the time can be much longer.

16:10.840 --> 16:24.840
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.

16:25.800 --> 16:29.860
The next one is poor transaction time handling leads to risk conditions.

16:29.860 --> 16:36.720
So, this is gaming, like, a game-fied app that allows users to purchase, like, in-game items using crypto assets.

16:37.280 --> 16:50.480
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.

16:51.100 --> 17:05.480
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.

17:05.480 --> 17:14.140
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.

17:14.580 --> 17:29.800
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.

17:29.980 --> 17:38.800
So, for example, in serum, like, 12-second block time, user have 12-second window to spend their, like, in-game currencies.

17:39.540 --> 17:50.340
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.

17:50.340 --> 17:54.340
This way, the user can basically purchase all the in-game items for free.

17:54.340 --> 18:02.000
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.

18:02.000 --> 18:05.400
But in Web 3.0, the time window in this case is at least 12 seconds.

18:05.400 --> 18:07.380
So, it's much easier to pull off.

18:08.680 --> 18:14.780
The next one is bridge contract, bridge backend, lack of smart contract address validations.

18:14.780 --> 18:18.880
So, I talk about how bridge work briefly, previous slide.

18:18.880 --> 18:27.500
So, for this particular bridge, the workflow is, like, user deposit tokens into smart contract on the source chain and obtain a transaction hash.

18:27.500 --> 18:38.460
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.

18:38.460 --> 18:46.990
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.

18:47.850 --> 18:53.410
So, for this kind of bridge, the backend actually needs to validate tons of stuff.

18:53.630 --> 19:05.710
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.

19:06.510 --> 19:11.490
And if anything is not validated correctly, it can cause the bridge to become vulnerable.

19:11.490 --> 19:21.310
And in this case, the backend does not verify the smart contract that received the token is the one operated by the project.

19:22.490 --> 19:34.610
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.

19:34.610 --> 19:39.590
And I make a token deposit into that fake bridge contract and obtain a transaction hash.

19:39.590 --> 19:46.790
And I submit a transaction hash to the bridge backend through APIs and wait for the bridge backend to process the hash.

19:46.790 --> 19:53.170
And because I'm missing the address validations, he thinks the address is correct.

19:53.170 --> 19:58.950
And then it's going to release the tokens to the users on the destination chain.

19:58.950 --> 20:07.950
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.

20:08.010 --> 20:13.970
And if this vulnerability gets exploited, all the tokens in the destination chain smart contract can be stolen.

20:14.650 --> 20:16.030
So, the last case.

20:16.030 --> 20:22.530
So, this is a lightweight crypto trading application where users can deposit assets and perform token swap.

20:22.530 --> 20:25.730
The backend uses Fireblock as custodian services.

20:25.730 --> 20:31.290
The deposit work is user requests a deposit address through APIs.

20:31.350 --> 20:33.690
And then the backend is going to get one from Fireblock.

20:33.690 --> 20:37.310
And then the user is going to deposit a crypto asset to the address.

20:37.650 --> 20:43.030
And then the backend periodically curates the Fireblock.getTransaction API.

20:43.090 --> 20:48.430
And if it sees the deposit transactions, it's going to give the user the in-app balance.

20:48.990 --> 20:54.270
So, when we are doing the testing, we deposit like 0.1 metatoken to the deposit address.

20:54.270 --> 20:57.030
And the balance increased by 1.1.

20:57.030 --> 21:00.230
And we were so confused because this is not like double or 10 times.

21:00.230 --> 21:01.770
It just, it's like increased by one.

21:01.950 --> 21:08.450
So, we go to the Polygon scam and see there's only like 0.1 metatoken arrived in the address.

21:09.570 --> 21:14.730
However, we found a record of like a scam NFT airdropped into that address.

21:14.730 --> 21:23.810
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.

21:23.810 --> 21:31.670
Newly added address means the address like received like a crypto with value for the first time.

21:32.190 --> 21:37.590
So, the backend treat that value list NFT as a valid like a magic deposit.

21:37.990 --> 21:50.510
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.

21:50.510 --> 22:01.590
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.

22:02.310 --> 22:05.410
So, to summarize the state of like dApp security.

22:05.410 --> 22:13.650
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.

22:13.750 --> 22:20.970
And often vulnerability are introduced in dApp because a lot of developers either lack of Web3 security knowledge or Web2 security knowledge.

22:21.590 --> 22:28.690
And Web2 vulnerability in Web3 application often has like increased severity because it can touch monies.

22:29.470 --> 22:39.570
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.

22:39.570 --> 22:51.310
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.

22:52.610 --> 22:54.150
This is the last slide.

22:54.150 --> 23:07.710
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.

23:07.710 --> 23:10.950
That way you will know what the attack services are for this app.

23:10.950 --> 23:14.630
And the best way to do it is play around with dApp to experiment then.

23:14.630 --> 23:19.990
An investment of like $100 of crypto, probably going to waste gas, is going to be enough.

23:19.990 --> 23:27.530
And to understand like basic concept of blockchain, include those like Web2 technology, you don't really need to understand how blockchain works.

23:27.890 --> 23:32.090
And then you learn the solidity of small contract language so you can understand small contract.

23:32.090 --> 23:34.770
And sometimes you can find some like hidden attack services.

23:34.770 --> 23:39.730
And it's not necessarily require you to know like how to do a secure audit of small contract.

23:39.730 --> 23:41.270
That's a completely different topic.

23:41.490 --> 23:52.950
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.

23:53.230 --> 23:59.150
And well, if you want to ask me like why like Web3 security, I mean like look at this bounty, like $10 million.

23:59.370 --> 24:02.890
Well, I don't think this can ever happen in Web2.

24:02.950 --> 24:05.810
So yeah, I guess people love money.

24:06.450 --> 24:07.070
All right.

24:07.070 --> 24:08.250
So that's my talk.

24:08.250 --> 24:11.570
I hope you guys enjoy and learn something about Web3 security.

24:11.570 --> 24:12.310
Thank you.

