WEBVTT

00:00.000 --> 00:01.280
Hey everybody!

00:01.520 --> 00:04.880
If you're standing next to a round table, you're in the wrong place.

00:05.040 --> 00:07.600
If you're sitting in a chair, you're in the correct place.

00:07.600 --> 00:10.980
If there's a chair next to you, put your hand up and make a friend.

00:11.060 --> 00:13.560
Everyone not sitting down, that's where your chairs are.

00:13.560 --> 00:15.100
There's lots of them.

00:15.100 --> 00:17.120
Please come in and sit down.

00:17.120 --> 00:18.420
And I'll tell you why.

00:18.560 --> 00:23.420
Because this fine man is going to teach you about more than you could possibly imagine in the next...

00:23.420 --> 00:24.640
How long did I actually give you?

00:24.640 --> 00:26.000
I said 15 minutes?

00:26.000 --> 00:26.520
12.

00:26.880 --> 00:27.800
12 minutes.

00:27.800 --> 00:31.660
He's got 12 minutes and he's going to go over how to build a rootkit on OpenWorks.

00:31.660 --> 00:32.880
It's going to be amazing.

00:32.880 --> 00:33.840
Take notes.

00:33.840 --> 00:38.220
You can play the recording back at 1 tenth speed and it will be amazing.

00:38.840 --> 00:42.740
So yeah, definitely watch the long version of this talk when you get home.

00:42.740 --> 00:44.260
The short version is going to be fun.

00:44.300 --> 00:46.960
I'm going to get out of the way and I'm going to let this fine gentleman talk.

00:46.960 --> 00:49.220
But seriously, everybody sit down.

00:49.220 --> 00:52.220
There are plenty of seats and you really want to hear this.

00:52.700 --> 00:54.020
Nishant, please.

00:54.020 --> 00:54.540
Thank you.

01:00.540 --> 01:03.220
Thank you all for coming, coming for my talk.

01:03.220 --> 01:04.760
And thanks to the...

01:06.380 --> 01:07.700
So he told me that...

01:07.700 --> 01:12.180
He told me that this one...

01:12.180 --> 01:16.520
So they already told me that the mic is a little hot.

01:16.520 --> 01:19.500
This one and this one is cold.

01:19.500 --> 01:22.760
So I was supposed to stay a little bit far from that.

01:22.840 --> 01:27.140
Again, thanks for coming for the workshop that I will be delivering.

01:27.140 --> 01:33.320
Thanks for the wireless village people for all the good work for bringing all of us wireless fans together.

01:33.720 --> 01:42.140
So as you can observe on the screens, the title of the workshop is developing Wi-Fi access point rootkits.

01:42.460 --> 01:45.700
My name is Nishant Sharma, as you can read.

01:46.300 --> 01:48.720
I work for Pentester Academy.

01:48.980 --> 01:50.520
Have you guys heard of it?

01:50.520 --> 01:51.820
Just show of hands.

01:52.060 --> 01:53.780
Oh, nice.

01:53.780 --> 01:55.320
Catch you after the talk.

01:55.320 --> 01:59.000
So yeah, we are a cyber security training company.

01:59.000 --> 02:03.340
We run PentesterAcademy.com, we run AttackDefense.com.

02:03.760 --> 02:07.080
A little bit about me so that you know why to trust me, right?

02:07.080 --> 02:09.540
When I'm teaching you, you need that credibility.

02:10.220 --> 02:16.180
So I work as R&D manager and the lead trainer at Pentester Academy.

02:16.520 --> 02:20.000
I conduct trainings on Wi-Fi for private clients.

02:20.020 --> 02:24.800
Just five days before I was conducting it for the black hat here, the Wi-Fi master class.

02:25.540 --> 02:30.800
Before joining Pentester Academy, I worked as a firmware engineer with one of the providers.

02:31.120 --> 02:38.620
My job was to create firmwares for the access points as well as for the wireless intrusion prevention systems.

02:38.920 --> 02:43.360
I have a master's degree in InfoSec, you know, doesn't matter still.

02:43.900 --> 02:50.140
I have been publishing my research in Black Hat, Defcon and other venues for the last four years.

02:50.140 --> 03:01.900
My prime area is Wi-Fi and today we will be talking about a specific space in the Wi-Fi which no one is giving importance to.

03:02.200 --> 03:07.320
So, you know, some of the pretty logos just so that you know.

03:07.720 --> 03:10.280
This is the PentesterAcademy.com.

03:10.420 --> 03:12.080
It's an online library.

03:12.080 --> 03:14.060
This is the AttackDefense.com.

03:14.060 --> 03:17.500
It's our online cyber range.

03:17.500 --> 03:21.700
The main thing about it is dedicated instances.

03:21.700 --> 03:25.620
Every player gets dedicated instances, no VPN, only the browser.

03:26.360 --> 03:33.660
We have multiple scenarios as well, not restricted to one user, one lab, you know, multiple labs, multiple machines.

03:33.780 --> 03:35.780
And done with the promotion.

03:36.300 --> 03:41.780
So, as you know, the workshop outline as you can observe, right?

03:41.780 --> 03:44.240
We'll talk about the rootkit.

03:44.240 --> 03:50.020
I am going to take OpenWRT as the main system on which we are going to do it.

03:50.120 --> 03:52.360
The reasons we will be covering.

03:52.860 --> 03:55.420
First, we will talk about OpenWRT.

03:55.420 --> 03:58.400
So, just for the lay of the land, right?

03:58.400 --> 04:01.700
How many of you are already aware of OpenWRT?

04:01.700 --> 04:02.760
Show of hands.

04:03.220 --> 04:04.380
Oh, that's good.

04:04.380 --> 04:07.640
That's better than, you know, than the other audiences I get.

04:07.640 --> 04:08.680
Oh, cool.

04:08.960 --> 04:11.720
So, yeah, we'll talk about OpenWRT.

04:11.720 --> 04:17.160
I'll quickly run through the introduction so that those people who do not know about it, it's a wonderful project.

04:17.160 --> 04:22.880
You should know about it if you are in Wi-Fi or even if you are concerned about your security.

04:22.980 --> 04:26.600
Then we will talk about how we actually create firmware.

04:26.860 --> 04:35.360
Those of you guys who haven't created a firmware before, you know, you know that it comes from the vendor's website or, you know, it comes pre-installed.

