Hey guys, uh, so we're gonna talk about SSH. And this has been probably the most exciting year in SSH since x2.cd got leaked, x2.cd got leaked by Teso. So, um, uh, props to anyone who used that. Uh, so, uh, SSH for folks who aren't aware, um, you probably, probably should be here if you don't know what SSH is, but, um, SSH, secure shell, port 22, the thing we've been using to admin the internet for many years, like almost 30 years. Um, there's really two flavors of SSH that we use the most. There's open SSH, which is like 80 something percent of all SSH installations. And then there's DropBear, which is like another like five to eight percent. And then this long tail of random weird stuff out there. So we decided to do some research into first looking into the XC backdoor. And then part of that, we just accidentally found a couple tens of thousands of shells and we're like, well, let's go figure out what all these random things, all these free shells were. Uh, and that led to this giant pile of work and this open source tool. Um, so if you want to play with the toolkit, you can get it right now. It's this, the shamble.com S S H A M B L E. And that goes to GitHub and you can go grab the stuff and play with it. And it's a big hot mess, but we're making it better. And it should be a lot of fun as we start cranking on, make polishing up, making it cool. Um, so with that, we'll go ahead and get started. Um, fortunately, we're only doing 67 slides in 45 minutes, not 100. So we had a little breathing room this time. Um, so I'm sure we're all very much aware of the XCUTLs backdoor. Well, step back a little bit. So there's, you know, four major events this year in SSH that were really important. Obviously, XCUTLs backdoor targeted SSH using the system vpatches and Debian and, uh, Red Hat builds of OpenSH. We also had the really cool Terrapin vulnerability, which affected pretty much everything because of the truncation attack. Um, we also had, uh, the regression vulnerabilities, the really fantastic work by the Qualys Threat Research Unit. Um, and then the other regression bug found by SolarDesigner that only affected Red Hat. And regression was amazing. It's a signal re-entrance bug that gets you remote route in OpenSH by default. It just takes six hours on a 32-bit machine or weeks or months on a 64-bit to compromise. So, but it's been a really cool year. Um, one of my favorite SSH bugs this year kind of flew under the radar. Um, the guys at Watchtower Labs did a really cool analysis of the move-it vulnerability that uses the SFTP server. And so they found a vulnerability where any public key being sent to the service, um, would be treated like a file path. Like the binary blog gets treated like a file path. And it just opened random UNC URLs and all kinds of fun stuff. They threaded like a million little needles to be able to get a shell remotely and boot it. But the really cool thing about that bug is it affected every other vendor also using IPWorks as the underlying library. So, they actually uncovered like a supply chain bug, if you will, which is really neat. So, going kind of back on topic again, um, the XEUtils vulnerability or backdoor was amazing. It was like its own little Netflix docu-series, right? We're going to see like the true crime of XEUtils for years. But like who is Gia Chan? Like it's going to, it's the most dramatic thing to happen to InfoSec in a very long time. Um, so the, this is a multi-year campaign where this person, um, contributed to open source for a long time, then eventually kind of twisted the knife and tried to backdoor the world. And I got caught at the very last minute by, uh, Anders Frond, who says, hey, my SSH is taking slightly too much longer than it should, and then unraveled the whole thing right before it got put into the stable distributions. So, we got really close to the whole internet being backdoored. Uh, but what was really important about that backdoor that it was a nobody but us backdoor, which is normally, you know, normally the US government is famous for those. But in this case, who knows who it was. Um, in fact, it was a encryption key controlled by the attacker that only people with a private key had access could abuse the backdoor. That was really a neat thing about it. So, we thought it'd be fun to go figure out who this Gia Chan person was. And we're like, hey, you know, everyone's looking for Gia Chan, we're going to go find some Gia Chan. Uh, and we're very happy, Alfredo, if you're out here, thank you so much for designing your graphics, they're amazing. Um, so we decided to go hunting. And, you know, before we go hunting for Gia specifically, we want to talk a little bit about SH protocol. So, uh, Gia Chan targeted SH, uh, with ex- with ex-utils backdoor. So, we're going to target Gia Chan using SH. But before we go there, we need to talk about how SH public key authentication works. So, SH public key authentication is two-stage. The first thing you do is say, hey server, would you accept this public key for this username on your machine? And it says, yeah, sure. And then you have to sign this big blob of data that proves that you have the private key. But you can do that first part without the private key at all. And it's really cool. There's been a module in Metasploit 4 since 2012, lets you take someone else's public key that you got, however you got, and then check a bunch of servers to see whether that public key has access to, uh, those servers for that username. So, you can kind of see where this is going. Um, it's, there's this great comment on OpenSH saying, is this a problem? I don't know. But it's been there forever. It's just kind of the protocol spec at this point. It is what it is. Maybe it's not a big security deal. So, we decided to create this thing called Shamble, which started off being a half-off scanner for SH. So, what we do is you take a bunch of public keys and then you'd like put them in Shamble and scan the whole internet saying, what on the internet can you access using these public keys? And the idea is like, well, if we had, let's say, Gia Tan's public key, we can find all the servers that they use and then from there we figure out who they are. So, that was, that was the idea. But it ended up evolving to this massive tool to find all kinds of other crap because of all the things that we found. So, you know, first thing you do say is, hey, my name's Gia Tan, we're gonna go download your GitHub keys. So, we grabbed our two GitHub keys, which are still present today, um, and basically took those two public keys, ran them into Shamble, and then, um, you know, threw that at the whole internet, all the, all the sh-demons we could find, let it grind out for a couple days. And what's, what's exciting about it is, like, we spent the whole week on this, we hadn't slept or anything like that, Rob and I were like working at four in the morning, like, we got one! We got a hit for Gia! It's really exciting. Um, in the meantime, we're melting all of our DigitalOcean nodes. So, this is this poor little DO droplet just like falling apart as we're like destroying it. It's, I think it's sent like a terabyte of traffic at this point. Like, we're, yeah, we made DO VMs very unhappy. Um, so, just heads up for law enforcement, um, we sent the public key for GiaTAN to every server on the internet from RIPs. We are not GiaTAN, we are not backdoor exe-utils, even though it very much looks like we did. So we sort of accidentally framed ourselves. Uh, we realized that after the fact that we probably might, I'm sure the long-arm law will catch up at some point, like, you guys, you're GiaTAN, like, ten years from now, and like, yeah, we are not, sorry. So, um, unfortunately, like, every single result we found that we thought was false positive. It was like a buggy server with, like, the memory was corrupted, or the service would accept every fifth public key, or every third public key. So we had to say, okay, let's try a bunch of random public keys, and if you reject all those, now try the Gia key. And let's try, like, an RSA key, RSA 1024, 2048. We've still found devices that just randomly accept or randomly not accept keys, and it just drove us crazy. So we finally fixed all these bugs, re-scanned, re-scanned, re-scanned, uh, you know, clicked all those digital ocean abuse notices, says, yeah, we're good, our server's not compromised, we're cool. Um, and we still found no Gia 10. So, whoever this, you know, actor was, they had really good OPSEC, we found nothing, so good job them. Um, but we did find, like, thousands of free shells. So, we're like, how come we're getting all these random shells and all these random machines? And that's really what this talk is, is about. Uh, so with that, um, a little bit of a detour. So, an SH, um, public keys used to not be something that you actually made public. They used to be something you kind of kept privately, and you were .SH directly, and you copied to a server here and there. But, um, in the last five or six years, we've seen people using, uh, SH keys like identities. So, just like people used PGP back in the day, you can now use SH keys as your identity when you're installing a bunch of server. You can tell it to grab your key from GitHub or from Launchpad and automatically give you access to your server during installation by username. Um, you can also, uh, um, use these keys for things like, uh, OJ encryption. So, if you use the OJ tool or H tool, you can use it almost like a PGP key now these days as well. So, it's all kinds of cool stuff you can do with, uh, SH keys you didn't before. But the key thing here is, like, keys are effectively public if you use any of these major platforms. And literally public. So, there's this great little, uh, daemon by Filippo where if you SSH into it, it'll say who you are. It'll use the public key you send to the server, dock to you based on the GitHub database and say, oh, you're so and so, welcome. So, it's kind of a fun little trick. And effectively, we're doing that, but at scale for the whole internet. So, if you want to link a user to a particular key on a particular server, you need, um, one, a list of all the SH servers out there. So, ZMap, Mascan, dump it, show it in, whatever you want to do to get the list. You want a list of all the public keys, so you go grind all those out of GitHub through their BigQuery API, about 117 million users as of about a month ago. Launchpad's got a bunch of users, too. You get all their keys, too. Why not? And then Bad Keys is a great project by, uh, Hanno Bach, um, that allows you to, that keeps track of all the compromised keys out there. So, you can look for keys that give you access to the system. And then lastly, you need a list of common usernames the user might have, like root, ec2 user for cloud, Ubuntu, et cetera, or whatever the comment is in the key. So, one of the nice things about GitHub is that when you upload your public key to there, they actually preserve the comment field, which is typically your, your username when you uploaded the key. So, you know what their default username is. So, if you're trying to find, like, their server someplace, you can pull it out the comment, use that to talk to the user, and so on. So, you, you take this nice little recipe and you throw it in the oven. And, um, it gives you a nice little primitive to take a one key and check lots of servers really fast. Like, you can grind through all the servers on the internet in, like, an hour or something like that on a single box. It's pretty quickly. Just for one key. Um, but if you want to test, um, so that works great if you're looking for, like, a geotan everywhere. But what if you want to say, for this server on the internet that's acting fishy, which GitHub user has access to it and do the other way, to check all 117 million keys on one server. Well, that's a very different attack. That's like, you know, duck-sized horse or horse-sized ducks, you know, kind of approach. So if we want to test a million keys against, uh, a single server, it's a little bit tougher because, uh, SH will slow you down. Uh, they have, uh, this thing called max auth limit, which is how many tries you can authenticate before it kicks you off of that connection. And there's a max connection limit, so you can only do so many of those at once, right? So the idea is that with OpenSH, if you try to brute force keys, you get four into it and it knocks you out and you can't auth anymore. So if you ever had more than four keys in your SH, uh, agent, and you try to shell out a machine and it just immediately says, you know, too many tries, that's why. It's because you're hitting the max auth limit of OpenSH. However, um, OpenSH is the only one that does that. Everything else lets you just bang keys all day long. So DropBear lets you just grind keys as fast as that little device can, can test them. Um, also a lot of commercial products like Bitbuys, GlobalScape, Maverick, LanCom, all this stuff, all their SH daemons do not care. They'll let you just try every possible key in the world until, until you're done. It's great. Uh, we emailed the DropBear folks, they didn't care, they didn't even bother replying, so we're like, it's not really a bug, it's a feature. So, we like that feature. So, uh, with the shamble code you mentioned before, we tested the GitHub, like 4.6 million key database at the time, and you can do about 10,000 keys per second on a DropBear box on an embedded node without it spiking the CPU on the target device at all. It just doesn't even care. It's like super fast. So it doesn't even murder the machine. And this is 10,000 keys per second per connection, and DropBear is typically configured with 15 connections. So you can do 150,000 keys per second on a machine for pub key testing to dock someone's server. So if you see someone like hitting you on a random box and SH is open, just go take all the keys and get it. I'd be like, yeah, you jerk, stop that. And just email him, like quit it. Like, it's really, really easy to dock to your hackers. And if you're running an SH honeypot and your SH honeypot collects the public key being sent to you, you can turn around and flip that on them again and immediately figure out who they are. Like, people forget all the time that their SH agent's configured and they're sending their public key to every server they connect to. Even if their agent is not authenticating to it, they're still automatically sending that public key as a task whenever you touch anything. So if you're a, a lead hacker and you've been just SHing at random machines on the internet, you're also sending your public key identity to all those machines and if they're logging at your host. So, um, by contrast, if you try the same attack against open SH, you can do 132 keys per second. So it'll take you 10 hours to do the same 4.8 million keys with a single connection. So, um, obviously the open SH approach is much nicer, um, but it's great if you're trying to, um, adapt, docks people. So, uh, with that, I'll hand it to Rob to talk about shaking out shells. Testing, testing, testing. Testing, testing. Hey, all right. So shaking out shells, say that five times fast. Um, what we did with shamble is it resulted in, uh, around 27 million devices on the public internet that are listening on port 22. We got another, you know, 14 million or so that actually negotiated, uh, SSH off and we ended up with about 110,000 sessions. Um, what's really interesting about SSH, so SSH, uh, especially open SSH has done an immense amount of work in, do what? Oh, sorry, front mics are hot. Uh, so, sorry. So, uh, we ended up with, um, about 110,000, uh, that are actually listening and we were able to get sessions. What's fascinating about open SSH is, or SSH, is that there's a fairly large post-authentication attack surface. So SSH does lots of things. You can create tunnels, you, uh, can create pseudo-terminals, there's subsystems, there's all sorts of things that are running on, uh, SSH once you're inside. Uh, it kind of assumes that once you've authenticated, you're okay, but there's an immense, uh, an immense amount of systems out there that actually will do this interesting post-auth-auth. So you authenticate, uh, non-authentication with left beef and you get in and then it actually gives you a secondary authentication mechanism. It'll prompt you for a username and then a password, but you're inside the session at that point. So you can start doing some interesting things. This is one of the, the interesting cool things that, that Shamble will do. Um, you can say, oh, okay, uh, I can send signals, I can send, uh, SIGWINCH, I can, uh, forward X11, things like that. And you can see there's a fair amount of large, uh, devices, uh, popular devices out there that do this post-auth-auth. So you can see you've got, uh, SonicWall firewalls, um, Juniper network devices, you can SSH in with auth none, and then it'll give you the secondary one. That, uh, that smaller one, the please login, that's, uh, a ruckus one that HD's gonna talk about here in a minute. That's super, uh, super fascinating. But it's worth noting that there is this post-auth attack surface that is kind of not considered, but is exposed. So, uh, and with that, with sort of the first one that you can talk about is signal injection. I'm gonna pass it back to HD for that. Did we get the second mic working? Cool, thank you. Sorry, just trying to stay away from the front mic so we don't get feedback here. Um, so, uh, Rob mentioned that one of the things you can do to a post-auth session is, uh, inject signals into the process before you've fully authenticated. So if actually you can connect to a machine, it'll pass through the authentication from SH auth equal none, and then drop you to a real login shell, and it'll say, please login. And you can just say, signal seg v, and it goes, ah, and dies. Which is a lot of fun. So effectively you can just, you know, we talk about regression being signal re-entrance, this is just signal entrance. You just bang signals all day long into whatever process you want and see what terrible things fall back out of it. So, uh, we didn't get too far into this testing, but we, there's all kinds of fun things that come out of it. You can send a SIGINT request, you can pass Python scripts that are part of the login shell to crash, uh, you can do SIG alarms, SIG childs, SIG ills, SIG aborts, you can pass core dumps, uh, all kinds of crazy stuff you can just do with signals. And OpenSH tries to protect you a little bit by limiting things like sig seg v, sig abort, and so on, uh, but DropBear does not. DropBear is like, anything that you can possibly send me, I'll treat as a signal and deliver to the process, thank you. Um, so there's a lot of really cool attacks that we think you can do there, and we're gonna start working on expanding the shamble code to then basically just mash symbols into random processes so you get a shell. And, yeah, um, with that, hand it back to Rob to talk about TSP forwarding. I, I do always love that, uh, DropBear is like, I, you know, it's like if it were dying, it wouldn't be dictating, right? It wouldn't be writing it out, it would just say IEE, but no. Um, but another part of this post-auth, uh, uh, attack surface is forwarding, right? So SSH allows you to generate or create tunnels, uh, you know, through channels and create encrypted tunnels. It's almost like a little miniature VPN thing, and this is a pretty popular and common, uh, feature. But once you po-, once you're in this post-auth situation, you can start doing that. You can start creating these things on a lot of these systems. Um, many of them will administratively restrict you from doing it or they'll only let you go to certain things, but for example, uh, uh, you can say, okay, well I'm gonna try to forward to this particular host, or I'm gonna try to forward to a local host and do a loopback, um, and we actually found, uh, this is an ION, yeah, okay, good, the chip's playing, uh, this is, uh, an ION network's access point, and you can see that it's trying to, uh, forward to google.com, and it, it gets rejected, and then it's gonna try, oh, and by the way, this is the shambles shell, uh, which I love. Um, and it'd say, oh, I'm gonna try to get to 88888, but then you can actually forward back to local host, so you can actually use that to get around restrictions and things like that once you're in this sort of, uh, uh, mystery, uh, uh, post-auth shell. But, the big, the big one is shell injection, I'm gonna let you take this one, cause this is super cool. So one thing that was kind of fun about this is that we found bugs that, like, we shouldn't have found. Like, because of this post-auth sequence, effectively you SH to the machine, and instead of asking for a password, you just, it drops you straight in, but it drops you straight into a secondary shell. And that secondary shell has its own bugs. So we kept finding these vulnerabilities in these secondary shells that no one had found before, even though they were, like, stupid. Like, we found so many dumb bugs just because no one really tested that level of the protocol. So in this case, um, we're right across these, like, ruckus access points, and you SH them, there's about 36,000 of these suckers exposed to the internet, about 900 are vulnerable to this particular attack, still right now, today, and it asks you for a username, you type in root, you type in, you start entering your password, and for your password, you just type in, like, dollar, parenthesis, whatever command you want to run, right? And just redirect it back out to standard error so you can see the result, and it just runs this root, pre-auth, it's great. Um, so we'll, we reached out to ruckus, of course, like, hey, what's up? Like, you guys, is this a new bug? Is this a fixed bug? We can't really tell what's patched. Like, oh yeah, we patched that already. I'm like, did you tell anyone? Nope, they didn't tell anyone. There's no CV, no security note whatsoever. So of course no one's applying patches because they didn't know they had to apply a patch. Um, so they've got two different tracks, the 521 and the 621, those both fix it, but there's, you know, still about, you know, almost a thousand folks out there still running unpatched up. But the question was, like, why did this bug live so long? How did we end up with this, like, a stupid login prompt, like, password character injection, and it's because it was behind this SSH auth layer that no one really bothered to test it. Like, all your folks who normally hit a telnet prompt, something like that, just hadn't tried this SSH post auth attack. So we uncovered this whole, like, layer of bugs that really should have been found 20 years ago, but they were just hiding behind this extra SSH layer. Uh, and that's one of the interesting kind of side effects of this work. So here's an example of us, uh, rooting one of these random ruckus boxes. SSH in with all the, I don't care about my cipher stuff, please log in, R-O-O-O-O-T, and then for the password, we're just typing in $PSAOX-W and getting a big process listing. And the funny thing about it is you can actually see the echo command in the PS listing showing that it's going to shop 256 sum, that's how they check your password. So they fixed it just by putting in proper quotes, but the whole thing is ridiculous. So it's amazing, like, how many dumb bugs are out there if you just go a little bit further into the protocol stack. And back to Rob for the permit. So SSH, you know, is the secure shell, it's designed to talk as your shell, it replaces Telnet and RSH and all that, and it lets you set environment variables. Um, environment variables are used to control the execution of things and, you know, keep track of the environment and all that. And a lot of, uh, SSH implementations will limit what you can send, but a lot won't. Um, there's been a, uh, and it's configurable, of course, some will, uh, accept these environment variables, some don't accept these. So there's been this renaissance in, uh, Gitforges lately, there's a ton, there's, there's GITI, there's GOGS, there's, uh, I always pronounce this wrong, FORGEHO, tell me if I'm saying that right, GARET, things like that. And they are using these embedded SSH libraries that speak the SSH protocol, and these libraries, because they're, you know, designed for general use, they will accept, you know, any environment variable you send, and they rely on the client, the user of the library, to, uh, limit what is going on. Um, and so that's generally okay, like a lot of them do it correctly, uh, for example, GitLab, GITI, FORGEHO, they will only accept Git protocol as, uh, an environment variable, and that's, uh, something that's looked at by Git to negotiate protocol versions, so you can say, oh, I want to use Git protocol version 2 or whatever. But, for example, there's still some vulnerabilities there, if you were using a version of one of these, these are all written in Go, and it was compiled using a version of Go prior to 1.19.3, which is a year or two old, um, on Windows systems, they don't properly sanitize the, uh, the value of the environment variable, so if you put a null in there, you can actually just inject arbitrary environment variables, which is, uh, super fun. But, um, there was another one that was really interesting in, uh, GOGS, where whenever it gets an environment variable, it actually runs the env command, and so the point of the env command is to start a new process, um, with a new environment, with, you know, setting certain environment variables or whatever. And it starts a new process, it doesn't affect the environment that you're in, right? It, it, that's not how POSIX works. So you could just say, okay, well, I want to set an environment variable with, you know, dash, dash S A equals B, and then, you know, bash, or, you know, touch temp foo, or whatever, and you are just executing arbitrary commands. And we, we did reach out, there's, there's no patch for this, uh, it's, seems moribund, so maybe don't use it. Um. This is a great example of, like, parallel discovery, so, not in, not in the court sense, but in the, uh, we reported this vulnerability on, like, April 24th, and Sonar Research had reported the same bug to the same maintainer on the 22nd, and they scooped us on the advisory, and we both had our own separate GitHub advisories, but it's just hilarious that we both managed to look at the same bug at the same time, so, it's funny, like, how often that happens, and this is a great example. So props to the Sonar source folks for beating us by two days, uh, and they did a really great blog post about how the bug works, but it, it almost looks like a backdoor, because it doesn't actually influence the environment of the subprocess, it's just a straight command exec pre-auth, so it's a, it's a funky bug. Yeah. Yeah, exactly, thank you, HG. Um, so going back to these, uh, these libraries, so, for example, uh, Apache Nino, which is a Java, uh, implementation of SSH, will accept any variable you want, um, and most of the time, uh, it doesn't really run into anything, but this is, this is maybe my whole, this is maybe my favorite thing that we found, uh, personally. Uh, so there's this piece of software called SoftServe, and it's designed to build, um, Git repos, and it gives you this beautiful, uh, SSH, or, you know, CLI, you SSH in, you control it, you can do whatever, and it uses, um, the Charm Bracelet SSH, uh, library, which is built on top of Go's SSH, um, and it will accept any environment variable, or it did, we reported it, they fixed it, this is our CVE, Go us, um, but what's fun is you can, first off, watch how slow I am when I'm typing in, uh, in GIF form, but, um, you can, uh, we just basically created some shellcode, and we checked it into LFS, and you can actually do this in lots of different ways, LFS just, uh, Git LFS is large file storage, it, it just makes it to where it's not compressed, and, uh, the file name is predictable, so we don't have to worry about it too much, uh, makes it easier to exploit, we push it up to, uh, to SoftServe, and then, uh, doing the SHA 256 sum of our shellcode, because that gives us the, uh, the file name that we can, you know, guess, and then we just set LD preload to our shellcode, and we now have, you know, shell on that system. So, that was super fun, uh, I, I always love when I get a shell, and I'm just like, oh, this is great, you know, uh, so that made me really happy, and these, uh, these folks were really super cool to work with, um, we, uh, we disclosed that, they were very, very nice. Um, but now moving on to, uh, Broken States, which is the SSH state machine to HD. Thanks, um, another fun thing about the, the SoftServe side, so that particular exploit, um, because it's using git LFS, you can, you can reference a raw file on disk, and you don't have to know your file location, you can use relative paths and stuff, but this works just fine for unauthenticated git access too, so if you're running SoftServe for read-only access, you can still exploit it, it just requires jumping through more hoops, because you can specify LD preload, LD load library, you can set LD library debug out in the past, there's a million ways you can, like, eventually get a file onto disk to then load, or to trigger a shell script, but just LFS was the quickest way, but like, yes, we're loading arbitrary code, so, it, write access to the repo is not a requirement to exploit SoftServe, and there's still about ten of those suckers hanging out on the internet right now that are exploitable, so, if you're quick, they're yours, um, kidding, but, um, so, I'll talk a little bit about the SSH state engine. So, SSH is like, incredibly complicated in terms of how it makes you go through these different states to get to each phase of the protocol. The stuff you're mostly familiar with is like, when you first connect to the port 22, you'll see like, SSH-2.0, uh, server banner, things like that. If you happen to send the same manner back to it, or you connect to dropper, then you'll get this big blob of stuff with null delimited strings, which have like, ciphers, and max, and algorithms, things like that inside of it. So, all that's kind of during the, uh, server version exchange, and the key exchange, um, the SSH daemons are very clear that they will only accept a certain range of message values for each state. So, before you've done the, uh, version exchange, you can't do the key exchange, before you do the key exchange, you can't do authentication exchange, and this is enforced two ways. The protocol itself has a range of values allowed for each state. So, values 1 through 49 are allowed in state 1, 0 to 49 in state 2, and so on. So, if you're trying to like, just open a channel, or open a shell, technically there's no even message handler for it, because it hasn't even configured the state handler to even accept that type of message yet. But that depends very much on the implementation. Uh, DropBear and OpenSH are really good at keeping a big command table, and when they go to another state, they just remove that command table handler for the previous state. So, there's really no way to like, accidentally call the wrong function pointer. Um, and that mostly works the way you expect. What's also interesting here is everything after the key exchange, of course, is encrypted. So, SH is kind of like TLS in a lot of ways, in that you have your normal, like, version exchange, key exchange, algorithm, Diffie-Hellman type thing, and then you have, like, your encrypted transport, and that's where all the fun stuff happens, like authentication, your banner, if you will. Like, have you ever seen a pre-auth banner in SH? It's actually being sent over the encrypted connection, not over the unauth connection. So, typically when you're talking about an SH banner, you're not talking about the version string, you're talking about the pre-auth big blob of data that it sends you when you try to authenticate. Um, so lots of cool stuff happening there, but you can see the state engine is pretty complicated. Um, what's also worth pointing out here is there's something called a larval session. So, that means you've successfully authenticated, or maybe not, and it's the state of your shell before there's a shell. So, effectively, if you haven't created a sub-process yet, you're in this kind of, like, larval state, and that's how the code generally references it. And that's important when we start getting into some of these other exploits. So, a historic example of where this has gone wrong is libsh. In 2018, uh, someone reported vulnerability where this library is used for both client and server side, same with OpenSH, same with DropBear, they kind of share the same code base for both halves of the protocol. Um, and if you sent the user-authenticated succeeded message from the client to the server, the server's like, oh, okay, cool, you're in, and that's fine. Um, there's still a bunch of these libsh informations out there that'll just drop you to a shell if you send user auth success, and of course, you know, shamble test for that and makes it easy for you to use it. Um, so we decided to take this up another level. Instead of just saying, let's just send a fake success message, let's just try to get a shell everywhere. Let's take every single part of the protocol transition and say, let's do half auth, let's do full auth, let's do a fake pubkey, let's do a password, let's do a password none, let's do, even before sh user auth command at all, and between every one of those attempts, we're going to ask you for a shell. We're just going to be like, how about a shell now? How about a shell now? How about a shell now? And how about now? Um, and it worked. Like, we got crap loads of shells from random devices because we asked them in weird states to give us a shell. So there's some out there where you don't even bother even starting the authentication process and it gives you a shell. There's some out there where you start the authentication process but don't finish, it gives you a shell. Like, it's all over the map. So, um, there's three good examples we talk about here. The first one is the digi transport, uh, gateways. They're mostly using like ICS environments, they're kind of like out in the field with hardened stuff. They act as like kind of the VPN router, if you will, for all the, all the juicy OT stuff you want to hack behind it. Um, so having remote admin to these means you basically have serial port access to all the stuff behind it, which is great. So if you want to like blow up pipelines, things like that, that's how you do it. Um, so the digi team was really cool. They were great to work with. Um, this device had already been like basically effectively legacy and retired, but it's still up for maintenance on screen patches. But they had to go find like the one developer who hadn't looked at this thing in five years and dust off their compiler and try to figure out how to build the damn thing and all that. And the funny thing about this is it ended up being an un, uh, an uninitialized variable in the SH engine. So it took us forever to repro, because we'd say, hey, we can get shells in like all these machines on the internet. Like here's a bunch of them, here's the serial numbers, like it's bad, go fix it. Like we can't repro it. I'm like, you got to be kidding me. Like just run the command. Like what are you doing wrong? Like it's run command, what's doing, it was not their fault of course. It's that when they were setting up the machine to test, they were logging in for the rest of the H first and setting up their monitoring on it. And then they'd run our exploit and it wouldn't work because the uninitialized variable had been set. So just one of those things was like freaking Heisenbug to repro. It took forever to fix. Anyways, so we finally got to the end of it, but the team was really cool. They're great to work with. They got a patch out even for this legacy hardware. So awesome to see them actually supporting older systems. Uh, then we found these real tech devices that are like branded all kinds of things. Netterbit, um, Netis, there's probably a good dozen vendors out there and they all have like different flavors of firmware from 2018 to 2023. And it's just like free shells everywhere. We don't even know who to report it to. So that's, there's a bunch out there. Um, yeah, have fun with that. Uh, we also ran across a bunch of Panasonic switches, but also a really weird set. And we had no idea who to report that one to either. Like the normal Panasonic thing wasn't the right fit. And so all the docs were in Japanese. We kind of gave up on that too. So we'll eventually figure out how to disclose that one. But there's a bunch of random Panasonic switches that'll just give you a shell pre-op as well through the same mechanism. Um, and this is just kind of the tip of the iceberg. We found another like 70 odd devices. We just haven't figured out where they are yet. Um, so, you know, basically take Shamble, throw it in your home network, throw it in your work network and you might just get random free shells out of crap through this stage transition. The only tricky bit here is you may have to specify a username that's not the default username. So if the device typically has like an admin or manager username, specify all the default admin usernames for the products and you'll be more likely to shake out some shells. So here's an example of the Netterbit NSL224s. These are really popular in Iran. So a huge portion of Iran uses these things and you just basically log in as, you know, whatever you like. Um, so in this case we're using the Shamble shell for it. We're just saying like brute force all the different session states and it logs us directly into it and it shows data, here's the firmware, all the info, things like that. So super straightforward. And here's an example of the Digitransport ICS gateways. Same thing. What I love about this is when you log in it says, welcome, your access is super. So I also have the, you know, the South Park voice in my head when I see that. So it's amazing. Um, with that, I would like to talk a little bit about the OpenSH landscape. So, you know, typically we think about like SSH being OpenSH and sure it's like 90% of us, it's 87% of all SSH in the world, but OpenSH isn't just OpenSH either. There's a lot of different flavors of OpenSH. So for folks who aren't super familiar, uh, OpenSH was forked from OSSH, which was forked from the original V1, um, you know, tattoo, um, version of SH back in the day. Um, but OpenSH wasn't designed for Linux. OpenSH was hardcoded for OpenBSD. Like they didn't want our dirty Linux paws all over their beautiful SH daemon. So eventually they conceded and said, you know what, you guys can, all you plebs can actually touch our beautiful SH code, but we're going to create a version of OpenSH just for you called OpenSH portable. So when you talk about OpenSH, you're really talking about the portable version of OpenSH, which has a compatibility layer that makes, um, all of us heathens be able to use the nice functions of VSD basically, uh, without all the pledge and cool things like that. But if you look at OpenSH portable, there's actually a bunch of variants of that too. So if you look at like who is molested OpenSH the most, we're going to start off with Apple. Apple was just light touch. They just gave a little hug. They didn't really do much to it. Uh, they did not do terrible things to OpenSH. They, um, added some changes for, um, let's see the key login, the endpoint event logging, uh, PKCS helper and keychain, things like that. Really straightforward, not terrible at all. Very happy that they did not destroy OpenSH. Um, they start looking at Debian and Ubuntu. They've got about 36 different patches on top of the core OpenSH code. Uh, and those patches make it libXE utils backdoor compatible. Um, among other things, right? But there's a lot of changes and those changes aren't getting the same scrutiny that let's say the rest of OpenSH code is getting. It's, it's basically linking it to all kinds of other libraries. It's the reason why it linked to system D. Um, there's a lot more attack service because of all those changes they put into the, those system patches. Now moving up to Red Hat, now you're like 60 plus different patches. So even, even bigger attack service. And, you know, hopefully they're auditing this stuff and everyone's looking at it because it's important because if you're hacking a Linux server, it's probably going to be either Debian, Ubuntu, or Red Hat based these days, right? Unless you're like, I use ARC, you know, you know, there's only a few of those out there. Um, so, um, if you're using, uh, you know, Debian, Ubuntu, Red Hat, Linux, et cetera, um, you probably have a ton of different patches on top of OpenSH that are not pure OpenSH, if you will. Uh, you may go pretty well. And then there's a thing called PKIX SSH, which I think probably a lot of folks haven't heard about. It was forked from OpenSH back in 2002 to support X.509 certificates and then FIPS code. So because it supports X.509 and FIPS, a lot of the networking vendors decided to use that instead of regular SSH, uh, to build out their products because they want to sell to the federal government and they want to use crusty old crypto protocols. Um, so there's a thing called PKI SSH. It forked in 2002. It mostly, it's almost like they hate each other. If you do, like, so, put it this way, we diffed all of it. We looked at, like, OpenSH mainline to every one of these forks and just read every single line of code for days and weeks. Well, that was my vacation. I just did that for hours a day. Um, but PKIX one is really funny because you'll see a change in OpenSH and then a change is written slightly differently in PKIX SSH and they oftentimes disagree. Like, once in a while they mostly match, like, if one equal this, if that equal that. But occasionally it's like, if not, one equal this. And it's like, so, there's probably some weird compatibility bugs because the changes weren't followed entirely. They obviously don't want to look like they're copying OpenSH, but they also can't not copy it and stay compatible. So, you can just, you can feel the rage between the two teams there. It's great. Um, I've never felt so much, like, animosity in a code diff before. Um, but finally, the, the really fun one here is Windows. So, Microsoft Windows, um, shipped OpenSH on Windows 10. Everyone's like, oh my god, I can actually type SSH and curl. I don't have to do all these stupid commands anymore to back to my Windows box. I can use the built-in, I did nice native Linux commands to back to my, my Linux boxes. And that was great. So, we love the fact that SSH clients on Windows, we can use them on all kinds of stuff. Um, there's also SSH server for Windows. And so, there's a fork for, uh, of OpenSH portable called OpenSH, um, under the PowerShell GitHub repo. And they just massacred it. There's like 350 files were changed. They ripped out everything. All those secure parts of SSH kind of just got put into the corner over there, uh, and, and deleted. And then it's like, if Windows do something totally different. So, they ripped out your support. They ripped out, um, the PrivSep stuff works totally different through a sub-process versus the fork, because there's no forks on Windows. Um, they, uh, logged to Windows Event Viewer. They logged, uh, they sent telemetry back to Microsoft for everything you do. Um, they still haven't bothered fixing Terrapin. Like, it just, it's a very different fork. So, if you're using Windows and SSH, either a client or a server, you probably want to pay attention to this next slide, which is, uh, let's see, this is what it looks like. Not super exciting. But, if you start looking through the OpenSH for Windows code, you can start looking at the telemetry callback. You can't disable this crap, unless you disable telemetry total on your machine. Every single connection going to your Windows, your SSH server on Windows, is sending your client version and server version back to Microsoft in the telemetry. So, every time you port scan your system, every time you run a Nessus scan against your Windows server, it's sending that info back. Every time you SSH directly from your Mac OS client or whatever it is to a Windows server, it's sending your version string back to them. So, Microsoft knows who you talk to, who knows who you shell into, it collects all those craps for default telemetry. It even collects telemetry for things that are part of an encrypted session, like things like authentication methods that are negotiated over the secure channel, that's also shipped off to telemetry. So, uh, you know, I know we're all good, you know, cool kids here and we disable telemetry in VS code, but like, have you done so in OpenSH? Probably not, right? Um, so it's worth digging out the diagnostics viewer where you can look at the telemetry data on Windows and seeing like all your SH stuff being shipped off to the cloud. Um, so, yeah. But the next thing we'll talk about is even worse. Uh, so there's this really key function, we talked about OpenSH portal being a, a compatibility layer to make it, um, work not on OpenBSD. So the pure OpenBSD people, you know, can, can give us their code. Um, one of the functions that they implemented was timing safe B comp, which is like you expect. It compares two binary blobs, are these identical, in a way that doesn't change based on how long the strings are, what contents they have. They, it can be consistent either way. This is to prevent side channel attacks, it's really clean, really code, it's only like four lines of code. Maybe take out the return in the int, in the variable, it's only three lines of code. It's really hard to, to break this, right? This is a super nice, great piece of code by, uh, you know, Damian, uh, Miller. It's great, it's perfect, it's beautiful. And then OpenSH for Windows comes along. And they made it Windows compatible. So, uh, Windows compatible means, uh, first they look for a back R and a back N, and they scrub out the back R, and so they said, they allied the fact that there's a back R back N, they treated it as if it was equal to a back N. But you can probably see there's some problems here. Um, we'll kind of highlight those real quick. First off, there's only two lines of code they added, and they introduced a ton of bugs. It's no longer timing safe, because they look one byte ahead. It's no longer, uh, secure, because they read one byte out of, out of band memory. They're actually reading the, the pointer plus one, not the pointer, which could be beyond the end of that particular variable. So for every back R back N sequence you have in the source buffer called by this function, you're actually going one byte out of the memory buffer and moving forward. And that, and then that value's being compared for your byte comparison. So if you know there's a lot of data at the end of your buffer, you can now just tell SH to not compare the bytes you thought you were comparing and now compare the bytes at the end of the buffer, which are typically a bunch of nulls or something more predictable. So there's a bunch of like really gnarly bugs that happen just because somebody decided their config parser didn't work with this function that wasn't designed to parse configs in the first place. Um, so it's, it's about as bad as it gets. So this function's used in every single packet that gets processed by SH. So every crypto buffer coming into it gets the SH comp or comp buff check on it. And, and basically it, it gets buggy really quick. Um, it's used for RSA signature validation, all this stuff. But the question was like, can we actually exploit it? And that's where it gets tricky. It's like the buffer that you can, that triggers the bug is the first buffer, first parameter, and the attacker doesn't control it directly. But if you do enough signing operations, you know, packets, eventually you get a buffer that has at least one back or back end in it. If you get to two, you get a little more interesting, but it's been really tough to actually get an exploit out of it. So of course, when we report to Microsoft, uh, their take is, you know, even though we've got $1 billion annual security budget, we've got 3,500 security professionals, and we backdoor your timing safe B comp code, you do not get a banana. So, we got nothing. They said, no, no, you guys don't get anything. We're not going to fix it. Have fun. Like, all right, well, we're going to talk about it at DEF CON. See you guys. Uh, so we did. Cool. Um, so that's the end of the, most of the content about SH. We're getting a little close to time. I want to make sure you have time for a little bit of questions here. Uh, we're going to talk a little about the shamble tool. So, uh, this tool is a research tool for SH limitations. It's a combination of like, a thing you can use today to scan your network, but a thing you can extend to find even more horrible bugs in SH and then share them with the world. So, uh, we, we'd like you to, uh, play with it, make it better, and, and rain hell upon vendors that do it wrong. Um, there's a lot of really cool interesting attacks against authentication, off-bypass, null-bytes, uh, ends up when you send a, uh, uh, SH password authentication, there's a, if you send a second parameter in addition to your password, that tells SH server that you want to change your password to that new value. So, you can imagine that when we're developing this tool, we might have accidentally changed a lot of passwords. Uh, so, be careful about that part. Uh, other than that, and it's kind of funny, it's like, oh, I got into all these machines, and then you scan them again, like, now I can't get into all those machines, what happened? Well, we accidentally sent all the passwords to a null-byte. Uh, there's also a lot of systems out there that will, uh, accept a null-byte as a password, and specifically a lot of honeypots. So, we doxed like 5,000 honeypots by accident because they accept null-byte passwords where nothing else does. It's like, oh, here's all the honeypots, that makes our lives a lot easier. Uh, a lot of the pre-auth state transition stuff, so you can extend those, make your own. It's kind of modular. It's not as cool as menisplate, but it does a lot of stuff like that. You can kind of add your own checks to register them. Uh, and then all the post session stuff, too. If you get a session, but you don't get a shell, you can use shamble to, like, bang on that session, try signals, jam keystrokes into it, generally do all the crap you don't want to do by hand that's really annoying, and eventually, um, do that. Plus, we added some timing analysis stuff, too. So, if you think there's, like, timing leak in a username, we've got some built-in functions that'll tell you, like, what's the, what's the statistical probability of this username being different than this other one based on a timing tag with really tight, uh, timing. So, shamble.com gets you all that stuff, and there's a whole bunch of stuff it does. So, I think, first off, I'll hand it to Rob to talk about all the vulnerability checks we do. So, uh, shamble will actually check for all the vulnerabilities we talked about, uh, over this, and they will not only check for you, it will give you proof, so you can run through, uh, it'll check for TCP forwarding, see if it can forward anywhere, it'll try different, uh, destinations, see what it can find, see if it's, uh, administratively prohibited for some. Uh, it will do generic environment injection, so it'll take, uh, environment variables, it'll control execution of processes, and we'll check to see if the output changes and things like that, uh, LD preload, stuff like that. Super useful, we'll say, oh, this is actually how it's vulnerable, this is what it can do, it'll tell you what to do next. Um, the software vulnerability that we talked about, it will, uh, it will give you the exact, uh, version and exactly the repo that it used and everything to get into there. Um, it will check the GOGS thing, that's the, uh, that's the, uh, ENV thing that looks vaguely like a backdoor, um, where it's executing ENV, and it'll try to give you commands, uh, command execution there. And, uh, it will check the ruckus password escape, that's the one where you can, uh, you can put backticks or, uh, dollar parens in the password, and, uh, it'll just give that to you and it'll say, and the report, you can actually see, uh, in the report, it'll say, okay, here's what I found, here's the references, and here's the proof, it'll actually give you the output that it found. Um, and you can just run that, they're automatically, it will automatically detect it, and it will continue, we're continually adding more vulnerabilities here, so, uh, stay tuned and run that on all your systems and tell us what you find. Well, thanks, Rob. And even in the last 24 hours since the code's gone live, we've got a lot of great feedback, feature requests, things like that, so we're really excited to keep expanding it, adding things like the, you know, keystroke masher, where it just, like, hits every possible keystroke trying to break out of the shell, like, the things you usually put your toddler in front of to make them give you shells, like, we'll just do that for you here, so, uh, who needs AI, right? Um, but in that sense, um, lots of cool stuff's already built in today, uh, to get started, you just run shamblescan-o, it generates a gigantic JSON file, um, if you run this across the whole internet, you get about 60 gigs of data, I don't know why I know that, but it's a lot of fun and you have millions of shells to go play with, uh, and then you can run the analyze command, it'll try to, like, bucket your results based on what cool things you found, so if it, if it's, like, a known backdoor, a known, uh, bug, it'll hopefully stick into its own little file and you can track them that way. We also report, like, vulnerabilities in the JSON, you can scrape out and import, uh, of course all this stuff's been, a lot of this has been linked into the run zero tool that we work on at, at our day job, and so it does a lot of these checks for you automatically, including grabbing all your keys, stuff like that. We're also looking at integrating it with, uh, honobox, a bad keys project to automatically identify host keys that have been compromised, and shambles is unique in that it's one of the very few tools that test all of your host keys, not just your first host key. So if your machine has an RSA key, an ECDSA, an ED25519, et cetera, we'll actually grab all the different host keys by grabbing them all and then test all those keys for weak keys and, uh, things like that. So we're still a little bit early for the bad key stuff, but we're, we're making progress. Uh, so an example, one of the neat things about shamble is that you can tell it to get into that larval session state without actually opening the process, which is a pain in the butt to do otherwise with the message client. So essentially you say, um, you know, shamble scan dash dash interact equal first. So interact with the first session you get and the interact auto equal nothing. Do not do any, do not do anything at all and just drop you straight to the interpreter shell instead. And then from that interpreter shell, you can like set any environment variables you want. LD debug equal all, LD preload, whatever you like. Uh, you can start sending signals to it even pre shell. And then when you want to drop a shell, you either type exec to run a command or you can do shell to get interactive shell. And at that point you can then mess with the shell itself. So it gives you kind of all the tools you need to manually mess with it and control E is how you open the shamble shell, uh, from the prompt there. Just so we don't conflict with SSH escape codes. And there's a million other things we can talk about, but we're going to keep kind of hammering on the code a little bit. And of course, happy scanning. And, uh, here's us just throwing out a slash 24 real quick, but it is pretty fast too. It'll just, it'll eat all your CPU and RAM just grinding away all your things. Um, and yeah, here's a bunch of bones we found. Thanks. We've got a couple of minutes, I think for questions, looks like. Uh, if you have a question, please come up to the middle standy thing and the mic so that everyone else can hear you. Um, the mic may not be on, I'm not sure. You want to grab this one instead? Yeah. Oh, sorry. You're still on mic. All right. So out of all the implementations that you have, that you've scanned, what is in your opinion, the most secure? Uh, the most seeker or the most insecure? The most secure. Okay. Yeah. The, yeah, two, you know, the, the TLDR of this entire talk is just use openness H98P1 and don't do anything else. Just don't roll your own. That's basically all you found. Just like any other crypto. Anytime you try to mess with it, you break it. Oh, thank you. Uh, any other questions? Does anybody recognize my shirt? It's, it's particularly nerdy. I'll be your friend if you know. Okay. Anybody? One more question? Yes. Did you guys try anything with Putty? Putty, P-U-T-T-Y client? Sorry. Yeah. It's a TTY client for windows called Putty SSH. Yeah. We didn't look at the code for it, but it's mostly client side. We really focused on all the, just the server side of invitations. I know Putty does a bunch of weird things with the keys. Like it has a weird preferences in which E-D-S-A keys uses, but we didn't get the chance to test Putty itself. There, there was an interesting, uh, not volume per se, but there was an interesting, uh, key generation issue with Putty this year. I need to go back and look at that. Yeah. Sorry. Another question? Does Shamble detects honeypots? Like how do you guys are detecting honeypots? And like, how Shamble detects honeypots? Okay. Yeah. So the short version is you, it just makes the TCP connection to whatever port and range you tell it to. And then it looks for that stage version, does the handshake, all that. So, um, that's about it. Unless I missed your question. How is it detecting honeypots? Oh, honeypots. Yeah. Um, so the funny thing is most honeypots, uh, have a bug where they accept a null-byte password and they just drop and they accept that where a real machine will never accept the null-byte password. So in a, in a, in an open-stage implementation, by default, if you put a null into the password field, it'll kick you back out. But most honeypots will accept you with a null-byte password. And that's an easy way to find like 5,000 of them. Um, we found a bunch of other ones through, uh, some of them accept any public key, no matter what key you give it. Other ones will take, uh, passwords that are, uh, outside the spec otherwise or m-mangled password requests. So you just throw a garbage item and it accepts it. You know it's not open-stage. Cool. All right. And that's it. Thank you very much. Thanks everybody. Look for us if you have any questions. We're happy to talk to y'all.