Hey everybody! If you're standing next to a round table, you're in the wrong place. If you're sitting in a chair, you're in the correct place. If there's a chair next to you, put your hand up and make a friend. Everyone not sitting down, that's where your chairs are. There's lots of them. Please come in and sit down. And I'll tell you why. Because this fine man is going to teach you about more than you could possibly imagine in the next... How long did I actually give you? I said 15 minutes? 12. 12 minutes. He's got 12 minutes and he's going to go over how to build a rootkit on OpenWorks. It's going to be amazing. Take notes. You can play the recording back at 1 tenth speed and it will be amazing. So yeah, definitely watch the long version of this talk when you get home. The short version is going to be fun. I'm going to get out of the way and I'm going to let this fine gentleman talk. But seriously, everybody sit down. There are plenty of seats and you really want to hear this. Nishant, please. Thank you. Thank you all for coming, coming for my talk. And thanks to the... So he told me that... He told me that this one... So they already told me that the mic is a little hot. This one and this one is cold. So I was supposed to stay a little bit far from that. Again, thanks for coming for the workshop that I will be delivering. Thanks for the wireless village people for all the good work for bringing all of us wireless fans together. So as you can observe on the screens, the title of the workshop is developing Wi-Fi access point rootkits. My name is Nishant Sharma, as you can read. I work for Pentester Academy. Have you guys heard of it? Just show of hands. Oh, nice. Catch you after the talk. So yeah, we are a cyber security training company. We run PentesterAcademy.com, we run AttackDefense.com. A little bit about me so that you know why to trust me, right? When I'm teaching you, you need that credibility. So I work as R&D manager and the lead trainer at Pentester Academy. I conduct trainings on Wi-Fi for private clients. Just five days before I was conducting it for the black hat here, the Wi-Fi master class. Before joining Pentester Academy, I worked as a firmware engineer with one of the providers. My job was to create firmwares for the access points as well as for the wireless intrusion prevention systems. I have a master's degree in InfoSec, you know, doesn't matter still. I have been publishing my research in Black Hat, Defcon and other venues for the last four years. 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. So, you know, some of the pretty logos just so that you know. This is the PentesterAcademy.com. It's an online library. This is the AttackDefense.com. It's our online cyber range. The main thing about it is dedicated instances. Every player gets dedicated instances, no VPN, only the browser. We have multiple scenarios as well, not restricted to one user, one lab, you know, multiple labs, multiple machines. And done with the promotion. So, as you know, the workshop outline as you can observe, right? We'll talk about the rootkit. I am going to take OpenWRT as the main system on which we are going to do it. The reasons we will be covering. First, we will talk about OpenWRT. So, just for the lay of the land, right? How many of you are already aware of OpenWRT? Show of hands. Oh, that's good. That's better than, you know, than the other audiences I get. Oh, cool. So, yeah, we'll talk about OpenWRT. I'll quickly run through the introduction so that those people who do not know about it, it's a wonderful project. You should know about it if you are in Wi-Fi or even if you are concerned about your security. Then we will talk about how we actually create firmware. 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. There is a third way of doing that and we will be covering that. We'll talk about the user space applications, how you can compile them in firmware. Apart from that, then we will also talk about the kernel-based rootkits. That's the main takeaway. But to get there, these are the steps, right? These are the baby steps that you take. 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. So, access point security, right? Everyone is talking about Wi-Fi security, especially the enterprises, right? WPA3 standard just came out, WPA2, PSK enterprise, pretty secure, right? WEP was the bad one, already out of the market. But when it comes to the security of Wi-Fi routers, not everyone is that aware. When we talk about enterprise gate access points, yes, they are doing a good job. How good? Again, debatable. 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? You use them at your home, you use that at the small business venues that you have, right? Most of the time you're running WPA2, PSK. 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? So they run for years till the time they break. 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? So that is something that is not right. We have seen multiple reports, multiple events in which Wi-Fi routers were hacked. You know, there are multiple vectors. Some of you don't change their default password. Some of the routers have vendor-installed firmware backdoors. Some of them are using weak passwords. Some of them are exposed to internet over SSH or web UI. There are multiple ways. So the problem is, once your router is compromised, there is a plethora of attacks that other people can do. So it's like giving the command and control of your internet to somebody who you don't know, right? Some of the issues can be the passive monitoring. Because it's the router that sends all the traffic out, all the Wi-Fi traffic out. So once they are on it, just one line change can direct all of your traffic to their server. They can do passive analysis there. They can do active MIPM there. 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. And then they are using it to attack some third party, which is obviously not good. It's your infra, right? They should not be able to do that. So what kind of malwares are there and what they can do? We have already discussed, you know, worms. We have seen worms. We have seen rootkits, spywares, trojans, all kind of things are now moving to the router space as well. The problem is because they are neglected, no antivirus or heads is running on most of the routers. You don't even know if you get hacked, right? So that's one of the issues. Access point rootkits, one of the subpart of the other malware. It's important because this is the one which actually helps all of the payload, all of the other payload to stay hidden. So we will see how actually they are doing it. 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. A special case of rootkits is bootkits. If you are interested, really good things. Coming to OpenWrt, OpenWrt is an embedded operating system which again is based on Linux. It uses Linux kernel, it uses utils like you have in your Linux. 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. The only difference is everything, just so that it can run on a cheap hardware, is cut down on the functionality. It has less command, it has less power, all of that. It comes with the Ash cell, just like you use your Bash or SH on Linux, it comes with ASH. It uses BusyBox for all the commands, all the commands put in one binary so that it is lightweight, only that. It uses Lucy as its web UI so that you can configure it easily. And just like your Ubuntu has apt-get, it has opkg so you can actually install things on it. It supports routers, residential gateways, smartphones, and that was one of the reasons why we actually chose this one to do all of this. It's the most popular open source firmware out there. Currently it has 3500 plus packages. So when I say packages, these are the kind of softwares, tools that are already there. You just need an opkg install to install them and run them. It supports more than 1200 devices. These devices are of each range. You have devices which are up for $20 or $30. You have devices which can go up to $1000 as well. So depending on the need that you have, you can use this thing to create your custom gadgets. You can create your custom snippers because 11ac is coming in. So the WiFi monitoring that you used to do on your conventional A, B, G, or N, now that has become more difficult. So all of this can be helped. All of this is that OpenWrt can help, but that is not the topic. So what we will discuss about first is the OpenWrt build system. A lot of people who are using OpenWrt, even they don't like to compile their own firmware. Why? Because it is messy. Or that's what people think. It's not, but that's the way things are. So what we will learn is how you can actually create your own build system. Don't worry about noting down the commands. I'll make sure that these slides are available to you. So you can actually use them. I have simplified everything so that you don't run into errors. You can use them to build your own things. And for now, I have already created a build system that you guys can also use if you like to. You can go back, you can use it that time if that is the case. So first, for the simplest scenario, we go with Ubuntu. Because Ubuntu is the simplest. You do your apt-get and update and upgrade. Pretty standard. Then these are the dependencies that you have to install to build the system. The reason of explaining all of this is so that you can do it. It's a workshop. It's not the cutting-edge research talk that we give. That you are used to. But this is something that you can actually go back and do on your own. After that, you add a low-privileged user. Because otherwise it creates problems when you build some packages. You switch to its home repository. And as I said, OpenWrt is open source. So it is on GitHub. You can download the latest stable version. I will always recommend you to go for the stable version. Don't go for the trunk. Don't go for the branch that is under development. It has active bugs. It has build issues. So you know, most of the time you will be wasting your time. So go for the stable one. Current stable one is 18.06.4. The one I am using here is 0.2. Doesn't matter. Not that much of difference. First you take it. You unzip it. Why? Because you know, it's zipped. You have to. And then we use the makemenuconfig command to select the hardware that we want to build for it. Don't worry. These are just the steps. We are going to see how to do it in practical as well. You have to then update the feeds and install them. Feeds are nothing but the kind of software tools that you can add while you are building all of this. And I have a build ready setup here. So I will be using that. And the internet is back. That's a good thing. So this is the attack defense lab I was talking about. It's the community section of attack defense lab. So what I have done is, if you guys want to try it back home, you can actually go here. You can log in with your Google account. You don't need a paid subscription. Just go here, free labs. 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. You choose the server which is nearest to you. Obviously for the latency reasons. You give it 25 seconds. In 25 seconds it will spin a dedicated thing for you. If you are doing it right now, you will get another thing. I will get another setup. So that's how it is. 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. So you can actually directly copy paste them and they will work. Because I have ran them like for 50-100 times I have used them. So they work. Once the lab is ready, you go inside the lab. So the lab is only to practice. If you really want to create your own, you have to do it on your own machine. Because for security reasons, our labs are contained. Nothing goes in, nothing comes out. It's like that. So now, what I have done here is, I have created... I have taken the code from GitHub. This is how the build system looks like. Now as I was telling you, we have to do a make-menu-config. So all the commands before it, they only tell you how to build this setup. 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. You do make-menu-config. It will throw a small UI so that you can select stuff. As you can see here. First step, as you can observe, is to select the card that you have. The kind of card or the kind of architecture your machine supports. Very easy to guess. You can directly use your box to check for it. If you see QCA or Qualcomm Atheros, it means you are using Atheros of some kind. If you check the datasheet or the booksheet that comes with it, you will be able to find this number. So here I am using for this one. This is the sub-target one. If you don't know what you are doing, don't touch it. Generic will work for everything. No need to touch it. Target profile, here are the device profiles that are under that architecture. So from here, you can select the device that you want to build it for. So I am using AR750. It's a pretty thrifty device. This is the one. It's a travel router. Very cheap, $50. You can get it on Amazon or any other website. The delivery is throughout the world. So first, you do that. Now if you pay attention here, you will see multiple kind of things. If I go to the base system, all of these things are the packages. Now the second question is, how would you know which packages to install and which not to? So all of this documentation is available on openwrt.org. All the main things that you need for mounting the USB, mounting something else, like a SD card or something, you search for it. OpenWrt community is well backed by people. You will find a lot of documentation, more than that you can handle. So from here, what I'll suggest is, don't mess with the base system. Most of the things there, unless you know these are the kernel modules that you need, don't go there. Because the things that you need are here. So if we are talking about building your own attack gadget, If you go here, you will see Aircrack, Airmon, Host and what not. So this is how you actually select the things that you want to add. So right now, as you can see, Host is checked. This means it will be built as a part of the firmware when I build a firmware. You exit from it, again exit from it. Similarly, you have multiple options. So it is more than that I get cover even if it is a one day class. All you have to do is browse. 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. After that you do exit, you do exit and it will save the file. 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. Obviously, save it. So all the changes that we just did went into this file. So you can observe that this is the chipset. 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. Y means they are selected, they will be built. After this, you don't have to do anything. Just do a make minus j 8. So minus j 8 is nothing but to run it in parallel. So it will be using 8 threads to compile it on parallel. Build systems are pretty heavy things. When you build them for the first time, you should have a powerful machine, otherwise it is going to take you hours. But that's the first run. Once you build all the basic things, the second run will be faster. 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. Because the system that I am using is not that powerful. It is for the demo, right? It is not the main development machine that I use. So once you do that, now what you have to find is the firmware that is created. So in this case, I have already created it. But as soon as you run make minus j 8, it will be created for you. So the firmware images, they come with this extension called .bin, and that is it. 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. And this is the firmware that you can now download and flash your device with. 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. Because sometimes people, the first time they go crazy. They are like, I will put everything on the world in this. And then they build a big firmware, they are flashing it. Some of the devices are not smart enough to detect that you are building a bigger firmware for a smaller device. So when you will flash it, it will reject. It will not work. So don't blame me then. Check your size before. So this is how you do it. Now, coming to the main part that the talk is about. So, second thing that we want to build now. This is how you will be able to compile your own code. You can put it in the build system. There is a ton of documentation on it, how to do it. It is pretty easy. They have standard stuff. You have to put it here. Then you have to add a line here. All of 5-4 things you have to do and you will be able to build your own code. For all the available packages, you just need to select and you just need to run it. Now, coming to the third part. This is the user space we are talking, right? So now, bootkits or rootkits, when we are talking about them, we are more interested in the kernel-based rootkit. So, just to summarize, again, the same stuff. Selected it. You make a download directory when you are doing it on your system. Then you do a make-download. When you do a make-download, it will download all the packages that you have selected from the internet. And again, the last thing to do is make-jh. If you want to build only one package, instead of selecting it with space, you select it with m. So, m will make sure that it will be modularized. So, thing is, if you don't want to flash the complete device, you have option that you can create a package. You can take that package to your device and you can install that using opkg install package name. Just like you do for Ubuntu using your dpkg for debian packages. So, in that case, you just need to do this. It will appear as m. And then this is the command where you have to mention the name of the package. And only this package will be compiled. So, I am not doing that because we are running late on time. Now, why kernel modules? Kernel modules, because when you load them, they are inserted into kernel, they run in kernel. And due to that thing, they can access the kind of structure, the kind of memory that is there in the kernel side. So, no user process can actually do this. Even if it is privileged, it has to use a kernel module to make all of these changes. 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. And even to make sure that you can create something which will be hidden from the user space. Even if you are running a demo or something on the user space, it will be hidden. It will be replying, it will be taking orders from other things. So, that's why the kernel modules are important here. Now, second question can be, can we directly insert kernel modules? On your Linux system, if you don't have root, no you cannot. 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. 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. And he can then insert his kernel module inside. So, we have build system ready. After that, you need the kernel code, kernel module code that we have created here, just to show you. After that, you need to make sure that your kernel code, when you are compiling it, can link to the build system. Because build system is the one that you will be using to do all of this. You have to make sure that everything is in the path. All of these are just steps, you just need to file these commands on the build system. 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. Because this thing here, it runs on MIPS. Almost all of your, these devices, small devices, they run on ARM, MIPS. You won't find a lot of these specially built things running on x86 or x86x64. So, for that reason, you have to cost compile it. Cost compile sounds difficult, but it is not. It's just one word that you have to define if you know what the word is. So, once you do that, you are ready. Once you have the kernel module, you can insert it using insmod, that's the command to insert it. lsmod is used to list it, and rmmod is used to remove the kernel module once you are done. So, what we will do now, is we will see a hello world module, which we have written just for this class. So, this is how it looks. You know, if you are familiar with C language, these are the header files that we use. These are important here, because your module in it defines the function, which will be executed as soon as your kernel module loads in. Similarly, you can also define a function, which will run when you take it out. So, these are the basic things. And even this knowledge is more than enough to create something, which can do pretty nasty stuff. This is the example here, because obviously it's a hello world. It will just print kernel logs. So, here we have two functions. First one here is the init function, which will be called when we insert it. It will just print, you know, hello cruel world of kernel programming to the kernel logs. Just to make sure, it's a POC, right? If it works, you can go forward, you can go for the more powerful code. Similarly, this one will run when you exit it. So, let's do one thing. Let's see all of that. So, in the rootkit code, you will find two folders. For now, you can just ignore the kernel space program. You go into kernel fun. You go into hello world. So, if you do ls-l, it will show you two files. Let's first check the hello world.c. It's the same file that we just saw. It has two simple functions. And these are the declarations. So, the code is written by my boss, you know, for this thing. His name is Vivek. That's why the name is Vivek. I'm not stealing code from third party. Just so that you know. And then, to compile these files, you use makefile. 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. So, this is the simplest possible makefile one can make. 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. Okay, so it actually ran into some error. Pretty strange. Must be missing some link. So, in a normal scenario, because you know, the demo gods, right? It was working in the morning. That's why I put it inside the machine. So, the thing is, on running nips make, it should run, if all the links are correct. So, you have to make these four links, as I was showing you here. One of these links are currently not working. So, you export staging directory, the path, and the kernel root. If one of these is messed up, then, you know, it will fail, just like it is failing right now. You have to make sure that, you know, the kernel that you are targeting, you are only running it on the same kernel. You cannot compile it for 4.9.152 and run it on something else. It won't work. That is one of the things that you have to do. You have to make sure. 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. So, what we will do now is, I have compiled these already, because, you know, I had to show you how they run. 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. So, what we have done here is, we have emulated an openability system inside the lab. So, in this, you know, it will behave just like this device, apart from the Wi-Fi thing, because obviously, no physical antennas. For all other practical reasons, it is MIPS, it is behaving like a complete Linux system. 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. Once we do the Hello World, then we will move to the more advanced ones, which are of interest. Hello World, we all know, is just the POC, right? 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. This one uses 4.9.53, I think. That one is different. So, as soon as you press this, it will boot just like the device. 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. Now, before inserting it, you can use lsmod to check what are all the kernel modules already there. Now, if you do nsmod, for the Hello World kernel module, you will observe that this is the kernel log that is being printed. It is coming on console because, you know, as of now, we haven't set the debugging level. So, if I do n-1, it will not come anymore. We will be able to see it using dmessage, which shows the kernel messages, right? So, this is the POC thing, right? Now, if I want to check if it was inserted, I will just do lsmod and I will grab for the Hello World. And there it is. I can again remove it using the Hello World. And if I do dmessage, it will also show that it existed, right? 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. Now, coming to something, you know, which looks like hackish, right? Which looks like something of use. So, suppose you are running something in the user space, right? 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? So, what do you do? You change the name of that. 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. They will just assume that it is one of the system things that run on Linux and that is beyond my understanding, right? That's what we do. So, let's do that. So, if I do PS here, I should be able to see all of these, right? So, let's do one thing. 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. 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. 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. Change mod is the kernel module here. In the PID, we have to provide the PID of the process for which we want to change the name. So, for example, this one here is a server daemon. So, let's do it for this. It's 2110. You do this. You do PS and there you go. Right? So, here we appended it so that we can find it easily. You can see it visually. We can also change it completely. We can make it look like something like this. Right? Something gibberish. That, you know, that the user will not be able to make sense out of. So, that's the first kind of thing that you can do. 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. 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. So, here is a quick description of NetFlipter architecture. It has multiple points where you can put hooks. These are also called hooks. 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. Similarly, if machine generates the packets it goes out from here and it hits the point 5. Point 5 is the NFIP local out, which is the packet generated by the machine. 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. 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, for this one, we haven't put any logs. 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. So, because you can observe here, there are no logs, right? 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? 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, right? 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, whoever is issuing the command is sending those commands to your socket, right? 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 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, you plug it in 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, 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, 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, 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, so 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, 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, 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, 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, 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, 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, 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, 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, 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, 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 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, 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, 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? 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 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, 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, 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, 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, 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, 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, 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, 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. 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. Thank you