04:35.500 --> 04:39.620
There is a third way of doing that and we will be covering that.

04:40.380 --> 04:45.660
We'll talk about the user space applications, how you can compile them in firmware.

04:45.660 --> 04:50.480
Apart from that, then we will also talk about the kernel-based rootkits.

04:50.480 --> 04:52.200
That's the main takeaway.

04:52.340 --> 04:55.380
But to get there, these are the steps, right?

04:55.380 --> 04:57.240
These are the baby steps that you take.

04:57.620 --> 05:07.600
And I will try to cover as much as possible in this one hour, which apparently is now came down to 50 minutes to see what all I can teach you.

05:08.420 --> 05:11.000
So, access point security, right?

05:11.000 --> 05:15.000
Everyone is talking about Wi-Fi security, especially the enterprises, right?

05:15.000 --> 05:20.320
WPA3 standard just came out, WPA2, PSK enterprise, pretty secure, right?

05:20.320 --> 05:24.100
WEP was the bad one, already out of the market.

05:24.200 --> 05:29.360
But when it comes to the security of Wi-Fi routers, not everyone is that aware.

05:29.460 --> 05:33.980
When we talk about enterprise gate access points, yes, they are doing a good job.

05:34.220 --> 05:35.060
How good?

05:35.060 --> 05:36.340
Again, debatable.

05:36.340 --> 05:43.740
But still, when we talk about the SOHO routers, right, as we like to call them, SOHO stands for your small office, home office, right?

05:43.740 --> 05:49.280
You use them at your home, you use that at the small business venues that you have, right?

05:49.300 --> 05:51.880
Most of the time you're running WPA2, PSK.

05:51.960 --> 05:59.900
The thing is, once you buy a router at such place, most of the times you don't have a dedicated guy to take care of them, right?

05:59.900 --> 06:02.980
So they run for years till the time they break.

06:02.980 --> 06:10.620
And they're running, and you know, you're just happy that you have a good password on WPA2, PSK, and you think that you're unhackable, right?

06:10.620 --> 06:13.120
So that is something that is not right.

06:13.280 --> 06:20.720
We have seen multiple reports, multiple events in which Wi-Fi routers were hacked.

06:21.080 --> 06:22.740
You know, there are multiple vectors.

06:22.740 --> 06:25.760
Some of you don't change their default password.

06:25.760 --> 06:30.020
Some of the routers have vendor-installed firmware backdoors.

06:30.020 --> 06:31.940
Some of them are using weak passwords.

06:31.940 --> 06:36.200
Some of them are exposed to internet over SSH or web UI.

06:36.200 --> 06:38.140
There are multiple ways.

06:38.200 --> 06:44.980
So the problem is, once your router is compromised, there is a plethora of attacks that other people can do.

06:45.020 --> 06:51.880
So it's like giving the command and control of your internet to somebody who you don't know, right?

06:51.880 --> 06:55.100
Some of the issues can be the passive monitoring.

06:55.100 --> 07:00.960
Because it's the router that sends all the traffic out, all the Wi-Fi traffic out.

07:01.000 --> 07:06.900
So once they are on it, just one line change can direct all of your traffic to their server.

07:06.900 --> 07:08.600
They can do passive analysis there.

07:08.600 --> 07:10.680
They can do active MIPM there.

07:11.100 --> 07:24.520
And on top of that, for a few years, for a few past years, we have seen occurrences where botnets were there, who actually took over the routers, then infected other things that were running on the network.

07:24.520 --> 07:28.780
And then they are using it to attack some third party, which is obviously not good.

07:28.780 --> 07:30.320
It's your infra, right?

07:30.320 --> 07:32.040
They should not be able to do that.

07:33.020 --> 07:36.700
So what kind of malwares are there and what they can do?

07:37.000 --> 07:40.020
We have already discussed, you know, worms.

07:40.020 --> 07:41.020
We have seen worms.

07:41.020 --> 07:48.100
We have seen rootkits, spywares, trojans, all kind of things are now moving to the router space as well.

07:48.100 --> 07:55.920
The problem is because they are neglected, no antivirus or heads is running on most of the routers.

07:56.060 --> 07:58.320
You don't even know if you get hacked, right?

07:58.320 --> 08:00.000
So that's one of the issues.

08:01.600 --> 08:06.700
Access point rootkits, one of the subpart of the other malware.

08:06.880 --> 08:13.320
It's important because this is the one which actually helps all of the payload, all of the other payload to stay hidden.

08:13.340 --> 08:16.200
So we will see how actually they are doing it.

08:16.200 --> 08:24.340
We only will be able to see 2-3 things but it will give you a lay of the land how exactly the things are happening there.

08:24.340 --> 08:27.840
A special case of rootkits is bootkits.

08:27.840 --> 08:31.000
If you are interested, really good things.

08:31.440 --> 08:38.360
Coming to OpenWrt, OpenWrt is an embedded operating system which again is based on Linux.

08:38.360 --> 08:44.200
It uses Linux kernel, it uses utils like you have in your Linux.

08:44.200 --> 08:54.860
So for all other practical purposes, if you SSH into it, if you login into it, it will look like a Linux from file system angle, from the utilities.

08:54.860 --> 09:02.740
The only difference is everything, just so that it can run on a cheap hardware, is cut down on the functionality.

09:02.840 --> 09:06.020
It has less command, it has less power, all of that.

09:06.020 --> 09:15.260
It comes with the Ash cell, just like you use your Bash or SH on Linux, it comes with ASH.

09:15.280 --> 09:22.960
It uses BusyBox for all the commands, all the commands put in one binary so that it is lightweight, only that.

09:23.060 --> 09:27.880
It uses Lucy as its web UI so that you can configure it easily.

09:28.140 --> 09:34.520
And just like your Ubuntu has apt-get, it has opkg so you can actually install things on it.

09:35.400 --> 09:44.820
It supports routers, residential gateways, smartphones, and that was one of the reasons why we actually chose this one to do all of this.

09:45.120 --> 09:49.340
It's the most popular open source firmware out there.

09:49.340 --> 09:52.920
Currently it has 3500 plus packages.

09:52.920 --> 09:57.260
So when I say packages, these are the kind of softwares, tools that are already there.

09:57.260 --> 10:00.480
You just need an opkg install to install them and run them.

10:00.480 --> 10:03.440
It supports more than 1200 devices.

