So vehicle manufacturers don’t like you… why? Because they know you want to modify your car in ways they never intended. They know you want to break your car and make them fix it under a warrantee claim. They know you want to Hack your car and make it do fun things. So they put in place a service that will deter you from accessing privileged functions on your vehicle.
What are these functions? Things like reflashing a controller. Not just anyone should be able to do this. Resetting the Odometer. Accessing control commands that would potentially stop a vehicle from functioning properly.
How do they stop you? Security Access a.k.a. Mode 0x27. This is the service that validates an application is authorized to do one or more of the privileged functions.
So how does it work? Well it varies a bit from OEM to OEM, but they all typically work the same. First you must be in a diagnostic mode (not all OEMs require this, but many do). So you have to use Service 0x10 – Start Diagnostics.
Start Diagnostics will typically take a Subfunction. This Subfuction tells the ECU which Level of Diagnostics it needs to go into. Some OEMs have two or three levels of Diagnostics: OBDII/Standard Diagnostics, Reflashing, and Enhanced Diagnostics. These subfunctions vary widely depending on the OEM so you’ll have to poke around to find out which your vehicle supports. Some good ones to try are 0x01, 0x02, 0x03, 0x80, 0x81, 0x82, 0x90). I’ve found these to be common. So an example is this: 0x7E0 02 10 82 00 00 00 00 00. If done correctly you will get back this: 0x7E8 02 50 82 00 00 00 00 00. If not you will likely get this 0x7E8 03 7F 10 12 00 00 00 00 00 meaning that the Subfunction is not supported, so you’ll need to try another. You might just want to increment through the entire range of 256 possible subfunction levels. Once you’ve found one that works, you can move on.
So Security Access is a Seed/Key authentication method. First you request a Seed from the ECU then you calculate the appropriate Key response then send it back to the ECU. Of course you likely don’t have the appropriate algorithm to successfully calculate the Key. So you may need to brute force it. (I’ve spoke about this in an early post, but I’m going to reiterate it here with some more general examples).
Brute forcing the key will take a while. How long? Well that depends on how wide the Key is (is it 2 bytes wide, 3 bytes, etc.). How do you know how wide it is? You have to make an educated guess. You do this by seeing how wide the Seed is. You know this by requesting the Seed from the controller (I’ll go into how to do this in a bit). So if the Seed is 2 bytes, likely the Key is too. If the Seed is 4 bytes or larger, the odds that you’ll be able to brute force it in any reasonable time is unlikely as manufactures add some simple steps to slow down the brute forcing method.
So how do you request a Seed? Send this 0x7E0 02 27 01 00 00 00 00 00 (do this within 3 seconds of the Start Diagnostics command). You should get back a Seed in the response: 0x7E8 04 67 01 XX XX 00 00 00 or 0x7E8 05 67 01 XX XX XX 00 00. Remember that the 0x04 indicates that the Seed will be two bytes wide (two bytes for the control information and two bytes for the seed) and 0x05 means the Seed will be three bytes wide. Also, you don’t have to send 0x01 as the subfunciton, but all Seed request have odd numbers (except 0xFF) as the subfunction. This is how you differentiate from a Seed Request from a Key (Key requests are even numbers and must be x+1 where the Seed request subfunction is x).
Now you have a Seed, that’s nice. But you have no way of calculating the Key so why even bother asking for one? Why not just send the Key? Because you can’t, you must ask for a Seed before you can send a Key. The system requires it.
Now you need to send the Key.. but wait not yet. Because there is one thing you need to determine first. Is the Seed static or dynamic? You want to know this because this will let you know if you are going to increment your key or not. If the Seed is static, then you’ll need to change the Key when you are brute forcing the system. If the Seed is dynamic, then you’ll want to keep the Key Static. So send another Seed Request. Did the Seed change? If so it’s a dynamic Seed. If not it’s static.
Now we need to send a Key. To do this we send 0x7E0 04 27 02 XX XX 00 00 00, where XX XX is the Key (remember 0x02 subfunction is x+1 of the Seed request). Likely we will get a negative response because the odds of us guessing the exact Key for the Seed we received is 1/(2^key width). So if key width = 65536 then we have a 1/65536 chance of getting it right. Now if we increment through all possible Keys then our odds of getting the response approach 100% quickly (see the birthday problem). But if the Seed is dynamic we don’t want to increment the Key. So this is a much different problem.
However those pesky engineers at the auto manufactures thought of this brute force method and took some steps to slow us down. How? By making it so that we after 3 or 4 attempts we get locked out. How do we know that we’ve reached this condition? They let us know by sending this: 0x7E8 03 7F 27 36 00 00 00 00. Which means “Exceeded Number of Attempts.” This means we have to someone reset the controller so we can try again. This can be achieved by either cycling the power. You can do this by finding the fuse for the controller and simply pulling it. Now this could be cumbersome so you may want to automate it using your favorite open source embedded controller. Or we may be able to reset it using the ECU Reset Service a.k.a. Mode 11.
ECU Reset is the funnest service ever… because it allows you to tell a controller to cycle its power. (Don’t try it while you are actually driving bad things may happen……). The problem with ECU Reset is there are so many different permutations of it, it’s hard to describe universally. So you’ll have to do some experimenting on how your vehicle has it implemented. But here is an example of how it may work: 0x7E0 02 11 01 00 00 00 00 00. Because you did a reset, you may not get a response from the controller at all if you did it correctly. However if it didn’t like the request, it will give you a negative response 0x7E8 03 7F 11 XX 00 00 00 00, where XX is the negative response code. You’ll have to parse the code know how to handle the exception. If the NRC is 0x12 just keep trying all subfunctions until one of them works.
Once you’ve reset the controller, send another Seed request. If you still get “Exceeded Number of Attempts” as a response. Then the reset didn’t work. Keep trying more subfunction of the reset command until you’ve exhausted them all. If still no luck, you’ll have to do a hard reset of the power to the ECU (pulling the fuse). Now try to send another Seed request. Likely if you do this quickly (within 10 or so seconds of the ECU powering up), you’ll get another negative response, 0x7E8 03 7F 27 37 00 00 00 00, “Required Time Delay Not Expired.” Meaning that you have to wait a few seconds longer. Keep trying until this error goes away. This is just another way that the manufacturer has made it difficult for you to brute force the system. Because of this delay, the brute force will take much longer. But if you’re motivated you’ll eventually get there.
How will you know you’ve got it? You’ll see this: 0x7E8 02 67 02 00 00 00 00 00. Then you can be sure. And if you missed that message you can always send another Seed request. If you get Seed of Zero that means that the ECU security is bypassed.
Don’t let the window close. If you want to keep the ECU “unlocked” then you’ll need to maintain this state. To do this simply keep sending a Seed request or better, send a Tester Present message: 0x7E0 02 3E XX 00 00 00 00 00, where XX is the subfunction (you’ll have to test this first to see what works) or 0x7E0 01 3E 00 00 00 00 00 00.
Good Luck and as always feel free to contact me if you have any questions.
With all of this information in the news, you can learn yourself. Just email me by clicking on the contact link above. Shoot me a request. We'll see if we can get some of us together. We have some curriculum ready to go.
Hope to hear from you soon.
Been a long time coming but finally someone else is out there making some news on Car hacking front.
Congrats to Chris Valasek and Charlie Miller for really trying to open the door to this world.
If you're in Amsterdam March 14th stop by Black Hat Europe and check out my 5+ hour Workshop:
Or if you are in San Jose April 23rd, stop by Design West and check out my one hour talk on Vehilce Network Denial of Service.
I will be doing a quick 1 hour presentation at this year’s HOPE (Hackers On Planet Earth) conference at the Hotel Pennsylvania in New York, NY July 13-15 (http://www.hopenumbernine.net). The title will be “Exploited from Detroit.” I plan to talk about how to get started in Reverse Engineering vehicle network data and give some particle examples of this data. Because its only one hour, it will be short and to the point. I will be fielding questions and if anyone wants to volunteer a vehicle we may even be able to find time to connect to a car and have a real world demonstration.
More details to come as they are released.
Just got the time and Date for
“Exploited from Detroit” "How to Communicate with Your Car’s Network"
Day/Time: Friday, July 13, 2012 - 2200
Location: Sassaman (18th floor)
Some services are boring.. like really, really, really, boring.. but others can make the car move gauges or make the car’s warning lights light up. Here is a bit more about these types of services.
Stop Normal Communications (GMLAN and Others):
This service is fun because you can make the Normal Communications (the ECU to ECU communications that occurs normally on the network) stop. Why would such a service exist, mostly to clear the bus for large amounts of data such as when a controller is going to be reflashed over the CAN Bus. On GMLAN this service is 0x28. It does not require any sub-function so an example of this might be: 0x7E0 01 28 00 00 00 00 00 00. This will command the engine controller to stop sending normal communications. Of course you don’t ever want to do this while the car is being driven, but it’s pretty fun to see what happens when you do it!
You will see the Engine Controllers Normal messages virtually disappear. I say virtually because not all messages will go away, some that are mission critical will stay, but a lot of them will not.
This service can also be useful if you want to simulate the messages the ECU would send without removing the power to the controller or cutting the CAN Bus itself.
This service requires that you continually send a Tester Present (0x3E) message periodically (2 seconds is good) in order to maintain this. If you want to return the communications send a Return to Normal message (0x20): 0x7E0 01 20 00 00 00 00 00 00. This will restore communications. Or simply stop sending the Tester Present message and it will automatically restore communications after 3 seconds. Oh what fun you’ll have.
Input/Output Control (ISO 14229 – UDS):
This is pretty much the coolest services ever made. I/O Control is exactly as it sounds, you can command Outputs on the Module to do your bidding. Of course software control will limit your bidding to a safe and secure bidding, but it’s still cool.
I/O Control (Service 0x2F) requires 3 parameters: a DID (Data ID), Control Record, and Control Mask. The DID is a two byte ID for the output (or input) you want to modify. Control Record is what you want the output to do (On/Off, Up/Down, etc.). Control Mask is a bitwise mask of one or more parameters that will be modified. An Example of a I/O Control is something like this: 0x7E0 06 2F 11 22 07 01 00 00 00. Where 0x1122 is the DID, 0x07 is the Control Record, and 0x0100 is the mask. This is not a real function, but you could potentially iterate through all possibilities and wait for the controller to give you a positive response. It would take a while, but it’d be interesting to see what happened…. Right!?
It’s likely that you will get a negative response from the controller 0x7E8 03 7F 2F 13 00 00 00 00, where 0x13 is the Negative Response Code (NRC).
Here are a few possible NRCs you may receive:
• 0x13 – Incorrect Message Length or Invalid Format.
• 0x22 – Condition Not Correct.
• 0x31 – Request Out of Range.
• 0x33 – Security Access Denied.
• 0x80-0xFF – OEM Specific.
Good luck……. .. have fun ..
Because diagnostics is really just a simple way to interact with an ECU, there are a few very common diagnostic services that you’ll find in nearly every permutation of diagnostics.
Definitely the most common service you’ll find, tester present (typically 0x3E) is used to let the controller(s) know that there is a.. wait for it.. Tester present. I know it was a bit obvious, but the idea is that some services keep the controller in an augmented state or a diagnostic state. When this happens there needs to be some way of maintaining that state while the tool that initiated the state is still connected to the diagnostic connector.
So Tester Present is designed to be a heart beet of the diagnostic tool and in the event that the device stops working or is disconnected from the network, the ECU whose state has been altered will stop seeing the tester present message and thus transition out of its altered state.
So if you want to maintain a diagnostic state you should send the tester present message. A typical timeout for Tester Present is 3 Seconds. So as long as you send the message between 1 and 2.5 seconds, you will be able to maintain the diagnostic state of a controller.
Read Data by PID:
Reading data from a controller is pretty much the reason for diagnostics in the first place. So there is no surprise that there are at least two ways to accomplish this task on nearly every new vehicle on the market today. Services 0x01 and 0x22 are used for this purpose.
Service 0x01 is the OBDII Read data by PID (Parameter ID) where the PID is a one byte number representing the data you want to read. Service 0x22 is the Enhanced diagnostic method for reading data. Service 0x22 is typically a two byte PID that represent the parameter you want to read. In some cases this two byte parameter may also be used in conjunction with another Enhanced diagnostic service to write the data as well (however exactly how this is done varies).
Controllers contain data that manufactures do not want just anyone having access to. This is typically to stop strange people such as yourself writing data to the controller to modify how it performs. So in nearly every controller there is a method to “unlock” the data. To perform this, it is done with service 0x27, the security access service.
In order to “unlock” the controller you must first ask it for a Seed. This seed will be used in conjunction with a proprietary algorithm to generate a Key. Then the key will be sent back to the controller. If the calculation that the controller did is the same as the key that you sent, then the controller will send a positive response indicating that the controller is now unlocked.
There may be several levels of Security Access. This is due because they may want certain features available to one group of people such as locksmiths who may need to add a new key to the vehicle while still keeping the other levels secure. So a typically Security Access transaction will have sub-functions that will essentially be the level that you wish to access, these sub-functions operation in Odd/Even Pairs. So sub-function 0x01 will be the seed request and 0x02 will be the key response. Then it’s 0x03/0x04, 0x05/0x06, … 0x21/0x22, etc.
That’s pretty much all that is very similar across all of the diagnostic protocols. Once you’ve learned these three services, you find that they very similar.