Hi everyone, I'm Nikhil Mittal and I'm presenting on Hacking with Human Interface Devices. Welcome to the Hardware Hacking Village. A couple of things about me. I'm a hacker. Still not audible? A bit louder. I'm a hacker. I'm a trainer. I speak at conferences. I'm in two open source toolkits, Cautelia and Nishan. So, Cautelia is the toolkit which we are going to have a look at today. It could be used to generate ready-to-use sketches for Arduino-like devices. And those sketches could be used for penetration testing or breaking into machines if you are authorized to do so. This is my Twitter handle and that is my blog, so follow me. I'm a sucker for followers. I'm generally interested in offensive information security. And new ways to get into systems. And I've spoken at a couple of conferences previously as well. So, what we are going to have a look at today is why should we use human interface devices? What is a human interface device? And obviously, a lot about my tool. We will also see some live demonstrations and hope they work. I've just tested everything in the morning. So, if something doesn't work, assume and trust me. And at last, we will talk about a couple of defenses against these attacks. So, I missed a slide. What is a human interface device? So, those of you who don't know it, it is something. So, we as humans interface with computers using different things like mouse, keyboard, touch, joystick. A human interface device is something which allows us to do that. For example, a keyboard is a HID. A mouse. A mouse is a HID and so on. So, why should we use these things in penetration tests? First and foremost, they are really powerful as you will see in a few minutes. Countermeasures like antivirus, HIPs, security teams, they trust these devices. For example, when you plug in a programmable keyboard, it's obviously detected as a keyboard. And I've rarely seen any corporate environment or any of my clients. Who block keyboards to be attached to their machines. A lot of people block mass storage devices, but no one really cares about keyboards. And the last thing is, it's really cheap. The device I'm going to use is a TNC 3.0 from pgrc.com. It's just like a $20-$22 device. So, you can literally use dozens of them in your penetration test gigs. There are so many devices. There are so many HIDs or human-driven devices which hackers can use. I've listed a couple of them which are really cheap and small in size. For example, TNC which I'm going to use today. OpenCubos. Arduino Micro. And a lot more devices. In fact, I've not listed here of them. There are so many devices. Just keep in mind that if you really want to use them in penetration tests, the size, the physical size should be small. For example, I've seen using guys, Arduino Duo. As a human-driven device, but it's like this big. At least this big. Like the size of a palm. So, it could not be easily hidden inside other devices. So, about my toolkit. Kautilya. It is named after some Indian guy who was a political thinker back there. So, do not think about it. It is written in Ruby. And it's available on my GitHub. It contains like 54 payloads right now. 45 for Windows, 5 for Linux and 4 for OS X. So, your mileage may vary on OS X. Because I just ported it on VMware. I own a PC. I work on Windows technologies. But Windows payloads should be quite stable. Okay. So, Kautilya currently supports TNC++ 2.0 and TNC 3.0. So, as you will see, we can just input some things to this tool. And it has an old-school GUI, menu-driven thing. Okay. I'm scared of this thing. I'm still audible? Yeah. That's fine. Okay. And because Arduino supports only TNC devices, there has been a port of Kautilya for Arduino Micro by some awesome guy. So, you can check that one as well. And that brings us to the pen test scenarios. So, we'll be having a look at these things. So, these are the things which I've tested today. There are a lot more things which you can do with Kautilya. If there is any user of Kautilya, you can ask for a demonstration and I will do that. Right now. And the target I'm going to use is a Windows 7. It's not pirated. It's a demo version, but its activation has, I mean, it shows that it is not activated. So, do not think that it is a pirated one. I just created that, like, 30, 40 days back and it has expired a couple of days back. So, it's not a pirated thing. Do not complain to Microsoft, please. So... This is going to be our target. What we are going to do is we program our HID and connect it to this target. And let's see what happens. So, this is our device, TwinC3.0. As you can see, the target must be unlocked. Only in that case you can use this. I mean, it works even if the target is locked, but you won't be able to type anything. So, the target must be unlocked. And this is not a pirated version. Okay. So, this would be our target. And this is how Quartillion looks. It looks a bit ugly here. It is designed and developed on Ubuntu. But I'm using it on Windows right now. If you have Ruby installed on Windows, you can use this on Windows as well. So, our first Pinterest scenario is getting access to a target environment. And we would use a couple of reverse shells. That is, the shells which connect back to us. And the target, which is this machine. It is in a fairly restricted environment. On both TCP, only 80 and 443 are allowed. On UDP, only 53 and only ICMPV4. So, that's quite a restricted environment. So, Quartillion has a really old-school GUI. You have to enter your options like this. Is it visible to the back? You save one here. Sorry. Then, the shells are in the execute category. Press 2. And we have 11 options for shells. Let's use a reverse TCP, which is the seventh one. It shows a small help and the options you can enter. So, right now, it is asking for the IP address to which the reverse shell will connect back. And now, the port. So, let's use 443 because it is generally allowed through the firewalls. And now, it asks for the type of board you want to use. So, let's go to NC3. And it has created a sketch, which could be used in the Arduino IDE. And the sketch is in the output directory of Quartillion. So, let's just open that. Okay. So... So, this is our sketch. We'll just either open it in IDE, Arduino IDE, or just copy it and paste it here. Now, I'll connect the device. First, I'll upload the sketch to it. And because there is a sketch already loaded on it, first, I have to stop the device after inserting it. So, I'll just... Disable the auto-reboot and stop the device. Oh, it started working. Okay. So, the device is now ready. Now, we can upload our sketch to this device. Just press upload. Just stay more... Okay. No. Stop. Stop. Stop. Okay. I believe the sketch has been uploaded. Let's just try it out. so we I entered the IP address of my host machine and put 443 so let's start a listener on it okay so I'm going to use power cut which is a net cat code to PowerShell or you can use your net get on Linux as well so it's our choice and let's use net cat so for that I need to just change the IP address so this is IP of this Kali Linux running over here let's start you start a listener on port 443 and now if I connect this device to the VM that is our target let's see if it works so what it will do first if it is for the first time it is being used on a machine it waits for the drivers that minimizes everything and opens up a really small command prompt types in dark blue one just that is what I want so let me just disconnect and reconnect it be connected and let's see if it So the idea behind this thing is you can program it as a keyboard and it can type really fast and without errors. So in internal gigs you can assume it as you have access to a machine and you want to really fast add a user and do something like that then this device is for you. Let me just re-burn it to the device because it was. The different IP address previously. How I use it in external pentest gigs is I take a couple of dozen of these things, hide them inside either thumb drives or USB toys and things like that and then I drop it in my client's parking lots, cafeterias, etc. or near their office and the success rate is very high. It has been quite high, like 30 to 40 percent. So that's really, really good because once you have access to even a single machine you are in. So let's see if right now we have something. Oh, it sucks. Okay. Let me start a powercat listener. Let me start a powercat listener. Okay. So it drops partial scripts in the temp directory of the user because this is not working right now. let me check that script if it is something wrong with the script I'm trying to make it file less but right now this is what it does so it dropped these partial script and we be script in the temporary directory of the user and I don't know what's wrong with this nice it connects to my okay it's there so it took some time I'm sorry so we have this interactive PowerShell connect back from the target machine it took some time so now we can run the native commands PowerShell let's as well whatever you want and once you have a PowerShell session you can really like in couple of seconds upgrade it to a metapeter or in fact only using PowerShell you can do really cool stuff and I do a training for that so please join that so this is a reverse TCP proxy of your shell you can use it over internet in your external gigs or whatever another thing I would like to show you is a reverse ICMP shell please note that that reverse ICMP shell is not churning anything so if someone is looking at the network I'm sorry to say he will see everything your commands your responses I'm walking on and putting things right now the problem is if you include this base 64 Endo things they would be so huge that you will generate malformed ICMP packets so that is not we want so is this good I'm going to close this shell okay so if you want to have a look at it just in case you don't feel like that it's off I'm sorry I'll just turn this on and if you see we have only a couple of outbound rules let's enable outbound ICMP as well so for an ICMP reverse shell we'll again go to payload for windows execute and now let's select the reverse ICMP shell option or if you want I can show reverse HTTPS shell as well so the reverse HTTPS shell is a certificate paint completely encrypted shell so really hard to detect let's see both of them okay so nine notice that in this case you must have the listener on a Linux machine because you cannot turn off ping replies on Windows so this is my Kali Linux couple of other options we have a sketch let's just copy this a sketch to the Arduino IDE and let's upload at two devices now we must start a listener and if you notice the help here it will it top the comes out list if you notice the help here it will it shows the cargo it self it will come modern use command you need to execute on your Linux machine to turn off ping replies let me just copy this we have stopped ping replies by the OS it's our server which will reply to the pings and we need as a server we need the server from ICMP as such tool suit so let's start that so now our server is listening for ICMP probe so now our server is listening for ICMP probe now if I reboot the device that is connected to the victim it again will open up a command prompt and type some stuff in case of windows most of the payloads are in PowerShell . . . . . . . . . . . . an elevated shell, for example, to dump user passwords in plain. It uses the, we have our reverse PowerShell shell here. For example, let's run whoami again. So this is completely ICMP. Let's just exit this one. Yeah. So that was our first pentest use case, reverse shells or shell or shells for Windows machines. Let's use the second one. For example, in a social engineering campaign, you may be asked to gather user code. So let's try that. So for that, you need to go to the gathered category, which is one. And then the ninth one, which is dump passwords in plain. So what this script does is it needs to pull Mimikatz ported into PowerShell, which is a script called invoke Mimikatz. It needs to pull it from the internet. That's a bad part. It executes it in memory on the power of target, dumps, passwords, and paste it back or exfiltrate it to whatever you want. So let's use our local web server. So this is the URL of our script. We need not pass any argument. And let's exfiltrate to our own local web server. So that would be option number three. Post requests to your own website or web server. And that is my Kali Linux. And that is it. So we have a sketch. Let's open that sketch. Paste it here and upload it to the device. And now if I run or connect this device or reboot it here, now the mode of operation would be a bit different. It will open up an elevated shell because that script, obviously like any other method, needs administrative access to do that. But I don't think this user has administrative access. Let's see. I don't know. I think this user, okay, I don't know. Okay, it does. Now it presses left arrow and Y to say yes to this UAC prompt. And that thing right now is an elevated shell. So it types the PowerShell code for downloading a script which we specified and executing it. The time it takes prior to closing this is because it waits if the drivers needs to be installed. Also it has a reliability check. Okay. That if a user clicks in between where it is typing, it restarts the process. Okay. So as you can see, it was downloaded from my local web server and should be executed. Let's check. Okay. It is, it should be this. So this is obviously an encoded output. Let's just copy this. So Cortelia in the extras directory has scripts to decode things. So it has written the decoded data to Decoded.txt. Okay. And now if I open it, you can see that we have password in plain for that user. So it's quite powerful, but you must have internet access to pull the script. Right now what I am working on is to mount an SD card over this device which pulls the scripts from it so that we need not depend on access to an external web server in case of large scripts. So we used, we downloaded the script here because it is so huge that if, I don't think the device would be able to hold that and even if it holds that, it would take so much time to type that out, which is non-practical. So that was just another case. Okay, the third one is, obviously I cannot show it at DEF CON. Because both of these, these are my favorite ones, not really practical, but really cool. For example, this one, the first one, which means GOPT, which means secret in my language, that reads SSID names. So the idea behind that thing is, it looks for a specifically crafted SSID name and the command which it needs to execute, the target needs to execute, is within that SSID name. That is. And it never connects to that network. So there are slight chances that of WIPS or any Wi-Fi countermeasure may detect or may not detect it. So I'll show you how to configure it, but obviously I cannot run it here. So these are the back doors available. So this is how it works. You need to specify a magic string, a four character magic string. If I go by the example in the payload itself, or nothing, okay, so what happens now if I connect it to a target, is it will look for an SSID whose name, whose first four characters are open. And if the fifth character is open, it will look for an SSID whose name, whose first four characters are open. And if the sixth character is C for command, then the rest of the SSID name, up to 32 characters, is considered a command. For example, if you, if I run this on my machine, and you start a hotspot called open C who am I, it will execute who am I on the target. And to execute scripts, unfortunately, because SSID names are limited to 32 characters, you have to specify open U and the shortened path of Google URL shortener. So it will look for an SSID whose name is open U and the shortened path of Google URL But it takes that URL shortener, expands it, and pulls down the script from there. So I like it because it looks cool, but not really practical, unless you are sitting with a targeted antenna in a cafe across the road of your client, which is always possible. So okay, I cannot show this. Let's look at the next one as well, the rogue AP. So I can explain what it does. A Windows 7 and onwards, there's a feature of hosted wireless networks. So what this rogue AP does is this. You can provide SSID, which would be created, which would be used on the target machine. And that. Okay. And then there is a metadata bind started on the machine. So it is like you have SSID with proper key on the target, and you can connect to it. And as soon as you connect to it, there would be a bind metadata. This payload adds firewall exceptions as well. So there would be a bind metadata listening for it. You can just connect to it so that you have a private network on a single machine with a metadata session. So again, because my VM does not have a Wi-Fi card, unfortunately, I'm not getting an external one. So I have to create it in my machine, so I'm not doing that. So just close this. Okay. What else? We can drop infected files as well. Again, in case of Windows, PowerShell allows a lot of things to do. So we can drop infected files as well. We can drop a Word, Excel, Compile, Help file, LNK shortcut files on the target which are infected. Word and Excel files use auto-executable macros. So if there is something which detects auto-executable macros, it will catch that. But I've not seen any AV flagging it yet. So we can use it. Another thing is, as far as I know and I tried, it is not working. It is not programmatically possible to password protect your macros. So someone can open it and have a look at your macro. So let's just try this one out. Okay. I forgot the HTTPS. So I'll demonstrate the HTTPS shell first. I just missed that. So. Okay. Okay. Okay. So this is our listener, so this needs to be executed on the attacker's machine. And this is Windows Specific right now. So we have our listener running on our attacker machine. Okay. Let's choose 10 which is reverse HTTPS shell and the IP address of our machine and the port. Now let's just paste it here, upload it to the device. And now if I connect it to the target, let's see if it works. It is one of the smallest payloads in Cordula, just two lines needs to be typed on the target. It is really fast, doesn't need administrative privileges or anything like that. No, it didn't work. Yes, it's perfect, it should work. There could be some issue with the payload, let's not waste time on it. Keep one thing in mind that if you are using, if you are trying to use this with Arduino, you must install TNC 3.0 and things. So that is written in detail on the website of these vendors. Make sure that you use the correct board, which is in this case TNC 3.0 and the USB type. So these two things should be kept in mind. Okay, that could be firewall here. Just let me see if I have allowed port 4.3 or not. Okay, it's allowed. So it should work. I don't know why it didn't work. It didn't work. Okay. Again, sorry, it took time. So this is a completely encrypted certificate pinned session. It should work. So this was a reverse HTTPS shell. Now onto dropping infected files. Let's test. So the idea behind dropping infected file is just to have another way of breaking into a system. For example, if you can have a reverse shell. There is no need to basically drop files on a target. But let's see it anyways. So these are the options which we have with us. Let's go for MS Word. So it asks for a PowerShell one-liner or native command, whatever you want. So let's use MS Word. Okay, let's use a reverse shell, a one-liner reverse shell. Let's see if that works. Okay. So you can always copy it from here. And let me copy a one-liner reverse shell. It connects back to again 443. Okay. So it asks for, so if you want, you can change the name of the file as well. And if you see the sketch. You will see that it is nothing but just a simple PowerShell script which drops the file on the target. So let's just try this thing out. I need to execute this on the local machine because there is no MS Office on the target. So let me just reboot it here. So it will drop that file on the user's desktop. Hopefully. So it is a good thing to have if you want. You just want a different way to stay in a client's world. Okay. So let's try this machine on the target machine. So the Word file, this one, is the infected one. And, okay. If I start, let me start a new one. I have to start a listener before I open that file. Whoa. Okay, no. Let me just close this one. So it connected back actually. So this is how our infected file works. And hopefully we will have a reverse shell here. The flip side with this thing is this. Anyone can go to the macros and see what we are up to. So if you are really using it in a social engineering campaign, then you have to password protect it. Otherwise, anyone would be able to see. For example, if you are downloading a script, anyone looking at the macro would be able to see. Your IP address. So that's a flip side. Maybe it is taking time. Let's come back to it in a couple of minutes. Okay. A reverse meta printer. So there are two ways of getting a reverse meta printer. A reverse meta printer using this thing. The first one is, which we saw a couple of minutes back. Get a reverse power shell and use it to upgrade it to a meta printer. Or you can use this one. Okay. Six, which is execute shellcode. So you need just create a shellcode using msfvenom. Paste it. To... Okay, not this one, sorry. Not this one. Not this one. It is... Okay, sorry. It is the first one. So you can create... So msfvenom supports creating meta printer in power shell. You can just create that and execute it on the target and you will be fine. I'm not going to demonstrate that. We have already seen so many reverse shells. So defenses against these things. So you can always control installation of devices using group policies. But I have seen in real corporate environment and in my clients, what they do, they at max, they block mass storage devices and nothing else. So if someone is really smart enough and blocks installation of any hardware device or hardware device by class, then this thing could be blocked. But if someone is using, for example, so many antivirus vendors, block devices by VID, vendor ID and product ID. You can always change that by going here. Okay. And Arduino. Okay. Hardware, TNC, course and this one. Not this one. I believe it's this one. So it's there on my blog. I'm not able to recall it right now. Okay. Here it is. So you can always change these vendor ID and product ID. So if there is, you know that there is an antivirus or any endpoint protection which blocks a particular VID and PID, you can always mimic HP keyboard or Microsoft keyboard or whatever you want. So you can just change it here. So there's a list of vendor IDs and PIDs on usb.org and so many websites. So one defense is to, on Windows machines, is to use group policy. On Linux is to use UDAV. But the best thing is just put glue on, in all the USB ports but one and lock that USB device to the machine. So that's the best defense. If you have USB ports open, there are so many devices, as we saw a couple of minutes back, you can do really nasty things with them. And the best thing is to make your employees aware of the risks of attaching unclustered or new USB devices to their work machines. I mean, I've seen like in one of my Pentas gigs, this device didn't work. So it was, I used it that way that I used a two-port USB hub and connected the toy, and the device together inside the toy, and there was a single cable coming out of it. So it didn't work on one of the guy's machine, so they connected it in their colleague's machine and I got like three shells from a single device. So employee awareness is the best defense. And a couple of closing remarks. Bad guys are already using it. I have myself seen this with a couple of clients. Clients getting hacked by this thing. Even good guys are using it. It's not really something groundbreaking. And as long as operating systems and system administrators and countermeasures keep trusting things, these things will work. Because security ends with trust. Okay, so some shameless self-promotion. I do training for this thing, so have a look at it on my blog. And these are my contact details. You can find Quartile on my GitHub. There is another tool, open source tool I maintain. You can find it there as well. So that was all. Any questions? No questions? Thank you.