10:03.440 --> 10:05.960
These devices are of each range.

10:05.960 --> 10:08.840
You have devices which are up for $20 or $30.

10:08.840 --> 10:12.840
You have devices which can go up to $1000 as well.

10:12.840 --> 10:18.400
So depending on the need that you have, you can use this thing to create your custom gadgets.

10:18.400 --> 10:23.500
You can create your custom snippers because 11ac is coming in.

10:23.500 --> 10:32.940
So the WiFi monitoring that you used to do on your conventional A, B, G, or N, now that has become more difficult.

10:33.520 --> 10:35.440
So all of this can be helped.

10:35.500 --> 10:39.880
All of this is that OpenWrt can help, but that is not the topic.

10:40.400 --> 10:45.900
So what we will discuss about first is the OpenWrt build system.

10:45.980 --> 10:51.800
A lot of people who are using OpenWrt, even they don't like to compile their own firmware.

10:51.800 --> 10:52.100
Why?

10:52.100 --> 10:53.580
Because it is messy.

10:53.580 --> 10:55.380
Or that's what people think.

10:55.380 --> 10:58.700
It's not, but that's the way things are.

10:58.860 --> 11:04.480
So what we will learn is how you can actually create your own build system.

11:04.480 --> 11:06.800
Don't worry about noting down the commands.

11:06.800 --> 11:11.780
I'll make sure that these slides are available to you.

11:11.780 --> 11:13.220
So you can actually use them.

11:13.220 --> 11:16.820
I have simplified everything so that you don't run into errors.

11:16.960 --> 11:19.940
You can use them to build your own things.

11:19.940 --> 11:26.160
And for now, I have already created a build system that you guys can also use if you like to.

11:26.160 --> 11:29.960
You can go back, you can use it that time if that is the case.

11:31.060 --> 11:34.720
So first, for the simplest scenario, we go with Ubuntu.

11:34.720 --> 11:36.880
Because Ubuntu is the simplest.

11:36.980 --> 11:40.480
You do your apt-get and update and upgrade.

11:40.600 --> 11:41.640
Pretty standard.

11:42.400 --> 11:46.360
Then these are the dependencies that you have to install to build the system.

11:46.360 --> 11:51.000
The reason of explaining all of this is so that you can do it.

11:51.000 --> 11:51.860
It's a workshop.

11:51.860 --> 11:54.880
It's not the cutting-edge research talk that we give.

11:54.960 --> 11:57.220
That you are used to.

11:57.220 --> 12:01.000
But this is something that you can actually go back and do on your own.

12:01.840 --> 12:04.140
After that, you add a low-privileged user.

12:04.140 --> 12:07.760
Because otherwise it creates problems when you build some packages.

12:08.280 --> 12:10.080
You switch to its home repository.

12:10.500 --> 12:14.060
And as I said, OpenWrt is open source.

12:14.060 --> 12:15.480
So it is on GitHub.

12:15.480 --> 12:18.660
You can download the latest stable version.

12:18.740 --> 12:21.260
I will always recommend you to go for the stable version.

12:21.260 --> 12:22.600
Don't go for the trunk.

12:22.640 --> 12:25.160
Don't go for the branch that is under development.

12:25.160 --> 12:26.920
It has active bugs.

12:26.920 --> 12:28.160
It has build issues.

12:28.160 --> 12:30.580
So you know, most of the time you will be wasting your time.

12:30.600 --> 12:32.060
So go for the stable one.

12:32.080 --> 12:34.980
Current stable one is 18.06.4.

12:35.340 --> 12:37.500
The one I am using here is 0.2.

12:37.500 --> 12:38.440
Doesn't matter.

12:38.440 --> 12:39.880
Not that much of difference.

12:40.180 --> 12:41.140
First you take it.

12:41.140 --> 12:42.060
You unzip it.

12:42.060 --> 12:42.340
Why?

12:42.340 --> 12:43.660
Because you know, it's zipped.

12:43.660 --> 12:44.580
You have to.

12:44.580 --> 12:52.000
And then we use the makemenuconfig command to select the hardware that we want to build for it.

12:52.000 --> 12:52.560
Don't worry.

12:52.560 --> 12:53.600
These are just the steps.

12:53.600 --> 12:56.600
We are going to see how to do it in practical as well.

12:57.700 --> 13:01.920
You have to then update the feeds and install them.

13:01.920 --> 13:07.020
Feeds are nothing but the kind of software tools that you can add while you are building all of this.

13:07.540 --> 13:11.100
And I have a build ready setup here.

13:11.100 --> 13:12.740
So I will be using that.

13:12.740 --> 13:14.020
And the internet is back.

13:14.620 --> 13:16.060
That's a good thing.

13:16.260 --> 13:18.660
So this is the attack defense lab I was talking about.

13:18.660 --> 13:21.180
It's the community section of attack defense lab.

13:21.220 --> 13:26.940
So what I have done is, if you guys want to try it back home, you can actually go here.

13:26.940 --> 13:28.960
You can log in with your Google account.

13:28.960 --> 13:30.500
You don't need a paid subscription.

13:30.720 --> 13:32.680
Just go here, free labs.

13:33.300 --> 13:39.260
And here I have created a build system so that if you want to use it, if you want to try it out, you can.

13:40.280 --> 13:43.780
You choose the server which is nearest to you.

13:43.780 --> 13:45.540
Obviously for the latency reasons.

13:45.860 --> 13:47.140
You give it 25 seconds.

13:47.140 --> 13:51.300
In 25 seconds it will spin a dedicated thing for you.

13:51.400 --> 13:54.960
If you are doing it right now, you will get another thing.

13:54.960 --> 13:56.320
I will get another setup.

13:56.320 --> 13:57.720
So that's how it is.

13:58.260 --> 14:07.400
So if you want to do all of the setup at your place, what I have done is, I have put all the commands that we discussed here.

14:07.400 --> 14:12.120
So you can actually directly copy paste them and they will work.

14:12.120 --> 14:16.280
Because I have ran them like for 50-100 times I have used them.

14:16.280 --> 14:17.320
So they work.

14:18.160 --> 14:21.460
Once the lab is ready, you go inside the lab.

14:21.680 --> 14:24.280
So the lab is only to practice.

14:24.280 --> 14:28.080
If you really want to create your own, you have to do it on your own machine.

14:28.080 --> 14:31.040
Because for security reasons, our labs are contained.

