1 00:00:00,500 --> 00:00:17,480 Am I doing my thing now? Yes? Wow. It's an R&B in here. Hi, my name is Stök. Oh, no. Hi, my name is Fredrik Alexandersson, but most people actually know me more by my hackle hand as Stök. 2 00:00:17,480 --> 00:00:28,240 And I'm going to welcome all of you to my talk, Weaponizing Plain Text, Unseen Escape Sequences as a Forensic Nightmare. 3 00:00:28,560 --> 00:00:36,500 And leading up to this talk, I was kind of told that you need to have this table of content that explains things that are going to happen, 4 00:00:36,560 --> 00:00:43,140 because otherwise people get bored and really sad. But I figured that we got 281 slides to go through, 5 00:00:43,220 --> 00:00:45,900 so screw that other thing and just head straight into it. 6 00:00:47,900 --> 00:00:59,220 Thank you. So, I spent a good time of digging into this vulnerability class CB150 that's been dormant for the last two decades or so. 7 00:00:59,420 --> 00:01:06,900 And that was real fun, and that's what this talk is all about. But I used to travel the world to all these live hacking events 8 00:01:06,900 --> 00:01:17,460 and create educational videos on YouTube. But nowadays I fight cybercrime over at TruSec, and I also do shitloads 9 00:01:17,480 --> 00:01:25,420 of incident response. So, I realized that I'm really passionate about getting log files, because that's kind of the whole part 10 00:01:25,420 --> 00:01:32,440 of creating a good timeline. So, I figured that maybe I'm the only one, maybe some other people like log files, too. 11 00:01:32,560 --> 00:01:37,460 So, I went on the application formerly known as Twitter and asked, are log files important? 12 00:01:38,060 --> 00:01:46,140 And I got a bunch of really good answers coming back. And the short answer is kind of like, yes. 13 00:01:47,480 --> 00:01:55,380 Log files are important, because logs are a vital component for maintaining application reliability, performance, and security. 14 00:01:56,320 --> 00:02:01,640 But it also seems like the common idea is that logs don't lie, people do. 15 00:02:02,580 --> 00:02:08,600 And even though your log files might just not lie to you, do you still trust them? 16 00:02:09,000 --> 00:02:14,460 And what happens if you don't? Because, imagine this for a second. 17 00:02:14,660 --> 00:02:17,460 You are now the incident response lead of Twitter. 18 00:02:17,480 --> 00:02:22,740 Of a global logistics corporation. It's four o'clock in the morning, and you're sound asleep in your bed. 19 00:02:23,600 --> 00:02:28,200 Dreaming about boats, or maybe containers into Docker and stuff. 20 00:02:28,720 --> 00:02:34,660 When you get this rude awakening call from your manager that's pissed because you got breached. 21 00:02:35,180 --> 00:02:43,460 And since you are the incident response lead, it's your responsibility to call up all those tired people that work in the incident response team 22 00:02:43,460 --> 00:02:46,360 and get those starting with collecting all the logs that you need. 23 00:02:47,480 --> 00:02:49,160 And be able to create a timeline. 24 00:02:50,140 --> 00:02:54,800 You're a manager, so you don't do grunt work, so you log into your big data app for a thousand. 25 00:02:55,160 --> 00:02:57,820 And since you're a professional, you log shipped stuff already. 26 00:02:58,060 --> 00:03:03,580 So you export the data, save it into a local file called everything.log. 27 00:03:04,120 --> 00:03:04,900 You're happy. 28 00:03:05,300 --> 00:03:11,320 But just to verify that you got any data in there, you decided that maybe I should just cat the file and see what's in there. 29 00:03:11,740 --> 00:03:13,700 In the beginning, everything looks just great. 30 00:03:14,020 --> 00:03:16,100 It contains the things that you wanted. 31 00:03:17,480 --> 00:03:18,920 But then suddenly, out of nowhere, boom. 32 00:03:19,880 --> 00:03:23,320 You're getting an ad for a restoring service. 33 00:03:24,240 --> 00:03:31,780 And they're nice enough to provide you with a calculator so you can do the math for how much it's going to cost you. 34 00:03:33,040 --> 00:03:37,820 And that's kind of the situation where you're starting to realize that, shit. 35 00:03:41,120 --> 00:03:45,320 And the reason for all this is that it has to do with ANSI escape sequences. 36 00:03:45,320 --> 00:03:49,820 And what got me all into this is this CVE here. 37 00:03:50,120 --> 00:03:55,760 And I was just going to read this straight out from my monitor because I didn't remember it all. 38 00:03:56,240 --> 00:03:59,820 Effective versions of this package are vulnerable to arbitrary code injection. 39 00:04:00,060 --> 00:04:02,620 There we are interested, right? 40 00:04:03,240 --> 00:04:10,440 This is a possible shell escape sequence injection vulnerability in racks and lint and common logger components. 41 00:04:11,120 --> 00:04:15,240 Carefully crafted requests can cause shell escape sequences. 42 00:04:15,320 --> 00:04:19,460 To be written to the terminal via racks, lint, middleware, and common logger. 43 00:04:19,500 --> 00:04:19,920 Middleware. 44 00:04:20,080 --> 00:04:20,700 Okay. 45 00:04:20,860 --> 00:04:27,880 These escape sequences can be leveraged to possibly execute commands in the victim's terminal. 46 00:04:28,260 --> 00:04:29,480 What do you got here with me? 47 00:04:31,040 --> 00:04:32,840 Excuse me, tiny sterk. 48 00:04:33,420 --> 00:04:34,800 What do you mean possibly? 49 00:04:35,520 --> 00:04:39,620 Either you can or you cannot run arbitrary commands, right? 50 00:04:41,260 --> 00:04:41,880 Yeah. 51 00:04:42,100 --> 00:04:43,940 Thank you for that, giant sterk. 52 00:04:43,940 --> 00:04:46,240 For pitching in and helping out here in the presentation. 53 00:04:47,920 --> 00:04:49,480 Well, you're actually right. 54 00:04:49,660 --> 00:04:50,520 It depends. 55 00:04:50,860 --> 00:04:54,680 But it apparently depends on the terminal that you're using. 56 00:04:55,140 --> 00:04:58,400 And there's a shitload of different terminals out there today. 57 00:04:58,700 --> 00:05:03,460 And some of them come built into the software that you're using like VS Code and Docker. 58 00:05:03,760 --> 00:05:08,900 Then you have like third-party stuff like iTerm, Kitty, and other ones and stuff that people build on their own. 59 00:05:09,020 --> 00:05:13,860 Then you have the ones that get shipped within your operational system like Windows Terminal. 60 00:05:14,320 --> 00:05:17,620 Terminal.app, GNOME, VTE, and other stuff. 61 00:05:17,740 --> 00:05:19,200 And then you've got old stuff like Xterm. 62 00:05:19,500 --> 00:05:22,660 So we also got this when we were in the cloud. 63 00:05:22,880 --> 00:05:30,300 Maybe you don't know this, but if you're going to try to use like a digital ocean to connect to your droplet or you're going to do some recovery console stuff, 64 00:05:30,720 --> 00:05:35,700 that is actually like an Xterm thingy connecting to that over TTY. 65 00:05:35,800 --> 00:05:37,120 You were able to interact with it. 66 00:05:37,200 --> 00:05:37,700 It's a terminal. 67 00:05:39,100 --> 00:05:41,960 And I wasn't really interested in the possibly part. 68 00:05:41,960 --> 00:05:45,500 I wanted to execute commands in the victim terminals. 69 00:05:45,960 --> 00:05:49,980 But I had no idea where to begin. 70 00:05:50,220 --> 00:05:51,100 It sounded cool. 71 00:05:51,320 --> 00:05:54,880 So I did everything that every self-respecting researcher do. 72 00:05:55,020 --> 00:05:57,220 I googled what ANSI escape codes were. 73 00:05:57,560 --> 00:05:58,660 I had no idea. 74 00:05:58,880 --> 00:06:07,280 And I quickly realized that people actually like to customize their terminals in the weirdest kind of ways, especially if you're using Arc. 75 00:06:07,600 --> 00:06:10,720 And this is the thing that just got me interested. 76 00:06:10,720 --> 00:06:11,380 They're like, oh, cool. 77 00:06:11,460 --> 00:06:12,680 You can change colors and stuff. 78 00:06:12,860 --> 00:06:21,260 But I also realized that in 1978, the Yildstrand boys dropped their banger album, We're Gonna Have Some Fun Tonight. 79 00:06:23,240 --> 00:06:37,000 But even though it would release the same year, the VT100 terminal, and connecting that using serial cables to a big VAX system is probably not what those guys thought would be fun to do on a Saturday night. 80 00:06:37,560 --> 00:06:40,200 Even though I personally would think that would be kind of cool. 81 00:06:41,100 --> 00:06:46,540 But I also realized that ANSI escape sequences are the shit that puts stuff on your terminal that you look at. 82 00:06:47,740 --> 00:06:50,980 And it can do stuff like you can move the cursor around. 83 00:06:51,240 --> 00:06:53,320 You can remap the keys using these. 84 00:06:53,600 --> 00:06:55,420 And you can actually print stuff. 85 00:06:55,780 --> 00:06:56,200 Ding. 86 00:06:57,580 --> 00:06:58,140 Interesting. 87 00:06:58,660 --> 00:07:01,640 But you can also build whole UIs. 88 00:07:01,680 --> 00:07:04,880 Like all this UI here is built in ANSI escape codes. 89 00:07:05,360 --> 00:07:09,780 Positioning of stuff, colors and output and all that, refreshing, clearing screens. 90 00:07:09,780 --> 00:07:14,060 All that is part of something called the control sequences standard. 91 00:07:14,320 --> 00:07:18,460 This is the standard for Xterm and it's vast and it's super hard to understand. 92 00:07:18,760 --> 00:07:20,360 I know you're all super smart. 93 00:07:20,500 --> 00:07:21,200 I wasn't. 94 00:07:21,300 --> 00:07:23,260 So I'm going to go through the basics with you. 95 00:07:24,040 --> 00:07:29,880 And the first I started looking through the documentation, it said CSI PM character attribute something something. 96 00:07:30,340 --> 00:07:31,720 No idea what that meant. 97 00:07:32,060 --> 00:07:32,960 But it's this. 98 00:07:33,700 --> 00:07:38,140 So all it actually is is printing out something that turns into green. 99 00:07:38,140 --> 00:07:38,660 Cool. 100 00:07:39,040 --> 00:07:44,040 And the reason why this works is due to this funny thing here called the escape character. 101 00:07:44,400 --> 00:07:45,560 That's important to remember. 102 00:07:45,860 --> 00:07:48,620 And it's also non-visible escape character. 103 00:07:49,080 --> 00:07:51,960 And it comes in many shapes and forms. 104 00:07:52,100 --> 00:08:01,140 Because the reason why they didn't print out exactly the command is because it depends if you're using octal, hex, unicode, decimal or ASCII. 105 00:08:01,320 --> 00:08:02,900 All of these are the same sequence. 106 00:08:03,020 --> 00:08:05,820 There's different kind of ways to portrait it. 107 00:08:06,060 --> 00:08:07,160 And I also realized that. 108 00:08:07,160 --> 00:08:08,740 Bash likes octal. 109 00:08:08,840 --> 00:08:09,900 Python likes hex. 110 00:08:10,580 --> 00:08:12,420 Java and JavaScript likes unicode. 111 00:08:12,500 --> 00:08:14,780 And PowerShell likes decimal for some reason. 112 00:08:15,600 --> 00:08:20,720 And this escape character here is the one that starts the whole sequence. 113 00:08:20,880 --> 00:08:22,060 It needs to start with that. 114 00:08:22,220 --> 00:08:27,820 Then we have this control sequence introducer which tells the terminal to do shit. 115 00:08:28,680 --> 00:08:31,700 Next one is the parameter of the number. 116 00:08:31,840 --> 00:08:33,660 So we'll go with 32 which is green here. 117 00:08:33,940 --> 00:08:36,640 M is to change whatever continuous output. 118 00:08:37,160 --> 00:08:38,820 Turning that into green. 119 00:08:39,060 --> 00:08:40,520 Which is the string we have here. 120 00:08:40,940 --> 00:08:45,300 And then we're just going to close it off with another escape character. 121 00:08:46,040 --> 00:08:47,860 Another control sequence introducer. 122 00:08:48,300 --> 00:08:49,740 And this is the important part. 123 00:08:50,340 --> 00:08:51,880 Here we do 0, M. 124 00:08:52,040 --> 00:08:54,300 And that means we're resetting the terminal back. 125 00:08:54,980 --> 00:08:59,100 And then, because if you don't do that, apparently this is going to happen. 126 00:08:59,220 --> 00:09:01,880 The rest of your shit is going to be all green. 127 00:09:02,380 --> 00:09:03,000 Hulk smash. 128 00:09:05,120 --> 00:09:06,560 But we need to terminate this. 129 00:09:06,560 --> 00:09:09,960 Using a ST or string terminator or bell character. 130 00:09:10,220 --> 00:09:15,400 And if you're like me and you accidentally kind of like grepped something. 131 00:09:15,720 --> 00:09:16,320 You know, money say. 132 00:09:16,480 --> 00:09:19,180 And then your terminal starts like ding, ding, ding, ding, ding. 133 00:09:19,740 --> 00:09:22,120 That is it being interpreted as the bell character. 134 00:09:22,420 --> 00:09:25,120 So we got escape secrets that's been shoved in there. 135 00:09:25,840 --> 00:09:27,160 So I thought, okay, cool. 136 00:09:27,240 --> 00:09:27,880 That's fun. 137 00:09:28,000 --> 00:09:29,920 I can put colors on my screen. 138 00:09:30,060 --> 00:09:30,500 Fancy. 139 00:09:31,140 --> 00:09:34,900 What happens if I put that in something called a bad log and see what happens. 140 00:09:34,900 --> 00:09:36,320 And then interact with it. 141 00:09:36,400 --> 00:09:42,660 Well, if I'm using vim, it's going to show the exact what the escape character is. 142 00:09:43,300 --> 00:09:44,320 It's this one here. 143 00:09:44,920 --> 00:09:46,840 And that's cool because it's not rendering. 144 00:09:47,000 --> 00:09:47,620 It just shows it. 145 00:09:47,760 --> 00:09:48,560 Same for nano. 146 00:09:48,720 --> 00:09:50,360 If you're using that, you're cool. 147 00:09:51,920 --> 00:09:56,520 And if you're using a browser, instead it's going to show it as Unicode. 148 00:09:56,680 --> 00:09:58,060 So that's also interesting to know. 149 00:09:58,620 --> 00:10:02,060 It's get interpreted differently depending on the system you're using. 150 00:10:03,020 --> 00:10:04,260 But if you kept it. 151 00:10:05,060 --> 00:10:06,220 Color's going to get displayed. 152 00:10:06,760 --> 00:10:07,260 Grip. 153 00:10:07,640 --> 00:10:08,140 Tail. 154 00:10:08,640 --> 00:10:09,140 Orchid. 155 00:10:09,320 --> 00:10:10,100 The same thing. 156 00:10:10,380 --> 00:10:12,280 And even if you curl it, boom. 157 00:10:12,600 --> 00:10:14,040 Fun stuff's going to happen. 158 00:10:14,340 --> 00:10:19,240 Because all these systems interpret the sequence that renders it. 159 00:10:19,440 --> 00:10:22,100 And at this stage when I ran this through curl, I'm like, shit. 160 00:10:22,660 --> 00:10:24,080 What just happened? 161 00:10:24,480 --> 00:10:26,660 What just happened? 162 00:10:26,820 --> 00:10:29,800 And I started thinking, where can I stuff this? 163 00:10:30,460 --> 00:10:33,040 Where that would interact with other people's stuff. 164 00:10:33,320 --> 00:10:34,060 So I figured. 165 00:10:34,060 --> 00:10:35,860 Why not do it in a text record? 166 00:10:36,040 --> 00:10:39,600 Because DNS is always the source for all evil. 167 00:10:39,920 --> 00:10:41,460 So I put it in there. 168 00:10:42,060 --> 00:10:45,660 And I ran Endless Lookup on it on OS X. 169 00:10:46,140 --> 00:10:47,020 Nothing happened. 170 00:10:47,280 --> 00:10:51,080 And you can see here, the extra slash in front of it means that it's escaped. 171 00:10:51,240 --> 00:10:52,200 It's beautifully escaped. 172 00:10:52,360 --> 00:10:53,280 This is a real good thing. 173 00:10:53,700 --> 00:10:57,000 If you're doing that on Windows, though, it's a different kind of story. 174 00:10:58,100 --> 00:11:00,700 So it depends on what kind of OS you're using. 175 00:11:01,020 --> 00:11:03,040 And big ups to David for showing that. 176 00:11:03,040 --> 00:11:03,720 That was real cool. 177 00:11:04,160 --> 00:11:06,540 So I was starting to ask myself, OK, cool. 178 00:11:06,620 --> 00:11:07,040 That's fine. 179 00:11:07,320 --> 00:11:09,400 But is this even a security issue? 180 00:11:09,580 --> 00:11:09,980 Seriously? 181 00:11:10,280 --> 00:11:16,960 So this kind of feels like this self XXX thing where you're like, OK, I can put colors on my terminal fun times. 182 00:11:17,660 --> 00:11:20,520 I need to figure out, who would this be an issue for? 183 00:11:21,740 --> 00:11:22,940 Where would this be an issue? 184 00:11:23,080 --> 00:11:24,680 How would this be an issue? 185 00:11:24,960 --> 00:11:27,500 And what would be the consequences of this? 186 00:11:29,240 --> 00:11:32,380 Well, the where wasn't that hard to figure out. 187 00:11:32,380 --> 00:11:37,580 Apparently, since we had the common logger thing, log injection would be the way to go. 188 00:11:38,080 --> 00:11:40,680 And who would it affect? 189 00:11:41,040 --> 00:11:47,480 I reckon DevOps, sysadmin, IR forensic people, or anyone that interacts with the log files using a terminal. 190 00:11:47,880 --> 00:11:49,540 And we can take a quick break here. 191 00:11:49,660 --> 00:11:55,900 How many of you have ever catted, grepped, or jq'd a file that you parsed from some other software? 192 00:11:57,440 --> 00:11:58,380 I love you. 193 00:12:03,080 --> 00:12:06,100 To do this, as the scientists, we are researchers. 194 00:12:06,360 --> 00:12:06,900 We're professionals. 195 00:12:07,540 --> 00:12:12,040 Log injection vulnerabilities occur according to OWASP when data enters an application from an untrusted source. 196 00:12:12,640 --> 00:12:12,880 Yes. 197 00:12:13,020 --> 00:12:15,800 The data is written to an application or a system log file. 198 00:12:16,060 --> 00:12:16,500 Cool. 199 00:12:17,560 --> 00:12:20,940 I needed to adapt that, because this is kind of written to do XSS stuff. 200 00:12:21,060 --> 00:12:31,080 So I figured that, OK, to successfully have this as a measurement, I needed to be able to inject new log files or events by forging a log. 201 00:12:31,080 --> 00:12:33,440 I needed to be able to inject an escape sequence. 202 00:12:33,760 --> 00:12:38,740 And I needed to, in some way or form, make that run in someone's terminal emulator. 203 00:12:39,120 --> 00:12:44,040 And I also needed that injection to execute some kind of stuff. 204 00:12:44,680 --> 00:12:48,180 And I figured, which would be the best test bench for this, huh? 205 00:12:48,800 --> 00:12:50,200 And Docker, obviously. 206 00:12:50,540 --> 00:12:53,600 Because it loves to send whatever logs to standard out. 207 00:12:53,820 --> 00:12:57,060 It has this real log that's running through. 208 00:12:57,240 --> 00:12:59,640 There are actually terminal rendering stuff. 209 00:12:59,640 --> 00:13:03,760 And it comes with a really nifty, getting started kind of app. 210 00:13:04,400 --> 00:13:05,180 Good stuff. 211 00:13:05,460 --> 00:13:06,600 I'll go for that. 212 00:13:08,160 --> 00:13:15,600 And also, a way for you, if you want to attach your work with Docker, you would use Docker attach inside a terminal, connect to it. 213 00:13:15,680 --> 00:13:20,100 Or Docker logs to do like a tail and see whatever happens inside your container. 214 00:13:20,560 --> 00:13:23,100 I'm like, mm-mm, seems tasty enough for me. 215 00:13:23,800 --> 00:13:27,580 But I also realized that I couldn't just take this print F thing and stuff it in a browser. 216 00:13:27,760 --> 00:13:28,900 Because, hey, shit. 217 00:13:29,640 --> 00:13:30,000 I can't do that. 218 00:13:30,060 --> 00:13:30,360 No, no, no. 219 00:13:30,440 --> 00:13:32,120 So I needed to URL encode it. 220 00:13:32,240 --> 00:13:35,040 And for good measure, we added a new line in there. 221 00:13:35,200 --> 00:13:44,800 Because everyone knows that if you're triaging some kind of bugs, new lines are very important to show that it's actually able to inject some kind of false log entries. 222 00:13:47,640 --> 00:13:52,980 So I figured, let's see what happens if I curl this and you send that straight in. 223 00:13:53,880 --> 00:13:58,420 And I was really excited when I realized that, oh, nothing came back. 224 00:13:59,640 --> 00:14:00,540 So I started looking at the log. 225 00:14:00,620 --> 00:14:01,960 And over here, it's like, oh, ho. 226 00:14:02,440 --> 00:14:04,600 Nothing comes in return in the response. 227 00:14:04,920 --> 00:14:06,940 But new line has been entered. 228 00:14:07,140 --> 00:14:11,520 The color has been rendered inside the log that's being displayed in real time. 229 00:14:11,680 --> 00:14:17,400 Which means, like, on the first try, more or less, we checked all the boxes to prove a successful log injection. 230 00:14:17,700 --> 00:14:24,140 Because we're injecting new lines, we are enabled to run escape sequences that will be viewed in a terminal emulator. 231 00:14:24,360 --> 00:14:25,240 In this case, Docker. 232 00:14:25,420 --> 00:14:29,620 And I'm able to inject commands that the terminal emulator could execute. 233 00:14:29,620 --> 00:14:31,240 In this case, we're changing the color. 234 00:14:32,420 --> 00:14:37,820 Because remember, even though that was the only line that I put in, we can create this. 235 00:14:38,180 --> 00:14:43,940 Because it's all about the limitations and creativity of whoever decides to design this. 236 00:14:44,800 --> 00:14:48,500 And even though I'm like, fuck yeah, confirmed. 237 00:14:49,960 --> 00:14:53,720 The Yildstrand boys weren't that impressed. 238 00:14:54,940 --> 00:14:56,820 They wanted me to provide more impact. 239 00:14:57,880 --> 00:14:58,720 So I'm like, OK. 240 00:14:59,060 --> 00:14:59,900 I can do that. 241 00:15:00,180 --> 00:15:02,260 I started, once again, Googling stuff. 242 00:15:02,440 --> 00:15:06,760 And then I stumbled upon this great research from 2003 by H.D. Moore. 243 00:15:07,060 --> 00:15:14,880 And he found a really, really interesting, cool way to just misuse the terminal and use it against them in a way. 244 00:15:15,040 --> 00:15:21,020 So what happens here is that they were able to use something called OSC2 sequence. 245 00:15:21,540 --> 00:15:24,120 Where you will actually put this on a command line. 246 00:15:24,440 --> 00:15:26,800 And that would change the time. 247 00:15:26,820 --> 00:15:28,580 The title of the terminal you're in. 248 00:15:28,700 --> 00:15:32,140 And if you're currently using a terminal, you're changing directories and stuff. 249 00:15:32,280 --> 00:15:35,520 And it just updates there inside the title. 250 00:15:35,700 --> 00:15:36,560 I've seen that. 251 00:15:36,620 --> 00:15:37,480 We're connecting to a shell. 252 00:15:37,560 --> 00:15:38,000 It's changing it. 253 00:15:38,160 --> 00:15:40,260 That is actually the sequence doing that. 254 00:15:40,700 --> 00:15:42,120 But that wasn't enough. 255 00:15:42,460 --> 00:15:47,140 They digged into the deeper parts of the whole documentation. 256 00:15:47,200 --> 00:15:54,300 And realized that in this CSI code here, 21T. 257 00:15:54,300 --> 00:15:59,300 You were actually able to report back whatever was put inside the title. 258 00:15:59,360 --> 00:16:02,120 And push that to the command line. 259 00:16:02,520 --> 00:16:04,300 That could only mean trouble. 260 00:16:05,100 --> 00:16:09,340 Because even if this stuff were put on the command line. 261 00:16:09,500 --> 00:16:12,800 And in this case, you needed to have a social interaction with the user. 262 00:16:12,840 --> 00:16:15,760 The user needs to be fooled into pressing enter. 263 00:16:15,940 --> 00:16:19,300 It's still a cool way to just push something in the title. 264 00:16:19,500 --> 00:16:20,500 Read it back. 265 00:16:20,640 --> 00:16:21,240 And then boom. 266 00:16:21,520 --> 00:16:22,500 Shit happens. 267 00:16:22,500 --> 00:16:25,220 But that's been fixed for ages. 268 00:16:26,180 --> 00:16:29,080 2003, if you want to feel old, is like two decades ago. 269 00:16:30,500 --> 00:16:32,500 So, I started searching some more. 270 00:16:32,600 --> 00:16:37,700 And I found this really nice write-up from Evil Alive, Jekyll and ASCII. 271 00:16:37,940 --> 00:16:42,380 That did some cool research on all these different web servers back in 2010. 272 00:16:42,740 --> 00:16:45,160 Where they're using the same kind of sequence here. 273 00:16:45,460 --> 00:16:47,080 But we know that's been fixed. 274 00:16:47,140 --> 00:16:48,380 So, can't do much with that. 275 00:16:48,720 --> 00:16:52,480 But then in 2022, Evitar Gursey released some sort of code. 276 00:16:52,500 --> 00:16:53,520 Sorry for crashing the name. 277 00:16:53,640 --> 00:16:55,240 Don't know how to pronounce it. 278 00:16:55,540 --> 00:16:57,840 A cool way to create a DOS sequence. 279 00:16:58,180 --> 00:17:02,880 When they were able to read a bunch of stuff into the title. 280 00:17:03,000 --> 00:17:04,300 And just creating crashes. 281 00:17:04,880 --> 00:17:08,640 And I'm just tasting buffer overflows here for the future to come. 282 00:17:09,400 --> 00:17:10,700 But that's been fixed too. 283 00:17:11,000 --> 00:17:11,900 So, here I am. 284 00:17:12,640 --> 00:17:14,160 Feeling like an epic fail. 285 00:17:14,700 --> 00:17:16,580 Can't do the arbitrary command injection. 286 00:17:16,820 --> 00:17:19,420 That seems so cool that the person talked about in the CBE. 287 00:17:19,860 --> 00:17:21,120 So, I did the thing. 288 00:17:21,120 --> 00:17:23,480 I think the end is the only thing you do. 289 00:17:24,120 --> 00:17:26,760 You reach out to the original poster and ask them. 290 00:17:26,820 --> 00:17:28,320 Can I ask the RC Epoch? 291 00:17:29,240 --> 00:17:30,520 And the answer back. 292 00:17:30,580 --> 00:17:31,360 I didn't write any. 293 00:17:31,460 --> 00:17:33,380 I used this paper as a reference. 294 00:17:34,340 --> 00:17:36,840 And that sucks because we know that's fixed. 295 00:17:37,720 --> 00:17:38,620 So, here I am. 296 00:17:39,160 --> 00:17:40,020 Super excited. 297 00:17:40,220 --> 00:17:41,700 But oh, I got old stuff. 298 00:17:42,560 --> 00:17:44,260 And speaking about old stuff. 299 00:17:44,620 --> 00:17:46,680 This is what I looked like in the 80s. 300 00:17:49,480 --> 00:17:50,220 No, I'm kidding. 301 00:17:50,220 --> 00:17:51,800 I'm probably more like this badass here. 302 00:17:52,280 --> 00:17:54,900 And if you look at the angle of the arm here. 303 00:17:55,500 --> 00:17:56,600 That's very important. 304 00:17:56,680 --> 00:18:00,800 Because it's exactly the same angle as this gentleman here in this band poster. 305 00:18:01,240 --> 00:18:02,860 That's pretty fucking darn cool. 306 00:18:03,040 --> 00:18:08,080 Because he was one of the first people to sell Diab and Unix computers in Sweden. 307 00:18:08,380 --> 00:18:09,680 And not only that. 308 00:18:10,160 --> 00:18:11,220 He's my dad. 309 00:18:11,560 --> 00:18:16,980 So, I'm very grateful to him to put stuff and give me access to computers at an early age. 310 00:18:19,280 --> 00:18:19,940 Thank you. 311 00:18:23,480 --> 00:18:25,200 But I'm starting to look at this picture. 312 00:18:25,300 --> 00:18:26,740 I'm starting to realize that I'm actually. 313 00:18:27,040 --> 00:18:28,760 Maybe I'm looking more like Lasse. 314 00:18:29,000 --> 00:18:31,860 That was on the same tour as my dad when he met my mom. 315 00:18:36,980 --> 00:18:38,680 Anyway, the standard is vast. 316 00:18:38,780 --> 00:18:39,460 And it's deep. 317 00:18:39,700 --> 00:18:41,680 And it takes a lot of things to go through. 318 00:18:42,020 --> 00:18:46,320 But that wasn't enough for the fine developers and users of terminal jobs today. 319 00:18:46,320 --> 00:18:46,800 No. 320 00:18:47,020 --> 00:18:47,760 They wanted more. 321 00:18:48,000 --> 00:18:53,320 Because all these different terminals have different kind of functionality. 322 00:18:53,740 --> 00:18:57,340 And, you know, with more features, we need more stuff. 323 00:18:57,560 --> 00:19:00,180 So, they invited something called proprietary escape codes. 324 00:19:00,340 --> 00:19:04,160 Which is a local edition of the standard. 325 00:19:04,380 --> 00:19:05,720 And it works in certain terminals. 326 00:19:05,840 --> 00:19:06,540 Not all of them. 327 00:19:06,640 --> 00:19:08,500 Some of them are being shared internally. 328 00:19:08,720 --> 00:19:10,620 And some work over the whole bar. 329 00:19:11,180 --> 00:19:16,220 And what that does is gives you the opportunity to, you know, make a fun twirly thing. 330 00:19:16,320 --> 00:19:18,740 Maybe in your title. 331 00:19:19,000 --> 00:19:19,840 Get notifications. 332 00:19:20,080 --> 00:19:21,900 And all these other cool stuff that's in there. 333 00:19:21,960 --> 00:19:23,400 Maybe even change your background. 334 00:19:23,740 --> 00:19:24,440 Fancy stuff. 335 00:19:25,240 --> 00:19:30,020 But some thought that it was a great idea to always run some processes with arguments. 336 00:19:30,360 --> 00:19:31,060 Why not? 337 00:19:31,200 --> 00:19:32,380 Using escape sequences. 338 00:19:32,960 --> 00:19:34,960 I mean, that's a really bad idea. 339 00:19:36,700 --> 00:19:42,840 But luckily enough, it's rare to find stuff that runs a really bad idea, too, nowadays. 340 00:19:43,000 --> 00:19:44,760 Because it's old and it's been fixed. 341 00:19:44,760 --> 00:19:49,340 So, I needed to find something that was, like, adapted by everyone. 342 00:19:49,640 --> 00:19:51,400 Everybody loved it and trusted it. 343 00:19:51,440 --> 00:19:53,320 And they thought it was nice. 344 00:19:54,400 --> 00:19:55,840 That we could weaponize. 345 00:19:57,440 --> 00:19:58,100 Why not? 346 00:19:58,240 --> 00:20:00,260 Because we are tricksy hobbitses. 347 00:20:02,140 --> 00:20:03,440 And I found OSC 8. 348 00:20:03,700 --> 00:20:04,400 I'm like, cool. 349 00:20:04,540 --> 00:20:09,960 If you ever run PowerShell and you mess that up, you'll get this prompt coming back that says, you suck. 350 00:20:10,320 --> 00:20:12,820 Click this link and somebody's going to tell you how to do it. 351 00:20:13,040 --> 00:20:13,760 I'm like, cool. 352 00:20:14,760 --> 00:20:15,260 That seems doable. 353 00:20:15,460 --> 00:20:21,180 And the reason why that works is because you have this ANSI escape sequence that gives you the HTTP thing. 354 00:20:21,420 --> 00:20:24,020 And then it has the title of whatever you want to print out. 355 00:20:24,280 --> 00:20:27,360 And then you close it off and it turns into this link inside your terminal. 356 00:20:27,600 --> 00:20:28,500 And that's great. 357 00:20:29,740 --> 00:20:34,780 Initially, that was only allowed to use URI like HTTP and HTTPS. 358 00:20:35,400 --> 00:20:42,740 But recently, the fine people over at Windows Terminal decided that we should allow file, too. 359 00:20:43,760 --> 00:20:45,180 That's even a great idea. 360 00:20:45,780 --> 00:20:49,400 Because what could even happen if you typed in CMD there and clicked it? 361 00:20:49,960 --> 00:20:50,780 I wonder. 362 00:20:52,240 --> 00:20:54,180 Fun things popping inside user space. 363 00:20:54,640 --> 00:21:00,720 And even though this is kind of filtered in a way where you can start CMD but you can't use any parameters, 364 00:21:01,440 --> 00:21:07,520 I'm willing to guess that some smart person in here is going to figure out how to bypass that, put a link in, and pop shells. 365 00:21:08,020 --> 00:21:09,200 It's definitely doable. 366 00:21:10,740 --> 00:21:12,720 And the fun thing with OSC 8. 367 00:21:12,720 --> 00:21:14,460 Is if you don't terminate it correctly. 368 00:21:14,660 --> 00:21:19,060 You remember what we did with the green when it all went hulk everywhere? 369 00:21:19,320 --> 00:21:26,140 If we don't terminate it correctly, the rest of the output starting from that injection is going to be one big link. 370 00:21:26,940 --> 00:21:28,060 Everything is going to be a link. 371 00:21:28,160 --> 00:21:33,840 And if you click that, some terminals will be very nice for you and just block that out with a warning. 372 00:21:35,020 --> 00:21:37,100 And I figured out, okay, that's cool. 373 00:21:37,200 --> 00:21:39,540 I wonder if I can inject this somewhere. 374 00:21:39,680 --> 00:21:42,440 Because obviously me putting links on my own shit would be boring. 375 00:21:42,720 --> 00:21:45,360 So what happens if I put that inside Docker? 376 00:21:45,540 --> 00:21:48,240 Well, everything is going to turn into one big link there too. 377 00:21:48,760 --> 00:21:50,460 And that one has a protection in. 378 00:21:51,020 --> 00:21:53,400 But it's not everywhere this turns into a protection. 379 00:21:53,580 --> 00:21:56,220 Because injections can be put in different places. 380 00:21:56,400 --> 00:21:59,840 And then suddenly you can click links and you can just imagine how fun this could be. 381 00:22:03,920 --> 00:22:06,040 But that wasn't enough for people. 382 00:22:06,780 --> 00:22:08,720 Because, you know, text is cool. 383 00:22:08,900 --> 00:22:11,160 But inline image support? 384 00:22:11,160 --> 00:22:13,980 That's definitely something we need in text space. 385 00:22:14,280 --> 00:22:19,720 So the Windows terminal people, they decided to adapt the inline support for it in the recent build 386 00:22:19,720 --> 00:22:25,440 where you're able to do, you have 6L and inline support inside the terminal. 387 00:22:25,700 --> 00:22:26,460 And that's great. 388 00:22:26,660 --> 00:22:28,140 I see no problem with that. 389 00:22:28,220 --> 00:22:28,880 I think that's great. 390 00:22:29,180 --> 00:22:32,340 I just wonder what's going to be inside this log file. 391 00:22:34,920 --> 00:22:38,640 So can I get a raise of hands if any of you wants to see what's in that log file? 392 00:22:41,160 --> 00:22:41,440 I love you. 393 00:22:42,820 --> 00:22:44,480 And it's not what you thought it would be. 394 00:22:45,540 --> 00:22:46,320 Shame on you! 395 00:22:50,020 --> 00:22:52,260 Then we have OC52, which is great. 396 00:22:52,380 --> 00:22:57,640 If you ever used T-marks or anything and back in the days you weren't able to copy-paste between shells, sucked. 397 00:22:58,060 --> 00:22:58,860 Now you can. 398 00:22:59,100 --> 00:23:00,440 The reason is OC52. 399 00:23:01,200 --> 00:23:04,120 And what it does is that it takes this sequence. 400 00:23:04,520 --> 00:23:09,840 If you have something base 64 coded, it's going to put that inside user space clipboard. 401 00:23:10,300 --> 00:23:11,060 Super sweet. 402 00:23:11,160 --> 00:23:11,300 Great. 403 00:23:11,680 --> 00:23:17,740 I wonder what happens if we do open a something calculator app and a new line on the end because we need that new line. 404 00:23:17,900 --> 00:23:22,360 If you put that into CS Edge and paste it, this is what's going to happen. 405 00:23:22,600 --> 00:23:25,080 It requires the users to do something. 406 00:23:25,640 --> 00:23:28,100 And you press that, boom, okay, it pops calc. 407 00:23:28,520 --> 00:23:31,940 But if you do the same thing in Bash, Bash honors the new line. 408 00:23:32,120 --> 00:23:37,820 So if you just paste it straight in there, it fires it directly. 409 00:23:38,580 --> 00:23:41,000 There are room for improvement here though. 410 00:23:42,080 --> 00:23:45,000 So I figured I wonder how can I test this in different spaces. 411 00:23:45,200 --> 00:23:49,680 I did this kind of basic four string with these commands in it and said I'm curious what's going to happen. 412 00:23:49,900 --> 00:23:51,820 And I started to paste that in different places. 413 00:23:52,060 --> 00:23:53,240 Docker, that fired directly. 414 00:23:53,380 --> 00:23:54,140 That was nice. 415 00:23:54,720 --> 00:23:57,980 VSCode, it did it differently depending on what kind of shell you're using. 416 00:23:58,200 --> 00:24:01,900 And even in some cases gave you this warning, which is super good. 417 00:24:02,140 --> 00:24:03,380 Of course, with your own people. 418 00:24:04,040 --> 00:24:05,660 Terminal.app honors it. 419 00:24:05,740 --> 00:24:07,000 It runs it directly. 420 00:24:07,360 --> 00:24:10,460 And even, you know, you will get inside Windows Terminal. 421 00:24:10,460 --> 00:24:13,300 You will get even this preview of showing things that are bad. 422 00:24:13,840 --> 00:24:17,540 And the reason for that is that if you wanted to run this command, 10 lines, into whom, 423 00:24:17,560 --> 00:24:23,720 Windows Terminal is going to be nice of you to show the first lines and tell you, yeah, you've got your shit going on here. 424 00:24:23,900 --> 00:24:28,660 So why not just add seven lines of nothing and then see what happens? 425 00:24:28,840 --> 00:24:29,760 Well, there's nothing in there. 426 00:24:30,680 --> 00:24:34,120 And everybody knows that nobody is going to scroll down. 427 00:24:34,620 --> 00:24:37,320 And what happens if you add 400 lines in there? 428 00:24:38,000 --> 00:24:39,320 Nobody is ever going to scroll down. 429 00:24:39,320 --> 00:24:43,000 Or you can even, in this, add some kind of those EULA things. 430 00:24:43,280 --> 00:24:44,860 Then people just press OK. 431 00:24:47,660 --> 00:24:50,700 So with that in there, it's going to be OK if you're just running it. 432 00:24:50,820 --> 00:24:51,560 I think that's pretty cool. 433 00:24:51,660 --> 00:24:52,280 It's a decent thing. 434 00:24:52,460 --> 00:24:55,120 So I think, OK, so I have this sort of thing for Windows Terminal. 435 00:24:55,200 --> 00:24:55,980 I've got one for Bash. 436 00:24:56,520 --> 00:24:58,820 Let's create a polyglot and see what happens. 437 00:24:59,260 --> 00:25:03,760 So I figured that why not have a little bit of an SVG in there. 438 00:25:04,040 --> 00:25:07,060 You stop that one off with a good old hash mark at the end. 439 00:25:07,320 --> 00:25:08,900 Do a curl command, obviously. 440 00:25:09,320 --> 00:25:11,720 You want this to run locally and not fuck around on the interwebs. 441 00:25:12,080 --> 00:25:17,380 And then we do a PowerShell kind of mix where we're using CMD that calls PowerShell and stuff 442 00:25:17,380 --> 00:25:20,560 because they want it to work in whatever kind of environment you end up in. 443 00:25:20,700 --> 00:25:23,480 And we want to exfiltrate stuff to know what's happening. 444 00:25:24,440 --> 00:25:26,680 So here's the hash that's important. 445 00:25:27,060 --> 00:25:28,680 And then eventually this last one here. 446 00:25:29,920 --> 00:25:35,980 Encode that into one big basic support thing and just send that to bad log, cat bad log, 447 00:25:36,220 --> 00:25:38,060 and then start pasting it in places. 448 00:25:38,060 --> 00:25:40,060 Well, it obviously worked there. 449 00:25:40,260 --> 00:25:42,600 This removed all the info in the beginning. 450 00:25:43,240 --> 00:25:44,700 It's going to pop here, too. 451 00:25:44,980 --> 00:25:49,940 And if you go to the browser and you paste that in, you have some JavaScript running, which is great. 452 00:25:50,880 --> 00:25:56,340 Then you can just refresh it here, and you'll see that, OK, it's running who am I 453 00:25:56,340 --> 00:26:02,200 and then different other kind of stuff in there that's just exfiltrating stuff for you inside the request. 454 00:26:02,560 --> 00:26:07,980 And this is just being dormant in some poor bastard's clipboard by just interacting with the file. 455 00:26:08,060 --> 00:26:09,580 Because you can sit there and work. 456 00:26:09,620 --> 00:26:12,900 You catch something, and then you decide to paste, and then boom, it's on you. 457 00:26:15,080 --> 00:26:16,040 It's not limited there. 458 00:26:16,100 --> 00:26:20,740 Obviously, you can exfiltrate stuff like sending things out and do reverse shells and all that. 459 00:26:20,860 --> 00:26:22,380 I didn't go through that in this demo. 460 00:26:22,520 --> 00:26:23,480 You are smart people. 461 00:26:23,580 --> 00:26:24,120 You know what to do. 462 00:26:25,220 --> 00:26:30,980 But if we're doing this, we might just want to hide our tracks or just mess things up because we can. 463 00:26:31,280 --> 00:26:32,980 And there's different ways to do this. 464 00:26:33,120 --> 00:26:36,940 You can use everything from just moving the cursor to a certain position. 465 00:26:37,120 --> 00:26:37,940 You can clear the screen. 466 00:26:38,060 --> 00:26:40,560 You can erase stuff or clear the scroll-up buffer. 467 00:26:41,000 --> 00:26:44,700 And to showcase this, I'm just putting like 50 lines here on the screen for you. 468 00:26:44,920 --> 00:26:48,320 And then we're just going to run the command, and it's empty. 469 00:26:48,600 --> 00:26:51,180 And that's perfect to have a proof of concept myself. 470 00:26:51,540 --> 00:26:58,160 But what happens if we run that inside, let's say, this Docker instance and we send in the reset screen and just go back? 471 00:26:58,400 --> 00:26:59,980 Well, this is what's going to happen. 472 00:27:00,860 --> 00:27:02,720 It empties the log file for you. 473 00:27:03,100 --> 00:27:07,960 And every time you load it, all the way up to that's getting rendered. 474 00:27:08,840 --> 00:27:10,360 It's going to clean it anyway for you. 475 00:27:10,400 --> 00:27:12,120 So you need to sanitize and clean that out. 476 00:27:13,160 --> 00:27:13,580 Fun. 477 00:27:13,940 --> 00:27:15,720 And that is somewhat annoying. 478 00:27:16,700 --> 00:27:19,080 For anyone that's using that, that's really annoying. 479 00:27:19,240 --> 00:27:20,880 But it's not annoying enough. 480 00:27:21,600 --> 00:27:24,020 We need to do some brick stuff to really be annoying. 481 00:27:24,940 --> 00:27:26,660 And why not use the standard? 482 00:27:26,820 --> 00:27:28,380 Like we have this print screen functionality. 483 00:27:28,460 --> 00:27:35,460 We gave ourselves the opportunity if we're typing that one in, it will send in a printer prompt for you. 484 00:27:35,760 --> 00:27:37,700 Imagine getting that every minute or so. 485 00:27:38,100 --> 00:27:39,220 It could be annoying. 486 00:27:40,720 --> 00:27:42,440 But you can also do this cool thing. 487 00:27:42,580 --> 00:27:45,320 Instead of doing the 0i, you can do 5i. 488 00:27:45,540 --> 00:27:54,060 Because back in the days, we used to have matrix printers next to our computers that were like, eh, eh, eh, having a paper copy of said log. 489 00:27:55,100 --> 00:27:56,200 We don't have those anymore. 490 00:27:56,380 --> 00:28:03,080 So we can't send anything out to this buffer that doesn't exist, which means, as you can see here, if you send it in, all the commands are going to send it to Vivian. 491 00:28:03,420 --> 00:28:06,120 And it's still going to render, but you can't see shit. 492 00:28:06,260 --> 00:28:07,540 So that's really annoying. 493 00:28:07,700 --> 00:28:10,520 And the only way to get rid of that is to close the browser. 494 00:28:11,700 --> 00:28:13,060 But it's not annoying enough. 495 00:28:14,100 --> 00:28:15,500 No, we need to be really annoying. 496 00:28:15,740 --> 00:28:19,260 And one way to do that is to use the mouse tracking functionality. 497 00:28:19,500 --> 00:28:20,000 It was great. 498 00:28:20,180 --> 00:28:31,500 If you ever installed some kind of, I don't know, Slackware or something or whatever, Debian, and you're in that CLI mode and suddenly you realize my mouse works and I can click on stuff, that's cool. 499 00:28:32,580 --> 00:28:37,680 That is the reason because somebody is tracking what kind of where your mouse are in that space. 500 00:28:37,700 --> 00:28:44,260 And if you run that on the terminal and move your mouse around, it's going to report all that stuff all the time. 501 00:28:44,400 --> 00:28:47,340 And if you click, it's going to execute whatever kind of happened there. 502 00:28:47,820 --> 00:28:56,060 And what's really interesting when doing this is that imagine you're sneaking some other shit in there and somebody clicks stuff and then it's going to pop it. 503 00:28:56,760 --> 00:28:57,160 Fun. 504 00:28:57,400 --> 00:29:01,720 And if you combine those, you see where I'm going, a bunch of chains here. 505 00:29:01,920 --> 00:29:06,220 You can just combine those things together and just create a lot of interesting stuff. 506 00:29:06,780 --> 00:29:08,800 But then I stumbled upon this one here. 507 00:29:08,940 --> 00:29:10,480 It looks so sweet. 508 00:29:10,680 --> 00:29:11,540 And it's perfect. 509 00:29:11,800 --> 00:29:15,100 Repeat the preceding graphic character X amount of times. 510 00:29:15,420 --> 00:29:16,560 And that is perfect. 511 00:29:16,640 --> 00:29:18,860 You want to measure, like, how big a terminal screen are. 512 00:29:19,240 --> 00:29:23,580 And so in this case, let's see that we wanted to repeat this ten times. 513 00:29:24,220 --> 00:29:27,140 It's going to do it ten times for us in the output of the terminal. 514 00:29:28,060 --> 00:29:29,660 But one simply wonders. 515 00:29:33,240 --> 00:29:35,520 A billion times is a lot of fucking piece. 516 00:29:36,220 --> 00:29:39,460 And since this is not a single character. 517 00:29:39,660 --> 00:29:40,360 This is Unicode. 518 00:29:40,440 --> 00:29:42,320 You get five characters for the price of one. 519 00:29:44,720 --> 00:29:48,320 And my recommendation to you is to do not run this in prod. 520 00:29:49,080 --> 00:29:50,140 Things will break. 521 00:29:51,400 --> 00:29:55,520 Like, I can't open this Docker container again without it crashing. 522 00:29:55,680 --> 00:29:58,370 And when it crashes, it kills Docker desktops. 523 00:29:58,760 --> 00:30:00,100 I need to start it all over again. 524 00:30:01,080 --> 00:30:02,400 It can be somewhat annoying. 525 00:30:09,660 --> 00:30:10,300 Thank you. 526 00:30:12,360 --> 00:30:13,920 So it breaks most terminal. 527 00:30:14,080 --> 00:30:17,980 And some terminals, even like the one I have on my phone here, you know, it crashes that one. 528 00:30:18,180 --> 00:30:22,120 So it's just, once again, I'm starting to think, like, okay, that's cool. 529 00:30:22,180 --> 00:30:23,140 I wonder what happens. 530 00:30:23,800 --> 00:30:25,640 What can I do to weaponize this? 531 00:30:28,560 --> 00:30:33,180 Maybe if I put it in my service signature on a host. 532 00:30:33,420 --> 00:30:35,920 And then request a let's encrypt certificate. 533 00:30:35,920 --> 00:30:38,420 I wonder if the bots will come running. 534 00:30:40,860 --> 00:30:46,460 I'm betting you there's a bunch of fucking automation scripts that's going to scrape and look for the kind of version I'm running. 535 00:30:46,740 --> 00:30:50,240 That's going to get dosed out whenever somebody decides to look at that entry. 536 00:30:51,100 --> 00:30:51,820 Real fun. 537 00:30:54,020 --> 00:30:56,040 Okay, you got a question, scary-looking kid? 538 00:30:58,400 --> 00:30:59,400 No RC? 539 00:31:01,720 --> 00:31:02,220 No. 540 00:31:03,340 --> 00:31:04,080 I know. 541 00:31:04,080 --> 00:31:07,600 I wasn't able to do any kind of arbitrary command injection. 542 00:31:08,000 --> 00:31:08,580 Sucks. 543 00:31:08,720 --> 00:31:11,220 I got malicious stuff, but not really bad stuff. 544 00:31:11,540 --> 00:31:15,020 So these were dark times in the middle of my research. 545 00:31:15,460 --> 00:31:19,820 The light came in the shape of David Leadbeater. 546 00:31:20,580 --> 00:31:29,080 And his amazing fucking talk, sorry, pardon my French, at Blue Hat 2023 called Houdini in the Terminal, where he doesn't provide just one. 547 00:31:29,220 --> 00:31:29,500 No. 548 00:31:29,500 --> 00:31:31,100 He brings on six. 549 00:31:31,100 --> 00:31:36,240 Six remote code executions in Terminals that are live today. 550 00:31:36,580 --> 00:31:37,980 I'm like, mmm, tasty. 551 00:31:38,200 --> 00:31:39,100 David knows stuff. 552 00:31:40,100 --> 00:31:45,740 And he's doing that, but using kind of the same thing that H.D. Moore back in the days with this CRLF injection. 553 00:31:46,060 --> 00:31:48,520 But he's using something called device control request string. 554 00:31:48,700 --> 00:31:51,120 I'm not going to try to pronounce that. 555 00:31:52,600 --> 00:31:55,940 If you want to check out his Git repo, it's really, really good. 556 00:31:56,120 --> 00:31:57,300 He's got a lot of cool stuff there. 557 00:31:57,640 --> 00:32:00,040 And he's speaking tomorrow. 558 00:32:01,760 --> 00:32:02,200 Here. 559 00:32:02,400 --> 00:32:04,540 So please go visit that talk. 560 00:32:04,700 --> 00:32:06,920 I'm going to be there. 561 00:32:07,040 --> 00:32:11,860 And the Yieldstrand voice is definitely going to be there because he's going to release some banger stuff. 562 00:32:12,120 --> 00:32:13,640 And you don't want to miss that. 563 00:32:14,320 --> 00:32:18,340 So this is all David's work, but I'm going to show it now because, hey, why not? 564 00:32:18,720 --> 00:32:20,960 So I figured that he had this thing provided. 565 00:32:21,140 --> 00:32:24,620 I needed to put that in a way that I could infiltrate others. 566 00:32:24,740 --> 00:32:26,460 So I basic for this string here. 567 00:32:26,860 --> 00:32:28,540 More or less this is kind of what it does. 568 00:32:28,720 --> 00:32:30,960 It sends in a bunch of control sequences. 569 00:32:31,760 --> 00:32:33,540 I'm not going to bore you with that. 570 00:32:33,640 --> 00:32:37,740 But more or less what it does, it asks you what kind of color you have on the screen. 571 00:32:38,060 --> 00:32:43,260 But we're feeding that with other stuff instead and then adding new lines and voila, bub, fun stuff. 572 00:32:44,260 --> 00:32:50,760 So if you're using version 3.17 of iTerm, which is not the newest one. 573 00:32:50,880 --> 00:32:51,640 It's been patched now. 574 00:32:51,960 --> 00:32:55,860 And you're interacting with the logs using this docker. 575 00:32:57,020 --> 00:33:00,440 What's going to happen if I paste that inside your terminal 576 00:33:00,440 --> 00:33:01,780 and you're running that live tail? 577 00:33:02,260 --> 00:33:03,780 I'm going to pop tag for you. 578 00:33:03,900 --> 00:33:04,540 Why not? 579 00:33:05,360 --> 00:33:08,180 Super simple way to just make sure that things break. 580 00:33:08,300 --> 00:33:11,360 So update your iTerms, people, if you're playing around with that. 581 00:33:11,720 --> 00:33:14,740 And the reason why this is working, and I love this, 582 00:33:15,000 --> 00:33:21,100 is simply because what David figured out is that he could sneak in X03 here, 583 00:33:21,320 --> 00:33:24,200 which is control C kind of thing or control X. 584 00:33:24,340 --> 00:33:27,040 So you're escaping out of whatever thing that's running. 585 00:33:27,240 --> 00:33:30,420 And imagine what happens if you're trying to, like, escape out. 586 00:33:30,440 --> 00:33:32,140 You're escaping out of a docker attach sequence. 587 00:33:32,420 --> 00:33:33,820 It's going to shut down the docker. 588 00:33:34,260 --> 00:33:39,060 And after that, we're adding whatever command that we want to run. 589 00:33:39,340 --> 00:33:42,620 And then simply, we're going back again and it tells the system, 590 00:33:42,760 --> 00:33:48,120 could you please report back for us whatever kind of color that we're running? 591 00:33:48,320 --> 00:33:52,700 But we already tainted that with other stuff, so it's just going to boom, which is great. 592 00:33:53,740 --> 00:33:59,240 And for me, David was this kind of Mike Metzger moment for me when he did that stuff. 593 00:33:59,240 --> 00:34:03,940 Because what Mike did for the motocross circuit was that, 594 00:34:04,020 --> 00:34:07,020 just before he did the first backflip in competition, 595 00:34:07,400 --> 00:34:11,060 it was, like, rumors and shit, and nobody thought it was even remotely possible. 596 00:34:11,340 --> 00:34:16,280 But as soon as he did that, today, if you're not doing, like, a double flip, 597 00:34:16,500 --> 00:34:19,780 can-can, woohoo, fucking dang, you suck. 598 00:34:21,300 --> 00:34:23,300 So that was kind of the opener. 599 00:34:23,520 --> 00:34:27,220 So I started to look at this OSC 5113, which I thought was like, 600 00:34:27,280 --> 00:34:29,220 mm, Kitty has this proprietary skill. 601 00:34:29,240 --> 00:34:29,520 It has this scape code. 602 00:34:29,620 --> 00:34:30,600 I wonder what that does. 603 00:34:31,080 --> 00:34:37,500 And what I figured out real fast is that test here reflects back in the flow. 604 00:34:37,700 --> 00:34:41,000 So I'm starting to think, what happens if we add a new line 605 00:34:41,000 --> 00:34:44,040 and open a bit of Calculate there and send that away? 606 00:34:45,140 --> 00:34:46,440 Well, let's see what happens. 607 00:34:47,100 --> 00:34:50,000 What's going to happen first is it's going to give you a request. 608 00:34:50,160 --> 00:34:51,200 Are you really sure you want to do this? 609 00:34:51,300 --> 00:34:53,640 He said, no, but you got a calculator. 610 00:35:01,600 --> 00:35:04,140 Because he's adding new lines, and he's honoring them. 611 00:35:04,440 --> 00:35:05,520 Time is running out. 612 00:35:05,560 --> 00:35:05,980 Thanks, babe. 613 00:35:07,260 --> 00:35:10,760 The other one here, and I know you said, yeah, but you pressed no. 614 00:35:10,860 --> 00:35:12,000 What happens if you press yes? 615 00:35:12,300 --> 00:35:14,280 Well, I figured out it's the same. 616 00:35:15,860 --> 00:35:16,940 No escaping here. 617 00:35:17,940 --> 00:35:18,860 Yield time, boys. 618 00:35:19,060 --> 00:35:19,560 Fuck yeah. 619 00:35:20,100 --> 00:35:21,600 I thought that was sweet. 620 00:35:22,120 --> 00:35:24,980 So now I'm getting hyped, and I'm all happy about it. 621 00:35:25,060 --> 00:35:27,460 And this shows the whole proof of concept. 622 00:35:27,620 --> 00:35:29,220 Is it actually possible to add a new line? 623 00:35:29,240 --> 00:35:31,000 Execute commands in the victim terminal. 624 00:35:31,220 --> 00:35:33,680 And the short answer to this is yes. 625 00:35:34,780 --> 00:35:36,300 But whose fault is it? 626 00:35:37,220 --> 00:35:41,860 This conversation has been going on for like the last 10, 20 years. 627 00:35:41,980 --> 00:35:43,660 Because every 10 years or so, somebody's 628 00:35:43,660 --> 00:35:44,840 going to poke around at this stuff. 629 00:35:45,040 --> 00:35:49,580 And the terminal developers are going to say, it is the developer's fault. 630 00:35:49,740 --> 00:35:51,100 They need to do their shit. 631 00:35:51,520 --> 00:35:55,040 The app people say, no, it's the terminal people. 632 00:35:55,260 --> 00:35:58,500 They need to stop using escape sequences at all. 633 00:35:58,620 --> 00:35:59,180 It's terrible. 634 00:35:59,240 --> 00:35:59,540 It's a terrible idea. 635 00:36:00,060 --> 00:36:02,600 But we all use them all the time. 636 00:36:03,120 --> 00:36:04,920 And then there's the third part. 637 00:36:05,120 --> 00:36:08,500 It's these super angry old developers that are sitting in the back. 638 00:36:08,640 --> 00:36:09,540 I see you. 639 00:36:10,200 --> 00:36:16,040 That thinks that everyone with a brain knows that you can't just cut a file or click on an email link. 640 00:36:17,060 --> 00:36:18,740 But that's simply not true. 641 00:36:19,320 --> 00:36:22,220 Because we are cybersecurity professionals. 642 00:36:22,620 --> 00:36:23,680 Some more malicious ones. 643 00:36:24,120 --> 00:36:28,240 And we need to protect our users, especially our shell users. 644 00:36:28,240 --> 00:36:33,420 Because they also are privileged users using these systems on a daily basis. 645 00:36:33,600 --> 00:36:40,140 And they should be able to grep cat or jq whatever shit that's running inside the terminal without any issues. 646 00:36:40,320 --> 00:36:45,340 Especially if they're downloading files from a third party that took care of them. 647 00:36:45,840 --> 00:36:51,020 And the only way to do that is that we need to sanitize our input and escape our output. 648 00:36:51,360 --> 00:36:53,640 And if we don't do that, it's going to be consequences. 649 00:36:54,860 --> 00:36:56,460 And I figured it would be kind of cool. 650 00:36:56,460 --> 00:37:04,460 What happens if I took this web page and stuck a bunch of different kind of escape sequences in there and see what happens? 651 00:37:04,720 --> 00:37:07,760 So I created this evil.terminalinjection.com site. 652 00:37:07,940 --> 00:37:12,180 So if you curl that inside your terminal, any of them, you can see what happens. 653 00:37:12,440 --> 00:37:14,740 It's not going to do anything bad stuff for you. 654 00:37:15,020 --> 00:37:18,400 It's going to pop a calc if you're vulnerable. 655 00:37:18,860 --> 00:37:20,840 But I'm not exfiltrating your data. 656 00:37:20,960 --> 00:37:22,940 You can just right click the source and see what's in there. 657 00:37:23,000 --> 00:37:23,260 It's cool. 658 00:37:23,460 --> 00:37:25,900 And if you run that. 659 00:37:25,900 --> 00:37:28,000 On some systems, it's going to be all right. 660 00:37:28,060 --> 00:37:32,240 On other systems, when you do it, it's not going to be as such all right. 661 00:37:33,600 --> 00:37:36,660 So it's kind of trusted things, but it will break stuff. 662 00:37:36,960 --> 00:37:43,000 So if we're doing black box testing on this, the whole game if you're hunting for bugs is going to 400, 500 errors. 663 00:37:43,140 --> 00:37:46,820 Because 200 errors usually ends up in access logs. 664 00:37:46,920 --> 00:37:48,620 And those are well sanitized and nice and all. 665 00:37:48,900 --> 00:37:54,020 So the easiest way to do this, to break stuff, is to take whatever kind of thing you have here. 666 00:37:54,120 --> 00:37:55,220 This is an API request. 667 00:37:55,900 --> 00:37:57,780 You have a key and some value stuff. 668 00:37:57,960 --> 00:37:59,780 And just append shit on the end. 669 00:38:00,020 --> 00:38:01,260 And see what happens. 670 00:38:01,980 --> 00:38:05,040 Sometimes it will break and you will get some information coming back. 671 00:38:05,320 --> 00:38:12,880 And if it does contain something like unescaped stuff, because this one here is a big chance that it actually ended up in the error log. 672 00:38:13,280 --> 00:38:15,780 This one here, though, is properly escaped. 673 00:38:16,120 --> 00:38:18,080 So it's a good job on the devs. 674 00:38:18,160 --> 00:38:18,820 Fuck yeah. 675 00:38:20,620 --> 00:38:25,400 But sometimes, you know, you put that stuff in and it's going to sanitize with a backslash. 676 00:38:25,400 --> 00:38:29,060 So why not put some invisible characters and hex in there? 677 00:38:29,580 --> 00:38:33,220 The results can be really interesting because then it might just render anyway. 678 00:38:33,640 --> 00:38:36,360 Because you're bypassing the whole backslash scenario. 679 00:38:38,280 --> 00:38:40,340 Okay, this is very prone to false positives. 680 00:38:40,660 --> 00:38:46,080 So sometimes the developers are really good at just filtering the kind of output comes out. 681 00:38:46,180 --> 00:38:47,000 They're stripping the error message. 682 00:38:47,240 --> 00:38:49,660 And they're even not displaying any data. 683 00:38:49,760 --> 00:38:50,600 We saw that in the beginning. 684 00:38:50,760 --> 00:38:52,260 It was an error, but nothing happened. 685 00:38:52,340 --> 00:38:53,160 But it smashed the log. 686 00:38:53,360 --> 00:38:53,600 Boom. 687 00:38:53,600 --> 00:38:58,660 So even though, you know, you need to take that into consideration. 688 00:38:59,380 --> 00:39:03,240 And even though if you see like 400 errors, they're rarely logged. 689 00:39:03,380 --> 00:39:05,320 So 500 errors is what you're going to be looking for. 690 00:39:05,720 --> 00:39:07,520 But this seems to be everywhere. 691 00:39:08,400 --> 00:39:11,860 Everywhere I looked, it just pops and scrambles. 692 00:39:12,140 --> 00:39:19,700 And before you create this nuclei template and go all brrrr all over the Internet hoping that it's going to end up in somebody's log somewhere. 693 00:39:20,640 --> 00:39:23,480 To verify this, you will need to have access to the access. 694 00:39:23,600 --> 00:39:25,580 And just dig into that. 695 00:39:25,660 --> 00:39:27,160 Because otherwise it would be a false positive. 696 00:39:27,360 --> 00:39:32,380 Because if I wrote the logging system and I didn't log in the output, you can say that it renders, but it's not. 697 00:39:33,260 --> 00:39:34,560 So time's running out. 698 00:39:34,700 --> 00:39:36,320 Let's recap real fast on this. 699 00:39:37,880 --> 00:39:38,760 People forget. 700 00:39:40,820 --> 00:39:42,420 The old is the new new. 701 00:39:42,760 --> 00:39:45,400 There's way more things that's going to come in this area. 702 00:39:45,520 --> 00:39:48,480 And I hope you are intrigued now to start poking in this. 703 00:39:48,700 --> 00:39:52,000 And let's create a community around this and see whatever fun stuff we can do. 704 00:39:52,620 --> 00:39:53,580 And it's true. 705 00:39:53,580 --> 00:39:54,280 It's like everywhere. 706 00:39:54,460 --> 00:39:56,580 Like I told you, I created this nuclei template. 707 00:39:56,860 --> 00:39:58,460 And when I ran it, it rendered in there. 708 00:39:58,800 --> 00:39:59,800 That can be problematic. 709 00:40:00,500 --> 00:40:12,680 So if something's like meh today, it can easily turn into oh crap by tomorrow if somebody decides to put a bunch of creativity in it. 710 00:40:14,500 --> 00:40:20,340 That means your log files, do you still trust them? 711 00:40:21,420 --> 00:40:23,660 I'm at all social media. 712 00:40:23,960 --> 00:40:25,340 Thank you for attending my talk.