{"id":5968,"date":"2023-04-20T20:51:25","date_gmt":"2023-04-20T12:51:25","guid":{"rendered":"https:\/\/blog.hoyo.idv.tw\/?p=5968"},"modified":"2023-04-20T20:51:47","modified_gmt":"2023-04-20T12:51:47","slug":"esp8266-%e4%bd%bf%e7%94%a8-wifi-%e5%9f%ba%e5%9c%b0%e5%8f%b0%e6%89%93%e5%bb%a3%e5%91%8a","status":"publish","type":"post","link":"https:\/\/blog.hoyo.idv.tw\/?p=5968","title":{"rendered":"ESP8266 - \u4f7f\u7528 WiFi \u57fa\u5730\u53f0\u6253\u5ee3\u544a"},"content":{"rendered":"<p>--<\/p>\n<h2>\u53c3\u8003\u8cc7\u6e90<\/h2>\n<ul>\n<li><a id=\"ccfba02a74968afa813753685413e181-863e1e567ef81c621542a83bb0f7574db67301a4\" class=\"js-navigation-open\" title=\"FakeBeaconESP8266.ino\" href=\"https:\/\/github.com\/markszabo\/FakeBeaconESP8266\/blob\/master\/FakeBeaconESP8266\/FakeBeaconESP8266.ino\" target=\"_blank\" rel=\"noopener\">FakeBeaconESP8266.ino<\/a><\/li>\n<\/ul>\n<p>\u9019\u662f ESP8266 \u4e00\u500b\u5f88\u6709\u8da3\u7684\u61c9\u7528<\/p>\n<p>--<\/p>\n<h2>Arduino<\/h2>\n<pre class=\"lang:default decode:true\">#include &lt;ESP8266WiFi.h&gt; \/\/more about beacon frames https:\/\/mrncciew.com\/2014\/10\/08\/802-11-mgmt-beacon-frame\/\r\n\r\nextern \"C\" {\r\n#include \"user_interface.h\"\r\n}\r\n\r\nvoid setup() {\r\n    delay(500);\r\n    wifi_set_opmode(STATION_MODE);\r\n    wifi_promiscuous_enable(1);\r\n}\r\n\r\nvoid loop() {\r\n    \/\/sendBeacon(\"test\"); \/\/sends beacon frames with the SSID 'test'\r\n    \/\/sendRandomBeacon(10); \/\/sends beacon frames with 10 character long random SSID\r\n    \/\/sendFuzzedBeacon(\"test\",10); \/\/sends beacon frames with 10 different SSID all starting with 'test' and ending with whitespaces (spaces and\/or tabs)\r\n    RickRoll();\r\n}\r\n\r\nvoid sendFuzzedBeacon(char* baseSsid, int nr) {\r\n    int baseLen = strlen(baseSsid);\r\n    int i = 0;\r\n    for (int j = 0; j &lt; 32 - baseLen; j++) { \/\/32 is the maximum length of the SSID\r\n        for (int k = 0; k &lt; pow(2, j); k++) {\r\n            int kk = k;\r\n            String ssid = baseSsid;\r\n            for (int l = 0; l &lt; j; l++) {\r\n                if (kk % 2 == 1) ssid += \" \"; \/\/add a space\r\n                else ssid += \"\\t\"; \/\/add a tab\r\n                kk \/= 2;\r\n            }\r\n            char charBufSsid[33];\r\n            ssid.toCharArray(charBufSsid, 33);\r\n            sendBeacon(charBufSsid);\r\n            if (++i &gt;= nr) return;\r\n        }\r\n    }\r\n}\r\n\r\nvoid sendRandomBeacon(int len) {\r\n    char ssid[len + 1];\r\n    randomString(len, ssid);\r\n    sendBeacon(ssid);\r\n}\r\n\r\nvoid randomString(int len, char* ssid) {\r\n    String alfa = \"1234567890qwertyuiopasdfghjkklzxcvbnm QWERTYUIOPASDFGHJKLZXCVBNM_\";\r\n    for (int i = 0; i &lt; len; i++) {\r\n        ssid[i] = alfa[random(65)];\r\n    }\r\n}\r\n\r\nvoid sendBeacon(char* ssid) {\r\n    \/\/ Randomize channel \/\/\r\n    byte channel = random(1, 12);\r\n    wifi_set_channel(channel);\r\n\r\n    uint8_t packet[128] = { 0x80, 0x00, \/\/Frame Control\r\n                            0x00, 0x00, \/\/Duration\r\n                            \/*4*\/   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \/\/Destination address\r\n                            \/*10*\/  0x01, 0x02, 0x03, 0x04, 0x05, 0x06, \/\/Source address - overwritten later\r\n                            \/*16*\/  0x01, 0x02, 0x03, 0x04, 0x05, 0x06, \/\/BSSID - overwritten to the same as the source address\r\n                            \/*22*\/  0xc0, 0x6c, \/\/Seq-ctl\r\n                            \/\/Frame body starts here\r\n                            \/*24*\/  0x83, 0x51, 0xf7, 0x8f, 0x0f, 0x00, 0x00, 0x00, \/\/timestamp - the number of microseconds the AP has been active\r\n                            \/*32*\/  0xFF, 0x00, \/\/Beacon interval\r\n                            \/*34*\/  0x01, 0x04, \/\/Capability info\r\n                            \/* SSID *\/\r\n                            \/*36*\/  0x00\r\n                          };\r\n\r\n    int ssidLen = strlen(ssid);\r\n    packet[37] = ssidLen;\r\n\r\n    for (int i = 0; i &lt; ssidLen; i++) {\r\n        packet[38 + i] = ssid[i];\r\n    }\r\n\r\n    uint8_t postSSID[13] = {0x01, 0x08, 0x82, 0x84, 0x8b, 0x96, 0x24, 0x30, 0x48, 0x6c, \/\/supported rate\r\n                            0x03, 0x01, 0x04 \/*DSSS (Current Channel)*\/\r\n                           };\r\n\r\n    for (int i = 0; i &lt; 12; i++) {\r\n        packet[38 + ssidLen + i] = postSSID[i];\r\n    }\r\n\r\n    packet[50 + ssidLen] = channel;\r\n\r\n    \/\/ Randomize SRC MAC\r\n    packet[10] = packet[16] = random(256);\r\n    packet[11] = packet[17] = random(256);\r\n    packet[12] = packet[18] = random(256);\r\n    packet[13] = packet[19] = random(256);\r\n    packet[14] = packet[20] = random(256);\r\n    packet[15] = packet[21] = random(256);\r\n\r\n    int packetSize = 51 + ssidLen;\r\n\r\n    wifi_send_pkt_freedom(packet, packetSize, 0);\r\n    wifi_send_pkt_freedom(packet, packetSize, 0);\r\n    wifi_send_pkt_freedom(packet, packetSize, 0);\r\n    delay(1);\r\n}\r\n\r\nvoid RickRoll() {\r\n    sendBeacon(\"01 \u5c11\u6797\u529f\u592b\u597d\u8036\");\r\n    sendBeacon(\"02 \u5c11\u6797\u529f\u592b\u771f\u662f\u597d\");\r\n    sendBeacon(\"03 \u5c11\u6797\u529f\u592b\u9802\u5471\u5471\");\r\n    sendBeacon(\"04 \u6211\u6c92\u6709\u9435\u982d\u529f\");\r\n    sendBeacon(\"05 \u4f60\u624d\u6709\u9435\u982d\u529f\");\r\n    sendBeacon(\"06 \u5c31\u9019\u6a23\");\r\n    sendBeacon(\"07 \u6e4a\u5b57\u6578\");\r\n    sendBeacon(\"08 end\");\r\n}<\/pre>\n<p>--<\/p>\n<h2>\u6210\u679c<\/h2>\n<p><a href=\"https:\/\/blog.hoyo.idv.tw\/wp-content\/uploads\/2023\/04\/Screenshot_20191019-111133.png\" data-rel=\"lightbox-image-0\" data-rl_title=\"\" data-rl_caption=\"\" title=\"\"><img loading=\"lazy\" class=\"alignnone wp-image-12116 size-medium\" src=\"https:\/\/blog.hoyo.idv.tw\/wp-content\/uploads\/2023\/04\/Screenshot_20191019-111133-169x300.png\" alt=\"\" width=\"169\" height=\"300\" srcset=\"https:\/\/blog.hoyo.idv.tw\/wp-content\/uploads\/2023\/04\/Screenshot_20191019-111133-169x300.png 169w, https:\/\/blog.hoyo.idv.tw\/wp-content\/uploads\/2023\/04\/Screenshot_20191019-111133-576x1024.png 576w, https:\/\/blog.hoyo.idv.tw\/wp-content\/uploads\/2023\/04\/Screenshot_20191019-111133-768x1365.png 768w, https:\/\/blog.hoyo.idv.tw\/wp-content\/uploads\/2023\/04\/Screenshot_20191019-111133-864x1536.png 864w, https:\/\/blog.hoyo.idv.tw\/wp-content\/uploads\/2023\/04\/Screenshot_20191019-111133-1024x1820.png 1024w, https:\/\/blog.hoyo.idv.tw\/wp-content\/uploads\/2023\/04\/Screenshot_20191019-111133.png 1080w\" sizes=\"(max-width: 169px) 100vw, 169px\" \/><\/a><\/p>\n<p>--<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p class=\"pvc_stats all \" data-element-id=\"5968\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> &nbsp;1,057&nbsp;total views, &nbsp;2&nbsp;views today<\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"excerpt":{"rendered":"<p>-- \u53c3\u8003\u8cc7\u6e90 FakeBea...<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p class=\"pvc_stats all \" data-element-id=\"5968\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> &nbsp;1,057&nbsp;total views, &nbsp;2&nbsp;views today<\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[273],"tags":[275,331],"_links":{"self":[{"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/posts\/5968"}],"collection":[{"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5968"}],"version-history":[{"count":4,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/posts\/5968\/revisions"}],"predecessor-version":[{"id":12117,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/posts\/5968\/revisions\/12117"}],"wp:attachment":[{"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5968"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5968"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5968"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}