Pages: [1] 2 3
Author Topic: KWP2000 Security Access  (Read 12764 times)
adam-
Hero Member
*****

Karma: +123/-33
Offline Offline

Posts: 2179


« on: January 27, 2023, 04:19:02 AM »

Hello,

I'm trying to figure out how to gain security access on an ME7.1.1 (MK4 VR6).  I can use ReadMemoryByAddress without security access on ME7.5. 

In an ME7Logger trace I can see that it tries to start a diagnostic session but gets an invalid response (7F).  It then re-tries with security access (0x27 0x01), calculates the key and re-transmits.  It gets a positive response and then connects with a diagnostic session again.

My question is: how can I gain security access for ReadMemoryByAddress, either with 0x01 or 0x03?  I thought that 0x03 was for read only access (which is what I need).

What is the calc for the key?
Logged
prj
Hero Member
*****

Karma: +1072/-480
Offline Offline

Posts: 6035


« Reply #1 on: January 27, 2023, 04:37:26 AM »

A lot of stuff on VAG was key = seed + constant.
If it's not, then you're gonna have to reverse the $27 service handler and find out what the algo is.
The explanation of the service table and how to find it can be found in my KWP2000 logging repo.

Different security access is for different services and sessions, I have no clue where you got that 0x03 is some "read only access", that's BS.

Also, for me development session on Mk4 VR6 worked without any security access.
When you connect to the ECU you are already in a diagnostic session. The default session.
You're gonna have to be a ton more specific.

At some point in time you are going to have to start to use your brain, and not throw your hands up in the air, and lose your head the moment CTRL+C, CTRL+V stops working Wink
« Last Edit: January 27, 2023, 04:40:54 AM by prj » Logged

PM's will not be answered, so don't even try.
Log your car properly - WinOLS database - Tools/patches
adam-
Hero Member
*****

Karma: +123/-33
Offline Offline

Posts: 2179


« Reply #2 on: January 27, 2023, 05:29:32 AM »

I'll go through your repo.

