From 68f9f47288b672125ec25039c410fcecc1667482 Mon Sep 17 00:00:00 2001 From: Christian Zufferey Date: Sat, 19 Jan 2019 20:22:03 +0100 Subject: [PATCH] =?UTF-8?q?Ajout=C3=A9=20une=20page=20WEB=20pour=20affcihe?= =?UTF-8?q?r=20les=20r=C3=A9sultats=20du=20WIFI=20Sniffer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WIFI_sniffer/b.lua | 30 +++++++++++++--------- WIFI_sniffer/boot.lua | 5 ++-- WIFI_sniffer/oldies/wifi_ap_stop.lua | 10 ++++++++ WIFI_sniffer/web_html.lua | 32 +++++++++++++++++++++++ WIFI_sniffer/web_srv.lua | 38 ++++++++++++++++++++++++++++ WIFI_sniffer/wifi_ap_start.lua | 14 ++++++++++ wifi_ap_stop.lua | 10 ++++++++ 7 files changed, 125 insertions(+), 14 deletions(-) create mode 100644 WIFI_sniffer/oldies/wifi_ap_stop.lua create mode 100644 WIFI_sniffer/web_html.lua create mode 100644 WIFI_sniffer/web_srv.lua create mode 100644 WIFI_sniffer/wifi_ap_start.lua create mode 100644 wifi_ap_stop.lua diff --git a/WIFI_sniffer/b.lua b/WIFI_sniffer/b.lua index bea73e3..801a343 100644 --- a/WIFI_sniffer/b.lua +++ b/WIFI_sniffer/b.lua @@ -1,47 +1,53 @@ -- Scripts pour tester le sniffer de smartphone qui essaient de se connecter sur des AP WIFI -- source: https://nodemcu.readthedocs.io/en/dev/modules/wifi/#wifieventmonregister -print("\n b.lua zf190119.1804 \n") +print("\n b.lua zf190119.1920 \n") + +--f= "set_time.lua" if file.exists(f) then dofile(f) end -- apzuzu6 38:2c:4a:4e:d3:d8 zmac_adrs={} zmac_adrs["b8:d7:af:a6:bd:86"]={["zname"]="S7 zf"} zmac_adrs["cc:c0:79:7d:f5:d5"]={["zname"]="S7 Mélanie"} -zmac_adrs["5c:f9:38:a1:f7:f0"]={["zname"]="maczf"} +zmac_adrs["5c:f9:38:a1:f7:f0"]={["zname"]="MAC zf"} +zmac_adrs["d8:30:62:5a:d6:3a"]={["zname"]="IMAC Maman"} -function zdisp_table() +function zshow() for k, v in pairs(zmac_adrs) do - print(k,zmac_adrs[k]["zname"],zmac_adrs[k]["zrssi"]) + print(k,zmac_adrs[k]["zname"],zmac_adrs[k]["zrssi"],zmac_adrs[k]["ztime"]) end end - --[[ -zdisp_table() +zshow() ]] -function zsniff(T) --- print("\n\tAP - PROBE REQUEST RECEIVED".."\n\tMAC: ".. T.MAC.."\n\tRSSI: "..T.RSSI) - print("\n\tMAC: ".. T.MAC.."\n\tRSSI: "..T.RSSI) +function zround(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end +function zsniff(T) + print("\n\tMAC: ".. T.MAC.."\n\tRSSI: "..T.RSSI) + ztime() if zmac_adrs[T.MAC] == nil then print("Oh une inconnue !") zmac_adrs[T.MAC]={} end + zmac_adrs[T.MAC]["ztime"]=string.format("%04d/%02d/%02d %02d:%02d:%02d", tm["year"], tm["mon"], tm["day"], tm["hour"], tm["min"], tm["sec"]) if zmac_adrs[T.MAC]["zrssi"] == nil then zmac_adrs[T.MAC]["zrssi"]=T.RSSI else - zmac_adrs[T.MAC]["zrssi"]=(4*zmac_adrs[T.MAC]["zrssi"]+T.RSSI)/5 + zmac_adrs[T.MAC]["zrssi"]=zround((4*zmac_adrs[T.MAC]["zrssi"]+T.RSSI)/5, 0) end if zmac_adrs[T.MAC]["zname"] ~= nil then print("Bonjour "..zmac_adrs[T.MAC]["zname"].." !") end - end +wifi.eventmon.register(wifi.eventmon.AP_PROBEREQRECVED, zsniff) --[[ wifi.eventmon.unregister(wifi.eventmon.AP_PROBEREQRECVED) ]] -wifi.eventmon.register(wifi.eventmon.AP_PROBEREQRECVED, zsniff) diff --git a/WIFI_sniffer/boot.lua b/WIFI_sniffer/boot.lua index 06e037e..a83edb8 100644 --- a/WIFI_sniffer/boot.lua +++ b/WIFI_sniffer/boot.lua @@ -1,6 +1,6 @@ -- Scripts à charger après le boot pour démarrer son appli -print("\n boot.lua zf190119.1759 \n") +print("\n boot.lua zf190119.1933 \n") function heartbeat() f= "flash_led_xfois.lua" if file.exists(f) then dofile(f) end @@ -11,11 +11,12 @@ function heartbeat() end) end -f= "wifi_ap_stop.lua" if file.exists(f) then dofile(f) end +f= "wifi_ap_start.lua" if file.exists(f) then dofile(f) end f= "wifi_cli_conf.lua" if file.exists(f) then dofile(f) end f= "wifi_cli_start.lua" if file.exists(f) then dofile(f) end f= "telnet_srv2.lua" if file.exists(f) then dofile(f) end f= "web_ide2.lua" if file.exists(f) then dofile(f) end +f= "web_srv.lua" if file.exists(f) then dofile(f) end f= "set_time.lua" if file.exists(f) then dofile(f) end --f= "dsleep.lua" if file.exists(f) then dofile(f) end f= "b.lua" if file.exists(f) then dofile(f) end diff --git a/WIFI_sniffer/oldies/wifi_ap_stop.lua b/WIFI_sniffer/oldies/wifi_ap_stop.lua new file mode 100644 index 0000000..2738627 --- /dev/null +++ b/WIFI_sniffer/oldies/wifi_ap_stop.lua @@ -0,0 +1,10 @@ +-- Démarre le WIFI en mode AP +print("\n wifi_ap_stop.lua zf180824.2000 \n") + +local zmodewifi=wifi.getmode() +if zmodewifi == wifi.SOFTAP then + wifi.setmode(wifi.NULLMODE) +elseif zmodewifi == wifi.STATIONAP then + wifi.setmode(wifi.STATION) +end +print("WIFI AP arrêté") diff --git a/WIFI_sniffer/web_html.lua b/WIFI_sniffer/web_html.lua new file mode 100644 index 0000000..648ff29 --- /dev/null +++ b/WIFI_sniffer/web_html.lua @@ -0,0 +1,32 @@ +-- petit script pour le HTML du serveur web + +print("\n web_html.lua zf190119.2018 \n") + +--Partie HTML et CSS pour la page web +function html_home() + buf = "\n" + buf = buf .. "