14:31.040 --> 14:32.780
Nothing goes in, nothing comes out.

14:32.780 --> 14:33.840
It's like that.

14:34.940 --> 14:40.800
So now, what I have done here is, I have created...

14:41.600 --> 14:44.520
I have taken the code from GitHub.

14:45.140 --> 14:48.240
This is how the build system looks like.

14:48.500 --> 14:57.250
Now as I was telling you, we have to do a make-menu-config.

14:57.310 --> 15:02.210
So all the commands before it, they only tell you how to build this setup.

15:02.210 --> 15:09.330
Once the setup is ready, now we are focusing on the part where you select what you want to be in your firmware, what you don't want to be.

15:09.770 --> 15:11.510
You do make-menu-config.

15:11.510 --> 15:16.450
It will throw a small UI so that you can select stuff.

15:16.770 --> 15:18.050
As you can see here.

15:18.270 --> 15:23.150
First step, as you can observe, is to select the card that you have.

15:23.150 --> 15:26.450
The kind of card or the kind of architecture your machine supports.

15:26.590 --> 15:27.950
Very easy to guess.

15:28.090 --> 15:31.390
You can directly use your box to check for it.

15:31.390 --> 15:37.550
If you see QCA or Qualcomm Atheros, it means you are using Atheros of some kind.

15:37.550 --> 15:42.290
If you check the datasheet or the booksheet that comes with it, you will be able to find this number.

15:42.670 --> 15:45.230
So here I am using for this one.

15:45.810 --> 15:47.870
This is the sub-target one.

15:47.870 --> 15:50.530
If you don't know what you are doing, don't touch it.

15:50.530 --> 15:52.890
Generic will work for everything.

15:53.230 --> 15:54.610
No need to touch it.

15:54.870 --> 15:59.930
Target profile, here are the device profiles that are under that architecture.

15:59.930 --> 16:04.670
So from here, you can select the device that you want to build it for.

16:04.790 --> 16:06.990
So I am using AR750.

16:07.290 --> 16:09.390
It's a pretty thrifty device.

16:16.860 --> 16:18.320
This is the one.

16:18.320 --> 16:19.640
It's a travel router.

16:19.640 --> 16:21.260
Very cheap, $50.

16:21.260 --> 16:24.900
You can get it on Amazon or any other website.

16:25.020 --> 16:26.880
The delivery is throughout the world.

16:27.640 --> 16:30.200
So first, you do that.

16:30.200 --> 16:34.600
Now if you pay attention here, you will see multiple kind of things.

16:34.600 --> 16:40.000
If I go to the base system, all of these things are the packages.

16:40.200 --> 16:44.520
Now the second question is, how would you know which packages to install and which not to?

16:44.520 --> 16:49.260
So all of this documentation is available on openwrt.org.

16:49.480 --> 16:58.740
All the main things that you need for mounting the USB, mounting something else, like a SD card or something, you search for it.

16:58.780 --> 17:01.820
OpenWrt community is well backed by people.

17:01.820 --> 17:05.600
You will find a lot of documentation, more than that you can handle.

17:05.880 --> 17:10.900
So from here, what I'll suggest is, don't mess with the base system.

17:10.900 --> 17:16.720
Most of the things there, unless you know these are the kernel modules that you need, don't go there.

17:16.800 --> 17:19.980
Because the things that you need are here.

17:20.280 --> 17:31.960
So if we are talking about building your own attack gadget, If you go here, you will see Aircrack, Airmon, Host and what not.

17:32.140 --> 17:37.820
So this is how you actually select the things that you want to add.

17:37.820 --> 17:40.900
So right now, as you can see, Host is checked.

17:40.900 --> 17:47.160
This means it will be built as a part of the firmware when I build a firmware.

17:47.780 --> 17:51.560
You exit from it, again exit from it.

17:51.640 --> 17:54.880
Similarly, you have multiple options.

17:54.880 --> 17:58.260
So it is more than that I get cover even if it is a one day class.

18:00.480 --> 18:02.760
All you have to do is browse.

18:03.220 --> 18:10.700
Just browse for it, you select the package, all the dependencies will be automatically selected by the build system and it will build it for you.

18:11.220 --> 18:15.840
After that you do exit, you do exit and it will save the file.

18:16.140 --> 18:21.960
Sometimes when you make changes, it will show you a pop-up in which it will ask you if you want to save it or not.

18:21.960 --> 18:23.280
Obviously, save it.

18:23.280 --> 18:30.300
So all the changes that we just did went into this file.

18:30.460 --> 18:33.960
So you can observe that this is the chipset.

18:33.960 --> 18:43.920
If you go down, if you search for say Aircrack, you will see that all the packages that we have selected have Y in front of them.

18:43.920 --> 18:47.100
Y means they are selected, they will be built.

18:47.880 --> 18:50.900
After this, you don't have to do anything.

18:50.900 --> 18:55.020
Just do a make minus j 8.

18:55.020 --> 18:58.980
So minus j 8 is nothing but to run it in parallel.

18:58.980 --> 19:02.520
So it will be using 8 threads to compile it on parallel.

19:02.520 --> 19:04.500
Build systems are pretty heavy things.

19:04.500 --> 19:10.580
When you build them for the first time, you should have a powerful machine, otherwise it is going to take you hours.

19:10.840 --> 19:12.280
But that's the first run.

19:12.280 --> 19:16.080
Once you build all the basic things, the second run will be faster.

19:16.080 --> 19:22.780
So I won't do the whole thing here, because even after building it, this thing is going to take at least 10-15 minutes.

19:22.780 --> 19:25.800
Because the system that I am using is not that powerful.

19:25.920 --> 19:28.200
It is for the demo, right?

19:28.200 --> 19:30.740
It is not the main development machine that I use.

19:31.120 --> 19:39.260
So once you do that, now what you have to find is the firmware that is created.

19:39.540 --> 19:42.240
So in this case, I have already created it.

19:42.240 --> 19:47.720
But as soon as you run make minus j 8, it will be created for you.

19:48.000 --> 19:53.520
So the firmware images, they come with this extension called .bin, and that is it.

19:54.540 --> 20:02.680
And what I am doing is, I am also graphing for the name of the device, so that you know I don't get a lot of garbage.

20:03.300 --> 20:08.600
And this is the firmware that you can now download and flash your device with.

