Hello everybody. I'm here to talk to you today about 3D printer security. I think it's an interesting topic. I used to work with 3D printers for a long time and was fascinated by the way they work. It's been a very big pop culture kind of topic and it still seems like the general functionality of 3D printers has not, most people who even use them don't fully understand how they work and the implications of that. So I think it's a really fun thing to talk to people about who haven't delved into the mechanics of what makes them work. Any of you here own 3D printers? Have you ever 3D printed? Yeah? Yeah? Cool. Cool. What kind of 3D printer do you have? I have a LulzBot. LulzBot, yeah. Cool. You like assembled that yourself, right? Or did you buy it pre-assembled? No, it was pre-assembled. Oh, that's awesome. Yeah, those are really solid printers. What about you? I built a RimRamp. I built a RimRamp. Oh, yeah? And then I purchased an Ultimate 2. Okay, like a Prusa Mendel, something like that? Prusa, yeah, Prusa. Oh, that's awesome. That was about four or five years ago. Totally. Yeah, and the Ultimate 2 is two years ago still in my garage. Nice. Nice. Anyone else have a 3D printer? Pretty familiar with the concept? All right, we'll go. So what is 3D printing security? It's kind of like this, right? This is like, if you've ever done a 3D print, this is what happens when things go very badly. We used to call this like printer spaghetti, right? Hence the name of the talk. We'll get into some of the reasons why this happens, but once you understand why you get 3D printer spaghetti, you can start to think about like some of the horrible, horrible ways things can go wrong with 3D printers. Actually, if you put in a 3D printer into Google, you'll get hundreds and hundreds and hundreds of these. For a long time, the industry around 3D printers struggled with how to get people to use these things and not run into troubles. And there are reasons why the printers just aren't as reliable as you'd like them to be or wish them to be. I think a conservative estimate that was put together for how many prints failed, something like 40% of all attempted prints fail. And when I tell that to people who've owned 3D printers, they're like, yeah, that seems about right. That has implications, right? It's a reliability thing, and it gets down to the core of like what's up with 3D printers. All right, so this is me. I'm John Dunlap. I work for Gotham Digital Sciences, pen tester. I do exploit dev, reverse engineering, embedded stuff, code review. I really like to get into the nooks and crannies of technologies people haven't thought about with security. So I'm going to talk a little bit about security. Like, you know, like what is COBOL security? What is Haskell security? I think that's really cool. And I'm surprised that this is like such an under-researched topic. I also used to work in 3D printing. I'm not going to call out my old employer for reasons that will be obvious in a moment. But I did. My other love in life besides exploits and security are praying mantises. This is my praying mantis, Duke. They're really hard to photograph. They're really hard to photograph. But he essentially looks like that. All right? So my life is finding bugs and raising bugs if you want to think about it like that. If you want to see some really cringey picture of me, though, I was a meme in this community at one point. If you know what, like, forum this is from and what printer this was from, like, I'm sorry. But yeah, I was a dude in 3D printing at one point. So in this talk, we're going to like look at the general structure of 3D printing. I'm going to general threat model for 3D printers? Like, at what stages in the process can things go horribly wrong, right? What are the common security failures in the, like, sort of standard model for 3D printing, right? Because all 3D printers are sort of descended from the same basic idea, or what we call 3D printers today. So how does that model work? Does it work at all for security? And where can we find some places to inject bad code or bad operations? What we're not going to look into deeply are the sort of more expensive, more industrial kinds of 3D printers, or even the higher end of the consumer market we're not going to really touch. Just, like, the basic model of 3D printers. So what we won't do in this stock, again, commercial printers, unfortunately I couldn't get a hold of a printer for a laser for the research involved in this. That would have been cool. I would have liked to burn some stuff up with lasers. If anyone around wants to, like, give me a free laser printer, that would be pretty freaking cool. That's a lot to ask, but, you know, I should, like, say it out loud so when this gets published on YouTube or whatever, someone's going to tweet me, like, yeah, I got a laser printer for you. That would be freaking great. But they work on more or less the same principles, approach from a different way. And we're not going to talk about printer Wi-Fi connections, because that's a whole different, like, bag of worms, separate issue entirely. We're just going to talk about the core mechanics of 3D printing and how that applies to security. All right. I mean, what's the worst that could happen to a 3D printer? I mean, I don't know. I don't know. It could happen, right? I think that's the first question people ask me when we're talking about 3D printers. I think one of the reasons that the threat model for these things hasn't been fully explored is that people say to themselves, like, it's a printer. What could go wrong? Right? What bad things could happen? I mean, were they going to, like, make prints I don't like? Are they going to waste my filament or, like, make something embarrassing pop out of my printer? Well, it actually could be much worse, right? So if your 3D printer gets owned, you could definitely get this, right? Maybe a little bit of this, right? And a real possibility of this. And by that, I mean your 3D printer exploding into horrible flames and burning your house down. This is a real thing. I don't feel uncomfortable saying that this is an issue with 3D printers because if you type the words 3D printer fire into Google, what you will get is, like, 20 pages of results and people being nervous and, you know, magazine articles and apologies from manufacturers and horror stories and pictures. Pictures like this or this or this or this suffice it to say this is not a new problem and it's a problem we should worry about. But what, in all these cases, okay, none of these were caused by hackers. These are all down to, more or less every case, they can be described as user error. The The most common reason this happens to the printers is that people modify them. As they want to do, you know, it's very common if you own a RepRap or some other kind of consumer-grade 3D printer to modify the printer and try to trick it out and make it work better, right? Since the printers are so buggy in the first place, it's very common for people to replace nozzles, replace heaters, replace temperature gauges, that kind of thing. And in the end, it creates a situation where if you don't rewire your printer correctly, bad things can happen. And that is the source of most of those pictures. In every case I sort of investigated, it traced back to things like that. But what we're going to sort of reveal in a second is that if you don't secure the 3D printer properly, if you don't keep hackers from executing code on your 3D printer, that could very much happen, right? And you're relying on a very thin set of security protections to keep that from happening. Let's talk about how that works. Right, yeah. I've got to give you a disclaimer. Anything I suggest here, I'm going to speak very vaguely about 3D printer exploits, because although I have found problems in 3D printer firmware, I don't want to publish how to exploit those problems until I'm absolutely sure that it's responsibly disclosed, because you could do horrible damage with the kind of exploits I'm about to talk about. So this is the obligatory, don't try this at home. Whatever I suggest here, however vague it is, do not try it. I warned you, like ever. I am freaking out. I'm freaking serious. Don't. You heard it from me first. Don't do these things. All right. Let's start with a brief history of 3D printers for people who have not experienced them, which seems like the majority of us. So 3D printers are really CNC machines. They're based off computer numerical control protocols, which date back to the 50s. Who here is familiar with CNC? You have CNC? All right, 3D printer guy, no CNC. You a little bit? Yeah, like you ever use a CNC? Router or anything like that? Have you? Oh, yeah. Yeah. I prefer a CNC control company. Oh, wow. That's awesome, dude. So 3D printers are essentially CNC machines in almost every way. And that means that the ideas and protocols that run them date back to that older mindset about machines, which is not really security oriented. It comes from a more trusted place. Because the home of these... Machines is sort of in the workshop. So at first, 3D printers, I mean, 3D printers seem like a new thing. They date back to the 1980s, at least. And they started off as basically industrial tools. You know, the original sort of buzzword for 3D printers was like rapid prototyping, right? You can make a prototype for your product very quickly, and that's what they're intended for. They weren't sold as a general purpose, make whatever you want, replicator type thing. It was more of like, you're a big company. And you need to make something that works. You need to make this widget in plastic quickly. It's not a shape or a size that works well with the CNC routing method. We'll do it this way. Later on, some very brave souls decided to make consumer versions of these machines. These were born out of hacker spaces, truly. This is one of the early versions of the MakerBot. And it's funny, like, this is from Wikipedia. Brie Pettis himself, if you know who he is, he's like the founder of MakerBot. And he uploaded his own photograph. To Wikipedia, which cracks me up every time I see it. It's like, how much of that article did you edit? But the idea was to make something affordable that people could use, right? People were hacking together technology they already understood. People were well familiar with CNC machines, how stepper motors worked. The, like, kind of robot control theory that would make them run. They knew how all those pieces fit together and decided to make something that would be cheaper they could share with their friends so that when you're making your hacker projects in your hacker space, you could do it. You could get that widget that you couldn't have before. Because there are always small bits and baubles of things that you just couldn't get, right? And that was the genesis of these things. And they weren't ever really designed in the first place to be this robust consumer product. It was more like some hack people found to get it together cheaply enough to sell, right? Which is noble, but causes some issues later on if you don't ever move and evolve away from that model. You know, when people are putting this together, they're just trying to get something started. And making them absolutely bulletproof machines wasn't a concern. So when the media caught wind of 3D printers, there was, like, buzz. And if anyone was watching this community in, like, 2012 to 2014 type area, you remember how much 3D printers were everywhere. 3D printers, to this day, there's an article, like, every day it feels like about how 3D printers are going to change the world. 3D printers are going to change the world. Or revolutionize some new industry. Which is fine. It was great to be part of that. But the buzz caused problems. Because people thought 3D printers were basically this. They thought they were, like, the replicator from Star Trek. You know, you put in a design and it makes it for you, there's no problems. That's not true, though. Right? 3D printers were made for a very specific use case for specific shapes and models. And because of that, general progress. There's some models they can't make or make well or make inexpensively. It wasn't just as simple as asking to have something made and have it come out correctly every time. That's just not the reality of it. So people thought 3D printers were this. But they're really closer to this. This is like a Rube Goldberg machine. You know, this is sort of what 3D printers are. You know, it's all these, like, kind of mechanical bits and pieces just, like, strung together with duct tape. And it's beautiful. And I love it. But it's not the replicator. It's not going to make exactly what you want every time without having to think about it. The people who are most successful with using 3D printers are the people who understand them well enough to take them apart, alter them, modify them, improve them. That's how you get the most of it. But it was sold to people and is sort of still sold today as a general purpose consumer thing that anyone could use without further training. Unfortunately, the reality is not quite up to date with that. Maybe it will be someday. During this time period, there was also what could be classified as the most expensive 3D printer. This is the most annoying commercial catchphrase around 3D printers ever. And if you watch interviews with 3D printer CEOs, you kept hearing this over and over again. Like, tea. Earl Grey. Hot. You know, they embraced the replicator idea. But this is where 3D printers are supposed to live. Right? In a lab. And this is where marketing departments tell us they should go. Everywhere. Which they are everywhere at this point. And this is where they often live today. In a school. In a library. But keep in mind, 3D printers like this are essentially CNC machines like this. That were originally invented for guys like this. Like an engineer. But they're marketed to everyone. Right? With none of the robustness of that industrial technology built in. So, let's move on and finally start talking about 3D printers in very specific terms. And, um, in sort of broad terms. We're going to break down what we're really like talking about and trying to uncover security-wise. Okay? So, 3D printers. How do they work? Right? They work like this. Um, we got some kind of design software. We got a slicer. We got a host program. We got firmware. And we got hardware. And we're going to go through each of these like sort of subsections and figure out what is the security model for this. Where might there be holes. What are the bad things that can happen if this part of the software gets owned. Right? And we have to be conscientious at every stage that someone doesn't get unauthorized access to the printer. And tell it to do something that is unsafe. Alright. Let's take like a 10,000 foot overview of what the technology is. So, here's a 3D printer. Or here's a typical rep wrap. And, uh, here's a figure of what a 3D printer does. It's essentially a robotic head. Uh, that sits above a platform. That can move up and down over the platform. Uh, in some models the platform moves and the head doesn't. Um, but the idea is that it is depositing layers of this melted plastic filament onto the, uh, platform. Right? It's almost like a glue gun on a robotic head that is spraying this plastic stuff down. Right? Um, this particular technology is known as, um, filament, uh, deposition, disposition printer. And, uh, uh, this is the main type of printer that's, that's, uh, marketed as a 3D printer. There are, uh, several alternative technologies to this. Right? There's ones with lasers that solidify things. There's even things with, uh, something akin to a digital projector. Which shines, uh, images into a sort of like, uh, solidifiable goop. Right? Uh, there's a bunch of variations on how these would work. But this is the one you'll see if you go on Amazon and ask for a 3D printer, this is what you'll get. Um. There are some issues with how this entire model is put together, uh, from a reliability standpoint, which may affect its security. Um. One, uh, piece of terminology that you'll see a lot with 3D printers is the hot end. If you hear me talking about the hot end or anyone else, uh, anything else, that is the, the entire, uh, assembly of the printer that is putting the filament out. And it's called the hot end because it gets really hot. Right? Um, a lot of times people, uh, have this thing set up to be heated to about 200 Celsius. Um. This is where the, uh, the, the gear that, that feeds the filament, uh, into the printer. Is, uh, this where there's usually a cooling fan, uh, heat sink, the nozzle itself, uh, and the, uh, temperature, uh, gauging equipment like a thermocouple or, uh, a thermistor will be there as well. Um. So that's an important piece of the printer to, uh, watch out for. Uh, we also have this heating log. This is just a close-up of what it looks like. Uh, the red wires there are, uh, the heating element, uh, going. They're sort of inset into this. Uh, it looks like aluminum block. They, like, milled out a hole in this little aluminum block and shoved a heating element into it. That's also where the, uh, thermistor would go. There's, there's a lot of different variations on this design in competing projects to make this, uh, better, more reliable. But that's basically what we're talking about. Uh, stepper motor. Uh, I'm, I'm sure everyone here understands what a stepper motor is. Right? Yeah. Okay. Cool. Uh, so let's, let's talk about that heating element. That's basically the same thing as, uh, what, what runs a soldering iron. If you were to take apart a soldering iron and pull the, like, heater element out of it, that's basically what you get. And these things, um, with sufficient, uh, electricity will get as hot as you like. Like, really, really hot. They will, uh, the printer will fail long, long before, uh, the heating cartridge does. Uh, they're not purpose-built for 3D printing in, uh, any kind of way. They're sort of an off-the-shelf part. Um, there's also a thermistor. There's a printer couple, which is usually somehow attached to this head. And it's very important that the, um, the temperature reading equipment never be separated from the head. And that's kind of a, like, a, a really tweaky point of, of safety and security is that, uh, in the early days of 3D printing, people were less conscientious of this issue and would do stuff like just tape it to the head. Like, that's a pretty common technique is just to tape this thermistor or whatever to the head. And if it ever leaves the head of the printer, you're in some, for some bad times. Right? And we'll talk about that. Um, these days, um, it seems like most people have gotten smarter about the issue and have actually sunk the, uh, thermistor into the sort of, uh, hot end. They've, they've milled out a hole for it and placed it in there. And usually they'll keep it stuck in there with some kind of thermal paste or something like that. It doesn't totally obviate the problem, uh, if it's not securely stuck in there. There's a bunch of things that can go wrong. All right. Uh, this is, uh, polydamide, or, uh, often, uh, market is capped on. If you see this, like, kind of yellow, uh, space-age-looking tape or film on the printer, that's, uh, basically it's a thermally resistant, uh, material. They actually put this on satellites. And, uh, often you'll see on, on some 3D printers, uh, stuff will be just taped to the printer with the polydamide. And the, uh, the idea is that it'll keep it there without the tape melting off when the printer gets hot. But you have parts that might be just held on with essentially tape. Uh, you can think of how that might go wrong. Uh, here's what goes in a 3D printer. It's, uh, ABS plastic. Uh, or this is one of two flavors of things that usually go in 3D printers. Um, obviously it is plastic. It is, uh, flammable. Here's some information about that. We're just kind of, kind of scoot along past that. Uh, the other alternative is, uh, PLA plastic, which is a bioplastic. It's a little more, uh, eco-friendly, I would say. Um, it, it's, people claim that it's, it's a little more fire resistant. I'm not sure if you, if you look at the, uh, sort of suggested information, like what the flame point of it is, it's, like, not that much better. Um, but this is what we put into the 3D printer. Uh, there's sometimes other stuff, uh, wood, metal, nylon, polycarbonate. Uh, and yeah, sometimes, like, bones, ajar. Random scientific stuff. People are trying to run through these things. Uh, solder is one thing I've seen a lot of people try to get to run through. Like, it seems like a natural idea. It doesn't actually work super well. Uh, mainly, uh, problem with a lot of these materials is actually that, uh, 3D printers are extremely prone to clogging. And if the, uh, material going into the front of the 3D printer isn't, like, in pristine condition and very, uh, clean, uh, then you can have some major problems with the printer itself. All right. So, just in case you thought the 3D printing community was unaware of the, uh, the, like, fire danger type thing, uh, here's a, uh, forum post from someone going on, uh, about, uh, you know, he, he's actually at home testing in his lab which stuff is most flammable. Right? And, like, how it, like, lives up to, uh, the suggestions from manufacturers. Because you can buy ABS and PLA and it'll say on the front, uh, flame resistant. Right? And so this guy took home some ABS and PLA and nylon and a couple other things and just tried to burn them and see what, um, what it'd be like. Uh, and then he gets this great idea that he wants to make a candle out of it. Like, he's gonna make an, uh, like, a PLA candle. Right? And the reply from everyone is, like, yeah, that's a great idea. Like, make a candle out of it. Right? Um, whoa. That's crazy. Um, there was even, uh, apparently this was a popular idea because, uh, MakerBot actually put out a PSA that was, like, don't make PSAs. Don't make candles out of 3D printed materials. That's a, that's a very scary, unsafe idea. Do not do that. Uh, because there's hundreds of candle designs popping up on Thingiverse. Thingiverse is, by the way, is a, uh, website where you, it's sort of like a file sharing website where you can upload, uh, your 3D printable stuff. Right? And people can download it, you know, and, uh, hypothetically it should just work in your printer. Um, they had to put out this PSA, like, that's a bad idea. Don't put flames next to our flammable plastic stuff, please. Um, so, like, let's look at this. Let's look at that pipeline I just uncovered in depth. Now, we're going to skip design software because that's not really part of 3D printing. It's not unique to that. It, it has some, some kind of play in here, but it's not 100% involved. So, the first thing we're going to talk about is slicers. All right? Not this kind of slicer, but a 3D printer slicer. Um, what a slicer is, is very akin to, like, a compiler. And what it does is it takes a 3D model and essentially analyzes it and turns it into routing information for the printer. And what I mean by that? What I mean by routing information is it says, move the head X inches this way. Right? X inches this way. Spray this much filament. Move the head this way. Right? So, it turns, uh, you know, like, uh, vertexes and, and volumetric 3D data into these routes. Um, it's kind of like a competitive space. There's a lot of people making slicers right now. Uh, the important thing to keep in mind, uh, with slicers is that you could do some real mischief to someone's 3D printer if you took control of their slicer. If the slicer isn't safe. And slicers do have to be safe. They have to have a, a security model involved with them because they're expected to process random files from the internet. From, you know, untrusted sources. So, it's important that, uh, 3D printer companies take security of slicers very seriously. Because if you own someone's slicer, I mean, not only could you own their computer, but you could also send them all kinds of corrupt key code and that kind of thing. It's something worth sort of worrying about. So, the, uh, we got kind of, um, two file formats. To worry about for slicers. Uh, we have SDL files. Which, uh, are sort of, um, stereolithography files. It was invented by 3D systems in the 80s. But the idea is it's sort of a 3D model with all the stuff that the printer wouldn't care about stripped out. Because, uh, 3D models might have, uh, metadata, information about color, that kind of thing. Uh, that, or textures. That sort of stuff. That aren't really relevant to the 3D printing process. And so, uh, the idea is to take one of these SDL files and convert it into the 3D printer. The next file format, uh, which is G-code. And G-code is, uh, actually considered by some to be like a full programming language. It existed from the 50s. But it's basically a quick way to specify the movement of the printer. So, any, uh, kind of, uh, CNC router you've ever used is probably run on G-code. And almost every 3D printer that I've ever seen has run on G-code. So, the basic idea here is we're going to convert this SDL file format into G-code. Um, safely. Um, uh, every slicer has to have a 3D printer. A set of device definition files. Or ways to specify what kind of printer you're talking about. Because each printer has different capabilities. Hardware. The size of the, uh, print bed is different. The optimal temperatures are different. And the, uh, slicer has to take all that into account to make it work. So, um, obviously these are big, gnarly, complex programs. Um, that very few people understand. Uh, so SDL files are basically straight up just lists of vertexes. Like. Uh, lists of triangles, essentially. Um, it's an old file format. Uh, and there isn't really a spec for it. Sort of like 3D systems came up with this, uh, in the 80s. And there was never a formal spec. Someone, someone described what a SDL file is supposed to be in, like, their doctoral thesis. But there's never been an RFC for it. And for that reason, every CAD package actually sort of, uh, exports them in subtly different ways. Uh, which means that if you're making 3D printing software that handles SDL files. You have to be very careful about how you do the parsing of them. Because every CAD software package might put out a slightly different variation. And people expect the software to work universally for all files. Um, but top level view. There's basically two flavors of SDL files. There's a binary representation. And then there's a strings, uh, sort of UTF-8 style, uh, or ASCII, uh, style representation. So, here's what the, uh, binary file format looks like. Uh, you know. We got Uint, uh, 80 header, uh, 32 bytes of number of triangles. And, uh, these are just our, our, uh, vertexes in a normal. Right? So that's what it would look like in binary. And this is the ASCII file format. Um, that's about as close that you, as you'll find from anywhere of, uh, specification for these things. Um, these look like this. Alright. Uh. This is a little more to, like, validating what, uh, a good SDL file is. But it's not super relevant to security. Uh, suffice it to say, um, there's, there's some restrictions on how the triangles are actually oriented. That might or might not prevent the, uh, slicer from being able to do its job at all. Um. The key thing is making sure that there's no way to leverage, uh, remote code execution from the input SDL files. Um. And the, the lack of a spec here really doesn't help that. Uh. We're gonna sort of explore that more deeply in a second. But first, uh, let's check out what G-code is like. So G-code is, uh, pretty ancient. It's existed for a whole variety of machines, uh, over the course of basically 50 years. Um. There is no canonical list of G-code instructions. Uh, every machine is sort of free to define them and redefine them as it chooses. And that includes, uh, 3D printer to 3D printer. Uh, uh, individual G-code might mean different things or have different side effects. Uh, there isn't any accepted standard for what the individual G-code should mean on a particular printer. Which is kind of problematic if you're writing a slicer because now you have all these, like, uh, device-dependent things that you have to code in. And things that might be safe on one printer are not safe on others. Or there might be features that are not safe on others. Or there might be features that are missing from some printers that exist in others. Um. It becomes a big complicated thing. Uh. So G-code instructions are basically, uh, some letter, usually V, then some number, and then an operand. Um. I told you that G-code is considered, uh, like, a full programming language by some. And you can kind of think of it as the assembly language of the printer. Um. So what is output by the slicing software is actual instructions for the firmware of the printer to execute. And that's a little scary because that means there's an intermediary file that you can mess with and tell the printer to do nonsensical things after the slicing process has ended. And that also means that you can, you know, share G-code files with other people that might be potentially malicious. And the G-code is, essentially, has full access to the printer. You can only do the things that the, uh, the G-code is capable of doing that's defined in the firmware. Uh. But if those things are unsafe, uh, there isn't any real protections in place to keep people from abusing it. You know, if you write it in the G-code file and you send it to the printer, it will be executed. As long as it's kosher with what the firmware has. Um. So it's, it's really the responsibility of the firmware developer to make the reading of the G-code safe. The, the printer will execute whatever G-code you give it. Uh. 3D printers typically use a very small subset of G-codes, uh, compared to what CNC routers use. Uh. Usually, it's stuff like, uh, CNC routers have, uh, ways of doing, like, arcs. Like automate, uh, some kind of arcing algorithm instead of giving it straight lines. That's a really common example. Or the, the heating element of the 3D printer needs its own G-code kind of ideas. Um. Here's, uh, here's what G-code looks like. And you can see here, this is a series of, uh, sort of coordinates and, and moves for the 3D printer to execute. This is moving the head around. Uh, this is the start of the print, basically. Uh. An important thing to consider here in, in our threat model of 3D printers is that the G-code has the ability to specify the temperature of the printer. Right? That is built into this file format that the 3D printer is eating. That, that means that, uh, in between the 3D printer deciding what temperature it wants to be, there's a file that can be messed with. Right? So, again, if that slicer is owned somehow, or if you have someone messing with your G-code files, they could set it to funky temperatures. Now, the firmware typically has some kind of protections against that. But, if you have, uh, misconfigured firmware somehow, or your, your printer just isn't up to snuff somehow, uh, bad things could happen. So, uh, you know, just as an example attack, you find someone who has the maximum temperature of their printer, uh, set too high. And you just give them an altered G-code file, uh, with a too high temperature. Something that would cause the ABS filament to catch fire. Uh, it's not that far-fetched. You know, people set up their printers for, uh, printing, uh, polycarbonate all the time. And they'll jack up the, uh, the maximum temperature in the firmware. And all it takes is someone malicious giving them a G-code file, uh, with a temperature that is too high for their filament to take. And you're in trouble. Again, the 3D printer trusts, for the most part, the G-code instructions you give it. Uh, here's some of the available slicer software. Slicer, Cura, KISS slicer. Uh, MakerBot's got one. Um, I ran AFL against these. And, uh, does everyone know what AFL is? Slic- uh, fuzzing software, yeah? Cool. Um, I saw someone- not everyone raised their hand. Okay. I'll explain. It's- it's- it's basically, uh, machine learning powered, uh, automated, uh, file fuzzer. It- it'll corrupt a file you give it until it causes, uh, a crash to happen, right? But it's smart. It actually parses over the call tree of the, uh, of the program and finds nooks and crannies. And the- the problem I ran into is that the- the problem that slicers have to solve is so large and inefficient it made it hard for them to fuzz. And I had to break apart the, uh, the program and fuzz individual sub-components of it. Because an individual slicing job could take anything from, like, two seconds to possibly hours. Um, it made it very difficult, uh, to work with fuzzers. So, if- if we look at, uh, Cura Engine, which is, uh, popular slicing software, it- it actually chips with no ASLR, uh, no DEP, uh, no control flow guard. Uh, basically, it's- it's pretty ripe for- if anyone found a buffer overflow of any description, it'd be trivial to put together an exploit of this thing and cause some havoc to happen. Okay. So, uh, yeah, we have some, you know, low-level code, parsing, untrusted code. This is a bad idea. Um, let's move on to host programs. So, uh, the job of the host software is to send over the model to be printed, uh, from your computer to the 3D printer. Uh, usually this is done, uh, over serial code. So, uh, we're gonna look at that in a second. But the idea is to give some kind of interface for people to, like, check in on the print, to monitor the temperature of the printer, see how far along they are. And again, what we have to watch out for is, like, any kind of way an attacker could send untrusted commands to the printer by exploiting the host software. Um, here's a comparison of the, uh, host softwares that are out there. Uh, we have, um, no one can agree how to pronounce this one. It's, uh, I think it's repeater hosts. Repetier hosts. I've never heard two people pronounce it the same way. Uh, and then you got Cura, Octoprint, Pronterface. Um, the problem here is less with the host software itself than the model of serial communication that's going on between the printer and the host software. Um, here, here's, here's what, uh, each of these looks like. And the problem is that they just basically speak over serial. And if the 3D printer is plugged in to the computer and the host software isn't talking to it currently, there isn't much to stop an attacker, uh, from just sending commands to the printer. If they have remote code execution on your computer, they can send commands to the printer. And there isn't anything to stop it. There isn't any kind of authentication or authorization or trusted G codes versus untrusted ones. If the host software is not connected, uh, there's really nothing to stop you from just sending over your own print. Um, the, uh, the only thing that might be problematic is if maybe the host software stopped in the middle of a print and released the port. And then you'd have a checksum to figure out. Um, 3D printing, uh, software usually has a very basic binary protocol where after each command, a number is incremented. Like, you know, this is line one, this is line two, and line three. And the firmware checks to make sure you're on the right line number. This is what that looks like. This is the checksum. Uh, obviously checksums like this aren't intended for security, but if you ever wanted to do this, this is what would get in your way. Like, knowing what the checksum is at any given time. So, how are we gonna figure out, like, what line number we're on so the 3D printer doesn't just, like, ignore our command and tell us that we've sent them corrupt stuff? Well, as it turns out, uh, many 3D printers and firmwares have a command to just reset the line number. So, not a problem. And, uh, even better, uh, the line number reset command has no checksum. So, good to go. No problem. Uh, if it starts rejecting your commands, just give it M110 and it's gonna reset. You're gonna be good. Uh, so, this is how you'd steal a, uh, uh, com port. Um, you send the printer a M110 command, reset the line number, and you're golden. There's really not anything in the way. Um, alright, so now let's look at the firmware. So, there's many variations on 3D printer firmwares. They're all sort of descended from the same family. Uh, they all work in more or less the same way. Again, there is no rigorous spec for how 3D printers should work, which is kind of a problem on its own. But, uh, people early on in the process sort of developed a, a common procedure that people, uh, adhere to more or less the same way. Um, what does happen all the time, though, is that people like to fork these projects. And make their own subtle remixes of it. Which means that even if the, like, main repository, the original author of the firmware, is in good shape. Is very conscientious about their binary security. Like looking for buffer overflows and that kind of thing. Uh, maybe the forks aren't. Right? Um, and that's a problem. Because the most common reason to fork something is if you're, if you're a 3D printer manufacturer. And you want your own firmware. And you want it to work slightly different than, you know, the mainline open source firmware. You're going to fork that, change it. And not everyone is conscientious about implementing those upstream changes to the firmware. So it's very possible, uh, that someone will find a buffer overflow in the, like, upstream repository. And the downstream repositories will never fix it. Um, there's also no idea of chain of trust. So, for a lot of devices like your cell phone, uh, things are cryptographically signed when the firmware is flashed on. So you can't just put any random firmware on the thing without it causing problems. Uh, if you have access to someone's 3D printer, or perhaps not, we'll talk about it in a second. Um, you can flash new firmware on there. Pretty much no problems. There's, there's very little boundary to just putting new firmware on a 3D printer. Uh, for the most part. Now, in a lot of hardware, what they'll do to prevent this from being an issue is require sort of, uh, a, uh, a circuit to be shorted. They have like a little, little, uh, two pins that you short together. And that's what allows the, uh, firmware upload to happen. And earlier on, when 3D printers were more commonly based off things that were essentially Arduinos, uh, you would have a little push button, right? You'd push a button, and you had like a five second window, uh, to flash the firmware. Now, in more recent editions, as these have hit the mainstream, I've increasingly found people marketing host software that has the ability to directly upload firmware with no further checks on the hardware side. That's kind of dangerous. Uh, to be frank with you. Because your firmware is your last, uh, bastion of defense. If you tell the, the 3D printer to do something horrible and dangerous and harmful, uh, it's the firmware's job to save you. And if you have control of the host software, and the host software has the ability to upload firmware, well, game over. You can reflash the firmware, remove every possible protection, and you're good to go. Alright. So, here are the, uh, most common, uh, flavors of free and open source, uh, firmwares. Uh, we got Marlin. It's probably, like, the king of 3D printing, uh, firmwares. It's been along for a long time. It's up, updated all the time. Uh, it's smaller than the other, uh, common firmwares because, uh, uh, honestly, it's been picked over and optimized and, and made clean, made small, uh, for many years. As, they're very conscientious about, uh, removing security, security problems from, uh, from their firmware. Uh, but other people don't update as often. If you look here at, um, at, uh, Repetier.com. Uh, that's not updated quite as often, and a lot of the, um, downstream forks and things like that are left alone for a long time. Uh, another problem you'll run into with these, uh, firmware packages is that it's kind of an open source type problem where, uh, people, people make modifications to the firmware for their proprietary printer and then drag their feet about releasing the GNU type source code, right? Which shouldn't be a problem. People should be, like, conscientious and open and honest about that. But it is a thing that'll happen. There might be a six or eight month gap between, you know, when they make a big change to the firmware and when it's actually published and released. So. Something to keep in mind. We got, uh, Marlin. Uh, these things, by the way, are meant to run on, uh, typically AVR, uh, 8-bit micros. Uh, ARM is starting to make a little bit of headway, bit by bit, which is a good thing. You can do a lot more. Um, but sort of the standard for 3D printers still is, uh, 8-bit. 8-bit AVR. Um, here's what, uh, like, if you're configuring Marlin, this is what it would look like. This is the part where you, uh, specify the maximum temperature of the printer. And unfortunately, again, the culture of this is that, uh, people pass around configuration files between each other all the time. Right? And it is not unthinkable for someone who's not your best friend to send you a configuration file for your firmware where the maximum temperature is sent really high. And if you're dumb enough to put, compile that into your firmware, there's nothing to save you. There's no hardware protection that will stop the printer from blowing itself up, typically. Uh, to save you if the firmware is not designed to help you in the way it should. Um, but Marlin is very, uh, conscientious about the temperature problem and has all kinds of safety aborts. Where if it thinks that things are going wrong, it will, uh, not just stop the print job, but just reset the firmware and stop all, uh, computation whatsoever. You know, we're basically dead in the water. Right? Uh, the security check I'm showing right here, or safety check you could say, uh, is the max temps error. This is what happens when you've achieved a temperature higher than what the firmware was compiled to accept. And if you get through two or three cycles of the, uh, temperature being higher than it should be, it just shuts off. Right? Uh, there are other ones we'll talk about in a second, but this is the main one. So if you were a bad guy trying to find a way to blow up a 3D printer, uh, this is what would be in your way of of doing it very easily. Uh, and it's a good thing, and it works, but things can go horribly wrong still. You know, I guess it won't be that easy to blow stuff up, but maybe it will be. Uh, so the first thing I want to talk about, and this is, again, a fundamental problem with 3D printers, uh, as they are as they are set up today, is uh, the calibration and manipulation of what are called PID algorithms. Um, anyone familiar with this? Anyone played with PID algorithms? If you've been printing, CNC people sort of know this. PID means Proportional Integral Derivative Control Algorithm. It's from control theory. The idea is that sort of, uh, if you naively adjust the temperature to the 3D printer, it's going to sine wave forever because you'll always be overcompensating. The PID algorithm is a way to keep the 3D printer at a stable temperature. But, the PID algorithm has to be tuned for the individual hardware on the printer. It has to be matched to the coefficients that are uh, compatible with that individual heating element, heating block, nozzle combo, right? And this can change over the time as the 3D printer ages so every 3D printer firmware I've ever seen has a PID setting tuning G-code. So that means that the 3D printable file that you send to the 3D printer has the ability to tune this PID algorithm itself. It can initiate the process and set the coefficients of PID tuning stuff. Right? That means your input file can calibrate your printer for you. Which is not a good thing. Uh, the reason this is set up, by the way, is because the only way that the host program uh, can communicate with the 3D printer is by sending G-code. So there has to be a G-code for the PID thing. Right? Uh, that means it's the same as any other print and you can stow it away in someone's 3D printable file. Um, documentation for most, uh, firmwares calls this out as a potential issue. The reason is um, that if you tune the PID values maliciously, or incorrectly as can even happen by accident, uh, the 3D printer can just overshoot its intended temperature. You can ask for, uh, 200 Celsius and end up with 250 Celsius or higher. And at that point, uh, you're basically relying on the, on the firmware to save your butt. Right? To detect that the temperature is not what it should be. Um, however, historically it's been a problem that it can linger up there for a while before the firmware catches on. Now, it, in truth, this shouldn't be, like, catastrophic because one of two things should happen. The 3D printer should just shut off or it will sine wave back down to an even lower temperature and maybe make another attempt to get higher up there. Um, but in practice people have found that bad things will happen if you maliciously tune these. Um, there's even some, some indication over what that would look like. Um, ... I'm not going to show you how to do it, though. Because I think it would be irresponsible. Um, the, the primary thing to learn here is that yeah, it's an issue, it's a knowledge issue, and it's something that the user inherently has control over. Um, I say if we're gonna fix this, just authenticate PID calibration. It's not a big deal to have a username, password, something in your firmware, uh, to keep this from happening. Uh, don't put it in the G code. Find some other protocol to keep this from going on. Um, but let's look at like, uh, much scarier firmware exploitation vectors. Um, number one, we have interfaces. Uh, I touched on this before, which allow the unauthenticated flashing of firmware. Uh, and then, uh, exploiting programming errors in the firmware itself, right? So, like, what is the sum of all fears, okay? It's, uh, it's return-oriented programming in the firmware itself. And we'll talk about what that would look like. Um, so buffer overflows are very possible on 3D printer firmware. They're written in C. Um, it's up to the, uh, author of the firmware to put the bounds checks in to keep you from doing buffer overflows. Uh, devs of this firmware are typically relatively conscientious about it. You can find lots of fixes for pre-existing buffer overflows in the past. Uh, for instance, uh, many firmwares had a set-size command queue that could be overflown, right? It would be like, you know, they would set as, uh, on the stack, like, the command queue for the printer will be 25 commands long, and if you send it 26 commands, it would overflow and bad things would happen. Uh, a lot of the better, safer 3D printer firmwares, uh, use, like, ring buffers, so if you send too many, it'll just overwrite the, uh, previous command, uh, but it's still something that happens. Um, the, the firmware has to have a very safe parser in it to make sure that what's, what's going into the printer are, is not malicious, right? And this is doubly so because 3D printers on AVR have no form of ASLR, they have no depth. If you control the printer, you fully control the printer, right? There's nothing, there's no randomization or anti-exploitation mitigation factors to make it even hard to do once you have control. Uh, the only thing staying your way is AVR being a, uh, Harvard architecture, which, uh, you guys familiar with Harvard architecture? It's the AVR, right? Uh, which means that uh, you will have to use return-oriented programming. You'll have to return to the code, uh, repeatedly. You can't just inject your own shellcode. Uh, what you have to do is re, uh, find pre-existing, uh, bits. Which is a little more challenging on a tiny piece of 3D printer heart, like, firmware. So, here's how that shellcode would look. Um, again, I'm not gonna show, uh, share any with you, uh, right now, just for safety sake, but, um, first thing you would do is, uh, overflow the program counter, uh, return to a gadget, and then we would overwrite some critical setting, and return, uh, control flow right back to the printer. So you could see, you could, uh, very easily use an exploit like this to just reset the maximum temperature of the printer and send it off heating, right? So it's critical that, uh, 3D printers, uh, have safe firmware, right? Uh, with no buffer overflows whatsoever. Um, and I bring that up especially because they're not, it's not like, uh, aerospace code or, or the code you would find on a plane where it was made for safety from the ground up. So, uh, just some, uh, ideas about finding these exploits. Uh, are these rare? Well, no. If you search around on GitHub, you can probably find some existing acknowledged ones that haven't even been fixed. To be honest, um, and then there's a lot of ones sitting around in the code that people acknowledge, and they're marked no fix because they don't think they can be exploited. But this is sort of readily findable, unfortunately. And when you consider that people have forks of the software that aren't updated, it really is kind of a, like, danger. Uh, if you ever want to do some, uh, reverse engineering of 3D printer firmware, uh, that's maybe closed source, uh, you could do it like this with AVR, object copy, and AVR object dump. Uh, another good reason to do this if you're developing an exploit is that, uh, while 3D printer manufacturers are typically releasing the source code to their firmware, uh, that might not match up 100% with the compiled binary they give you to, uh, install on the printer. And if you're developing an exploit against the, like, standard binary that's put out there, uh, you're gonna want to look and find the offsets yourself. Here's what that would look like. Here's some strings from firmware. Uh, it's all pretty easy, to be honest. Um, some people ask me in, uh, when I've given dry runs of this talk, uh, can you persist on the 3D printer? Uh, one thing I looked into when doing the research for this is whether you could store, uh, shell code on an EEPROM, uh, to get persistence on the printer. The answer is generally no. Uh, because, uh, every 3D printer firmware I analyzed had very conscientious controls about the length of the data you could put on the EEPROM, so. Oh, yeah. Sure, yeah. Oh, yeah, you're saying once you got RCE, you could just, like, write to the flash. Yeah. Nice. ... ... ... ... ... ... ... ... ... Nice. Everything is through USB within one minute. Right. Awesome. Okay. It looks like we're out of time here, guys. Yeah. What? Oh, yeah, yeah. Cool. So I guess we're done. If you guys want to hear anything more about this or ask me some questions, feel free to ask me afterwards. But thanks for listening, guys.