<p>I have a bit of an odd request. I am studying the vulnerability of 3D printers and would like to know if there is a way to disable the limit switches on, for example, an Ender 3 in the G-code.</p>
<p>Ideally, the exploit would be used by plugging in the malicious code via SD card into the 3D printer. I have found ways to change the nozzle temp and things like that, however, nothing on the limit switches.</p>
<p>If I were the manufacturer, I wouldn't implement the function, so if it's not possible it will not be a surprise. If that's the case, what would be some other options for tearing this thing up?</p>

[{'answer_id': 18719, 'author': 'OneWasNotEnough', 'author_id': 32640, 'author_profile': 'https://3dprinting.stackexchange.com/users/32640', 'pm_score': 3, 'selected': False, 'text': '<h2>Ethics and justification:</h2>\n<p>If you have physical access to the device you could just... physically damage the device. Running arbitrary G-code is just more complicated</p>\n<p>Most printer farms have a strict no outside G-code policy for good reason. Because direct physical access to the printer does not provide any security.</p>\n<p>This is also a problem for CNC Mills and other equipment. The firmware is not there to protect you. If you ask the system to put the spindle into XYZ_POS, the device\'s job is to deliver your 300 dollar end mill into the part as expediently and directly as you have told it. It does not hold your hand.</p>\n<p>As a result, it\'s probably best that <strong>no one</strong> run pre-compiled G-code. You should use an STL and generate your own G-code. Not only does it allow you to properly tune the print for your specific printer, but it prevents nasties from breaking your printer.</p>\n<p>Do not test this on a system you do not own. You will face civil and criminal liability for any damages as a result of performing this on printers that are not your own. Additionally, I would question the value of your research provided that physical access to a device automatically makes it vulnerable; let alone running arbitrary code from an untrusted source.</p>\n<p>To help your research: Most &quot;secure&quot; facilities prevent even touching a machine with external code. All code has to be generated on trusted and isolated machines by trusted persons. There is no guarantee that the &quot;trusted&quot; person can\'t manufacture a job that will crash their 300,000 dollar CNC mill and cause damage - but there are serious repercussions for doing so.</p>\n<h2>It\'s extremely difficult to &quot;tear up&quot; a printer by turning off the endstops.</h2>\n<p>You can disable physical endstops with a simple command <a href="https://marlinfw.org/docs/gcode/M121.html" rel="nofollow noreferrer"><code>M121</code></a>.</p>\n<p>However, this only does so much.</p>\n<p>With <a href="https://marlinfw.org/docs/gcode/M121.html" rel="nofollow noreferrer"><code>M121</code></a>, the printer is only really vulnerable before it has been <a href="https://marlinfw.org/docs/gcode/G028.html" rel="nofollow noreferrer">home</a>d. Most printers will <a href="https://marlinfw.org/docs/gcode/G028.html" rel="nofollow noreferrer">auto home</a> when starting a print, or refuse to print until they are <a href="https://marlinfw.org/docs/gcode/G028.html" rel="nofollow noreferrer">homed</a>. If issuing <code>M121</code> then arbitrarily trying to ram it past an endstop, it will continue until it counts steps to the <a href="https://marlinfw.org/docs/gcode/M211.html" rel="nofollow noreferrer">software endstop value</a> <code>[XYZ]_MIN_POS</code> to <code>[XYZ]_MAX_POS</code>.</p>\n<p>Older printers didn\'t have software endstops and would keep going until they were stopped or turned off. But this wouldn\'t <em>explicitly</em> cause damage as physical limitations would prevent it. Outside of old designs that do not physically limit the Z position - and crashing the nozzle into the printer.</p>\n<p>Nowadays - the printer would crash into the axis limit and then stop because it would hit the software endstop (and funnily enough, be homed as a result - I have done this as an experiment on my own printers)</p>\n<p>This would not damage the printer - just be annoying for a short time until it hits the software endstop.</p>\n<p>You can however make it work like an older printer provided it does not have stall or crash sensing (like Prusas have by default) by issuing <a href="https://marlinfw.org/docs/gcode/M211.html" rel="nofollow noreferrer"><code>M211 S0</code></a>.</p>\n<p>This turns off the software endstops. And should allow it to continually try to reach the value programmed in the G-code. It should continue to count until it gets to XYZ_POS then finally stop.</p>\n<p>Will this cause damage? Maybe. If the Z-axis is high and it can physically push its way into the printbed hard enough it can cause damage to the hotend. However, generally, most printers are designed (these days) that the Z-axis cannot go too far into the print bed and cause (too much) damage. Modified printers can be vulnerable if they modify the bed but do not physically limit the Z-axis from going down too far. Additionally, when the printer <a href="https://marlinfw.org/docs/gcode/G028.html" rel="nofollow noreferrer">autohomes</a> on print it usually will set zero to the endstop before the payload can be run, giving a home and only allowing excursion to the axis positives. When this happens, no damage can really occur outside of overheating the steppers/drivers and possibly damaging belts.</p>\n<p>There are also some firmware protections to help protect the end-user (e.g. Prusa Crash Detection) - depending on the printer these may need to be circumvented as well.</p>\n<p>How you can really tear up a printer? If you have physical access to it - you have total control over it. Simply being physically near it is enough for you to just throw it out a window. It\'s arbitrary to try to run any code. But if you\'re trying to research how a threat actor can mess up someone\'s printer?</p>\n<p>Thomas Sandladerer made an excellent video on these vulnerabilities (specific to 3D printers) here: <div class="youtube-embed"><div>\r\n                <iframe width="640px" height="395px" src="https://www.youtube.com/embed/RKdsp2vrmag?start=0"></iframe>\r\n            </div></div></p>\n<p>In his video, he\'s speaking directly on the threat of running pre-formed G-code from public sources. (Something that you should not do - something that <strong>no one</strong> should do)</p>\n<h2>Conclusion:</h2>\n<p>In security, physical access to a system by an untrusted person or running untrusted code on a machine is not allowed.</p>\n<p>For this vulnerability to be exploited, it requires a person to do things that they should not be doing - running generated G-code from an untrusted source. This includes from &quot;friends&quot; or even family.</p>\n<p>I won\'t tell you how to &quot;really tear up&quot; a 3D printer as there are a plethora of horror stories out on the internet of printers catching fire let alone the threat of running some random code on your printer. How to do it is publicly available. You just have to figure it out yourself.</p>\n<p>The lesson here is simple: <strong>Just don\'t run pre-compiled G-code.</strong></p>\n'}, {'answer_id': 18722, 'author': '0scar', 'author_id': 5740, 'author_profile': 'https://3dprinting.stackexchange.com/users/5740', 'pm_score': 2, 'selected': False, 'text': "<h2>Potential threat?</h2>\n<p>I can imagine that this is a potential threat for printers that are operated in an environment where there are lots of people using the printer where there is access to the SD card (e.g. schools, libraries or maker spaces). It would literally take a file on the SD card to be run the next time the printer boots to change settings through G-code. As you can imagine, it is quite easy to change the coordinates of the origin - this has been discussed in previous questions - but also speeds, endstop state and acceleration values for instance.</p>\n<h2>Would it destroy a printer?</h2>\n<p>Yes, it can. Lead screw motion is stronger than belts, the latter will just skip, but lead screws may do some serious damage depending on the printer construction (I've had my unintentional fair share of that). But, the most obvious problem is the time that is needed to fix the problem; re-calibrating and repairing.</p>\n<h2>Limited to malicious intent?</h2>\n<p>No, managing an Ultimaker 3 Extended for a staff association I can talk from experience that it doesn't take malicious code, or intent, to mess up a printer. Working from home due to COVID-19 measures (my work needs those who can work at home to stay at home, in order to allow those who operate machines and test equipment to go to work and comply with the x people per y square meter rules that the government laid out) I have been away from the UM3E to find it in a terrible state a year later. It appeared that there have been people, that had no experience in slicing, using the wrong type of materials for slicing with respect to that was loaded into the machine... (we operate non-Ultimaker materials, so the material is not recognized by the RFID reader). The printer is now under lock and key...</p>\n"}, {'answer_id': 18725, 'author': 'Trish', 'author_id': 8884, 'author_profile': 'https://3dprinting.stackexchange.com/users/8884', 'pm_score': 2, 'selected': False, 'text': '<h2>Physical Access is worse</h2>\n<p>If you really want to brick a printer, physical access allows to destroy any printer physically.</p>\n<p>If you really want to mess it up only via a remote command later, you would not just run arbitrary G-code, you\'d replace the firmware with one that <em>looks</em> and <em>feels</em> the same but contains neither <a href="https://3dprinting.stackexchange.com/questions/8466/what-is-thermal-runaway-protection">Thermal Runaway Protection</a> nor a Maxtemp. This way, the machine would just try to heat to arbitrary temperatures as commanded - making it possibly a fire hazard. In the worst case, installing bad Firmware is as simple as inserting a prepared SD and having the printer run a <em>firmware update</em> to your modified version!</p>\n<p>You see, Physical Access means any malicious person can turn a printer into what accounts to a timebomb, but as <a href="https://3dprinting.stackexchange.com/a/18722/8884">0scar</a> points out, it takes no malicious intent to mess up a printer - just being bad at maintaining or using it.</p>\n<h2>Network Access suffices</h2>\n<p>Let\'s for the sake of argument assume all we have is <a href="https://3dprinting.stackexchange.com/questions/10573/what-is-a-printer-console-terminal">remote terminal access</a> to the printer. No necessarily video feedback, just terminal access, for example via <a href="https://3dprinting.stackexchange.com/questions/tagged/octoprint">Octoprint</a>. This is sufficient to send arbitrary G-code, and some combinations can be outright devastating - which is why remote print servers are usually password secured and should <strong>never</strong> be public access!</p>\n<h3>With the right Terminal, Altering the EEPROM is easy</h3>\n<p>If you have remote access and can use a terminal that allows directly altering the EEPROM, changing fundamental values like the position of the endstops or the size of the printer quite easily. Repetier Host for example can do that, but usually uses a direct physical cable - which gets us back to <em>Physical Access is worse</em>.</p>\n<h3>You worry about the wrong command</h3>\n<p>Now, the worst command that with bad intent is very likely to destroy printers is the <a href="https://marlinfw.org/docs/gcode/M500.html" rel="nofollow noreferrer"><code>M500</code></a> command to save altered values into the EEPROM. This can result in problems if G-code before the command contains code that changes basic settings that are not firmware locked.</p>\n<p>For example, <code>M301</code> with nonsensical values can force very bad PID-setting that could result, depending on how they are set up, in massively overshooting the target temperature, regularly tripping Thermal Runaway Protection or just bad prints. With Particular bad settings and with disabled TRP, one might actually turn the printer into a fire-hazard.</p>\n<p>Due to the problems <code>M500</code> (and <code>M301</code>) can cause, Prusaprinters does not allow to upload any g-code that contains this command, but the best protection against this command is to <strong>NEVER</strong> run G-code that you didn\'t compile yourself.</p>\n<h2>Blocking Malicious G-code</h2>\n<p>Some companies, fearing accidental <code>M500</code> or other setting-altering commands, have disabled EEPROM. This however makes maintenance much harder, but prevents altering critical settings at all - they are now fixed in the firmware and have to be altered by recompiling and uploading an altered firmware. If done properly and combined with proper physical access control to the ability to upload firmware (e.g. sealed maintenance panel) can pretty much prevent malicious G-code to have any effect.</p>\n'}]
['https://3dprinting.stackexchange.com/questions/18718', 'https://3dprinting.stackexchange.com', 'https://3dprinting.stackexchange.com/users/32635/']