There was a thread (http://nefariousmotorsports.com/forum/index.php?topic=4983.0) that detailed security 01 & 03.  I'll dig out the protocol sheet that details it but I may be wrong.

I'll post up the trace from the scope when I get home but that ECU definitely issued a negative response when trying to diag session and then ME7Logger attempts with security login, after which it's successful the diagnostic session is successful.

I'm trying to work out if it's seed + constant or if it's something else.
Logged
prj
Hero Member
*****

Karma: +1072/-480
Offline Offline

Posts: 6035


« Reply #3 on: January 27, 2023, 05:35:42 AM »

It's for MED9. You have ME7.
Logged

PM's will not be answered, so don't even try.
Log your car properly - WinOLS database - Tools/patches
adam-
Hero Member
*****

Karma: +123/-33
Offline Offline

Posts: 2179


« Reply #4 on: January 27, 2023, 05:40:18 AM »

So how do you know what specifics the ECU wants?  The application says that the second bit is manufacture specific.  On the assumption it's 0x27 0x01, what calculation is then done to the seed to get the correct key?  In that instance, what is the difference between 01 and 03?  I get one is MED9 and ME7 but I'd have thought there would have been similarities.

I can likely help myself here by taking the handful of traces and calculating the difference.
Logged
prj
Hero Member
*****

Karma: +1072/-480
Offline Offline

Posts: 6035


« Reply #5 on: January 27, 2023, 05:43:19 AM »

So how do you know what specifics the ECU wants?
3 options:
1. OEM documentation
2. Reversing the comms stack
3. Trial and error.
Logged

PM's will not be answered, so don't even try.
Log your car properly - WinOLS database - Tools/patches
adam-
Hero Member
*****

Karma: +123/-33
Offline Offline

Posts: 2179


« Reply #6 on: January 27, 2023, 05:53:24 AM »

My lack of brains means it's option 3.

Thanks as always.
Logged
prj
Hero Member
*****

Karma: +1072/-480
Offline Offline

Posts: 6035


« Reply #7 on: January 27, 2023, 06:38:00 AM »

I never did flashing or looked into it, so I have no idea if ME7 also has SA2 or not.
Could well be, then just grab an SA2 implementation (for example bri3d has one in his repo) and then use that.
There was also one in C posted.
Then grab the algo from an sgo.

Usually ECU's don't need SA2 to read memory though, at least the later ones.
Logged

PM's will not be answered, so don't even try.
Log your car properly - WinOLS database - Tools/patches
adam-
Hero Member
*****

Karma: +123/-33
Offline Offline

Posts: 2179


« Reply #8 on: February 03, 2023, 04:57:16 AM »

Got Security Access to work fine, but getting a service not supported when attempting to ReadByMemoryAddress.  Looks like ME7Logger tries too, which fails.

Is there a way to enable the service?
Logged
prj
Hero Member
*****

Karma: +1072/-480
Offline Offline

Posts: 6035


« Reply #9 on: February 03, 2023, 06:50:25 AM »

Switch to the correct session. In which session are you trying it?

Security access was 03 with key 0x11223344?

Workaround for RMBA is DDLI ($2C), you can define up to 10 identifiers.
If you need to read more, you can clear, define, read. 3x slower if the identifiers can only hold 1 location.
« Last Edit: February 03, 2023, 06:54:02 AM by prj » Logged

PM's will not be answered, so don't even try.
Log your car properly - WinOLS database - Tools/patches
adam-
Hero Member
*****

Karma: +123/-33
Offline Offline

Posts: 2179


« Reply #10 on: February 03, 2023, 07:17:57 AM »

Diagnostic session: 0x86.  So init, get SA, get timing, diag session, RMBA.

Next daft question, how do you know what the identifier is?  I mean, how can you convert a variable to an identifier? 
Logged
prj
Hero Member
*****

Karma: +1072/-480
Offline Offline

Posts: 6035


« Reply #11 on: February 03, 2023, 11:26:07 AM »

The dynamically definable identifiers are from F0 to F9 on Bosch KWP2000 ECU's.
For DDLI syntax look at KWP2000 service layer standard.

You did not answer which SA you used btw.
Also you have never posted the file either. Use my repo to see where the service lookup table is and see if the ECU even has $23.

You're asking for help but it's like using a crowbar to pry information from you.
Every single question I ask is relevant. You answer only some, not all and you do not provide the basic info.
So I'm about to give up here.
« Last Edit: February 03, 2023, 11:28:39 AM by prj » Logged

PM's will not be answered, so don't even try.
Log your car properly - WinOLS database - Tools/patches
adam-
Hero Member
*****

Karma: +123/-33
Offline Offline

Posts: 2179


« Reply #12 on: February 03, 2023, 11:37:54 AM »

Using a BG 0004 for reference. 
Logged
adam-
Hero Member
*****

Karma: +123/-33
Offline Offline

Posts: 2179


« Reply #13 on: February 03, 2023, 11:45:02 AM »

I'm using SA Level 1.  I get a positive response when bitshifting:
  for (byte i = 0; i < 5; i++) {
    if ((seed & 0x80000000) == 0x80000000) {                 // can’t check the bit overflow / carry bit directly, but if the MSB is high then we can infer the next shift will set the carry bit
      seed = (seedData[63] ^ ((seed << 1) | (seed >> 31)));  // since C doesn’t have a rotate as such, OR the << and >> to make a rotate
    } else {
      seed = ((seed << 1) | (seed >> 31));
    }
  }

Where seedData[63] = 0x5FBD5DBD.  I'm struggling to get the ECU ID to calculate to this however.

I slow init, get a response, request security access (0x27 0x01), get the seed, calculate using the above and re-submit.  I then get a positive response and gain SA.

I then start a diagnostic session with:
    txBuf[0] = 0x03;  //Message Length
    txBuf[1] = 0x10;  //StartDiagnosticSession
    txBuf[2] = 0x86;  //Development Session
    txBuf[3] = 0x14;  // 10400 baud

Which is successful.  Attempting to RBMA fails (0x23...), as does write.  Hope that makes sense.

Logged
prj
Hero Member
*****

Karma: +1072/-480
Offline Offline

Posts: 6035


« Reply #14 on: February 03, 2023, 11:56:12 AM »

This is SA2 algo you are doing. Usually this is for flashing.

Have you tried requesting 03? Does it send you a seed?
Logged

PM's will not be answered, so don't even try.
Log your car properly - WinOLS database - Tools/patches
Pages: [1] 2 3
  Print  
 
Jump to:  

Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Page created in 0.02 seconds with 17 queries. (Pretty URLs adds 0s, 0q)