20:08.600 --> 20:16.160
Just make sure when you are flashing the firmware, the size of the firmware is not more than the memory that you have on your device.

20:16.160 --> 20:20.040
Because sometimes people, the first time they go crazy.

20:20.040 --> 20:22.680
They are like, I will put everything on the world in this.

20:22.760 --> 20:25.580
And then they build a big firmware, they are flashing it.

20:25.580 --> 20:31.520
Some of the devices are not smart enough to detect that you are building a bigger firmware for a smaller device.

20:31.520 --> 20:34.020
So when you will flash it, it will reject.

20:34.040 --> 20:35.160
It will not work.

20:35.160 --> 20:36.800
So don't blame me then.

20:36.800 --> 20:38.160
Check your size before.

20:39.120 --> 20:41.020
So this is how you do it.

20:41.680 --> 20:46.440
Now, coming to the main part that the talk is about.

20:46.800 --> 20:50.260
So, second thing that we want to build now.

20:50.280 --> 20:54.300
This is how you will be able to compile your own code.

20:54.300 --> 20:55.900
You can put it in the build system.

20:55.900 --> 20:58.460
There is a ton of documentation on it, how to do it.

20:58.460 --> 20:59.740
It is pretty easy.

20:59.780 --> 21:01.000
They have standard stuff.

21:01.000 --> 21:02.120
You have to put it here.

21:02.120 --> 21:03.740
Then you have to add a line here.

21:03.740 --> 21:08.120
All of 5-4 things you have to do and you will be able to build your own code.

21:08.720 --> 21:12.920
For all the available packages, you just need to select and you just need to run it.

21:13.380 --> 21:14.860
Now, coming to the third part.

21:14.860 --> 21:16.900
This is the user space we are talking, right?

21:16.900 --> 21:24.020
So now, bootkits or rootkits, when we are talking about them, we are more interested in the kernel-based rootkit.

21:27.260 --> 21:31.600
So, just to summarize, again, the same stuff.

21:31.740 --> 21:32.840
Selected it.

21:32.840 --> 21:37.080
You make a download directory when you are doing it on your system.

21:37.080 --> 21:39.000
Then you do a make-download.

21:39.000 --> 21:44.700
When you do a make-download, it will download all the packages that you have selected from the internet.

21:45.300 --> 21:48.820
And again, the last thing to do is make-jh.

21:49.540 --> 21:56.860
If you want to build only one package, instead of selecting it with space, you select it with m.

21:57.120 --> 22:00.040
So, m will make sure that it will be modularized.

22:00.040 --> 22:06.080
So, thing is, if you don't want to flash the complete device, you have option that you can create a package.

22:06.080 --> 22:11.300
You can take that package to your device and you can install that using opkg install package name.

22:11.300 --> 22:16.180
Just like you do for Ubuntu using your dpkg for debian packages.

22:16.520 --> 22:18.980
So, in that case, you just need to do this.

22:19.180 --> 22:20.960
It will appear as m.

22:20.980 --> 22:25.100
And then this is the command where you have to mention the name of the package.

22:25.100 --> 22:27.180
And only this package will be compiled.

22:27.180 --> 22:33.000
So, I am not doing that because we are running late on time.

22:33.000 --> 22:35.020
Now, why kernel modules?

22:35.260 --> 22:41.180
Kernel modules, because when you load them, they are inserted into kernel, they run in kernel.

22:41.280 --> 22:48.040
And due to that thing, they can access the kind of structure, the kind of memory that is there in the kernel side.

22:48.060 --> 22:51.020
So, no user process can actually do this.

22:51.020 --> 22:56.720
Even if it is privileged, it has to use a kernel module to make all of these changes.

22:56.720 --> 23:04.380
And that is what we are going to leverage to hide your processes, to make sure that you can see all the packets that the machine is sending.

23:04.520 --> 23:10.400
And even to make sure that you can create something which will be hidden from the user space.

23:10.400 --> 23:14.540
Even if you are running a demo or something on the user space, it will be hidden.

23:14.540 --> 23:18.140
It will be replying, it will be taking orders from other things.

23:18.480 --> 23:21.760
So , that's why the kernel modules are important here.

23:22.440 --> 23:26.160
Now, second question can be, can we directly insert kernel modules?

23:26.160 --> 23:31.140
On your Linux system, if you don't have root, no you cannot.

23:31.140 --> 23:39.660
But that's the problem, that's one of the problems that most of your SOHO routers, which are Linux based, when you login into them, they directly drop you into root.

23:39.820 --> 23:49.380
So, if anything, any malware, any worm, if it breaches my router which is running on OpenWrt or some other Linux, he is going to get the root.

23:49.380 --> 23:53.020
And he can then insert his kernel module inside.

23:53.020 --> 23:57.740
So, we have build system ready.

23:57.780 --> 24:04.660
After that, you need the kernel code, kernel module code that we have created here, just to show you.

24:05.380 --> 24:13.040
After that, you need to make sure that your kernel code, when you are compiling it, can link to the build system.

24:13.040 --> 24:17.160
Because build system is the one that you will be using to do all of this.

24:17.860 --> 24:21.000
You have to make sure that everything is in the path.

24:21.000 --> 24:25.360
All of these are just steps, you just need to file these commands on the build system.

24:26.160 --> 24:34.680
And just to make sure that I don't type a big command to make it, I will just create an alias, which will pass the MIPS architecture.

24:34.680 --> 24:37.020
Because this thing here, it runs on MIPS.

24:37.200 --> 24:41.560
Almost all of your, these devices, small devices, they run on ARM, MIPS.

24:41.640 --> 24:47.940
You won't find a lot of these specially built things running on x86 or x86x64.

24:47.940 --> 24:51.000
So, for that reason, you have to cost compile it.

24:51.000 --> 24:54.580
Cost compile sounds difficult, but it is not.

24:54.580 --> 24:58.720
It's just one word that you have to define if you know what the word is.

24:59.360 --> 25:02.600
So, once you do that, you are ready.

25:02.980 --> 25:09.400
Once you have the kernel module, you can insert it using insmod, that's the command to insert it.

25:09.480 --> 25:15.420
lsmod is used to list it, and rmmod is used to remove the kernel module once you are done.

25:15.420 --> 25:23.140
So, what we will do now, is we will see a hello world module, which we have written just for this class.

25:23.640 --> 25:25.220
So, this is how it looks.

