1 00:00:00,000 --> 00:00:01,280 Hey everybody! 2 00:00:01,520 --> 00:00:04,880 If you're standing next to a round table, you're in the wrong place. 3 00:00:05,040 --> 00:00:07,600 If you're sitting in a chair, you're in the correct place. 4 00:00:07,600 --> 00:00:10,980 If there's a chair next to you, put your hand up and make a friend. 5 00:00:11,060 --> 00:00:13,560 Everyone not sitting down, that's where your chairs are. 6 00:00:13,560 --> 00:00:15,100 There's lots of them. 7 00:00:15,100 --> 00:00:17,120 Please come in and sit down. 8 00:00:17,120 --> 00:00:18,420 And I'll tell you why. 9 00:00:18,560 --> 00:00:23,420 Because this fine man is going to teach you about more than you could possibly imagine in the next... 10 00:00:23,420 --> 00:00:24,640 How long did I actually give you? 11 00:00:24,640 --> 00:00:26,000 I said 15 minutes? 12 00:00:26,000 --> 00:00:26,520 12. 13 00:00:26,880 --> 00:00:27,800 12 minutes. 14 00:00:27,800 --> 00:00:31,660 He's got 12 minutes and he's going to go over how to build a rootkit on OpenWorks. 15 00:00:31,660 --> 00:00:32,880 It's going to be amazing. 16 00:00:32,880 --> 00:00:33,840 Take notes. 17 00:00:33,840 --> 00:00:38,220 You can play the recording back at 1 tenth speed and it will be amazing. 18 00:00:38,840 --> 00:00:42,740 So yeah, definitely watch the long version of this talk when you get home. 19 00:00:42,740 --> 00:00:44,260 The short version is going to be fun. 20 00:00:44,300 --> 00:00:46,960 I'm going to get out of the way and I'm going to let this fine gentleman talk. 21 00:00:46,960 --> 00:00:49,220 But seriously, everybody sit down. 22 00:00:49,220 --> 00:00:52,220 There are plenty of seats and you really want to hear this. 23 00:00:52,700 --> 00:00:54,020 Nishant, please. 24 00:00:54,020 --> 00:00:54,540 Thank you. 25 00:01:00,540 --> 00:01:03,220 Thank you all for coming, coming for my talk. 26 00:01:03,220 --> 00:01:04,760 And thanks to the... 27 00:01:06,380 --> 00:01:07,700 So he told me that... 28 00:01:07,700 --> 00:01:12,180 He told me that this one... 29 00:01:12,180 --> 00:01:16,520 So they already told me that the mic is a little hot. 30 00:01:16,520 --> 00:01:19,500 This one and this one is cold. 31 00:01:19,500 --> 00:01:22,760 So I was supposed to stay a little bit far from that. 32 00:01:22,840 --> 00:01:27,140 Again, thanks for coming for the workshop that I will be delivering. 33 00:01:27,140 --> 00:01:33,320 Thanks for the wireless village people for all the good work for bringing all of us wireless fans together. 34 00:01:33,720 --> 00:01:42,140 So as you can observe on the screens, the title of the workshop is developing Wi-Fi access point rootkits. 35 00:01:42,460 --> 00:01:45,700 My name is Nishant Sharma, as you can read. 36 00:01:46,300 --> 00:01:48,720 I work for Pentester Academy. 37 00:01:48,980 --> 00:01:50,520 Have you guys heard of it? 38 00:01:50,520 --> 00:01:51,820 Just show of hands. 39 00:01:52,060 --> 00:01:53,780 Oh, nice. 40 00:01:53,780 --> 00:01:55,320 Catch you after the talk. 41 00:01:55,320 --> 00:01:59,000 So yeah, we are a cyber security training company. 42 00:01:59,000 --> 00:02:03,340 We run PentesterAcademy.com, we run AttackDefense.com. 43 00:02:03,760 --> 00:02:07,080 A little bit about me so that you know why to trust me, right? 44 00:02:07,080 --> 00:02:09,540 When I'm teaching you, you need that credibility. 45 00:02:10,220 --> 00:02:16,180 So I work as R&D manager and the lead trainer at Pentester Academy. 46 00:02:16,520 --> 00:02:20,000 I conduct trainings on Wi-Fi for private clients. 47 00:02:20,020 --> 00:02:24,800 Just five days before I was conducting it for the black hat here, the Wi-Fi master class. 48 00:02:25,540 --> 00:02:30,800 Before joining Pentester Academy, I worked as a firmware engineer with one of the providers. 49 00:02:31,120 --> 00:02:38,620 My job was to create firmwares for the access points as well as for the wireless intrusion prevention systems. 50 00:02:38,920 --> 00:02:43,360 I have a master's degree in InfoSec, you know, doesn't matter still. 51 00:02:43,900 --> 00:02:50,140 I have been publishing my research in Black Hat, Defcon and other venues for the last four years. 52 00:02:50,140 --> 00: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. 53 00:03:02,200 --> 00:03:07,320 So, you know, some of the pretty logos just so that you know. 54 00:03:07,720 --> 00:03:10,280 This is the PentesterAcademy.com. 55 00:03:10,420 --> 00:03:12,080 It's an online library. 56 00:03:12,080 --> 00:03:14,060 This is the AttackDefense.com. 57 00:03:14,060 --> 00:03:17,500 It's our online cyber range. 58 00:03:17,500 --> 00:03:21,700 The main thing about it is dedicated instances. 59 00:03:21,700 --> 00:03:25,620 Every player gets dedicated instances, no VPN, only the browser. 60 00:03:26,360 --> 00:03:33,660 We have multiple scenarios as well, not restricted to one user, one lab, you know, multiple labs, multiple machines. 61 00:03:33,780 --> 00:03:35,780 And done with the promotion. 62 00:03:36,300 --> 00:03:41,780 So, as you know, the workshop outline as you can observe, right? 63 00:03:41,780 --> 00:03:44,240 We'll talk about the rootkit. 64 00:03:44,240 --> 00:03:50,020 I am going to take OpenWRT as the main system on which we are going to do it. 65 00:03:50,120 --> 00:03:52,360 The reasons we will be covering. 66 00:03:52,860 --> 00:03:55,420 First, we will talk about OpenWRT. 67 00:03:55,420 --> 00:03:58,400 So, just for the lay of the land, right? 68 00:03:58,400 --> 00:04:01,700 How many of you are already aware of OpenWRT? 69 00:04:01,700 --> 00:04:02,760 Show of hands. 70 00:04:03,220 --> 00:04:04,380 Oh, that's good. 71 00:04:04,380 --> 00:04:07,640 That's better than, you know, than the other audiences I get. 72 00:04:07,640 --> 00:04:08,680 Oh, cool. 73 00:04:08,960 --> 00:04:11,720 So, yeah, we'll talk about OpenWRT. 74 00:04:11,720 --> 00: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. 75 00:04:17,160 --> 00:04:22,880 You should know about it if you are in Wi-Fi or even if you are concerned about your security. 76 00:04:22,980 --> 00:04:26,600 Then we will talk about how we actually create firmware. 77 00:04:26,860 --> 00: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. 78 00:04:35,500 --> 00:04:39,620 There is a third way of doing that and we will be covering that. 79 00:04:40,380 --> 00:04:45,660 We'll talk about the user space applications, how you can compile them in firmware. 80 00:04:45,660 --> 00:04:50,480 Apart from that, then we will also talk about the kernel-based rootkits. 81 00:04:50,480 --> 00:04:52,200 That's the main takeaway. 82 00:04:52,340 --> 00:04:55,380 But to get there, these are the steps, right? 83 00:04:55,380 --> 00:04:57,240 These are the baby steps that you take. 84 00:04:57,620 --> 00: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. 85 00:05:08,420 --> 00:05:11,000 So, access point security, right? 86 00:05:11,000 --> 00:05:15,000 Everyone is talking about Wi-Fi security, especially the enterprises, right? 87 00:05:15,000 --> 00:05:20,320 WPA3 standard just came out, WPA2, PSK enterprise, pretty secure, right? 88 00:05:20,320 --> 00:05:24,100 WEP was the bad one, already out of the market. 89 00:05:24,200 --> 00:05:29,360 But when it comes to the security of Wi-Fi routers, not everyone is that aware. 90 00:05:29,460 --> 00:05:33,980 When we talk about enterprise gate access points, yes, they are doing a good job. 91 00:05:34,220 --> 00:05:35,060 How good? 92 00:05:35,060 --> 00:05:36,340 Again, debatable. 93 00:05:36,340 --> 00: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? 94 00:05:43,740 --> 00:05:49,280 You use them at your home, you use that at the small business venues that you have, right? 95 00:05:49,300 --> 00:05:51,880 Most of the time you're running WPA2, PSK. 96 00:05:51,960 --> 00: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? 97 00:05:59,900 --> 00:06:02,980 So they run for years till the time they break. 98 00:06:02,980 --> 00: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? 99 00:06:10,620 --> 00:06:13,120 So that is something that is not right. 100 00:06:13,280 --> 00:06:20,720 We have seen multiple reports, multiple events in which Wi-Fi routers were hacked. 101 00:06:21,080 --> 00:06:22,740 You know, there are multiple vectors. 102 00:06:22,740 --> 00:06:25,760 Some of you don't change their default password. 103 00:06:25,760 --> 00:06:30,020 Some of the routers have vendor-installed firmware backdoors. 104 00:06:30,020 --> 00:06:31,940 Some of them are using weak passwords. 105 00:06:31,940 --> 00:06:36,200 Some of them are exposed to internet over SSH or web UI. 106 00:06:36,200 --> 00:06:38,140 There are multiple ways. 107 00:06:38,200 --> 00:06:44,980 So the problem is, once your router is compromised, there is a plethora of attacks that other people can do. 108 00:06:45,020 --> 00:06:51,880 So it's like giving the command and control of your internet to somebody who you don't know, right? 109 00:06:51,880 --> 00:06:55,100 Some of the issues can be the passive monitoring. 110 00:06:55,100 --> 00:07:00,960 Because it's the router that sends all the traffic out, all the Wi-Fi traffic out. 111 00:07:01,000 --> 00:07:06,900 So once they are on it, just one line change can direct all of your traffic to their server. 112 00:07:06,900 --> 00:07:08,600 They can do passive analysis there. 113 00:07:08,600 --> 00:07:10,680 They can do active MIPM there. 114 00:07:11,100 --> 00: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. 115 00:07:24,520 --> 00:07:28,780 And then they are using it to attack some third party, which is obviously not good. 116 00:07:28,780 --> 00:07:30,320 It's your infra, right? 117 00:07:30,320 --> 00:07:32,040 They should not be able to do that. 118 00:07:33,020 --> 00:07:36,700 So what kind of malwares are there and what they can do? 119 00:07:37,000 --> 00:07:40,020 We have already discussed, you know, worms. 120 00:07:40,020 --> 00:07:41,020 We have seen worms. 121 00:07:41,020 --> 00:07:48,100 We have seen rootkits, spywares, trojans, all kind of things are now moving to the router space as well. 122 00:07:48,100 --> 00:07:55,920 The problem is because they are neglected, no antivirus or heads is running on most of the routers. 123 00:07:56,060 --> 00:07:58,320 You don't even know if you get hacked, right? 124 00:07:58,320 --> 00:08:00,000 So that's one of the issues. 125 00:08:01,600 --> 00:08:06,700 Access point rootkits, one of the subpart of the other malware. 126 00:08:06,880 --> 00: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. 127 00:08:13,340 --> 00:08:16,200 So we will see how actually they are doing it. 128 00:08:16,200 --> 00: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. 129 00:08:24,340 --> 00:08:27,840 A special case of rootkits is bootkits. 130 00:08:27,840 --> 00:08:31,000 If you are interested, really good things. 131 00:08:31,440 --> 00:08:38,360 Coming to OpenWrt, OpenWrt is an embedded operating system which again is based on Linux. 132 00:08:38,360 --> 00:08:44,200 It uses Linux kernel, it uses utils like you have in your Linux. 133 00:08:44,200 --> 00: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. 134 00:08:54,860 --> 00:09:02,740 The only difference is everything, just so that it can run on a cheap hardware, is cut down on the functionality. 135 00:09:02,840 --> 00:09:06,020 It has less command, it has less power, all of that. 136 00:09:06,020 --> 00:09:15,260 It comes with the Ash cell, just like you use your Bash or SH on Linux, it comes with ASH. 137 00:09:15,280 --> 00:09:22,960 It uses BusyBox for all the commands, all the commands put in one binary so that it is lightweight, only that. 138 00:09:23,060 --> 00:09:27,880 It uses Lucy as its web UI so that you can configure it easily. 139 00:09:28,140 --> 00:09:34,520 And just like your Ubuntu has apt-get, it has opkg so you can actually install things on it. 140 00:09:35,400 --> 00: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. 141 00:09:45,120 --> 00:09:49,340 It's the most popular open source firmware out there. 142 00:09:49,340 --> 00:09:52,920 Currently it has 3500 plus packages. 143 00:09:52,920 --> 00:09:57,260 So when I say packages, these are the kind of softwares, tools that are already there. 144 00:09:57,260 --> 00:10:00,480 You just need an opkg install to install them and run them. 145 00:10:00,480 --> 00:10:03,440 It supports more than 1200 devices. 146 00:10:03,440 --> 00:10:05,960 These devices are of each range. 147 00:10:05,960 --> 00:10:08,840 You have devices which are up for $20 or $30. 148 00:10:08,840 --> 00:10:12,840 You have devices which can go up to $1000 as well. 149 00:10:12,840 --> 00:10:18,400 So depending on the need that you have, you can use this thing to create your custom gadgets. 150 00:10:18,400 --> 00:10:23,500 You can create your custom snippers because 11ac is coming in. 151 00:10:23,500 --> 00: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. 152 00:10:33,520 --> 00:10:35,440 So all of this can be helped. 153 00:10:35,500 --> 00:10:39,880 All of this is that OpenWrt can help, but that is not the topic. 154 00:10:40,400 --> 00:10:45,900 So what we will discuss about first is the OpenWrt build system. 155 00:10:45,980 --> 00:10:51,800 A lot of people who are using OpenWrt, even they don't like to compile their own firmware. 156 00:10:51,800 --> 00:10:52,100 Why? 157 00:10:52,100 --> 00:10:53,580 Because it is messy. 158 00:10:53,580 --> 00:10:55,380 Or that's what people think. 159 00:10:55,380 --> 00:10:58,700 It's not, but that's the way things are. 160 00:10:58,860 --> 00:11:04,480 So what we will learn is how you can actually create your own build system. 161 00:11:04,480 --> 00:11:06,800 Don't worry about noting down the commands. 162 00:11:06,800 --> 00:11:11,780 I'll make sure that these slides are available to you. 163 00:11:11,780 --> 00:11:13,220 So you can actually use them. 164 00:11:13,220 --> 00:11:16,820 I have simplified everything so that you don't run into errors. 165 00:11:16,960 --> 00:11:19,940 You can use them to build your own things. 166 00:11:19,940 --> 00:11:26,160 And for now, I have already created a build system that you guys can also use if you like to. 167 00:11:26,160 --> 00:11:29,960 You can go back, you can use it that time if that is the case. 168 00:11:31,060 --> 00:11:34,720 So first, for the simplest scenario, we go with Ubuntu. 169 00:11:34,720 --> 00:11:36,880 Because Ubuntu is the simplest. 170 00:11:36,980 --> 00:11:40,480 You do your apt-get and update and upgrade. 171 00:11:40,600 --> 00:11:41,640 Pretty standard. 172 00:11:42,400 --> 00:11:46,360 Then these are the dependencies that you have to install to build the system. 173 00:11:46,360 --> 00:11:51,000 The reason of explaining all of this is so that you can do it. 174 00:11:51,000 --> 00:11:51,860 It's a workshop. 175 00:11:51,860 --> 00:11:54,880 It's not the cutting-edge research talk that we give. 176 00:11:54,960 --> 00:11:57,220 That you are used to. 177 00:11:57,220 --> 00:12:01,000 But this is something that you can actually go back and do on your own. 178 00:12:01,840 --> 00:12:04,140 After that, you add a low-privileged user. 179 00:12:04,140 --> 00:12:07,760 Because otherwise it creates problems when you build some packages. 180 00:12:08,280 --> 00:12:10,080 You switch to its home repository. 181 00:12:10,500 --> 00:12:14,060 And as I said, OpenWrt is open source. 182 00:12:14,060 --> 00:12:15,480 So it is on GitHub. 183 00:12:15,480 --> 00:12:18,660 You can download the latest stable version. 184 00:12:18,740 --> 00:12:21,260 I will always recommend you to go for the stable version. 185 00:12:21,260 --> 00:12:22,600 Don't go for the trunk. 186 00:12:22,640 --> 00:12:25,160 Don't go for the branch that is under development. 187 00:12:25,160 --> 00:12:26,920 It has active bugs. 188 00:12:26,920 --> 00:12:28,160 It has build issues. 189 00:12:28,160 --> 00:12:30,580 So you know, most of the time you will be wasting your time. 190 00:12:30,600 --> 00:12:32,060 So go for the stable one. 191 00:12:32,080 --> 00:12:34,980 Current stable one is 18.06.4. 192 00:12:35,340 --> 00:12:37,500 The one I am using here is 0.2. 193 00:12:37,500 --> 00:12:38,440 Doesn't matter. 194 00:12:38,440 --> 00:12:39,880 Not that much of difference. 195 00:12:40,180 --> 00:12:41,140 First you take it. 196 00:12:41,140 --> 00:12:42,060 You unzip it. 197 00:12:42,060 --> 00:12:42,340 Why? 198 00:12:42,340 --> 00:12:43,660 Because you know, it's zipped. 199 00:12:43,660 --> 00:12:44,580 You have to. 200 00:12:44,580 --> 00:12:52,000 And then we use the makemenuconfig command to select the hardware that we want to build for it. 201 00:12:52,000 --> 00:12:52,560 Don't worry. 202 00:12:52,560 --> 00:12:53,600 These are just the steps. 203 00:12:53,600 --> 00:12:56,600 We are going to see how to do it in practical as well. 204 00:12:57,700 --> 00:13:01,920 You have to then update the feeds and install them. 205 00:13:01,920 --> 00:13:07,020 Feeds are nothing but the kind of software tools that you can add while you are building all of this. 206 00:13:07,540 --> 00:13:11,100 And I have a build ready setup here. 207 00:13:11,100 --> 00:13:12,740 So I will be using that. 208 00:13:12,740 --> 00:13:14,020 And the internet is back. 209 00:13:14,620 --> 00:13:16,060 That's a good thing. 210 00:13:16,260 --> 00:13:18,660 So this is the attack defense lab I was talking about. 211 00:13:18,660 --> 00:13:21,180 It's the community section of attack defense lab. 212 00:13:21,220 --> 00:13:26,940 So what I have done is, if you guys want to try it back home, you can actually go here. 213 00:13:26,940 --> 00:13:28,960 You can log in with your Google account. 214 00:13:28,960 --> 00:13:30,500 You don't need a paid subscription. 215 00:13:30,720 --> 00:13:32,680 Just go here, free labs. 216 00:13:33,300 --> 00: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. 217 00:13:40,280 --> 00:13:43,780 You choose the server which is nearest to you. 218 00:13:43,780 --> 00:13:45,540 Obviously for the latency reasons. 219 00:13:45,860 --> 00:13:47,140 You give it 25 seconds. 220 00:13:47,140 --> 00:13:51,300 In 25 seconds it will spin a dedicated thing for you. 221 00:13:51,400 --> 00:13:54,960 If you are doing it right now, you will get another thing. 222 00:13:54,960 --> 00:13:56,320 I will get another setup. 223 00:13:56,320 --> 00:13:57,720 So that's how it is. 224 00:13:58,260 --> 00: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. 225 00:14:07,400 --> 00:14:12,120 So you can actually directly copy paste them and they will work. 226 00:14:12,120 --> 00:14:16,280 Because I have ran them like for 50-100 times I have used them. 227 00:14:16,280 --> 00:14:17,320 So they work. 228 00:14:18,160 --> 00:14:21,460 Once the lab is ready, you go inside the lab. 229 00:14:21,680 --> 00:14:24,280 So the lab is only to practice. 230 00:14:24,280 --> 00:14:28,080 If you really want to create your own, you have to do it on your own machine. 231 00:14:28,080 --> 00:14:31,040 Because for security reasons, our labs are contained. 232 00:14:31,040 --> 00:14:32,780 Nothing goes in, nothing comes out. 233 00:14:32,780 --> 00:14:33,840 It's like that. 234 00:14:34,940 --> 00:14:40,800 So now, what I have done here is, I have created... 235 00:14:41,600 --> 00:14:44,520 I have taken the code from GitHub. 236 00:14:45,140 --> 00:14:48,240 This is how the build system looks like. 237 00:14:48,500 --> 00:14:57,250 Now as I was telling you, we have to do a make-menu-config. 238 00:14:57,310 --> 00:15:02,210 So all the commands before it, they only tell you how to build this setup. 239 00:15:02,210 --> 00: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. 240 00:15:09,770 --> 00:15:11,510 You do make-menu-config. 241 00:15:11,510 --> 00:15:16,450 It will throw a small UI so that you can select stuff. 242 00:15:16,770 --> 00:15:18,050 As you can see here. 243 00:15:18,270 --> 00:15:23,150 First step, as you can observe, is to select the card that you have. 244 00:15:23,150 --> 00:15:26,450 The kind of card or the kind of architecture your machine supports. 245 00:15:26,590 --> 00:15:27,950 Very easy to guess. 246 00:15:28,090 --> 00:15:31,390 You can directly use your box to check for it. 247 00:15:31,390 --> 00:15:37,550 If you see QCA or Qualcomm Atheros, it means you are using Atheros of some kind. 248 00:15:37,550 --> 00:15:42,290 If you check the datasheet or the booksheet that comes with it, you will be able to find this number. 249 00:15:42,670 --> 00:15:45,230 So here I am using for this one. 250 00:15:45,810 --> 00:15:47,870 This is the sub-target one. 251 00:15:47,870 --> 00:15:50,530 If you don't know what you are doing, don't touch it. 252 00:15:50,530 --> 00:15:52,890 Generic will work for everything. 253 00:15:53,230 --> 00:15:54,610 No need to touch it. 254 00:15:54,870 --> 00:15:59,930 Target profile, here are the device profiles that are under that architecture. 255 00:15:59,930 --> 00:16:04,670 So from here, you can select the device that you want to build it for. 256 00:16:04,790 --> 00:16:06,990 So I am using AR750. 257 00:16:07,290 --> 00:16:09,390 It's a pretty thrifty device. 258 00:16:16,860 --> 00:16:18,320 This is the one. 259 00:16:18,320 --> 00:16:19,640 It's a travel router. 260 00:16:19,640 --> 00:16:21,260 Very cheap, $50. 261 00:16:21,260 --> 00:16:24,900 You can get it on Amazon or any other website. 262 00:16:25,020 --> 00:16:26,880 The delivery is throughout the world. 263 00:16:27,640 --> 00:16:30,200 So first, you do that. 264 00:16:30,200 --> 00:16:34,600 Now if you pay attention here, you will see multiple kind of things. 265 00:16:34,600 --> 00:16:40,000 If I go to the base system, all of these things are the packages. 266 00:16:40,200 --> 00:16:44,520 Now the second question is, how would you know which packages to install and which not to? 267 00:16:44,520 --> 00:16:49,260 So all of this documentation is available on openwrt.org. 268 00:16:49,480 --> 00: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. 269 00:16:58,780 --> 00:17:01,820 OpenWrt community is well backed by people. 270 00:17:01,820 --> 00:17:05,600 You will find a lot of documentation, more than that you can handle. 271 00:17:05,880 --> 00:17:10,900 So from here, what I'll suggest is, don't mess with the base system. 272 00:17:10,900 --> 00:17:16,720 Most of the things there, unless you know these are the kernel modules that you need, don't go there. 273 00:17:16,800 --> 00:17:19,980 Because the things that you need are here. 274 00:17:20,280 --> 00: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. 275 00:17:32,140 --> 00:17:37,820 So this is how you actually select the things that you want to add. 276 00:17:37,820 --> 00:17:40,900 So right now, as you can see, Host is checked. 277 00:17:40,900 --> 00:17:47,160 This means it will be built as a part of the firmware when I build a firmware. 278 00:17:47,780 --> 00:17:51,560 You exit from it, again exit from it. 279 00:17:51,640 --> 00:17:54,880 Similarly, you have multiple options. 280 00:17:54,880 --> 00:17:58,260 So it is more than that I get cover even if it is a one day class. 281 00:18:00,480 --> 00:18:02,760 All you have to do is browse. 282 00:18:03,220 --> 00: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. 283 00:18:11,220 --> 00:18:15,840 After that you do exit, you do exit and it will save the file. 284 00:18:16,140 --> 00: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. 285 00:18:21,960 --> 00:18:23,280 Obviously, save it. 286 00:18:23,280 --> 00:18:30,300 So all the changes that we just did went into this file. 287 00:18:30,460 --> 00:18:33,960 So you can observe that this is the chipset. 288 00:18:33,960 --> 00: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. 289 00:18:43,920 --> 00:18:47,100 Y means they are selected, they will be built. 290 00:18:47,880 --> 00:18:50,900 After this, you don't have to do anything. 291 00:18:50,900 --> 00:18:55,020 Just do a make minus j 8. 292 00:18:55,020 --> 00:18:58,980 So minus j 8 is nothing but to run it in parallel. 293 00:18:58,980 --> 00:19:02,520 So it will be using 8 threads to compile it on parallel. 294 00:19:02,520 --> 00:19:04,500 Build systems are pretty heavy things. 295 00:19:04,500 --> 00: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. 296 00:19:10,840 --> 00:19:12,280 But that's the first run. 297 00:19:12,280 --> 00:19:16,080 Once you build all the basic things, the second run will be faster. 298 00:19:16,080 --> 00: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. 299 00:19:22,780 --> 00:19:25,800 Because the system that I am using is not that powerful. 300 00:19:25,920 --> 00:19:28,200 It is for the demo, right? 301 00:19:28,200 --> 00:19:30,740 It is not the main development machine that I use. 302 00:19:31,120 --> 00:19:39,260 So once you do that, now what you have to find is the firmware that is created. 303 00:19:39,540 --> 00:19:42,240 So in this case, I have already created it. 304 00:19:42,240 --> 00:19:47,720 But as soon as you run make minus j 8, it will be created for you. 305 00:19:48,000 --> 00:19:53,520 So the firmware images, they come with this extension called .bin, and that is it. 306 00:19:54,540 --> 00: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. 307 00:20:03,300 --> 00:20:08,600 And this is the firmware that you can now download and flash your device with. 308 00:20:08,600 --> 00: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. 309 00:20:16,160 --> 00:20:20,040 Because sometimes people, the first time they go crazy. 310 00:20:20,040 --> 00:20:22,680 They are like, I will put everything on the world in this. 311 00:20:22,760 --> 00:20:25,580 And then they build a big firmware, they are flashing it. 312 00:20:25,580 --> 00:20:31,520 Some of the devices are not smart enough to detect that you are building a bigger firmware for a smaller device. 313 00:20:31,520 --> 00:20:34,020 So when you will flash it, it will reject. 314 00:20:34,040 --> 00:20:35,160 It will not work. 315 00:20:35,160 --> 00:20:36,800 So don't blame me then. 316 00:20:36,800 --> 00:20:38,160 Check your size before. 317 00:20:39,120 --> 00:20:41,020 So this is how you do it. 318 00:20:41,680 --> 00:20:46,440 Now, coming to the main part that the talk is about. 319 00:20:46,800 --> 00:20:50,260 So, second thing that we want to build now. 320 00:20:50,280 --> 00:20:54,300 This is how you will be able to compile your own code. 321 00:20:54,300 --> 00:20:55,900 You can put it in the build system. 322 00:20:55,900 --> 00:20:58,460 There is a ton of documentation on it, how to do it. 323 00:20:58,460 --> 00:20:59,740 It is pretty easy. 324 00:20:59,780 --> 00:21:01,000 They have standard stuff. 325 00:21:01,000 --> 00:21:02,120 You have to put it here. 326 00:21:02,120 --> 00:21:03,740 Then you have to add a line here. 327 00:21:03,740 --> 00:21:08,120 All of 5-4 things you have to do and you will be able to build your own code. 328 00:21:08,720 --> 00:21:12,920 For all the available packages, you just need to select and you just need to run it. 329 00:21:13,380 --> 00:21:14,860 Now, coming to the third part. 330 00:21:14,860 --> 00:21:16,900 This is the user space we are talking, right? 331 00:21:16,900 --> 00:21:24,020 So now, bootkits or rootkits, when we are talking about them, we are more interested in the kernel-based rootkit. 332 00:21:27,260 --> 00:21:31,600 So, just to summarize, again, the same stuff. 333 00:21:31,740 --> 00:21:32,840 Selected it. 334 00:21:32,840 --> 00:21:37,080 You make a download directory when you are doing it on your system. 335 00:21:37,080 --> 00:21:39,000 Then you do a make-download. 336 00:21:39,000 --> 00:21:44,700 When you do a make-download, it will download all the packages that you have selected from the internet. 337 00:21:45,300 --> 00:21:48,820 And again, the last thing to do is make-jh. 338 00:21:49,540 --> 00:21:56,860 If you want to build only one package, instead of selecting it with space, you select it with m. 339 00:21:57,120 --> 00:22:00,040 So, m will make sure that it will be modularized. 340 00:22:00,040 --> 00: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. 341 00:22:06,080 --> 00:22:11,300 You can take that package to your device and you can install that using opkg install package name. 342 00:22:11,300 --> 00:22:16,180 Just like you do for Ubuntu using your dpkg for debian packages. 343 00:22:16,520 --> 00:22:18,980 So, in that case, you just need to do this. 344 00:22:19,180 --> 00:22:20,960 It will appear as m. 345 00:22:20,980 --> 00:22:25,100 And then this is the command where you have to mention the name of the package. 346 00:22:25,100 --> 00:22:27,180 And only this package will be compiled. 347 00:22:27,180 --> 00:22:33,000 So, I am not doing that because we are running late on time. 348 00:22:33,000 --> 00:22:35,020 Now, why kernel modules? 349 00:22:35,260 --> 00:22:41,180 Kernel modules, because when you load them, they are inserted into kernel, they run in kernel. 350 00:22:41,280 --> 00: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. 351 00:22:48,060 --> 00:22:51,020 So, no user process can actually do this. 352 00:22:51,020 --> 00:22:56,720 Even if it is privileged, it has to use a kernel module to make all of these changes. 353 00:22:56,720 --> 00: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. 354 00:23:04,520 --> 00:23:10,400 And even to make sure that you can create something which will be hidden from the user space. 355 00:23:10,400 --> 00:23:14,540 Even if you are running a demo or something on the user space, it will be hidden. 356 00:23:14,540 --> 00:23:18,140 It will be replying, it will be taking orders from other things. 357 00:23:18,480 --> 00:23:21,760 So , that's why the kernel modules are important here. 358 00:23:22,440 --> 00:23:26,160 Now, second question can be, can we directly insert kernel modules? 359 00:23:26,160 --> 00:23:31,140 On your Linux system, if you don't have root, no you cannot. 360 00:23:31,140 --> 00: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. 361 00:23:39,820 --> 00: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. 362 00:23:49,380 --> 00:23:53,020 And he can then insert his kernel module inside. 363 00:23:53,020 --> 00:23:57,740 So, we have build system ready. 364 00:23:57,780 --> 00:24:04,660 After that, you need the kernel code, kernel module code that we have created here, just to show you. 365 00:24:05,380 --> 00: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. 366 00:24:13,040 --> 00:24:17,160 Because build system is the one that you will be using to do all of this. 367 00:24:17,860 --> 00:24:21,000 You have to make sure that everything is in the path. 368 00:24:21,000 --> 00:24:25,360 All of these are just steps, you just need to file these commands on the build system. 369 00:24:26,160 --> 00: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. 370 00:24:34,680 --> 00:24:37,020 Because this thing here, it runs on MIPS. 371 00:24:37,200 --> 00:24:41,560 Almost all of your, these devices, small devices, they run on ARM, MIPS. 372 00:24:41,640 --> 00:24:47,940 You won't find a lot of these specially built things running on x86 or x86x64. 373 00:24:47,940 --> 00:24:51,000 So, for that reason, you have to cost compile it. 374 00:24:51,000 --> 00:24:54,580 Cost compile sounds difficult, but it is not. 375 00:24:54,580 --> 00:24:58,720 It's just one word that you have to define if you know what the word is. 376 00:24:59,360 --> 00:25:02,600 So, once you do that, you are ready. 377 00:25:02,980 --> 00:25:09,400 Once you have the kernel module, you can insert it using insmod, that's the command to insert it. 378 00:25:09,480 --> 00:25:15,420 lsmod is used to list it, and rmmod is used to remove the kernel module once you are done. 379 00:25:15,420 --> 00: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. 380 00:25:23,640 --> 00:25:25,220 So, this is how it looks. 381 00:25:25,680 --> 00:25:30,840 You know, if you are familiar with C language, these are the header files that we use. 382 00:25:31,860 --> 00: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. 383 00:25:42,220 --> 00:25:48,480 Similarly, you can also define a function, which will run when you take it out. 384 00:25:48,480 --> 00:25:50,980 So, these are the basic things. 385 00:25:50,980 --> 00:25:57,460 And even this knowledge is more than enough to create something, which can do pretty nasty stuff. 386 00:25:58,200 --> 00:26:01,580 This is the example here, because obviously it's a hello world. 387 00:26:01,580 --> 00:26:04,240 It will just print kernel logs. 388 00:26:04,760 --> 00:26:07,080 So, here we have two functions. 389 00:26:07,080 --> 00:26:13,420 First one here is the init function, which will be called when we insert it. 390 00:26:13,600 --> 00:26:18,240 It will just print, you know, hello cruel world of kernel programming to the kernel logs. 391 00:26:18,240 --> 00:26:20,200 Just to make sure, it's a POC, right? 392 00:26:20,200 --> 00:26:24,540 If it works, you can go forward, you can go for the more powerful code. 393 00:26:25,040 --> 00:26:28,320 Similarly, this one will run when you exit it. 394 00:26:29,040 --> 00:26:31,760 So, let's do one thing. 395 00:26:32,180 --> 00:26:33,940 Let's see all of that. 396 00:26:33,940 --> 00:26:39,020 So, in the rootkit code, you will find two folders. 397 00:26:39,300 --> 00:26:42,780 For now, you can just ignore the kernel space program. 398 00:26:42,780 --> 00:26:44,540 You go into kernel fun. 399 00:26:44,640 --> 00:26:46,260 You go into hello world. 400 00:26:46,840 --> 00:26:50,560 So, if you do ls-l, it will show you two files. 401 00:26:51,000 --> 00:26:53,140 Let's first check the hello world.c. 402 00:26:53,240 --> 00:26:55,340 It's the same file that we just saw. 403 00:26:55,340 --> 00:26:57,420 It has two simple functions. 404 00:26:57,820 --> 00:27:00,140 And these are the declarations. 405 00:27:00,280 --> 00:27:03,640 So, the code is written by my boss, you know, for this thing. 406 00:27:03,640 --> 00:27:04,960 His name is Vivek. 407 00:27:05,340 --> 00:27:07,280 That's why the name is Vivek. 408 00:27:07,280 --> 00:27:09,320 I'm not stealing code from third party. 409 00:27:09,480 --> 00:27:11,020 Just so that you know. 410 00:27:12,780 --> 00:27:17,720 And then, to compile these files, you use makefile. 411 00:27:17,900 --> 00: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. 412 00:27:26,500 --> 00:27:29,680 So, this is the simplest possible makefile one can make. 413 00:27:29,680 --> 00: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. 414 00:27:47,630 --> 00:27:50,750 Okay, so it actually ran into some error. 415 00:27:52,830 --> 00:27:54,450 Pretty strange. 416 00:28:03,520 --> 00:28:05,640 Must be missing some link. 417 00:28:05,960 --> 00:28:10,240 So, in a normal scenario, because you know, the demo gods, right? 418 00:28:10,240 --> 00:28:11,800 It was working in the morning. 419 00:28:12,140 --> 00:28:15,840 That's why I put it inside the machine. 420 00:28:16,480 --> 00:28:22,340 So, the thing is, on running nips make, it should run, if all the links are correct. 421 00:28:22,340 --> 00:28:26,240 So, you have to make these four links, as I was showing you here. 422 00:28:26,240 --> 00:28:28,760 One of these links are currently not working. 423 00:28:28,860 --> 00:28:33,940 So, you export staging directory, the path, and the kernel root. 424 00:28:33,940 --> 00:28:39,860 If one of these is messed up, then, you know, it will fail, just like it is failing right now. 425 00:28:39,860 --> 00: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. 426 00:28:45,900 --> 00:28:50,900 You cannot compile it for 4.9.152 and run it on something else. 427 00:28:50,900 --> 00:28:51,980 It won't work. 428 00:28:51,980 --> 00:28:54,020 That is one of the things that you have to do. 429 00:28:54,140 --> 00:28:55,360 You have to make sure. 430 00:28:55,360 --> 00: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. 431 00:29:04,840 --> 00: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. 432 00:29:14,300 --> 00: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. 433 00:29:23,120 --> 00:29:28,620 So, what we have done here is, we have emulated an openability system inside the lab. 434 00:29:29,420 --> 00: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. 435 00:29:37,140 --> 00:29:43,540 For all other practical reasons, it is MIPS, it is behaving like a complete Linux system. 436 00:29:44,660 --> 00: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. 437 00:29:57,280 --> 00:30:03,160 Once we do the Hello World, then we will move to the more advanced ones, which are of interest. 438 00:30:03,160 --> 00:30:08,120 Hello World, we all know, is just the POC, right? 439 00:30:08,120 --> 00: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. 440 00:30:20,100 --> 00:30:24,240 This one uses 4.9.53, I think. 441 00:30:24,700 --> 00:30:26,060 That one is different. 442 00:30:27,000 --> 00:30:32,380 So, as soon as you press this, it will boot just like the device. 443 00:30:33,760 --> 00: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. 444 00:30:47,160 --> 00:30:55,900 Now, before inserting it, you can use lsmod to check what are all the kernel modules already there. 445 00:30:56,400 --> 00: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. 446 00:31:08,180 --> 00:31:12,880 It is coming on console because, you know, as of now, we haven't set the debugging level. 447 00:31:13,060 --> 00:31:18,300 So, if I do n-1, it will not come anymore. 448 00:31:18,460 --> 00:31:24,460 We will be able to see it using dmessage, which shows the kernel messages, right? 449 00:31:25,740 --> 00:31:27,740 So, this is the POC thing, right? 450 00:31:27,740 --> 00: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. 451 00:31:35,880 --> 00:31:37,080 And there it is. 452 00:31:37,080 --> 00:31:41,040 I can again remove it using the Hello World. 453 00:31:42,100 --> 00:31:48,580 And if I do dmessage, it will also show that it existed, right? 454 00:31:48,580 --> 00: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. 455 00:31:55,720 --> 00:31:59,680 Now, coming to something, you know, which looks like hackish, right? 456 00:31:59,680 --> 00:32:01,660 Which looks like something of use. 457 00:32:02,060 --> 00:32:04,660 So, suppose you are running something in the user space, right? 458 00:32:04,660 --> 00: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? 459 00:32:13,540 --> 00:32:14,260 So, what do you do? 460 00:32:14,260 --> 00:32:15,540 You change the name of that. 461 00:32:15,540 --> 00: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. 462 00:32:23,800 --> 00: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? 463 00:32:31,680 --> 00:32:32,860 That's what we do. 464 00:32:33,260 --> 00:32:35,540 So, let's do that. 465 00:32:36,660 --> 00:32:41,740 So, if I do PS here, I should be able to see all of these, right? 466 00:32:42,020 --> 00:32:43,520 So, let's do one thing. 467 00:32:43,520 --> 00: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. 468 00:32:53,900 --> 00: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. 469 00:33:03,780 --> 00: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. 470 00:33:22,900 --> 00:33:26,120 Change mod is the kernel module here. 471 00:33:27,480 --> 00:33:32,980 In the PID, we have to provide the PID of the process for which we want to change the name. 472 00:33:33,340 --> 00:33:37,920 So, for example, this one here is a server daemon. 473 00:33:37,920 --> 00:33:39,660 So, let's do it for this. 474 00:33:39,820 --> 00:33:43,160 It's 2110. 475 00:33:46,280 --> 00:33:47,960 You do this. 476 00:33:48,340 --> 00:33:52,540 You do PS and there you go. 477 00:33:53,320 --> 00:33:54,080 Right? 478 00:33:54,120 --> 00:33:57,180 So, here we appended it so that we can find it easily. 479 00:33:57,180 --> 00:33:58,560 You can see it visually. 480 00:33:58,680 --> 00:34:00,860 We can also change it completely. 481 00:34:00,860 --> 00:34:03,000 We can make it look like something like this. 482 00:34:03,000 --> 00:34:03,600 Right? 483 00:34:03,600 --> 00:34:04,920 Something gibberish. 484 00:34:05,300 --> 00:34:08,740 That, you know, that the user will not be able to make sense out of. 485 00:34:08,740 --> 00:34:11,140 So, that's the first kind of thing that you can do. 486 00:34:12,160 --> 00: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. 487 00:34:26,320 --> 00: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. 488 00:34:38,600 --> 00:34:43,160 So, here is a quick description of NetFlipter architecture. 489 00:34:43,160 --> 00:34:46,280 It has multiple points where you can put hooks. 490 00:34:46,280 --> 00:34:48,300 These are also called hooks. 491 00:34:48,680 --> 00: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. 492 00:35:01,740 --> 00:35:07,260 Similarly, if machine generates the packets it goes out from here and it hits the point 5. 493 00:35:07,480 --> 00:35:13,780 Point 5 is the NFIP local out, which is the packet generated by the machine. 494 00:35:13,900 --> 00: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. 495 00:35:25,460 --> 00: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, 496 00:35:53,120 --> 00:35:55,520 for this one, we haven't put any logs. 497 00:35:55,520 --> 00: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. 498 00:36:07,960 --> 00:36:10,960 So, because you can observe here, there are no logs, right? 499 00:36:10,960 --> 00: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? 500 00:36:50,470 --> 00: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, 501 00:37:13,520 --> 00:37:14,160 right? 502 00:37:14,160 --> 00: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, 503 00:37:34,560 --> 00:37:40,180 whoever is issuing the command is sending those commands to your socket, right? 504 00:37:40,180 --> 00: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 505 00:38:02,050 --> 00: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, 506 00:38:28,830 --> 00:38:29,970 you plug it in 507 00:38:33,710 --> 00: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, 508 00:38:57,830 --> 00: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, 509 00:39:17,150 --> 00: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, 510 00:39:34,290 --> 00: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, 511 00:39:54,070 --> 00:39:54,550 so 512 00:39:59,230 --> 00: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, 513 00:40:40,150 --> 00: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, 514 00:40:59,610 --> 00: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, 515 00:41:15,450 --> 00: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, 516 00:41:32,850 --> 00: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, 517 00:41:50,450 --> 00: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, 518 00:42:12,550 --> 00: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, 519 00:42:29,910 --> 00: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, 520 00:42:55,940 --> 00: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, 521 00:43:19,660 --> 00: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 522 00:43:52,620 --> 00: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, 523 00:44:22,900 --> 00: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, 524 00:44:40,520 --> 00: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? 525 00:44:51,240 --> 00: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 526 00:45:12,380 --> 00: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, 527 00:45:35,720 --> 00: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, 528 00:45:57,760 --> 00: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, 529 00:46:23,880 --> 00: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, 530 00:46:43,920 --> 00: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, 531 00:47:17,620 --> 00: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, 532 00:47:34,820 --> 00: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, 533 00:48:03,040 --> 00: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. 534 00:48:17,160 --> 00: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. 535 00:48:25,380 --> 00:48:25,880 Thank you