start	end	text
0	4880	Hey everybody! If you're standing next to a round table, you're in the wrong place.
5040	7600	If you're sitting in a chair, you're in the correct place.
7600	10980	If there's a chair next to you, put your hand up and make a friend.
11060	15100	Everyone not sitting down, that's where your chairs are. There's lots of them.
15100	18420	Please come in and sit down. And I'll tell you why.
18560	23420	Because this fine man is going to teach you about more than you could possibly imagine in the next...
23420	26000	How long did I actually give you? I said 15 minutes?
26000	31660	12. 12 minutes. He's got 12 minutes and he's going to go over how to build a rootkit on OpenWorks.
31660	33840	It's going to be amazing. Take notes.
33840	38220	You can play the recording back at 1 tenth speed and it will be amazing.
38840	42740	So yeah, definitely watch the long version of this talk when you get home.
42740	44260	The short version is going to be fun.
44300	46960	I'm going to get out of the way and I'm going to let this fine gentleman talk.
46960	52220	But seriously, everybody sit down. There are plenty of seats and you really want to hear this.
52700	54020	Nishant, please.
54020	54540	Thank you.
60540	63220	Thank you all for coming, coming for my talk.
63220	64760	And thanks to the...
66380	67700	So he told me that...
67700	72180	He told me that this one...
72180	76520	So they already told me that the mic is a little hot.
76520	79500	This one and this one is cold.
79500	82760	So I was supposed to stay a little bit far from that.
82840	87140	Again, thanks for coming for the workshop that I will be delivering.
87140	93320	Thanks for the wireless village people for all the good work for bringing all of us wireless fans together.
93720	102140	So as you can observe on the screens, the title of the workshop is developing Wi-Fi access point rootkits.
102460	105700	My name is Nishant Sharma, as you can read.
106300	108720	I work for Pentester Academy.
108980	111820	Have you guys heard of it? Just show of hands.
112060	115320	Oh, nice. Catch you after the talk.
115320	119000	So yeah, we are a cyber security training company.
119000	123340	We run PentesterAcademy.com, we run AttackDefense.com.
123760	127080	A little bit about me so that you know why to trust me, right?
127080	129540	When I'm teaching you, you need that credibility.
130220	136180	So I work as R&D manager and the lead trainer at Pentester Academy.
136520	140000	I conduct trainings on Wi-Fi for private clients.
140020	144800	Just five days before I was conducting it for the black hat here, the Wi-Fi master class.
145540	150800	Before joining Pentester Academy, I worked as a firmware engineer with one of the providers.
151120	158620	My job was to create firmwares for the access points as well as for the wireless intrusion prevention systems.
158920	163360	I have a master's degree in InfoSec, you know, doesn't matter still.
163900	170140	I have been publishing my research in Black Hat, Defcon and other venues for the last four years.
170140	181900	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.
182200	187320	So, you know, some of the pretty logos just so that you know.
187720	192080	This is the PentesterAcademy.com. It's an online library.
192080	197500	This is the AttackDefense.com. It's our online cyber range.
197500	201700	The main thing about it is dedicated instances.
201700	205620	Every player gets dedicated instances, no VPN, only the browser.
206360	213660	We have multiple scenarios as well, not restricted to one user, one lab, you know, multiple labs, multiple machines.
213780	215780	And done with the promotion.
216300	221780	So, as you know, the workshop outline as you can observe, right?
221780	224240	We'll talk about the rootkit.
224240	230020	I am going to take OpenWRT as the main system on which we are going to do it.
230120	232360	The reasons we will be covering.
232860	235420	First, we will talk about OpenWRT.
235420	238400	So, just for the lay of the land, right?
238400	241700	How many of you are already aware of OpenWRT?
241700	242760	Show of hands.
243220	247640	Oh, that's good. That's better than, you know, than the other audiences I get.
247640	248680	Oh, cool.
248960	251720	So, yeah, we'll talk about OpenWRT.
251720	257160	I'll quickly run through the introduction so that those people who do not know about it, it's a wonderful project.
257160	262880	You should know about it if you are in Wi-Fi or even if you are concerned about your security.
262980	266600	Then we will talk about how we actually create firmware.
266860	275360	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.
275500	279620	There is a third way of doing that and we will be covering that.
280380	285660	We'll talk about the user space applications, how you can compile them in firmware.
285660	290480	Apart from that, then we will also talk about the kernel-based rootkits.
290480	295380	That's the main takeaway. But to get there, these are the steps, right?
295380	297240	These are the baby steps that you take.
297620	307600	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.
308420	311000	So, access point security, right?
311000	315000	Everyone is talking about Wi-Fi security, especially the enterprises, right?
315000	320320	WPA3 standard just came out, WPA2, PSK enterprise, pretty secure, right?
320320	324100	WEP was the bad one, already out of the market.
324200	329360	But when it comes to the security of Wi-Fi routers, not everyone is that aware.
329460	333980	When we talk about enterprise gate access points, yes, they are doing a good job.
334220	336340	How good? Again, debatable.
336340	340960	But still, when we talk about the SOHO routers, right, as we like to call them,
340960	343740	SOHO stands for your small office, home office, right?
343740	349280	You use them at your home, you use that at the small business venues that you have, right?
349300	351880	Most of the time you're running WPA2, PSK.
351960	359900	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?
359900	362980	So they run for years till the time they break.
362980	368860	And they're running, and you know, you're just happy that you have a good password on WPA2, PSK,
368860	370620	and you think that you're unhackable, right?
370620	373120	So that is something that is not right.
373280	380720	We have seen multiple reports, multiple events in which Wi-Fi routers were hacked.
381080	382740	You know, there are multiple vectors.
382740	385760	Some of you don't change their default password.
385760	390020	Some of the routers have vendor-installed firmware backdoors.
390020	391940	Some of them are using weak passwords.
391940	396200	Some of them are exposed to internet over SSH or web UI.
396200	398140	There are multiple ways.
398200	404980	So the problem is, once your router is compromised, there is a plethora of attacks that other people can do.
405020	411880	So it's like giving the command and control of your internet to somebody who you don't know, right?
411880	415100	Some of the issues can be the passive monitoring.
415100	420960	Because it's the router that sends all the traffic out, all the Wi-Fi traffic out.
421000	426900	So once they are on it, just one line change can direct all of your traffic to their server.
426900	430680	They can do passive analysis there. They can do active MIPM there.
431100	438880	And on top of that, for a few years, for a few past years, we have seen occurrences where botnets were there,
438880	444520	who actually took over the routers, then infected other things that were running on the network.
444520	448780	And then they are using it to attack some third party, which is obviously not good.
448780	452040	It's your infra, right? They should not be able to do that.
453020	456700	So what kind of malwares are there and what they can do?
457000	461020	We have already discussed, you know, worms. We have seen worms.
461020	468100	We have seen rootkits, spywares, trojans, all kind of things are now moving to the router space as well.
468100	475920	The problem is because they are neglected, no antivirus or heads is running on most of the routers.
476060	480000	You don't even know if you get hacked, right? So that's one of the issues.
481600	486700	Access point rootkits, one of the subpart of the other malware.
486880	493320	It's important because this is the one which actually helps all of the payload, all of the other payload to stay hidden.
493340	496200	So we will see how actually they are doing it.
496200	504340	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.
504340	511000	A special case of rootkits is bootkits. If you are interested, really good things.
511440	518360	Coming to OpenWrt, OpenWrt is an embedded operating system which again is based on Linux.
518360	524200	It uses Linux kernel, it uses utils like you have in your Linux.
524200	534860	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.
534860	542740	The only difference is everything, just so that it can run on a cheap hardware, is cut down on the functionality.
542840	546020	It has less command, it has less power, all of that.
546020	555260	It comes with the Ash cell, just like you use your Bash or SH on Linux, it comes with ASH.
555280	562960	It uses BusyBox for all the commands, all the commands put in one binary so that it is lightweight, only that.
563060	567880	It uses Lucy as its web UI so that you can configure it easily.
568140	574520	And just like your Ubuntu has apt-get, it has opkg so you can actually install things on it.
575400	584820	It supports routers, residential gateways, smartphones, and that was one of the reasons why we actually chose this one to do all of this.
585120	589340	It's the most popular open source firmware out there.
589340	592920	Currently it has 3500 plus packages.
592920	597260	So when I say packages, these are the kind of softwares, tools that are already there.
597260	600480	You just need an opkg install to install them and run them.
600480	603440	It supports more than 1200 devices.
603440	605960	These devices are of each range.
605960	608840	You have devices which are up for $20 or $30.
608840	612840	You have devices which can go up to $1000 as well.
612840	618400	So depending on the need that you have, you can use this thing to create your custom gadgets.
618400	623500	You can create your custom snippers because 11ac is coming in.
623500	632940	So the WiFi monitoring that you used to do on your conventional A, B, G, or N, now that has become more difficult.
633520	635440	So all of this can be helped.
635500	639880	All of this is that OpenWrt can help, but that is not the topic.
640400	645900	So what we will discuss about first is the OpenWrt build system.
645980	651800	A lot of people who are using OpenWrt, even they don't like to compile their own firmware.
651800	653580	Why? Because it is messy.
653580	655380	Or that's what people think.
655380	658700	It's not, but that's the way things are.
658860	664480	So what we will learn is how you can actually create your own build system.
664480	666800	Don't worry about noting down the commands.
666800	671780	I'll make sure that these slides are available to you.
671780	673220	So you can actually use them.
673220	676820	I have simplified everything so that you don't run into errors.
676960	679940	You can use them to build your own things.
679940	686160	And for now, I have already created a build system that you guys can also use if you like to.
686160	689960	You can go back, you can use it that time if that is the case.
691060	694720	So first, for the simplest scenario, we go with Ubuntu.
694720	696880	Because Ubuntu is the simplest.
696980	700480	You do your apt-get and update and upgrade.
700600	701640	Pretty standard.
702400	706360	Then these are the dependencies that you have to install to build the system.
706360	711000	The reason of explaining all of this is so that you can do it.
711000	714880	It's a workshop. It's not the cutting-edge research talk that we give.
714960	717220	That you are used to.
717220	721000	But this is something that you can actually go back and do on your own.
721840	724140	After that, you add a low-privileged user.
724140	727760	Because otherwise it creates problems when you build some packages.
728280	730080	You switch to its home repository.
730500	734060	And as I said, OpenWrt is open source.
734060	735480	So it is on GitHub.
735480	738660	You can download the latest stable version.
738740	741260	I will always recommend you to go for the stable version.
741260	742600	Don't go for the trunk.
742640	745160	Don't go for the branch that is under development.
745160	746920	It has active bugs.
746920	748160	It has build issues.
748160	750580	So you know, most of the time you will be wasting your time.
750600	752060	So go for the stable one.
752080	754980	Current stable one is 18.06.4.
755340	757500	The one I am using here is 0.2.
757500	759880	Doesn't matter. Not that much of difference.
760180	762060	First you take it. You unzip it.
762060	763660	Why? Because you know, it's zipped.
763660	764580	You have to.
764580	772000	And then we use the makemenuconfig command to select the hardware that we want to build for it.
772000	773600	Don't worry. These are just the steps.
773600	776600	We are going to see how to do it in practical as well.
777700	781920	You have to then update the feeds and install them.
781920	787020	Feeds are nothing but the kind of software tools that you can add while you are building all of this.
787540	791100	And I have a build ready setup here.
791100	792740	So I will be using that.
792740	794020	And the internet is back.
794620	796060	That's a good thing.
796260	798660	So this is the attack defense lab I was talking about.
798660	801180	It's the community section of attack defense lab.
801220	806940	So what I have done is, if you guys want to try it back home, you can actually go here.
806940	808960	You can log in with your Google account.
808960	810500	You don't need a paid subscription.
810720	812680	Just go here, free labs.
813300	819260	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.
820280	823780	You choose the server which is nearest to you.
823780	825540	Obviously for the latency reasons.
825860	827140	You give it 25 seconds.
827140	831300	In 25 seconds it will spin a dedicated thing for you.
831400	834960	If you are doing it right now, you will get another thing.
834960	836320	I will get another setup.
836320	837720	So that's how it is.
838260	847400	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.
847400	852120	So you can actually directly copy paste them and they will work.
852120	856280	Because I have ran them like for 50-100 times I have used them.
856280	857320	So they work.
858160	861460	Once the lab is ready, you go inside the lab.
861680	864280	So the lab is only to practice.
864280	868080	If you really want to create your own, you have to do it on your own machine.
868080	871040	Because for security reasons, our labs are contained.
871040	872780	Nothing goes in, nothing comes out.
872780	873840	It's like that.
874940	880800	So now, what I have done here is, I have created...
881600	884520	I have taken the code from GitHub.
885140	888240	This is how the build system looks like.
888500	897250	Now as I was telling you, we have to do a make-menu-config.
897310	902210	So all the commands before it, they only tell you how to build this setup.
902210	909330	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.
909770	911510	You do make-menu-config.
911510	916450	It will throw a small UI so that you can select stuff.
916770	918050	As you can see here.
918270	923150	First step, as you can observe, is to select the card that you have.
923150	926450	The kind of card or the kind of architecture your machine supports.
926590	927950	Very easy to guess.
928090	931390	You can directly use your box to check for it.
931390	937550	If you see QCA or Qualcomm Atheros, it means you are using Atheros of some kind.
937550	942290	If you check the datasheet or the booksheet that comes with it, you will be able to find this number.
942670	945230	So here I am using for this one.
945810	947870	This is the sub-target one.
947870	950530	If you don't know what you are doing, don't touch it.
950530	952890	Generic will work for everything.
953230	954610	No need to touch it.
954870	959930	Target profile, here are the device profiles that are under that architecture.
959930	964670	So from here, you can select the device that you want to build it for.
964790	966990	So I am using AR750.
967290	969390	It's a pretty thrifty device.
976860	978320	This is the one.
978320	979640	It's a travel router.
979640	981260	Very cheap, $50.
981260	984900	You can get it on Amazon or any other website.
985020	986880	The delivery is throughout the world.
987640	990200	So first, you do that.
990200	994600	Now if you pay attention here, you will see multiple kind of things.
994600	1000000	If I go to the base system, all of these things are the packages.
1000200	1004520	Now the second question is, how would you know which packages to install and which not to?
1004520	1009260	So all of this documentation is available on openwrt.org.
1009480	1018740	All the main things that you need for mounting the USB, mounting something else, like a SD card or something, you search for it.
1018780	1021820	OpenWrt community is well backed by people.
1021820	1025600	You will find a lot of documentation, more than that you can handle.
1025880	1030900	So from here, what I'll suggest is, don't mess with the base system.
1030900	1036720	Most of the things there, unless you know these are the kernel modules that you need, don't go there.
1036800	1039980	Because the things that you need are here.
1040280	1045880	So if we are talking about building your own attack gadget,
1045880	1051960	If you go here, you will see Aircrack, Airmon, Host and what not.
1052140	1057820	So this is how you actually select the things that you want to add.
1057820	1060900	So right now, as you can see, Host is checked.
1060900	1067160	This means it will be built as a part of the firmware when I build a firmware.
1067780	1071560	You exit from it, again exit from it.
1071640	1074880	Similarly, you have multiple options.
1074880	1078260	So it is more than that I get cover even if it is a one day class.
1080480	1082760	All you have to do is browse.
1083220	1090700	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.
1091220	1095840	After that you do exit, you do exit and it will save the file.
1096140	1101960	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.
1101960	1103280	Obviously, save it.
1103280	1110300	So all the changes that we just did went into this file.
1110460	1113960	So you can observe that this is the chipset.
1113960	1123920	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.
1123920	1127100	Y means they are selected, they will be built.
1127880	1130900	After this, you don't have to do anything.
1130900	1135020	Just do a make minus j 8.
1135020	1138980	So minus j 8 is nothing but to run it in parallel.
1138980	1142520	So it will be using 8 threads to compile it on parallel.
1142520	1144500	Build systems are pretty heavy things.
1144500	1150580	When you build them for the first time, you should have a powerful machine, otherwise it is going to take you hours.
1150840	1152280	But that's the first run.
1152280	1156080	Once you build all the basic things, the second run will be faster.
1156080	1162780	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.
1162780	1165800	Because the system that I am using is not that powerful.
1165920	1168200	It is for the demo, right?
1168200	1170740	It is not the main development machine that I use.
1171120	1179260	So once you do that, now what you have to find is the firmware that is created.
1179540	1182240	So in this case, I have already created it.
1182240	1187720	But as soon as you run make minus j 8, it will be created for you.
1188000	1193520	So the firmware images, they come with this extension called .bin, and that is it.
1194540	1202680	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.
1203300	1208600	And this is the firmware that you can now download and flash your device with.
1208600	1216160	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.
1216160	1220040	Because sometimes people, the first time they go crazy.
1220040	1222680	They are like, I will put everything on the world in this.
1222760	1225580	And then they build a big firmware, they are flashing it.
1225580	1231520	Some of the devices are not smart enough to detect that you are building a bigger firmware for a smaller device.
1231520	1234020	So when you will flash it, it will reject.
1234040	1235160	It will not work.
1235160	1236800	So don't blame me then.
1236800	1238160	Check your size before.
1239120	1241020	So this is how you do it.
1241680	1246440	Now, coming to the main part that the talk is about.
1246800	1250260	So, second thing that we want to build now.
1250280	1254300	This is how you will be able to compile your own code.
1254300	1255900	You can put it in the build system.
1255900	1258460	There is a ton of documentation on it, how to do it.
1258460	1259740	It is pretty easy.
1259780	1261000	They have standard stuff.
1261000	1262120	You have to put it here.
1262120	1263740	Then you have to add a line here.
1263740	1268120	All of 5-4 things you have to do and you will be able to build your own code.
1268720	1272920	For all the available packages, you just need to select and you just need to run it.
1273380	1274860	Now, coming to the third part.
1274860	1276900	This is the user space we are talking, right?
1276900	1284020	So now, bootkits or rootkits, when we are talking about them, we are more interested in the kernel-based rootkit.
1287260	1291600	So, just to summarize, again, the same stuff.
1291740	1292840	Selected it.
1292840	1297080	You make a download directory when you are doing it on your system.
1297080	1299000	Then you do a make-download.
1299000	1304700	When you do a make-download, it will download all the packages that you have selected from the internet.
1305300	1308820	And again, the last thing to do is make-jh.
1309540	1316860	If you want to build only one package, instead of selecting it with space, you select it with m.
1317120	1320040	So, m will make sure that it will be modularized.
1320040	1326080	So, thing is, if you don't want to flash the complete device, you have option that you can create a package.
1326080	1331300	You can take that package to your device and you can install that using opkg install package name.
1331300	1336180	Just like you do for Ubuntu using your dpkg for debian packages.
1336520	1338980	So, in that case, you just need to do this.
1339180	1340960	It will appear as m.
1340980	1345100	And then this is the command where you have to mention the name of the package.
1345100	1347180	And only this package will be compiled.
1347180	1353000	So, I am not doing that because we are running late on time.
1353000	1355020	Now, why kernel modules?
1355260	1361180	Kernel modules, because when you load them, they are inserted into kernel, they run in kernel.
1361280	1368040	And due to that thing, they can access the kind of structure, the kind of memory that is there in the kernel side.
1368060	1371020	So, no user process can actually do this.
1371020	1376720	Even if it is privileged, it has to use a kernel module to make all of these changes.
1376720	1384380	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.
1384520	1390400	And even to make sure that you can create something which will be hidden from the user space.
1390400	1394540	Even if you are running a demo or something on the user space, it will be hidden.
1394540	1398140	It will be replying, it will be taking orders from other things.
1398480	1401760	So, that's why the kernel modules are important here.
1402440	1406160	Now, second question can be, can we directly insert kernel modules?
1406160	1411140	On your Linux system, if you don't have root, no you cannot.
1411140	1419660	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.
1419820	1429380	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.
1429380	1433020	And he can then insert his kernel module inside.
1433020	1437740	So, we have build system ready.
1437780	1444660	After that, you need the kernel code, kernel module code that we have created here, just to show you.
1445380	1453040	After that, you need to make sure that your kernel code, when you are compiling it, can link to the build system.
1453040	1457160	Because build system is the one that you will be using to do all of this.
1457860	1461000	You have to make sure that everything is in the path.
1461000	1465360	All of these are just steps, you just need to file these commands on the build system.
1466160	1474680	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.
1474680	1477020	Because this thing here, it runs on MIPS.
1477200	1481560	Almost all of your, these devices, small devices, they run on ARM, MIPS.
1481640	1487940	You won't find a lot of these specially built things running on x86 or x86x64.
1487940	1491000	So, for that reason, you have to cost compile it.
1491000	1494580	Cost compile sounds difficult, but it is not.
1494580	1498720	It's just one word that you have to define if you know what the word is.
1499360	1502600	So, once you do that, you are ready.
1502980	1509400	Once you have the kernel module, you can insert it using insmod, that's the command to insert it.
1509480	1515420	lsmod is used to list it, and rmmod is used to remove the kernel module once you are done.
1515420	1523140	So, what we will do now, is we will see a hello world module, which we have written just for this class.
1523640	1525220	So, this is how it looks.
1525680	1530840	You know, if you are familiar with C language, these are the header files that we use.
1531860	1542220	These are important here, because your module in it defines the function, which will be executed as soon as your kernel module loads in.
1542220	1548480	Similarly, you can also define a function, which will run when you take it out.
1548480	1550980	So, these are the basic things.
1550980	1557460	And even this knowledge is more than enough to create something, which can do pretty nasty stuff.
1558200	1561580	This is the example here, because obviously it's a hello world.
1561580	1564240	It will just print kernel logs.
1564760	1567080	So, here we have two functions.
1567080	1573420	First one here is the init function, which will be called when we insert it.
1573600	1578240	It will just print, you know, hello cruel world of kernel programming to the kernel logs.
1578240	1580200	Just to make sure, it's a POC, right?
1580200	1584540	If it works, you can go forward, you can go for the more powerful code.
1585040	1588320	Similarly, this one will run when you exit it.
1589040	1591760	So, let's do one thing.
1592180	1593940	Let's see all of that.
1593940	1599020	So, in the rootkit code, you will find two folders.
1599300	1602780	For now, you can just ignore the kernel space program.
1602780	1604540	You go into kernel fun.
1604640	1606260	You go into hello world.
1606840	1610560	So, if you do ls-l, it will show you two files.
1611000	1613140	Let's first check the hello world.c.
1613240	1615340	It's the same file that we just saw.
1615340	1617420	It has two simple functions.
1617820	1620140	And these are the declarations.
1620280	1623640	So, the code is written by my boss, you know, for this thing.
1623640	1624960	His name is Vivek.
1625340	1627280	That's why the name is Vivek.
1627280	1629320	I'm not stealing code from third party.
1629480	1631020	Just so that you know.
1632780	1637720	And then, to compile these files, you use makefile.
1637900	1643240	Makefile is nothing but it is a way by which the programmers make things easier to compile
1643240	1646500	when you are dealing with a lot of source code.
1646500	1649680	So, this is the simplest possible makefile one can make.
1649680	1653520	And because all of other things are already there,
1653520	1656040	and we have this ls set,
1656040	1659580	we have to just do nips make,
1659580	1662540	and it will automatically link everything.
1667630	1670750	Okay, so it actually ran into some error.
1672830	1674450	Pretty strange.
1683520	1685640	Must be missing some link.
1685960	1688600	So, in a normal scenario,
1688600	1690240	because you know, the demo gods, right?
1690240	1691800	It was working in the morning.
1692140	1695840	That's why I put it inside the machine.
1696480	1700820	So, the thing is, on running nips make, it should run,
1700820	1702340	if all the links are correct.
1702340	1706240	So, you have to make these four links, as I was showing you here.
1706240	1708760	One of these links are currently not working.
1708860	1713940	So, you export staging directory, the path, and the kernel root.
1713940	1717160	If one of these is messed up, then, you know,
1717160	1719860	it will fail, just like it is failing right now.
1719860	1723040	You have to make sure that, you know, the kernel that you are targeting,
1723040	1725880	you are only running it on the same kernel.
1725900	1730900	You cannot compile it for 4.9.152 and run it on something else.
1730900	1731980	It won't work.
1731980	1734020	That is one of the things that you have to do.
1734140	1735360	You have to make sure.
1735360	1738000	But if you are compiling a firmware,
1738000	1740460	you are installing the same firmware on the device,
1740460	1741940	whatever you compile here,
1741940	1744840	it will directly work on the box, out of the box.
1744840	1748180	So, what we will do now is,
1748180	1749740	I have compiled these already,
1749740	1754160	because, you know, I had to show you how they run.
1754300	1756880	And instead of using, you know, your own machines,
1756880	1759780	because for them, the kernel will be different,
1759780	1763080	so even if you download them and you try to run it, it won't run.
1763120	1764740	So, what we have done here is,
1764740	1768620	we have emulated an openability system inside the lab.
1769420	1772420	So, in this, you know, it will behave just like this device,
1772420	1773760	apart from the Wi-Fi thing,
1773760	1775960	because obviously, no physical antennas.
1777140	1780500	For all other practical reasons, it is MIPS,
1780500	1783540	it is behaving like a complete Linux system.
1784660	1787300	So, again, after 25 seconds,
1787300	1790400	it will give me a console on which I will be able to see
1790400	1793400	all the kernel modules that I have compiled,
1793400	1795200	and I can directly interact with them,
1795200	1796700	I can see what they do.
1797280	1798960	Once we do the Hello World,
1798960	1801340	then we will move to the more advanced ones,
1801340	1803160	which are of interest.
1803160	1808120	Hello World, we all know, is just the POC, right?
1808120	1813100	So, this one is the router,
1813100	1817600	the same firmware, but this one has the kernel different one,
1817600	1819700	that's why I had to compile it again.
1820100	1824240	This one uses 4.9.53, I think.
1824700	1826060	That one is different.
1827000	1829900	So, as soon as you press this,
1829900	1832380	it will boot just like the device.
1833760	1836980	And if I go to the root directory,
1836980	1839000	kernel modules,
1839000	1842640	I have already compiled these kernel modules and kept here,
1842640	1846600	just so that, you know, demo gods do this to me.
1847160	1850500	Now, before inserting it,
1850500	1852080	you can use lsmod to check
1852080	1855900	what are all the kernel modules already there.
1856400	1858820	Now, if you do nsmod,
1858820	1860560	for the Hello World kernel module,
1861320	1864120	you will observe that this is
1864770	1867960	the kernel log that is being printed.
1868180	1870900	It is coming on console because, you know, as of now,
1870900	1872880	we haven't set the debugging level.
1873060	1875840	So, if I do n-1,
1875840	1878300	it will not come anymore.
1878460	1881600	We will be able to see it using dmessage,
1881600	1884460	which shows the kernel messages, right?
1885740	1887740	So, this is the POC thing, right?
1887740	1890740	Now, if I want to check if it was inserted,
1891340	1895020	I will just do lsmod and I will grab for the Hello World.
1895880	1897080	And there it is.
1897080	1898780	I can again remove it
1899480	1901040	using the Hello World.
1902100	1904240	And if I do dmessage,
1904240	1905640	it will also show
1906160	1908580	that it existed, right?
1908580	1912080	So, that's the basic POC code that we do for, you know,
1912080	1914960	whenever you start programming, this is the first thing that you learn.
1915720	1917960	Now, coming to something, you know,
1917960	1919680	which looks like hackish, right?
1919680	1921660	Which looks like something of use.
1922060	1924660	So, suppose you are running something in the user space, right?
1924660	1927020	You are running your own backdoor
1927020	1928000	or you are running something
1928000	1930740	which you don't want the user to notice
1930740	1933500	even when it is coming in the PS output, right?
1933540	1935540	So, what do you do? You change the name of that.
1935540	1936760	If you change the name of that,
1936760	1939440	if you make it look something official,
1939440	1941840	most of the users, or almost everyone,
1941840	1943800	is not going to suspect on it.
1943800	1946800	They will just assume that it is one of the system things
1947520	1948640	that run on Linux
1948640	1951680	and that is beyond my understanding, right?
1951680	1952860	That's what we do.
1953260	1955540	So, let's do that.
1956660	1958340	So, if I do PS here,
1958920	1961740	I should be able to see all of these, right?
1962020	1963520	So, let's do one thing.
1963520	1966240	Just to make sure that you are able to understand
1966240	1968220	the effect, the change,
1968220	1970600	what we have done is, the kernel module,
1970600	1972020	it does not change the name
1972020	1973900	but it appends something to the name.
1973900	1976780	It's the same thing, if we can append something to the name,
1976780	1978580	we can always, you know,
1978580	1980320	go and completely wipe it out
1980320	1983440	and use the name that is there.
1983780	1985400	So, in this one,
1985400	1986980	I have to do ins mod
1989080	1992160	and then, after that,
1992160	1993800	I have to, you know,
1993800	1995460	so, you know, it is a big command
1995460	1997200	so I have actually written it here.
2002900	2003820	Change mod
2004290	2006120	is the kernel module here.
2007480	2008820	In the PID,
2008820	2010920	we have to provide the PID of the process
2010920	2012980	for which we want to change the name.
2013340	2014800	So, for example,
2014800	2015680	this one here
2016310	2017920	is a server daemon.
2017920	2019660	So, let's do it for this.
2019820	2023160	It's 2110.
2026280	2027960	You do this.
2028340	2029440	You do PS
2029440	2032540	and there you go.
2033320	2034080	Right?
2034120	2037180	So, here we appended it so that we can find it easily.
2037180	2038560	You can see it visually.
2038680	2040860	We can also change it completely.
2040860	2043000	We can make it look like something like this.
2043000	2044920	Right? Something gibberish.
2045300	2046300	That, you know,
2046300	2048740	that the user will not be able to make sense out of.
2048740	2051140	So, that's the first kind of thing that you can do.
2052160	2054220	If we talk about another thing,
2054220	2056060	one more thing that we can do is
2056060	2057900	we can use NetFlipter hooks
2057900	2059460	through our kernel module
2059460	2061780	to make sure that we can monitor
2061780	2064080	all the packets that are sent by the machine
2064080	2066240	or that are coming to machine.
2066320	2068220	So, for that, we will be using
2068220	2069240	NetFlipter hook
2069860	2071180	NFIP local out
2071800	2073880	which will correspond to all the
2073880	2076000	packets that this machine is generating
2076000	2077460	and sending out.
2078600	2079940	So, here is a quick
2080700	2081780	description of
2081780	2083160	NetFlipter architecture.
2083160	2086280	It has multiple points where you can put hooks.
2086280	2088300	These are also called hooks.
2088680	2090340	So, you can see, when the packet comes
2090340	2092000	in, it's checked
2092000	2093820	if it is coming for this machine
2094600	2095920	it will be sent here
2095920	2098080	that's the 2, denoted by 2
2098080	2100180	that's the in hook, because it is
2100180	2102460	coming to the machine. Similarly,
2102460	2103740	if machine generates the packets
2104280	2106020	it goes out from here and it
2106020	2108380	hits the point 5. Point 5
2108380	2110040	is the NFIP
2110040	2112100	local out, which is the packet
2112100	2114440	generated by the machine. So, suppose
2114440	2116660	even from the defendant's perspective
2116660	2118500	if you want to see what kind of
2118500	2120540	packets your machine is sending
2120540	2122240	So, this kind of
2122240	2125120	module can actually help to do that.
2125460	2126560	So, let's go back
2127420	2127980	and
2127980	2130580	let's do a quick ls-l
2131300	2132540	So, the one that we are
2132540	2133800	talking about is the
2134380	2136800	network funnel object
2137440	2138440	just do it
2139060	2139620	nsmod
2141220	2142340	network.co
2142340	2144940	and you are good to go
2144940	2146220	if you do
2146220	2148280	demessage, in this case
2148280	2150400	you won't be able to see anything here
2150400	2152400	because for specific
2152400	2154520	reasons, for this one, we haven't
2154520	2156480	put any logs. If you don't put
2156480	2158340	the logs, you won't see anything here
2158340	2160200	I'm just showing this so that
2160200	2162360	for the last kernel modules, you were seeing
2162360	2164460	logs, so you can always come back and say
2164460	2166260	that, you know, hey, whatever you are doing
2166260	2168440	there are logs. So, because
2168440	2170960	you can observe here, there are no logs, right?
2170960	2172540	Now, suppose
2172540	2175140	if someone from this
2175140	2177080	machine starts to
2177080	2179100	dial out using netcat
2179100	2181000	so, you know, random IP
2181720	2183000	anyway, it won't connect
2183000	2184600	because the lab is completely
2184600	2185740	boxed in
2186740	2189140	so, let's see what happens
2190100	2190940	it's doing
2190940	2191420	something
2193180	2195020	now, if we do demessage
2195720	2196940	what you will find
2196940	2198720	here is the hook
2198720	2199860	was executed
2200590	2202660	and it is showing you all the packets
2202660	2204740	UDP packets that
2204740	2205520	were going out
2206450	2208180	also some of the TCV packets here
2209020	2210080	right?
2210470	2212780	so, this is how you can actually
2212780	2214300	monitor something like this
2214300	2217000	now, the third demo that I have
2217980	2219160	for this one
2219160	2221040	is a
2221040	2222420	network stack backdoor
2222420	2224880	so, suppose, you have a virus
2224880	2226500	you have two parts of the virus
2226500	2228220	first part is the one
2228220	2230300	which executes commands on the system
2230300	2231640	that's the execution stub
2232260	2234160	or execution stub, right?
2234160	2236140	the other part is the one which maintains
2236140	2237680	that it is hidden
2237680	2240120	it does not have to open any socket
2240120	2240640	to listen
2240640	2243380	because when we talk about it normally
2243380	2246560	if you want to receive a packet from some other process
2246560	2248320	if you want to get commands
2248320	2250760	from a remote machine
2250760	2252360	you have to open a socket
2252360	2253640	you have to make sure that
2253640	2256100	the guy, whoever is issuing the command
2256100	2257980	is sending those commands
2257980	2260180	to your socket, right?
2260180	2261380	but if you open a socket
2261380	2263860	it will be listed when you do netstat
2263860	2265660	so, you don't want that
2265660	2267720	you want something which can intercept
2267720	2269920	packets directly in the kernel level
2269920	2271320	it can parse them
2271320	2273320	and it can execute commands from there
2273320	2275660	so, the execution stub
2275660	2277600	is not implemented here
2277600	2278440	but
2282050	2283710	but the other stub is
2283710	2285530	which actually looks into
2285530	2286550	the kernel part
2286550	2289650	so, what I will do is, I will connect this guy
2290610	2291130	because
2291710	2293890	we want a packet coming from other machine
2293890	2296030	which our lab
2296030	2296890	won't be able to do
2298290	2299850	so, I will just plug it in
2301970	2303030	plugging in the power
2303710	2305630	this guy is so small that you can
2305630	2307910	actually power it using the USB itself
2307910	2309970	so, you plug it in
2313710	2315890	you plug in this thing into Ethernet
2317210	2317950	so that
2317950	2318950	this can communicate
2320930	2321970	and after that
2321970	2322410	you wait
2323150	2325370	so, this is what is going to happen now
2326050	2327610	we are going to insert
2327610	2329970	the cover.co module on the one side
2330830	2331550	and then
2331550	2333750	we are going to use nping on the
2333750	2335390	host machine to send
2335390	2336590	specific packets
2336590	2339770	so, now, if we talk about the code
2339770	2341850	of this, the specific packets
2341850	2343550	that we are talking about, the code is written
2343550	2345370	in such a manner that
2346170	2348010	this thing will see
2348010	2349850	all the packets that are coming to this machine
2349850	2352110	but it will only pass those packets
2352110	2353710	which will have source
2353710	2356070	and destination port as 9999
2356070	2357930	so, that's the signature that
2357930	2358770	we are creating here
2358770	2361370	so, main thing here to notice is
2361370	2362870	we are not opening any socket
2362870	2365850	but still, we are able to monitor a specific
2365850	2367950	packet which will contain command for us
2367950	2369650	so, for example, when
2369650	2371570	we send something like this here
2372470	2373890	it contains the command
2373890	2375970	here, right, the cat, it is a shadow
2375970	2377610	just to see the contents
2377610	2378430	of the shadow file
2378430	2381770	and when you will do demessage, you will find
2381770	2382750	something like this
2382750	2385210	so, this one actually intercepted it
2385210	2387650	it got the command, now this command can be
2387650	2389410	passed to the user level thing
2389410	2391450	that is running there and that can
2391450	2392530	get your stuff
2393390	2394550	right, so
2399230	2400530	this should be online
2400530	2401010	and now
2403150	2404810	if you don't like SSH
2404810	2406470	you can always use something called
2406470	2408710	TTYD, it will drop you right
2408710	2410990	into the box, this box
2411810	2412650	so, now
2413450	2414910	let's see the IP address
2414910	2416230	it's already know, right
2416230	2417090	it's 10.1
2418810	2420430	it's 10.1, so
2421050	2422770	I can see the module here
2422770	2424550	I do insmod
2426270	2426790	cohort
2429290	2430290	it's inserted
2430290	2431750	and now
2431750	2434930	if I open this PowerShell
2434930	2436710	and fire this command here
2436710	2438750	nping commands come as
2438950	2440770	a part of nmap, so if you don't
2440770	2442710	have nmap installed, you won't have
2442710	2444690	this one, here what I am
2444690	2446770	defining is, we have
2446770	2448910	to, we need to set the TCP flags
2448910	2450550	as SYN and REST
2450550	2452310	and the port needs to be
2452310	2455110	9999 for the
2455110	2456690	source as well as for the destination
2456690	2459090	so this is nothing but this is the signature that
2459090	2461110	we have, we don't want it to listen
2461110	2463150	to any packet and do, you know, whatever it is
2463150	2465230	doing, we want it to be specific
2465230	2467230	that's why the flags as
2467230	2469130	well as the port combo will make
2469130	2470750	it so unique, that it will
2470750	2473090	only hear whatever we will send
2473090	2475130	it, right, so now, you can observe
2475130	2477110	right, I am not running anything on
2477110	2479090	the user side, I am not
2479090	2481170	running any socket, that's the main part here
2481170	2483170	there is no socket, most of the people
2483170	2484630	when they check for the backdoor
2485010	2487170	they do a netstat, what is listening
2487170	2489190	right, now this thing will not
2489190	2491350	appear, because it is not opening any socket
2491350	2493030	it's just scanning the packets, right
2493030	2495110	and that's the concept behind this
2495110	2497310	this is only one example, you can
2497310	2499190	actually make sure that, you know, the process
2499190	2501170	is hidden, you can make sure
2501170	2502950	that process cannot be killed by the
2502950	2505210	user space kill-9, you
2505210	2507250	can do all of that, but you
2507250	2509170	know, because of the time limits
2509170	2511230	that we have, this
2511230	2512310	is all we are going to cover
2512310	2514430	so it has sent the packet
2515070	2516470	now if you go here
2517150	2518530	you do demessage
2519130	2520950	you will find something like this here
2521970	2523370	so this is the part
2523370	2524890	which is undetectable
2524890	2527050	it will write it somewhere, it will
2527050	2529490	pass it using a channel or a
2529490	2531410	hook to the user space if something
2531410	2533330	is running there, or you can
2533330	2535890	you know, you can actually add code here itself
2535890	2537430	to run these commands
2537430	2538890	you can intercept all the syscalls
2538890	2540850	you can see which command
2540850	2542730	or which system or which
2542730	2544890	programmer or program is
2544890	2546970	making the syscalls, you can intercept
2546970	2548850	them, if you want, you can
2548850	2550930	actually block them too, so that's the power
2550930	2552930	of current level toolkits or
2552930	2554970	rootkits that, you know, most of the
2554970	2556950	people don't talk about or don't
2556950	2558370	understand when they talk about
2558790	2559630	WiFi security
2560470	2561890	in the routers context
2563290	2564790	so all of this is there
2566050	2566970	I can show
2566970	2568310	you code as well if you like
2568730	2571090	let me grab the LAN
2572210	2572770	again
2574520	2576900	but again, the router level code
2576900	2578700	is not the simplest thing
2578700	2580740	that you can see, the main point
2580740	2582520	of showing this thing in
2582520	2584780	workshop is to tell you that these are
2584780	2586760	the possibilities, even when
2586760	2588760	you are not able to see program in
2588760	2590720	PS or if you are not able to see
2590720	2592260	it in netstat
2592260	2594100	it can still be there
2594720	2596580	it can still listen for the commands
2596580	2597980	it can still reply
2597980	2600680	it can still do DOS, it can still make sure
2600680	2602700	that anyone or the hacker
2602700	2604140	who has this backdoor
2604140	2606380	can actually get into your
2606380	2608660	system anytime as he likes
2608660	2610880	so that's the main getaway
2610880	2612980	that we are talking about here
2612980	2614260	but still
2614260	2615780	if you like to see the code
2616500	2618460	just a quick code walkthrough
2620980	2622180	kernel pun
2622180	2624860	let's talk about a simple one first
2624860	2625600	let's talk about
2626520	2628040	the prepend process name
2632620	2633660	you open the
2634200	2634700	file
2635600	2637280	here, just like your
2637280	2637840	hello world
2639060	2640780	we are registering two functions
2642220	2643400	we are taking some
2643400	2645280	arguments because we want to take
2645280	2647340	the PID from the user, we want to take
2647340	2649500	the new name of the process from the user
2649500	2651440	so that's why these things are
2651440	2651720	here
2654240	2655680	and when you go up
2655680	2655760	here
2655760	2659720	what you will find here is
2659720	2661780	so it's very important to understand that
2661780	2663720	all the processes, they are stored
2663720	2665780	as a task structure in kernel
2665780	2667380	so what we are doing here
2667380	2669520	is we are going over all of the processes
2669520	2671820	that are running, we are matching the PID
2671820	2673880	because that is the identifier that we have
2673880	2675780	and as soon as it is
2675780	2677760	matched, we are overwriting
2678580	2679780	the name of
2679780	2681700	the command, or we are not overwriting here
2681700	2683140	we are just adding it in the front
2683140	2685440	to the structure
2685440	2686300	that is there
2687220	2688280	so that's all
2688280	2690720	you cannot do this thing from user mode
2690720	2693360	why? because the thing, the structure, the memory
2693360	2695460	that we are playing with right now
2695460	2696680	it is in kernel
2696680	2699060	and there are boundaries, you cannot breach them
2699060	2701180	without using something like
2701740	2702800	a zero-day exploit or something
2703940	2705600	similarly, if we talk about
2705600	2707380	the covert network thing
2712380	2714460	this one is a little bit more complex
2714460	2716960	because obviously it is doing the complex thing
2716960	2718880	but let's do a walkthrough
2720440	2722100	so what it is doing here
2722100	2724540	is it is registering its hook
2724540	2725860	with the netfilter
2725860	2727220	because you have to do that
2727220	2730440	because if you don't do that, netfilter is not going to
2730440	2731540	pass the packets to you
2732220	2733080	once that is done
2733700	2736260	this is the definition, this is the
2736260	2737260	hook that we are using
2737260	2740200	this one stands for incoming packets
2740200	2741240	as we just discussed
2741240	2743120	we are only doing it for
2743120	2743880	IPv4
2745000	2746300	and the priority is last
2746300	2748720	so our hook will execute in the end
2749320	2750760	no need to worry, still
2750760	2752380	it is going to get all the packets
2753580	2754560	so now
2754560	2756000	if you go here
2756000	2758980	what it will do, it will look for
2758980	2759940	specific packet
2759940	2762280	which has this specific port
2762280	2763480	which we have defined
2764140	2766620	and it will also check for the
2766620	2768780	TCP header flags
2768780	2770620	because ports can
2770620	2772980	be replicated by other people
2772980	2774780	also right, it can be
2774780	2776620	the thing that for some reason, some process
2776620	2778060	is using 9999
2778060	2780720	and now those packets will start
2781320	2782180	intercepting like
2782780	2784720	our channel right, it should not happen
2784720	2786380	so that's why we have made it
2786380	2788840	more complex, once that is
2788840	2789140	there
2790380	2792680	this is the code that you saw printed
2794260	2796440	so all of these things are being printed
2796440	2798480	you can then pass this command
2798480	2800100	to some other module that you have
2800100	2802860	or to some other function that you have here
2802860	2804560	right, so it's that
2804560	2806520	simple, that easy, once you know
2806520	2807660	what to do
2808300	2809320	going back
2809920	2812480	similarly, now you know, the second logical question
2812480	2814620	is, this is how we do it
2814620	2816600	for the vendors, this is how we do it
2816600	2818480	for the OpenWrt, but not
2818480	2819980	everyone runs OpenWrt
2819980	2822560	so how we can compile it for the vendor firmware
2822560	2824220	and that's a great question
2824220	2825580	so most of the time
2825580	2827300	what you have to find for this
2827300	2829740	is the code for the vendor firmware
2829740	2831720	now you will say that the vendors
2831720	2833500	they don't give their code out
2834680	2836020	that's partially correct
2836020	2838180	some of vendors has to, because they are
2838180	2840320	using GPL, and by the license
2840320	2842280	terms of GPL, they have
2842280	2843860	to give out all the modifications
2843860	2846200	that they make, you find it
2846200	2848260	and then you use the same way
2848760	2850260	you create their own build
2850260	2851980	system, you use their kernel
2851980	2854040	you use their cost compiler to compile
2854040	2856200	everything, and then in this way
2856200	2857580	you can compile it for them
2859020	2860120	so all of
2860120	2862040	this research was done when we were creating
2862040	2864300	this course for our customers
2864300	2866240	and all of the details
2866240	2867980	if you want to go extended
2867980	2870240	into it, it is available there
2870240	2871960	you can go and learn
2871960	2873440	this is the only thing that
2874220	2876440	was possible to be covered in one hour
2876440	2878140	but for all the other details
2878140	2880220	you can always refer to the course
2880220	2881220	if you like
2882400	2883820	again, community labs
2883820	2886260	if you want to try this out, whatever we have done
2886260	2888260	I'll make sure that the PPT is
2888260	2889980	available with the wireless village
2889980	2892220	so that you guys can download, you guys can
2892220	2893280	see all the commands
2893860	2896340	or you can directly go and do them
2896340	2898060	here. So that's all
2898060	2900360	if you have any questions, I'll be taking those
2900360	2902080	or if you come with some questions
2902080	2904380	after the talk or the workshop, you can always
2904380	2905880	mail me on this. Thank you
