Ajouté une page WEB pour affciher les résultats du WIFI Sniffer

This commit is contained in:
Christian Zufferey
2019-01-19 20:22:03 +01:00
parent 0ec0af8f07
commit 68f9f47288
7 changed files with 125 additions and 14 deletions

View File

@@ -1,47 +1,53 @@
-- Scripts pour tester le sniffer de smartphone qui essaient de se connecter sur des AP WIFI -- 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 -- 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 -- apzuzu6 38:2c:4a:4e:d3:d8
zmac_adrs={} zmac_adrs={}
zmac_adrs["b8:d7:af:a6:bd:86"]={["zname"]="S7 zf"} 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["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 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
end end
--[[ --[[
zdisp_table() zshow()
]] ]]
function zsniff(T) function zround(num, dec)
-- print("\n\tAP - PROBE REQUEST RECEIVED".."\n\tMAC: ".. T.MAC.."\n\tRSSI: "..T.RSSI) local mult = 10^(dec or 0)
print("\n\tMAC: ".. T.MAC.."\n\tRSSI: "..T.RSSI) 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 if zmac_adrs[T.MAC] == nil then
print("Oh une inconnue !") print("Oh une inconnue !")
zmac_adrs[T.MAC]={} zmac_adrs[T.MAC]={}
end 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 if zmac_adrs[T.MAC]["zrssi"] == nil then
zmac_adrs[T.MAC]["zrssi"]=T.RSSI zmac_adrs[T.MAC]["zrssi"]=T.RSSI
else 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 end
if zmac_adrs[T.MAC]["zname"] ~= nil then if zmac_adrs[T.MAC]["zname"] ~= nil then
print("Bonjour "..zmac_adrs[T.MAC]["zname"].." !") print("Bonjour "..zmac_adrs[T.MAC]["zname"].." !")
end end
end end
wifi.eventmon.register(wifi.eventmon.AP_PROBEREQRECVED, zsniff)
--[[ --[[
wifi.eventmon.unregister(wifi.eventmon.AP_PROBEREQRECVED) wifi.eventmon.unregister(wifi.eventmon.AP_PROBEREQRECVED)
]] ]]
wifi.eventmon.register(wifi.eventmon.AP_PROBEREQRECVED, zsniff)

View File

@@ -1,6 +1,6 @@
-- Scripts à charger après le boot pour démarrer son appli -- 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() function heartbeat()
f= "flash_led_xfois.lua" if file.exists(f) then dofile(f) end f= "flash_led_xfois.lua" if file.exists(f) then dofile(f) end
@@ -11,11 +11,12 @@ function heartbeat()
end) end)
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_conf.lua" if file.exists(f) then dofile(f) end
f= "wifi_cli_start.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= "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_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= "set_time.lua" if file.exists(f) then dofile(f) end
--f= "dsleep.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 f= "b.lua" if file.exists(f) then dofile(f) end

View File

@@ -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é")

32
WIFI_sniffer/web_html.lua Normal file
View File

@@ -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 = "<!DOCTYPE html><html><body><meta charset='utf-8' name='viewport' content='width=device-width, initial-scale=1.0'>\n"
buf = buf .. "<h1>Hello, this is NodeMCU WIFI Sniffer 2008 </h1>\n"
buf = buf .. string.format("%04d/%02d/%02d %02d:%02d:%02d", tm["year"], tm["mon"], tm["day"], tm["hour"], tm["min"], tm["sec"]) .. "<br><br>\n"
buf = buf .. "<table border='1'><tr><th>MAC</th><th>Name</th><th>RSSI</th><th>Time</th></tr>\n"
for k, v in pairs(zmac_adrs) do
buf = buf .. "<tr><td>" .. k .. "</td>\n"
buf = buf .. "<td>" .. tostring(zmac_adrs[k]["zname"]) .. "</td>\n"
buf = buf .. "<td>" .. tostring(zmac_adrs[k]["zrssi"]) .. "</td>\n"
buf = buf .. "<td>" .. tostring(zmac_adrs[k]["ztime"]) .. "</td>\n"
buf = buf .. "</tr>\n"
end
buf = buf .. "</table>\n"
buf = buf .. "</body></html>"
end
function html_status()
buf = "<!DOCTYPE html><html><body><meta charset='utf-8' name='viewport' content='width=device-width, initial-scale=1.0'>\n"
buf = buf .. "<h1>Hello, this is NodeMCU. 1608 </h1>\n"
buf = buf .. "Toto\n"
if gpio.read(zLED) == 1 then
buf = buf .. "<p>Led is off</p>\n"
else
buf = buf .. "<p>Led is on</p>\n"
end
buf = buf .. "</body></html>"
end

38
WIFI_sniffer/web_srv.lua Normal file
View File

@@ -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)

View File

@@ -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

10
wifi_ap_stop.lua Normal file
View File

@@ -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é")