25:25.680 --> 25:30.840
You know, if you are familiar with C language, these are the header files that we use.

25:31.860 --> 25:42.220
These are important here, because your module in it defines the function, which will be executed as soon as your kernel module loads in.

25:42.220 --> 25:48.480
Similarly, you can also define a function, which will run when you take it out.

25:48.480 --> 25:50.980
So, these are the basic things.

25:50.980 --> 25:57.460
And even this knowledge is more than enough to create something, which can do pretty nasty stuff.

25:58.200 --> 26:01.580
This is the example here, because obviously it's a hello world.

26:01.580 --> 26:04.240
It will just print kernel logs.

26:04.760 --> 26:07.080
So, here we have two functions.

26:07.080 --> 26:13.420
First one here is the init function, which will be called when we insert it.

26:13.600 --> 26:18.240
It will just print, you know, hello cruel world of kernel programming to the kernel logs.

26:18.240 --> 26:20.200
Just to make sure, it's a POC, right?

26:20.200 --> 26:24.540
If it works, you can go forward, you can go for the more powerful code.

26:25.040 --> 26:28.320
Similarly, this one will run when you exit it.

26:29.040 --> 26:31.760
So, let's do one thing.

26:32.180 --> 26:33.940
Let's see all of that.

26:33.940 --> 26:39.020
So, in the rootkit code, you will find two folders.

26:39.300 --> 26:42.780
For now, you can just ignore the kernel space program.

26:42.780 --> 26:44.540
You go into kernel fun.

26:44.640 --> 26:46.260
You go into hello world.

26:46.840 --> 26:50.560
So, if you do ls-l, it will show you two files.

26:51.000 --> 26:53.140
Let's first check the hello world.c.

26:53.240 --> 26:55.340
It's the same file that we just saw.

26:55.340 --> 26:57.420
It has two simple functions.

26:57.820 --> 27:00.140
And these are the declarations.

27:00.280 --> 27:03.640
So, the code is written by my boss, you know, for this thing.

27:03.640 --> 27:04.960
His name is Vivek.

27:05.340 --> 27:07.280
That's why the name is Vivek.

27:07.280 --> 27:09.320
I'm not stealing code from third party.

27:09.480 --> 27:11.020
Just so that you know.

27:12.780 --> 27:17.720
And then, to compile these files, you use makefile.

27:17.900 --> 27:26.500
Makefile is nothing but it is a way by which the programmers make things easier to compile when you are dealing with a lot of source code.

27:26.500 --> 27:29.680
So, this is the simplest possible makefile one can make.

27:29.680 --> 27:42.540
And because all of other things are already there, and we have this ls set, we have to just do nips make, and it will automatically link everything.

27:47.630 --> 27:50.750
Okay, so it actually ran into some error.

27:52.830 --> 27:54.450
Pretty strange.

28:03.520 --> 28:05.640
Must be missing some link.

28:05.960 --> 28:10.240
So, in a normal scenario, because you know, the demo gods, right?

28:10.240 --> 28:11.800
It was working in the morning.

28:12.140 --> 28:15.840
That's why I put it inside the machine.

28:16.480 --> 28:22.340
So, the thing is, on running nips make, it should run, if all the links are correct.

28:22.340 --> 28:26.240
So, you have to make these four links, as I was showing you here.

28:26.240 --> 28:28.760
One of these links are currently not working.

28:28.860 --> 28:33.940
So, you export staging directory, the path, and the kernel root.

28:33.940 --> 28:39.860
If one of these is messed up, then, you know, it will fail, just like it is failing right now.

28:39.860 --> 28:45.880
You have to make sure that, you know, the kernel that you are targeting, you are only running it on the same kernel.

28:45.900 --> 28:50.900
You cannot compile it for 4.9.152 and run it on something else.

28:50.900 --> 28:51.980
It won't work.

28:51.980 --> 28:54.020
That is one of the things that you have to do.

28:54.140 --> 28:55.360
You have to make sure.

28:55.360 --> 29:04.840
But if you are compiling a firmware, you are installing the same firmware on the device, whatever you compile here, it will directly work on the box, out of the box.

29:04.840 --> 29:14.160
So, what we will do now is, I have compiled these already, because, you know, I had to show you how they run.

29:14.300 --> 29:23.080
And instead of using, you know, your own machines, because for them, the kernel will be different, so even if you download them and you try to run it, it won't run.

29:23.120 --> 29:28.620
So, what we have done here is, we have emulated an openability system inside the lab.

29:29.420 --> 29:35.960
So, in this, you know, it will behave just like this device, apart from the Wi-Fi thing, because obviously, no physical antennas.

29:37.140 --> 29:43.540
For all other practical reasons, it is MIPS, it is behaving like a complete Linux system.

29:44.660 --> 29:56.700
So, again, after 25 seconds, it will give me a console on which I will be able to see all the kernel modules that I have compiled, and I can directly interact with them, I can see what they do.

29:57.280 --> 30:03.160
Once we do the Hello World, then we will move to the more advanced ones, which are of interest.

30:03.160 --> 30:08.120
Hello World, we all know, is just the POC, right?

30:08.120 --> 30:19.700
So, this one is the router, the same firmware, but this one has the kernel different one, that's why I had to compile it again.

30:20.100 --> 30:24.240
This one uses 4.9.53, I think.

30:24.700 --> 30:26.060
That one is different.

30:27.000 --> 30:32.380
So, as soon as you press this, it will boot just like the device.

30:33.760 --> 30:46.600
And if I go to the root directory, kernel modules, I have already compiled these kernel modules and kept here, just so that, you know, demo gods do this to me.

30:47.160 --> 30:55.900
Now, before inserting it, you can use lsmod to check what are all the kernel modules already there.

30:56.400 --> 31:07.960
Now, if you do nsmod, for the Hello World kernel module, you will observe that this is the kernel log that is being printed.

31:08.180 --> 31:12.880
It is coming on console because, you know, as of now, we haven't set the debugging level.

31:13.060 --> 31:18.300
So, if I do n-1, it will not come anymore.

31:18.460 --> 31:24.460
We will be able to see it using dmessage, which shows the kernel messages, right?

31:25.740 --> 31:27.740
So, this is the POC thing, right?

31:27.740 --> 31:35.020
Now, if I want to check if it was inserted, I will just do lsmod and I will grab for the Hello World.