Hello, this is NodeMCU WIFI Sniffer 2008

\n" + buf = buf .. string.format("%04d/%02d/%02d %02d:%02d:%02d", tm["year"], tm["mon"], tm["day"], tm["hour"], tm["min"], tm["sec"]) .. "

\n" + buf = buf .. "\n" + for k, v in pairs(zmac_adrs) do + buf = buf .. "\n" + buf = buf .. "\n" + buf = buf .. "\n" + buf = buf .. "\n" + buf = buf .. "\n" + end + buf = buf .. "
MACNameRSSITime
" .. k .. "" .. tostring(zmac_adrs[k]["zname"]) .. "" .. tostring(zmac_adrs[k]["zrssi"]) .. "" .. tostring(zmac_adrs[k]["ztime"]) .. "
\n" + buf = buf .. "" +end + +function html_status() + buf = "\n" + buf = buf .. "

Hello, this is NodeMCU. 1608

\n" + buf = buf .. "Toto\n" + if gpio.read(zLED) == 1 then + buf = buf .. "

Led is off

\n" + else + buf = buf .. "

Led is on

\n" + end + buf = buf .. "" +end diff --git a/WIFI_sniffer/web_srv.lua b/WIFI_sniffer/web_srv.lua new file mode 100644 index 0000000..16ad45e --- /dev/null +++ b/WIFI_sniffer/web_srv.lua @@ -0,0 +1,38 @@ +-- petit script de serveur WEB Wifi + +print("\n web_srv.lua zf190119.1932 \n") + +--dofile("web_get.lua") +dofile("web_html.lua") + +srv = net.createServer(net.TCP) +srv:listen(80, function(conn) + conn:on("receive", function(client, request) + _, _, method, path, vars = string.find(request, "([A-Z]+) (.+)?(.+) HTTP") + + --print("\n\nweb_srv") + --print("method: ",method) + --print("path: ",path) + --print("request: ",request) + --print("vars: ",vars) + + if not string.find(request, "/favicon.ico") then + --print("coucou") + if (method == nil) then + _, _, method, path = string.find(request, "([A-Z]+) (.+) HTTP") + end + _GET = {} + if (vars ~= nil) then + for k, v in string.gmatch(vars, "(%w+)=(%w+)&*") do + _GET[k] = v + print(k..": "..v) + end + end +-- web_get() + html_home() + client:send(buf) + buf=nil + end + end) + conn:on("sent", function(c) c:close() end) +end) diff --git a/WIFI_sniffer/wifi_ap_start.lua b/WIFI_sniffer/wifi_ap_start.lua new file mode 100644 index 0000000..60b5793 --- /dev/null +++ b/WIFI_sniffer/wifi_ap_start.lua @@ -0,0 +1,14 @@ +-- Démarre le WIFI en mode AP + +print("\n wifi_ap_start.lua zf181119.2359 \n") + +local zmodewifi=wifi.getmode() +if zmodewifi == wifi.NULLMODE then + print("WIFI mode AP only") + wifi.setmode(wifi.SOFTAP) +elseif zmodewifi == wifi.STATION then + print("WIFI mode AP+CLI") + wifi.setmode(wifi.STATIONAP) +end +wifi.ap.config({ ssid = "NodeMCU "..wifi.ap.getmac(), pwd = "12345678" }) +f= "wifi_info.lua" if file.exists(f) then dofile(f) end diff --git a/wifi_ap_stop.lua b/wifi_ap_stop.lua new file mode 100644 index 0000000..2738627 --- /dev/null +++ b/wifi_ap_stop.lua @@ -0,0 +1,10 @@ +-- Démarre le WIFI en mode AP +print("\n wifi_ap_stop.lua zf180824.2000 \n") + +local zmodewifi=wifi.getmode() +if zmodewifi == wifi.SOFTAP then + wifi.setmode(wifi.NULLMODE) +elseif zmodewifi == wifi.STATIONAP then + wifi.setmode(wifi.STATION) +end +print("WIFI AP arrêté")