如何制作用于27服务的dll

汽车安全 2年前 (2022) admin
598 0 0



1、简介

首先对于已有的安全算法来说,如果选择一种载体那必须的是需要能够动态修改且被调用的库文件,否则对于无序的安全种子来说,没有太多的手段去解决算法;同时它能够被代码调用、被Vector相关软件调用、Python调用等。而车辆在研发过程中,由于其体量的庞大,无法单独的一个部门或者公司能够完成,需要多方的合作,因此dll被选择使用作为安全算法的载体。

对于当前我们常见的诊断协议来说,27H服务被用于修改设备的安全等级,通过执行27H服务来解锁更高级别的服务。例如:2EH服务,修改车辆配置;2FH服务,控制硬件IO接口;31服务,控制车辆软件代码逻辑。

通常,Tester作为请求方请求ECU发送种子,然后Tester在接收到种子(seed)后,通过相应的算法去计算种子对应的密钥(key),并将密钥(key)发送给ECU,ECU同样计算出一个密钥跟接收到Tester的密钥进行对比,一致的话即可解锁更高级别的服务。

在利用CANOE 进行测试时,需要用到dll库用于生成27服务需要的Key。因此本文主要介绍如何识别Vector 默认的dll接口,并根据自己需要生成dll

2、找到CANOE提供的Demo工程

安装CANOD时,会提供生成符合CANOE接口的Demo工程,路径如下
如何制作用于27服务的dll

3、打开VS工程,修改代码

示例代码如下

//
///Example for a SeedKey.Dll used in CANoe.DiVa
///See also CANoe.DiVa help==>Proceedings/Entry masks/"General" entry mask
//


#include <windows.h>
#include "GenerateKeyEx.h"


// KeyGeneration.cpp : Defines the entry point for the DLL application.
BOOL APIENTRY DllMain( HANDLE hModule, 
                       DWORD  ul_reason_for_call, 
                       LPVOID lpReserved
      )
{
    return TRUE;
}



const unsigned char APP_MASK[4] = { 0xD6, 0xD7, 0x98, 0xFA };


KEYGENALGO_API VKeyGenResultEx GenerateKeyEx(
  const unsigned char* ipSeedArray,          /* Array for the seed [in] */
  unsigned int iSeedArraySize,               /* Length of the array for the seed [in] */
  const unsigned int iSecurityLevel,         /* Security level [in] */
  const char* ipVariant,                     /* Name of the active variant [in] */  
  unsigned char* iopKeyArray,                /* Array for the key [in, out] */
  unsigned int iMaxKeyArraySize,             /* Maximum length of the array for the key [in] */
  unsigned int& oActualKeyArraySize)         /* Length of the key [out] */
{
  //Copy seed from parameter to a integer 
  //Note: The byte order in the seed array is equal to the byte order in the bus message

  //begin calculate key from seed------------------------------------------------------------
  //for security access with Services 0x27 01 ->0x27 02
  unsigned char tmpKey[4];

  for (int i = 0; i<4; i++)
  {
   tmpKey[i] = ipSeedArray[i] ^ APP_MASK[i];
  }
  
  //end calculate key from seed------------------------------------------------------------

  //Copy key to the output buffer 
  //Note: The first byte of the key array will be the first key byte of the bus message
  iopKeyArray[0] = ((tmpKey[0] & 0x0F) << 4) | (tmpKey[1] & 0xF0);
  iopKeyArray[1] = ((tmpKey[1] & 0x0F) << 4) | ((tmpKey[2] & 0xF0) >> 4);
  iopKeyArray[2] = (tmpKey[2] & 0xF0) | ((tmpKey[3] & 0xF0) >> 4);
  iopKeyArray[3] = ((tmpKey[3] & 0x0F) << 4) | (tmpKey[0] & 0xF0);
  //setting length of key
  oActualKeyArraySize = 4;     
  return KGRE_Ok;
}
1

版权声明:本文为CSDN博主「Archieeeeee」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。

– END –


原文始发于微信公众号(车端):如何制作用于27服务的dll

版权声明:admin 发表于 2022年10月18日 上午8:01。
转载请注明:如何制作用于27服务的dll | CTF导航

相关文章

暂无评论

您必须登录才能参与评论!
立即登录
暂无评论...