[00:00.000 --> 00:04.880] Hey everybody! 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:15.100] Everyone not sitting down, that's where your chairs are. There's lots of them. [00:15.100 --> 00:18.420] Please come in and sit down. 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:26.000] How long did I actually give you? I said 15 minutes? [00:26.000 --> 00:31.660] 12. 12 minutes. He's got 12 minutes and he's going to go over how to build a rootkit on OpenWorks. [00:31.660 --> 00:33.840] It's going to be amazing. 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:52.220] But seriously, everybody sit down. 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:51.820] Have you guys heard of it? Just show of hands. [01:52.060 --> 01:55.320] Oh, nice. 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:12.080] This is the PentesterAcademy.com. It's an online library. [03:12.080 --> 03:17.500] This is the AttackDefense.com. 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:07.640] Oh, that's good. 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:55.380] That's the main takeaway. 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:36.340] How good? Again, debatable. [05:36.340 --> 05:40.960] But still, when we talk about the SOHO routers, right, as we like to call them, [05:40.960 --> 05:43.740] 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:08.860] And they're running, and you know, you're just happy that you have a good password on WPA2, PSK, [06:08.860 --> 06:10.620] 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:10.680] They can do passive analysis there. They can do active MIPM there. [07:11.100 --> 07:18.880] And on top of that, for a few years, for a few past years, we have seen occurrences where botnets were there, [07:18.880 --> 07:24.520] 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:32.040] It's your infra, right? 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:41.020] We have already discussed, you know, worms. 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 --> 08:00.000] You don't even know if you get hacked, right? 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:31.000] A special case of rootkits is bootkits. 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:53.580] Why? 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:54.880] It's a workshop. 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:39.880] Doesn't matter. Not that much of difference. [12:40.180 --> 12:42.060] First you take it. You unzip it. [12:42.060 --> 12:43.660] Why? 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:53.600] Don't worry. 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:25.880] So if we are talking about building your own attack gadget, [17:25.880 --> 17:31.960] 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:23.240] Makefile is nothing but it is a way by which the programmers make things easier to compile [27:23.240 --> 27:26.500] 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:33.520] And because all of other things are already there, [27:33.520 --> 27:36.040] and we have this ls set, [27:36.040 --> 27:39.580] we have to just do nips make, [27:39.580 --> 27:42.540] 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:08.600] So, in a normal scenario, [28:08.600 --> 28:10.240] 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:20.820] So, the thing is, on running nips make, it should run, [28:20.820 --> 28:22.340] 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:37.160] If one of these is messed up, then, you know, [28:37.160 --> 28:39.860] it will fail, just like it is failing right now. [28:39.860 --> 28:43.040] You have to make sure that, you know, the kernel that you are targeting, [28:43.040 --> 28:45.880] 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 --> 28:58.000] But if you are compiling a firmware, [28:58.000 --> 29:00.460] you are installing the same firmware on the device, [29:00.460 --> 29:01.940] whatever you compile here, [29:01.940 --> 29:04.840] it will directly work on the box, out of the box. [29:04.840 --> 29:08.180] So, what we will do now is, [29:08.180 --> 29:09.740] I have compiled these already, [29:09.740 --> 29:14.160] because, you know, I had to show you how they run. [29:14.300 --> 29:16.880] And instead of using, you know, your own machines, [29:16.880 --> 29:19.780] because for them, the kernel will be different, [29:19.780 --> 29:23.080] so even if you download them and you try to run it, it won't run. [29:23.120 --> 29:24.740] So, what we have done here is, [29:24.740 --> 29:28.620] we have emulated an openability system inside the lab. [29:29.420 --> 29:32.420] So, in this, you know, it will behave just like this device, [29:32.420 --> 29:33.760] apart from the Wi-Fi thing, [29:33.760 --> 29:35.960] because obviously, no physical antennas. [29:37.140 --> 29:40.500] For all other practical reasons, it is MIPS, [29:40.500 --> 29:43.540] it is behaving like a complete Linux system. [29:44.660 --> 29:47.300] So, again, after 25 seconds, [29:47.300 --> 29:50.400] it will give me a console on which I will be able to see [29:50.400 --> 29:53.400] all the kernel modules that I have compiled, [29:53.400 --> 29:55.200] and I can directly interact with them, [29:55.200 --> 29:56.700] I can see what they do. [29:57.280 --> 29:58.960] Once we do the Hello World, [29:58.960 --> 30:01.340] then we will move to the more advanced ones, [30:01.340 --> 30:03.160] which are of interest. [30:03.160 --> 30:08.120] Hello World, we all know, is just the POC, right? [30:08.120 --> 30:13.100] So, this one is the router, [30:13.100 --> 30:17.600] the same firmware, but this one has the kernel different one, [30:17.600 --> 30:19.700] 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:29.900] So, as soon as you press this, [30:29.900 --> 30:32.380] it will boot just like the device. [30:33.760 --> 30:36.980] And if I go to the root directory, [30:36.980 --> 30:39.000] kernel modules, [30:39.000 --> 30:42.640] I have already compiled these kernel modules and kept here, [30:42.640 --> 30:46.600] just so that, you know, demo gods do this to me. [30:47.160 --> 30:50.500] Now, before inserting it, [30:50.500 --> 30:52.080] you can use lsmod to check [30:52.080 --> 30:55.900] what are all the kernel modules already there. [30:56.400 --> 30:58.820] Now, if you do nsmod, [30:58.820 --> 31:00.560] for the Hello World kernel module, [31:01.320 --> 31:04.120] you will observe that this is [31:04.770 --> 31:07.960] the kernel log that is being printed. [31:08.180 --> 31:10.900] It is coming on console because, you know, as of now, [31:10.900 --> 31:12.880] we haven't set the debugging level. [31:13.060 --> 31:15.840] So, if I do n-1, [31:15.840 --> 31:18.300] it will not come anymore. [31:18.460 --> 31:21.600] We will be able to see it using dmessage, [31:21.600 --> 31:24.460] which shows the kernel messages, right? [31:25.740 --> 31:27.740] So, this is the POC thing, right? [31:27.740 --> 31:30.740] Now, if I want to check if it was inserted, [31:31.340 --> 31:35.020] 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:38.780] I can again remove it [31:39.480 --> 31:41.040] using the Hello World. [31:42.100 --> 31:44.240] And if I do dmessage, [31:44.240 --> 31:45.640] it will also show [31:46.160 --> 31:48.580] that it existed, right? [31:48.580 --> 31:52.080] So, that's the basic POC code that we do for, you know, [31:52.080 --> 31:54.960] whenever you start programming, this is the first thing that you learn. [31:55.720 --> 31:57.960] Now, coming to something, you know, [31:57.960 --> 31:59.680] 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:07.020] You are running your own backdoor [32:07.020 --> 32:08.000] or you are running something [32:08.000 --> 32:10.740] which you don't want the user to notice [32:10.740 --> 32:13.500] even when it is coming in the PS output, right? [32:13.540 --> 32:15.540] So, what do you do? You change the name of that. [32:15.540 --> 32:16.760] If you change the name of that, [32:16.760 --> 32:19.440] if you make it look something official, [32:19.440 --> 32:21.840] most of the users, or almost everyone, [32:21.840 --> 32:23.800] is not going to suspect on it. [32:23.800 --> 32:26.800] They will just assume that it is one of the system things [32:27.520 --> 32:28.640] that run on Linux [32:28.640 --> 32:31.680] 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:38.340] So, if I do PS here, [32:38.920 --> 32:41.740] 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:46.240] Just to make sure that you are able to understand [32:46.240 --> 32:48.220] the effect, the change, [32:48.220 --> 32:50.600] what we have done is, the kernel module, [32:50.600 --> 32:52.020] it does not change the name [32:52.020 --> 32:53.900] but it appends something to the name. [32:53.900 --> 32:56.780] It's the same thing, if we can append something to the name, [32:56.780 --> 32:58.580] we can always, you know, [32:58.580 --> 33:00.320] go and completely wipe it out [33:00.320 --> 33:03.440] and use the name that is there. [33:03.780 --> 33:05.400] So, in this one, [33:05.400 --> 33:06.980] I have to do ins mod [33:09.080 --> 33:12.160] and then, after that, [33:12.160 --> 33:13.800] I have to, you know, [33:13.800 --> 33:15.460] so, you know, it is a big command [33:15.460 --> 33:17.200] so I have actually written it here. [33:22.900 --> 33:23.820] Change mod [33:24.290 --> 33:26.120] is the kernel module here. [33:27.480 --> 33:28.820] In the PID, [33:28.820 --> 33:30.920] we have to provide the PID of the process [33:30.920 --> 33:32.980] for which we want to change the name. [33:33.340 --> 33:34.800] So, for example, [33:34.800 --> 33:35.680] this one here [33:36.310 --> 33:37.920] 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:49.440] You do PS [33:49.440 --> 33:52.540] 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:04.920] Right? Something gibberish. [34:05.300 --> 34:06.300] That, you know, [34:06.300 --> 34:08.740] 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:14.220] If we talk about another thing, [34:14.220 --> 34:16.060] one more thing that we can do is [34:16.060 --> 34:17.900] we can use NetFlipter hooks [34:17.900 --> 34:19.460] through our kernel module [34:19.460 --> 34:21.780] to make sure that we can monitor [34:21.780 --> 34:24.080] all the packets that are sent by the machine [34:24.080 --> 34:26.240] or that are coming to machine. [34:26.320 --> 34:28.220] So, for that, we will be using [34:28.220 --> 34:29.240] NetFlipter hook [34:29.860 --> 34:31.180] NFIP local out [34:31.800 --> 34:33.880] which will correspond to all the [34:33.880 --> 34:36.000] packets that this machine is generating [34:36.000 --> 34:37.460] and sending out. [34:38.600 --> 34:39.940] So, here is a quick [34:40.700 --> 34:41.780] description of [34:41.780 --> 34:43.160] 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 --> 34:50.340] So, you can see, when the packet comes [34:50.340 --> 34:52.000] in, it's checked [34:52.000 --> 34:53.820] if it is coming for this machine [34:54.600 --> 34:55.920] it will be sent here [34:55.920 --> 34:58.080] that's the 2, denoted by 2 [34:58.080 --> 35:00.180] that's the in hook, because it is [35:00.180 --> 35:02.460] coming to the machine. Similarly, [35:02.460 --> 35:03.740] if machine generates the packets [35:04.280 --> 35:06.020] it goes out from here and it [35:06.020 --> 35:08.380] hits the point 5. Point 5 [35:08.380 --> 35:10.040] is the NFIP [35:10.040 --> 35:12.100] local out, which is the packet [35:12.100 --> 35:14.440] generated by the machine. So, suppose [35:14.440 --> 35:16.660] even from the defendant's perspective [35:16.660 --> 35:18.500] if you want to see what kind of [35:18.500 --> 35:20.540] packets your machine is sending [35:20.540 --> 35:22.240] So, this kind of [35:22.240 --> 35:25.120] module can actually help to do that. [35:25.460 --> 35:26.560] So, let's go back [35:27.420 --> 35:27.980] and [35:27.980 --> 35:30.580] let's do a quick ls-l [35:31.300 --> 35:32.540] So, the one that we are [35:32.540 --> 35:33.800] talking about is the [35:34.380 --> 35:36.800] network funnel object [35:37.440 --> 35:38.440] just do it [35:39.060 --> 35:39.620] nsmod [35:41.220 --> 35:42.340] network.co [35:42.340 --> 35:44.940] and you are good to go [35:44.940 --> 35:46.220] if you do [35:46.220 --> 35:48.280] demessage, in this case [35:48.280 --> 35:50.400] you won't be able to see anything here [35:50.400 --> 35:52.400] because for specific [35:52.400 --> 35:54.520] reasons, for this one, we haven't [35:54.520 --> 35:56.480] put any logs. If you don't put [35:56.480 --> 35:58.340] the logs, you won't see anything here [35:58.340 --> 36:00.200] I'm just showing this so that [36:00.200 --> 36:02.360] for the last kernel modules, you were seeing [36:02.360 --> 36:04.460] logs, so you can always come back and say [36:04.460 --> 36:06.260] that, you know, hey, whatever you are doing [36:06.260 --> 36:08.440] there are logs. So, because [36:08.440 --> 36:10.960] you can observe here, there are no logs, right? [36:10.960 --> 36:12.540] Now, suppose [36:12.540 --> 36:15.140] if someone from this [36:15.140 --> 36:17.080] machine starts to [36:17.080 --> 36:19.100] dial out using netcat [36:19.100 --> 36:21.000] so, you know, random IP [36:21.720 --> 36:23.000] anyway, it won't connect [36:23.000 --> 36:24.600] because the lab is completely [36:24.600 --> 36:25.740] boxed in [36:26.740 --> 36:29.140] so, let's see what happens [36:30.100 --> 36:30.940] it's doing [36:30.940 --> 36:31.420] something [36:33.180 --> 36:35.020] now, if we do demessage [36:35.720 --> 36:36.940] what you will find [36:36.940 --> 36:38.720] here is the hook [36:38.720 --> 36:39.860] was executed [36:40.590 --> 36:42.660] and it is showing you all the packets [36:42.660 --> 36:44.740] UDP packets that [36:44.740 --> 36:45.520] were going out [36:46.450 --> 36:48.180] also some of the TCV packets here [36:49.020 --> 36:50.080] right? [36:50.470 --> 36:52.780] so, this is how you can actually [36:52.780 --> 36:54.300] monitor something like this [36:54.300 --> 36:57.000] now, the third demo that I have [36:57.980 --> 36:59.160] for this one [36:59.160 --> 37:01.040] is a [37:01.040 --> 37:02.420] network stack backdoor [37:02.420 --> 37:04.880] so, suppose, you have a virus [37:04.880 --> 37:06.500] you have two parts of the virus [37:06.500 --> 37:08.220] first part is the one [37:08.220 --> 37:10.300] which executes commands on the system [37:10.300 --> 37:11.640] that's the execution stub [37:12.260 --> 37:14.160] or execution stub, right? [37:14.160 --> 37:16.140] the other part is the one which maintains [37:16.140 --> 37:17.680] that it is hidden [37:17.680 --> 37:20.120] it does not have to open any socket [37:20.120 --> 37:20.640] to listen [37:20.640 --> 37:23.380] because when we talk about it normally [37:23.380 --> 37:26.560] if you want to receive a packet from some other process [37:26.560 --> 37:28.320] if you want to get commands [37:28.320 --> 37:30.760] from a remote machine [37:30.760 --> 37:32.360] you have to open a socket [37:32.360 --> 37:33.640] you have to make sure that [37:33.640 --> 37:36.100] the guy, whoever is issuing the command [37:36.100 --> 37:37.980] is sending those commands [37:37.980 --> 37:40.180] to your socket, right? [37:40.180 --> 37:41.380] but if you open a socket [37:41.380 --> 37:43.860] it will be listed when you do netstat [37:43.860 --> 37:45.660] so, you don't want that [37:45.660 --> 37:47.720] you want something which can intercept [37:47.720 --> 37:49.920] packets directly in the kernel level [37:49.920 --> 37:51.320] it can parse them [37:51.320 --> 37:53.320] and it can execute commands from there [37:53.320 --> 37:55.660] so, the execution stub [37:55.660 --> 37:57.600] is not implemented here [37:57.600 --> 37:58.440] but [38:02.050 --> 38:03.710] but the other stub is [38:03.710 --> 38:05.530] which actually looks into [38:05.530 --> 38:06.550] the kernel part [38:06.550 --> 38:09.650] so, what I will do is, I will connect this guy [38:10.610 --> 38:11.130] because [38:11.710 --> 38:13.890] we want a packet coming from other machine [38:13.890 --> 38:16.030] which our lab [38:16.030 --> 38:16.890] won't be able to do [38:18.290 --> 38:19.850] so, I will just plug it in [38:21.970 --> 38:23.030] plugging in the power [38:23.710 --> 38:25.630] this guy is so small that you can [38:25.630 --> 38:27.910] actually power it using the USB itself [38:27.910 --> 38:29.970] so, you plug it in [38:33.710 --> 38:35.890] you plug in this thing into Ethernet [38:37.210 --> 38:37.950] so that [38:37.950 --> 38:38.950] this can communicate [38:40.930 --> 38:41.970] and after that [38:41.970 --> 38:42.410] you wait [38:43.150 --> 38:45.370] so, this is what is going to happen now [38:46.050 --> 38:47.610] we are going to insert [38:47.610 --> 38:49.970] the cover.co module on the one side [38:50.830 --> 38:51.550] and then [38:51.550 --> 38:53.750] we are going to use nping on the [38:53.750 --> 38:55.390] host machine to send [38:55.390 --> 38:56.590] specific packets [38:56.590 --> 38:59.770] so, now, if we talk about the code [38:59.770 --> 39:01.850] of this, the specific packets [39:01.850 --> 39:03.550] that we are talking about, the code is written [39:03.550 --> 39:05.370] in such a manner that [39:06.170 --> 39:08.010] this thing will see [39:08.010 --> 39:09.850] all the packets that are coming to this machine [39:09.850 --> 39:12.110] but it will only pass those packets [39:12.110 --> 39:13.710] which will have source [39:13.710 --> 39:16.070] and destination port as 9999 [39:16.070 --> 39:17.930] so, that's the signature that [39:17.930 --> 39:18.770] we are creating here [39:18.770 --> 39:21.370] so, main thing here to notice is [39:21.370 --> 39:22.870] we are not opening any socket [39:22.870 --> 39:25.850] but still, we are able to monitor a specific [39:25.850 --> 39:27.950] packet which will contain command for us [39:27.950 --> 39:29.650] so, for example, when [39:29.650 --> 39:31.570] we send something like this here [39:32.470 --> 39:33.890] it contains the command [39:33.890 --> 39:35.970] here, right, the cat, it is a shadow [39:35.970 --> 39:37.610] just to see the contents [39:37.610 --> 39:38.430] of the shadow file [39:38.430 --> 39:41.770] and when you will do demessage, you will find [39:41.770 --> 39:42.750] something like this [39:42.750 --> 39:45.210] so, this one actually intercepted it [39:45.210 --> 39:47.650] it got the command, now this command can be [39:47.650 --> 39:49.410] passed to the user level thing [39:49.410 --> 39:51.450] that is running there and that can [39:51.450 --> 39:52.530] get your stuff [39:53.390 --> 39:54.550] right, so [39:59.230 --> 40:00.530] this should be online [40:00.530 --> 40:01.010] and now [40:03.150 --> 40:04.810] if you don't like SSH [40:04.810 --> 40:06.470] you can always use something called [40:06.470 --> 40:08.710] TTYD, it will drop you right [40:08.710 --> 40:10.990] into the box, this box [40:11.810 --> 40:12.650] so, now [40:13.450 --> 40:14.910] let's see the IP address [40:14.910 --> 40:16.230] it's already know, right [40:16.230 --> 40:17.090] it's 10.1 [40:18.810 --> 40:20.430] it's 10.1, so [40:21.050 --> 40:22.770] I can see the module here [40:22.770 --> 40:24.550] I do insmod [40:26.270 --> 40:26.790] cohort [40:29.290 --> 40:30.290] it's inserted [40:30.290 --> 40:31.750] and now [40:31.750 --> 40:34.930] if I open this PowerShell [40:34.930 --> 40:36.710] and fire this command here [40:36.710 --> 40:38.750] nping commands come as [40:38.950 --> 40:40.770] a part of nmap, so if you don't [40:40.770 --> 40:42.710] have nmap installed, you won't have [40:42.710 --> 40:44.690] this one, here what I am [40:44.690 --> 40:46.770] defining is, we have [40:46.770 --> 40:48.910] to, we need to set the TCP flags [40:48.910 --> 40:50.550] as SYN and REST [40:50.550 --> 40:52.310] and the port needs to be [40:52.310 --> 40:55.110] 9999 for the [40:55.110 --> 40:56.690] source as well as for the destination [40:56.690 --> 40:59.090] so this is nothing but this is the signature that [40:59.090 --> 41:01.110] we have, we don't want it to listen [41:01.110 --> 41:03.150] to any packet and do, you know, whatever it is [41:03.150 --> 41:05.230] doing, we want it to be specific [41:05.230 --> 41:07.230] that's why the flags as [41:07.230 --> 41:09.130] well as the port combo will make [41:09.130 --> 41:10.750] it so unique, that it will [41:10.750 --> 41:13.090] only hear whatever we will send [41:13.090 --> 41:15.130] it, right, so now, you can observe [41:15.130 --> 41:17.110] right, I am not running anything on [41:17.110 --> 41:19.090] the user side, I am not [41:19.090 --> 41:21.170] running any socket, that's the main part here [41:21.170 --> 41:23.170] there is no socket, most of the people [41:23.170 --> 41:24.630] when they check for the backdoor [41:25.010 --> 41:27.170] they do a netstat, what is listening [41:27.170 --> 41:29.190] right, now this thing will not [41:29.190 --> 41:31.350] appear, because it is not opening any socket [41:31.350 --> 41:33.030] it's just scanning the packets, right [41:33.030 --> 41:35.110] and that's the concept behind this [41:35.110 --> 41:37.310] this is only one example, you can [41:37.310 --> 41:39.190] actually make sure that, you know, the process [41:39.190 --> 41:41.170] is hidden, you can make sure [41:41.170 --> 41:42.950] that process cannot be killed by the [41:42.950 --> 41:45.210] user space kill-9, you [41:45.210 --> 41:47.250] can do all of that, but you [41:47.250 --> 41:49.170] know, because of the time limits [41:49.170 --> 41:51.230] that we have, this [41:51.230 --> 41:52.310] is all we are going to cover [41:52.310 --> 41:54.430] so it has sent the packet [41:55.070 --> 41:56.470] now if you go here [41:57.150 --> 41:58.530] you do demessage [41:59.130 --> 42:00.950] you will find something like this here [42:01.970 --> 42:03.370] so this is the part [42:03.370 --> 42:04.890] which is undetectable [42:04.890 --> 42:07.050] it will write it somewhere, it will [42:07.050 --> 42:09.490] pass it using a channel or a [42:09.490 --> 42:11.410] hook to the user space if something [42:11.410 --> 42:13.330] is running there, or you can [42:13.330 --> 42:15.890] you know, you can actually add code here itself [42:15.890 --> 42:17.430] to run these commands [42:17.430 --> 42:18.890] you can intercept all the syscalls [42:18.890 --> 42:20.850] you can see which command [42:20.850 --> 42:22.730] or which system or which [42:22.730 --> 42:24.890] programmer or program is [42:24.890 --> 42:26.970] making the syscalls, you can intercept [42:26.970 --> 42:28.850] them, if you want, you can [42:28.850 --> 42:30.930] actually block them too, so that's the power [42:30.930 --> 42:32.930] of current level toolkits or [42:32.930 --> 42:34.970] rootkits that, you know, most of the [42:34.970 --> 42:36.950] people don't talk about or don't [42:36.950 --> 42:38.370] understand when they talk about [42:38.790 --> 42:39.630] WiFi security [42:40.470 --> 42:41.890] in the routers context [42:43.290 --> 42:44.790] so all of this is there [42:46.050 --> 42:46.970] I can show [42:46.970 --> 42:48.310] you code as well if you like [42:48.730 --> 42:51.090] let me grab the LAN [42:52.210 --> 42:52.770] again [42:54.520 --> 42:56.900] but again, the router level code [42:56.900 --> 42:58.700] is not the simplest thing [42:58.700 --> 43:00.740] that you can see, the main point [43:00.740 --> 43:02.520] of showing this thing in [43:02.520 --> 43:04.780] workshop is to tell you that these are [43:04.780 --> 43:06.760] the possibilities, even when [43:06.760 --> 43:08.760] you are not able to see program in [43:08.760 --> 43:10.720] PS or if you are not able to see [43:10.720 --> 43:12.260] it in netstat [43:12.260 --> 43:14.100] it can still be there [43:14.720 --> 43:16.580] it can still listen for the commands [43:16.580 --> 43:17.980] it can still reply [43:17.980 --> 43:20.680] it can still do DOS, it can still make sure [43:20.680 --> 43:22.700] that anyone or the hacker [43:22.700 --> 43:24.140] who has this backdoor [43:24.140 --> 43:26.380] can actually get into your [43:26.380 --> 43:28.660] system anytime as he likes [43:28.660 --> 43:30.880] so that's the main getaway [43:30.880 --> 43:32.980] that we are talking about here [43:32.980 --> 43:34.260] but still [43:34.260 --> 43:35.780] if you like to see the code [43:36.500 --> 43:38.460] just a quick code walkthrough [43:40.980 --> 43:42.180] kernel pun [43:42.180 --> 43:44.860] let's talk about a simple one first [43:44.860 --> 43:45.600] let's talk about [43:46.520 --> 43:48.040] the prepend process name [43:52.620 --> 43:53.660] you open the [43:54.200 --> 43:54.700] file [43:55.600 --> 43:57.280] here, just like your [43:57.280 --> 43:57.840] hello world [43:59.060 --> 44:00.780] we are registering two functions [44:02.220 --> 44:03.400] we are taking some [44:03.400 --> 44:05.280] arguments because we want to take [44:05.280 --> 44:07.340] the PID from the user, we want to take [44:07.340 --> 44:09.500] the new name of the process from the user [44:09.500 --> 44:11.440] so that's why these things are [44:11.440 --> 44:11.720] here [44:14.240 --> 44:15.680] and when you go up [44:15.680 --> 44:15.760] here [44:15.760 --> 44:19.720] what you will find here is [44:19.720 --> 44:21.780] so it's very important to understand that [44:21.780 --> 44:23.720] all the processes, they are stored [44:23.720 --> 44:25.780] as a task structure in kernel [44:25.780 --> 44:27.380] so what we are doing here [44:27.380 --> 44:29.520] is we are going over all of the processes [44:29.520 --> 44:31.820] that are running, we are matching the PID [44:31.820 --> 44:33.880] because that is the identifier that we have [44:33.880 --> 44:35.780] and as soon as it is [44:35.780 --> 44:37.760] matched, we are overwriting [44:38.580 --> 44:39.780] the name of [44:39.780 --> 44:41.700] the command, or we are not overwriting here [44:41.700 --> 44:43.140] we are just adding it in the front [44:43.140 --> 44:45.440] to the structure [44:45.440 --> 44:46.300] that is there [44:47.220 --> 44:48.280] so that's all [44:48.280 --> 44:50.720] you cannot do this thing from user mode [44:50.720 --> 44:53.360] why? because the thing, the structure, the memory [44:53.360 --> 44:55.460] that we are playing with right now [44:55.460 --> 44:56.680] it is in kernel [44:56.680 --> 44:59.060] and there are boundaries, you cannot breach them [44:59.060 --> 45:01.180] without using something like [45:01.740 --> 45:02.800] a zero-day exploit or something [45:03.940 --> 45:05.600] similarly, if we talk about [45:05.600 --> 45:07.380] the covert network thing [45:12.380 --> 45:14.460] this one is a little bit more complex [45:14.460 --> 45:16.960] because obviously it is doing the complex thing [45:16.960 --> 45:18.880] but let's do a walkthrough [45:20.440 --> 45:22.100] so what it is doing here [45:22.100 --> 45:24.540] is it is registering its hook [45:24.540 --> 45:25.860] with the netfilter [45:25.860 --> 45:27.220] because you have to do that [45:27.220 --> 45:30.440] because if you don't do that, netfilter is not going to [45:30.440 --> 45:31.540] pass the packets to you [45:32.220 --> 45:33.080] once that is done [45:33.700 --> 45:36.260] this is the definition, this is the [45:36.260 --> 45:37.260] hook that we are using [45:37.260 --> 45:40.200] this one stands for incoming packets [45:40.200 --> 45:41.240] as we just discussed [45:41.240 --> 45:43.120] we are only doing it for [45:43.120 --> 45:43.880] IPv4 [45:45.000 --> 45:46.300] and the priority is last [45:46.300 --> 45:48.720] so our hook will execute in the end [45:49.320 --> 45:50.760] no need to worry, still [45:50.760 --> 45:52.380] it is going to get all the packets [45:53.580 --> 45:54.560] so now [45:54.560 --> 45:56.000] if you go here [45:56.000 --> 45:58.980] what it will do, it will look for [45:58.980 --> 45:59.940] specific packet [45:59.940 --> 46:02.280] which has this specific port [46:02.280 --> 46:03.480] which we have defined [46:04.140 --> 46:06.620] and it will also check for the [46:06.620 --> 46:08.780] TCP header flags [46:08.780 --> 46:10.620] because ports can [46:10.620 --> 46:12.980] be replicated by other people [46:12.980 --> 46:14.780] also right, it can be [46:14.780 --> 46:16.620] the thing that for some reason, some process [46:16.620 --> 46:18.060] is using 9999 [46:18.060 --> 46:20.720] and now those packets will start [46:21.320 --> 46:22.180] intercepting like [46:22.780 --> 46:24.720] our channel right, it should not happen [46:24.720 --> 46:26.380] so that's why we have made it [46:26.380 --> 46:28.840] more complex, once that is [46:28.840 --> 46:29.140] there [46:30.380 --> 46:32.680] this is the code that you saw printed [46:34.260 --> 46:36.440] so all of these things are being printed [46:36.440 --> 46:38.480] you can then pass this command [46:38.480 --> 46:40.100] to some other module that you have [46:40.100 --> 46:42.860] or to some other function that you have here [46:42.860 --> 46:44.560] right, so it's that [46:44.560 --> 46:46.520] simple, that easy, once you know [46:46.520 --> 46:47.660] what to do [46:48.300 --> 46:49.320] going back [46:49.920 --> 46:52.480] similarly, now you know, the second logical question [46:52.480 --> 46:54.620] is, this is how we do it [46:54.620 --> 46:56.600] for the vendors, this is how we do it [46:56.600 --> 46:58.480] for the OpenWrt, but not [46:58.480 --> 46:59.980] everyone runs OpenWrt [46:59.980 --> 47:02.560] so how we can compile it for the vendor firmware [47:02.560 --> 47:04.220] and that's a great question [47:04.220 --> 47:05.580] so most of the time [47:05.580 --> 47:07.300] what you have to find for this [47:07.300 --> 47:09.740] is the code for the vendor firmware [47:09.740 --> 47:11.720] now you will say that the vendors [47:11.720 --> 47:13.500] they don't give their code out [47:14.680 --> 47:16.020] that's partially correct [47:16.020 --> 47:18.180] some of vendors has to, because they are [47:18.180 --> 47:20.320] using GPL, and by the license [47:20.320 --> 47:22.280] terms of GPL, they have [47:22.280 --> 47:23.860] to give out all the modifications [47:23.860 --> 47:26.200] that they make, you find it [47:26.200 --> 47:28.260] and then you use the same way [47:28.760 --> 47:30.260] you create their own build [47:30.260 --> 47:31.980] system, you use their kernel [47:31.980 --> 47:34.040] you use their cost compiler to compile [47:34.040 --> 47:36.200] everything, and then in this way [47:36.200 --> 47:37.580] you can compile it for them [47:39.020 --> 47:40.120] so all of [47:40.120 --> 47:42.040] this research was done when we were creating [47:42.040 --> 47:44.300] this course for our customers [47:44.300 --> 47:46.240] and all of the details [47:46.240 --> 47:47.980] if you want to go extended [47:47.980 --> 47:50.240] into it, it is available there [47:50.240 --> 47:51.960] you can go and learn [47:51.960 --> 47:53.440] this is the only thing that [47:54.220 --> 47:56.440] was possible to be covered in one hour [47:56.440 --> 47:58.140] but for all the other details [47:58.140 --> 48:00.220] you can always refer to the course [48:00.220 --> 48:01.220] if you like [48:02.400 --> 48:03.820] again, community labs [48:03.820 --> 48:06.260] if you want to try this out, whatever we have done [48:06.260 --> 48:08.260] I'll make sure that the PPT is [48:08.260 --> 48:09.980] available with the wireless village [48:09.980 --> 48:12.220] so that you guys can download, you guys can [48:12.220 --> 48:13.280] see all the commands [48:13.860 --> 48:16.340] or you can directly go and do them [48:16.340 --> 48:18.060] here. So that's all [48:18.060 --> 48:20.360] if you have any questions, I'll be taking those [48:20.360 --> 48:22.080] or if you come with some questions [48:22.080 --> 48:24.380] after the talk or the workshop, you can always [48:24.380 --> 48:25.880] mail me on this. Thank you