31:35.880 --> 31:37.080
And there it is.

31:37.080 --> 31:41.040
I can again remove it using the Hello World.

31:42.100 --> 31:48.580
And if I do dmessage, it will also show that it existed, right?

31:48.580 --> 31:54.960
So, that's the basic POC code that we do for, you know, whenever you start programming, this is the first thing that you learn.

31:55.720 --> 31:59.680
Now, coming to something, you know, which looks like hackish, right?

31:59.680 --> 32:01.660
Which looks like something of use.

32:02.060 --> 32:04.660
So, suppose you are running something in the user space, right?

32:04.660 --> 32:13.500
You are running your own backdoor or you are running something which you don't want the user to notice even when it is coming in the PS output, right?

32:13.540 --> 32:14.260
So, what do you do?

32:14.260 --> 32:15.540
You change the name of that.

32:15.540 --> 32:23.800
If you change the name of that, if you make it look something official, most of the users, or almost everyone, is not going to suspect on it.

32:23.800 --> 32:31.680
They will just assume that it is one of the system things that run on Linux and that is beyond my understanding, right?

32:31.680 --> 32:32.860
That's what we do.

32:33.260 --> 32:35.540
So, let's do that.

32:36.660 --> 32:41.740
So, if I do PS here, I should be able to see all of these, right?

32:42.020 --> 32:43.520
So, let's do one thing.

32:43.520 --> 32:53.900
Just to make sure that you are able to understand the effect, the change, what we have done is, the kernel module, it does not change the name but it appends something to the name.

32:53.900 --> 33:03.440
It's the same thing, if we can append something to the name, we can always, you know, go and completely wipe it out and use the name that is there.

33:03.780 --> 33:17.200
So, in this one, I have to do ins mod and then, after that, I have to, you know, so, you know, it is a big command so I have actually written it here.

33:22.900 --> 33:26.120
Change mod is the kernel module here.

33:27.480 --> 33:32.980
In the PID, we have to provide the PID of the process for which we want to change the name.

33:33.340 --> 33:37.920
So, for example, this one here is a server daemon.

33:37.920 --> 33:39.660
So, let's do it for this.

33:39.820 --> 33:43.160
It's 2110.

33:46.280 --> 33:47.960
You do this.

33:48.340 --> 33:52.540
You do PS and there you go.

33:53.320 --> 33:54.080
Right?

33:54.120 --> 33:57.180
So, here we appended it so that we can find it easily.

33:57.180 --> 33:58.560
You can see it visually.

33:58.680 --> 34:00.860
We can also change it completely.

34:00.860 --> 34:03.000
We can make it look like something like this.

34:03.000 --> 34:03.600
Right?

34:03.600 --> 34:04.920
Something gibberish.

34:05.300 --> 34:08.740
That, you know, that the user will not be able to make sense out of.

34:08.740 --> 34:11.140
So, that's the first kind of thing that you can do.

34:12.160 --> 34:26.240
If we talk about another thing, one more thing that we can do is we can use NetFlipter hooks through our kernel module to make sure that we can monitor all the packets that are sent by the machine or that are coming to machine.

34:26.320 --> 34:37.460
So, for that, we will be using NetFlipter hook NFIP local out which will correspond to all the packets that this machine is generating and sending out.

34:38.600 --> 34:43.160
So, here is a quick description of NetFlipter architecture.

34:43.160 --> 34:46.280
It has multiple points where you can put hooks.

34:46.280 --> 34:48.300
These are also called hooks.

34:48.680 --> 35:01.560
So, you can see, when the packet comes in, it's checked if it is coming for this machine it will be sent here that's the 2, denoted by 2 that's the in hook, because it is coming to the machine.

35:01.740 --> 35:07.260
Similarly, if machine generates the packets it goes out from here and it hits the point 5.

35:07.480 --> 35:13.780
Point 5 is the NFIP local out, which is the packet generated by the machine.

35:13.900 --> 35:25.120
So, suppose even from the defendant's perspective if you want to see what kind of packets your machine is sending So, this kind of module can actually help to do that.

35:25.460 --> 35:53.120
So, let's go back and let's do a quick ls-l So, the one that we are talking about is the network funnel object just do it nsmod network.co and you are good to go if you do demessage, in this case you won't be able to see anything here because for specific reasons,

35:53.120 --> 35:55.520
for this one, we haven't put any logs.

35:55.520 --> 36:07.720
If you don't put the logs, you won't see anything here I'm just showing this so that for the last kernel modules, you were seeing logs, so you can always come back and say that, you know, hey, whatever you are doing there are logs.

36:07.960 --> 36:10.960
So, because you can observe here, there are no logs, right?

36:10.960 --> 36:50.080
Now, suppose if someone from this machine starts to dial out using netcat so, you know, random IP anyway, it won't connect because the lab is completely boxed in so, let's see what happens it's doing something now, if we do demessage what you will find here is the hook was executed and it is showing you all the packets UDP packets that were going out also some of the TCV packets here right?

36:50.470 --> 37:13.520
so, this is how you can actually monitor something like this now, the third demo that I have for this one is a network stack backdoor so , suppose, you have a virus you have two parts of the virus first part is the one which executes commands on the system that's the execution stub or execution stub,

37:13.520 --> 37:14.160
right?

37:14.160 --> 37:34.560
the other part is the one which maintains that it is hidden it does not have to open any socket to listen because when we talk about it normally if you want to receive a packet from some other process if you want to get commands from a remote machine you have to open a socket you have to make sure that the guy,

37:34.560 --> 37:40.180
whoever is issuing the command is sending those commands to your socket, right?

37:40.180 --> 37:58.440
but if you open a socket it will be listed when you do netstat so, you don't want that you want something which can intercept packets directly in the kernel level it can parse them and it can execute commands from there so, the execution stub is not implemented here but

38:02.050 --> 38:28.830
but the other stub is which actually looks into the kernel part so, what I will do is, I will connect this guy because we want a packet coming from other machine which our lab won't be able to do so, I will just plug it in plugging in the power this guy is so small that you can actually power it using the USB itself so,

38:28.830 --> 38:29.970
you plug it in

38:33.710 --> 38:57.830
you plug in this thing into Ethernet so that this can communicate and after that you wait so, this is what is going to happen now we are going to insert the cover.co module on the one side and then we are going to use nping on the host machine to send specific packets so,

