NVbit : Accessing Bitlocker volumes from linux.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

321 lines
11KB

  1. /*
  2. nvbit Bitlocker for linux
  3. ------------------------------
  4. Nitin Kumar nitin at nvlabs.in
  5. Vipin Kumar vipin at nvlabs.in
  6. web: http://www.nvlabs.in
  7. Licensed under GPL Version 3
  8. -------------------
  9. Copyright (c) 2008
  10. Released under the GPL Version 3
  11. http://www.gnu.org/licenses/gpl-3.0.txt
  12. */
  13. // this header file contains all definition to header structure
  14. #include "common.h"
  15. #include "fve.h"
  16. #include "time.h"
  17. #include "aes/aes.h"
  18. #ifndef HEADER_H
  19. #define HEADER_H
  20. // this is the header of every data contained in FVE_METADATA
  21. /* here goes a brief tree for the structure
  22. MAIN_HEADER
  23. HEADER // this contains drive label
  24. KEY_CONTAINER // there can be a number of key conatiner
  25. HEADER after some random no of bytes another HEADER is present
  26. the above 2 headers are no in the key container, is there something special about them
  27. the KEY_CONTAINER itself itself consists of a number of HEADER
  28. KEY_CONTAINER HEADER
  29. HEADER // contains info such as External Key, DiskPassword etc
  30. HEADER // the VMK key most probably
  31. HEADER // another key MOST probably FVEK
  32. */
  33. // this header is starts at 0x40 always
  34. // VMK header is prepended by this header
  35. //Main header, it acts like a sub container for other information
  36. ///structure is a minimum of 0x30 or 48 bytes total
  37. # pragma pack (1) // 1 byte packing
  38. typedef struct _MAIN_HEADER {
  39. int32 Size; // it should be value defined in FVE_SIGNATURE in fve.h
  40. int32 Version; // it's 1 for now
  41. int32 Isize; // it is size of initial structure and is always 0x30 // does it reallly serve any purpose
  42. int32 Size1; //a copy of Size
  43. int8 Reserved1[16]; // it's probably used to store something hash or salt but unknown,
  44. int32 Reserved2; // it's the same as Version
  45. int32 Encryption_Type; /* it's should be one of these
  46. 0x8000 AES 128 + diffuser
  47. 0x8001 AES 256 + diffuser
  48. 0x8002 AES 128
  49. 0x8003 AES 256
  50. */
  51. FILETIME Time; // it is the time when this structure was started to fill up;
  52. // so we can analyse this to found time or when it was last updated and tell when was Bitlocker enabled
  53. // this is just an assumption
  54. } MAIN_HEADER;
  55. # pragma pack () // restore original packing
  56. // codes assigned by M$FT, to various algorithms
  57. #define AES128_diffuser 0x8000
  58. #define AES256_diffuser 0x8001
  59. #define AES128 0x8002
  60. #define AES256 0x8003
  61. /* KEY_CONTAINER stores the data after the header,
  62. after header there are 3 header, one contains name, the other 2 contain keys
  63. */
  64. # pragma pack (1) // 1 byte packing
  65. typedef struct _KEY_CONTAINER {
  66. int16 Size; // it should be value defined in FVE_SIGNATURE in fve.h
  67. // if size is zero means no more headers
  68. int16 unknown1;
  69. int16 Type; /* the following types have been identified for now
  70. 0x2 for label , label data starts after this header and is in unicode
  71. 0x3 for VMK structure , it is immediately followed by guid
  72. then follow 12 byte unknown
  73. then comes the name such as "DiskPassword"
  74. 0x5 for key
  75. 0x8 This means it has the VMK means this header contains sub header
  76. after headr follows the GUID then a number of bytes with unknown type
  77. // however first sub header header starts at offset 36
  78. */
  79. int16 Version;
  80. GUID Guid; // it's used to store GUID,
  81. FILETIME Time; // it is the time when this structure was started to fill up;
  82. // so we can analyse this to found time or when it was last updated and tell when was Bitlocker enabled
  83. // this is just an assumption
  84. int32 Reserved2; // it's the same as Version
  85. } KEY_CONTAINER;
  86. # pragma pack () // restore original packing
  87. // this header is always followed by data , data size = Size - ( sizeof(_HEADER))
  88. # pragma pack (1) // 1 byte packing
  89. typedef struct _HEADER {
  90. int16 Size; // it should be value defined in FVE_SIGNATURE in fve.h
  91. // if size is zero means no more headers
  92. int16 unknown1;
  93. int16 Type; /* the following types have been identified for now
  94. 0x2 for label , label data starts after this header and is in unicode
  95. 0x3 for VMK structure , it is immediately followed by guid
  96. then follow 12 byte unknown
  97. then comes the name such as "DiskPassword"
  98. 0x5 for key
  99. 0x8 This means it has the VMK means this header contains sub header
  100. after headr follows the GUID then a number of bytes with unknown type
  101. // however first sub header header starts at offset 36
  102. */
  103. int16 Version;
  104. } HEADER;
  105. # pragma pack () // restore original packing
  106. /* BEK_CONTAINER stores the data after the header,
  107. after header there are 2 header, one contains name, the other one contains key
  108. BEK conatiner is only found in BEK extension files which are stored mostly on External USB drives
  109. NOTE: - Sometimes BEK conatins only 1 header the KEY header
  110. */
  111. # pragma pack (1) // 1 byte packing
  112. typedef struct _BEK_CONTAINER {
  113. int16 Size; // it should be value defined in FVE_SIGNATURE in fve.h
  114. // if size is zero means no more headers
  115. int16 unknown1;
  116. int16 Type; /* the following types have been identified for now
  117. 0x2 for label , label data starts after this header and is in unicode
  118. 0x3 for VMK structure , it is immediately followed by guid
  119. then follow 12 byte unknown
  120. then comes the name such as "DiskPassword"
  121. 0x5 for key
  122. 0x8 This means it has the VMK means this header contains sub header
  123. after headr follows the GUID then a number of bytes with unknown type
  124. // however first sub header header starts at offset 36
  125. */
  126. int16 Version;
  127. GUID Guid; // it's used to store GUID,
  128. FILETIME Time; // it is the time when this structure was started to fill up;
  129. // so we can analyse this to found time or when it was last updated and tell when was Bitlocker enabled
  130. // this is just an assumption
  131. } BEK_CONTAINER;
  132. # pragma pack () // restore original packing
  133. /*
  134. The type field in header denotes one of these, any extra header that is required
  135. is present just after header
  136. HEADER + (optional extra header) + data
  137. */
  138. enum int16 {
  139. HEADER_KEY = 1, /* extra header KEY_TYPE
  140. KEY is present in uncrypted form after optional header */
  141. HEADER_LABEL = 2, /* a unicode string is present as data or label */
  142. HEADER_KEY_DISK = 3, /* header + time + int32 unknown +
  143. 44 byte encrypted HEADER_KEY/60 byte encrypted blob*/
  144. HEADER_KEY_EXTERNAL = 4,
  145. HEADER_KEY_FVEK = 5,
  146. HEADER_KEY_CONTAINER =8, /* header + GUID + time +int32 + 1 or more headers*/
  147. HEADER_BEK_CONTAINER =9 /* header + GUID + time +int32 + 1 or more headers*/
  148. };
  149. enum KEY_TYPE{
  150. KEY_SALT = 0x00001000,
  151. KEY_VMK_COMPOSITE = 0x00002000,
  152. KEY_VMK = 0x00002003,
  153. KEY_VMK_USB = 0x00002002, // this key can be used to decode appropriate VMK key
  154. /*
  155. also encryption method is also stored here probably
  156. */
  157. KEY_FVEK_0 = 0x00008000, /* size including header is 0x40 bytes*/
  158. KEY_FVEK_1 = 0x00008001, /* size including header is 0x40 bytes*/
  159. KEY_FVEK_2 = 0x00008002, /* size is 0x10 bytes */
  160. KEY_FVEK_3 = 0x00008003 /* size is 0x20 bytes */
  161. };
  162. # pragma pack (1) // 1 byte packing
  163. typedef struct _PROCESSED_FVE_META_DATA {
  164. MAIN_HEADER Main_Header;
  165. HEADER Header; // a maximum of 3 have been seen till tonight
  166. unsigned char Header_Copy[1024]; // this also includes header
  167. struct {
  168. KEY_CONTAINER Container;
  169. struct {
  170. HEADER Header; // a maximum of 3 have been seen till tonight
  171. unsigned char Header_Copy[1024]; // this also includes header
  172. }Header[5];
  173. long Header_Count;
  174. }Key[8]; // unknown maximum number but only a few can exist
  175. // below we have 2 unlinked keys inaccessible from normal go through, fill them in here
  176. unsigned char UNLINKED_Header_Copy[2][1024]; // this also includes header
  177. long Key_Count;
  178. } PROCESSED_FVE_META_DATA;
  179. # pragma pack () // restore original packing
  180. #define KEY_RECOVERY_PASSWORD 1
  181. #define KEY_STARTUP_PASSWORD 2
  182. typedef struct _options_structure {
  183. unsigned char filename[512]; // this will store either the name of file or drive letter in windows
  184. int8 file;
  185. unsigned char recovery_password[512]; // this will store recovery password
  186. int8 rp;
  187. unsigned char startup_key_filename[512]; // file name for key
  188. unsigned char startup_key[512];
  189. int8 sk;
  190. long using_container; // this contain index of container which was used to obtain VMK
  191. long using_key;
  192. unsigned char key[512]; // this is used to store key which decrypts VMK;
  193. int8 key_present;
  194. unsigned char VMK_key[512]; // this is used to store key which decryptes FVEK
  195. int8 VMK_key_present;
  196. unsigned char FVEK_key[512]; // this is used to store key which actually decrypts the volume
  197. int8 FVEK_key_present;
  198. unsigned char Tweak_Key[512]; // this is the sector key which can be obtained from FVEK if diffuser is enabled
  199. int8 Tweak_key_present;
  200. PROCESSED_FVE_META_DATA processed_fve_meta_data;
  201. FVE_META_DATA fve_meta_data;
  202. MORE_FVE_DATA more_fve_data;
  203. unsigned long Encryption_Type;
  204. // keys are expanded and kept ready for use
  205. struct {
  206. aes_context VMK_E_ctx; // vmk encryption ctx
  207. aes_context VMK_D_ctx; // decryption ctx
  208. aes_context FVEK_E_ctx; //FVEK enc ctx
  209. aes_context FVEK_D_ctx; //FVEK dec ctx
  210. aes_context TWEAK_E_ctx; // tweak key enc ctx
  211. aes_context TWEAK_D_ctx; // tweak key dec ctx
  212. }context;
  213. }options_structure;
  214. // this function does the command line argument processing and fill the structure above
  215. int process_options (int argc, char *argv[], options_structure *options);
  216. void init_keys(options_structure *options);
  217. typedef struct _decrypt_structure {
  218. aes_context FVEK_ctx;
  219. aes_context Sector_ctx;
  220. }decrypt_context;
  221. #endif