38:57.830 --> 39:17.150
now, if we talk about the code of this, the specific packets that we are talking about, the code is written in such a manner that this thing will see all the packets that are coming to this machine but it will only pass those packets which will have source and destination port as 9999 so,

39:17.150 --> 39:34.290
that's the signature that we are creating here so, main thing here to notice is we are not opening any socket but still, we are able to monitor a specific packet which will contain command for us so, for example, when we send something like this here it contains the command here,

39:34.290 --> 39:54.070
right, the cat, it is a shadow just to see the contents of the shadow file and when you will do demessage, you will find something like this so, this one actually intercepted it it got the command, now this command can be passed to the user level thing that is running there and that can get your stuff right,

39:54.070 --> 39:54.550
so

39:59.230 --> 40:40.150
this should be online and now if you don't like SSH you can always use something called TTYD, it will drop you right into the box, this box so, now let's see the IP address it's already know, right it's 10.1 it's 10.1, so I can see the module here I do insmod cohort it's inserted and now if I open this PowerShell and fire this command here nping commands come as a part of nmap,

40:40.150 --> 40:59.610
so if you don't have nmap installed, you won't have this one, here what I am defining is, we have to, we need to set the TCP flags as SYN and REST and the port needs to be 9999 for the source as well as for the destination so this is nothing but this is the signature that we have,

40:59.610 --> 41:15.450
we don't want it to listen to any packet and do, you know, whatever it is doing, we want it to be specific that's why the flags as well as the port combo will make it so unique, that it will only hear whatever we will send it, right, so now, you can observe right,

41:15.450 --> 41:32.850
I am not running anything on the user side, I am not running any socket, that's the main part here there is no socket, most of the people when they check for the backdoor they do a netstat, what is listening right, now this thing will not appear, because it is not opening any socket it's just scanning the packets,

41:32.850 --> 41:50.450
right and that's the concept behind this this is only one example, you can actually make sure that, you know, the process is hidden, you can make sure that process cannot be killed by the user space kill-9, you can do all of that, but you know, because of the time limits that we have,

41:50.450 --> 42:12.550
this is all we are going to cover so it has sent the packet now if you go here you do demessage you will find something like this here so this is the part which is undetectable it will write it somewhere, it will pass it using a channel or a hook to the user space if something is running there,

42:12.550 --> 42:29.910
or you can you know, you can actually add code here itself to run these commands you can intercept all the syscalls you can see which command or which system or which programmer or program is making the syscalls, you can intercept them, if you want, you can actually block them too,

42:29.910 --> 42:55.940
so that's the power of current level toolkits or rootkits that, you know, most of the people don't talk about or don't understand when they talk about WiFi security in the routers context so all of this is there I can show you code as well if you like let me grab the LAN again but again,

42:55.940 --> 43:19.660
the router level code is not the simplest thing that you can see, the main point of showing this thing in workshop is to tell you that these are the possibilities, even when you are not able to see program in PS or if you are not able to see it in netstat it can still be there it can still listen for the commands it can still reply it can still do DOS,

43:19.660 --> 43:48.040
it can still make sure that anyone or the hacker who has this backdoor can actually get into your system anytime as he likes so that's the main getaway that we are talking about here but still if you like to see the code just a quick code walkthrough kernel pun let's talk about a simple one first let's talk about the prepend process name

43:52.620 --> 44:22.900
you open the file here, just like your hello world we are registering two functions we are taking some arguments because we want to take the PID from the user, we want to take the new name of the process from the user so that's why these things are here and when you go up here what you will find here is so it's very important to understand that all the processes,

44:22.900 --> 44:40.520
they are stored as a task structure in kernel so what we are doing here is we are going over all of the processes that are running, we are matching the PID because that is the identifier that we have and as soon as it is matched, we are overwriting the name of the command,

44:40.520 --> 44:51.240
or we are not overwriting here we are just adding it in the front to the structure that is there so that's all you cannot do this thing from user mode why?

44:51.240 --> 45:07.380
because the thing, the structure, the memory that we are playing with right now it is in kernel and there are boundaries, you cannot breach them without using something like a zero-day exploit or something similarly, if we talk about the covert network thing

45:12.380 --> 45:35.720
this one is a little bit more complex because obviously it is doing the complex thing but let's do a walkthrough so what it is doing here is it is registering its hook with the netfilter because you have to do that because if you don't do that, netfilter is not going to pass the packets to you once that is done this is the definition,

45:35.720 --> 45:57.760
this is the hook that we are using this one stands for incoming packets as we just discussed we are only doing it for IPv4 and the priority is last so our hook will execute in the end no need to worry, still it is going to get all the packets so now if you go here what it will do,

45:57.760 --> 46:23.880
it will look for specific packet which has this specific port which we have defined and it will also check for the TCP header flags because ports can be replicated by other people also right, it can be the thing that for some reason, some process is using 9999 and now those packets will start intercepting like our channel right,

46:23.880 --> 46:43.920
it should not happen so that's why we have made it more complex, once that is there this is the code that you saw printed so all of these things are being printed you can then pass this command to some other module that you have or to some other function that you have here right,

46:43.920 --> 47:17.620
so it's that simple, that easy, once you know what to do going back similarly, now you know, the second logical question is, this is how we do it for the vendors, this is how we do it for the OpenWrt, but not everyone runs OpenWrt so how we can compile it for the vendor firmware and that's a great question so most of the time what you have to find for this is the code for the vendor firmware now you will say that the vendors they don't give their code out that's partially correct some of vendors has to,

47:17.620 --> 47:34.820
because they are using GPL, and by the license terms of GPL, they have to give out all the modifications that they make, you find it and then you use the same way you create their own build system, you use their kernel you use their cost compiler to compile everything,

47:34.820 --> 48:03.040
and then in this way you can compile it for them so all of this research was done when we were creating this course for our customers and all of the details if you want to go extended into it, it is available there you can go and learn this is the only thing that was possible to be covered in one hour but for all the other details you can always refer to the course if you like again,

48:03.040 --> 48:16.880
community labs if you want to try this out, whatever we have done I'll make sure that the PPT is available with the wireless village so that you guys can download, you guys can see all the commands or you can directly go and do them here.

48:17.160 --> 48:25.380
So that's all if you have any questions, I'll be taking those or if you come with some questions after the talk or the workshop, you can always mail me on this.

48:25.380 --> 48:25.880
Thank you

