diff --git a/_example/example.js b/_example/example.js index f049bbb3..7d1799df 100644 --- a/_example/example.js +++ b/_example/example.js @@ -4,15 +4,22 @@ require("telegram") var fakeESSID = random.String(16, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'); var fakeBSSID = random.Mac() +function graph(who, where) { + // generates a .dot file with the graph for this mac + run('graph.to_dot ' + who); + // uses graphviz to make a png of it + run('!dot -Tpng bettergraph.dot > ' + where); +} + function onDeauthentication(event) { var data = event.data; - run('graph.to_dot ' + data.address1); - run('!dot -Tpng bettergraph.dot > /tmp/graph_deauth.png') + graph(data.address1, '/tmp/graph_deauth.png'); var message = '🚨 Detected deauthentication frame:\n\n' + - 'Time: ' + event.time + "\n" + - 'GPS: lat=' + session.GPS.Latitude + " lon=" + session.GPS.Longitude + " updated_at=" + session.GPS.Updated.String() + "\n\n" + + // 'Time: ' + event.time + "\n" + + // 'GPS: lat=' + session.GPS.Latitude + " lon=" + session.GPS.Longitude + " updated_at=" + + //session.GPS.Updated.String() + "\n\n" + 'RSSI: ' + data.rssi + "\n" + 'Reason: ' + data.reason + "\n" + 'Address1: ' + data.address1 + "\n" + @@ -27,12 +34,12 @@ function onDeauthentication(event) { function onNewAP(event){ var ap = event.data; if(ap.hostname == fakeESSID) { - run('graph.to_dot ' + ap.mac); - run('!dot -Tpng bettergraph.dot > /tmp/graph_ap.png') + graph(ap.mac, '/tmp/graph_ap.png'); var message = '🚨 Detected possible rogue AP:\n\n' + - 'Time: ' + event.time + "\n" + - 'GPS: lat=' + session.GPS.Latitude + " lon=" + session.GPS.Longitude + " updated_at=" + session.GPS.Updated.String() + "\n\n" + + // 'Time: ' + event.time + "\n" + + // 'GPS: lat=' + session.GPS.Latitude + " lon=" + session.GPS.Longitude + " updated_at=" + + //session.GPS.Updated.String() + "\n\n" + 'AP: ' + ap.mac + ' (' + ap.vendor + ')'; // send to telegram bot @@ -45,8 +52,7 @@ function onHandshake(event){ var data = event.data; var what = 'handshake'; - run('graph.to_dot ' + data.station); - run('!dot -Tpng bettergraph.dot > /tmp/graph_handshake.png') + graph(data.station, '/tmp/graph_handshake.png'); if(data.pmkid != null) { what = "RSN PMKID"; @@ -57,8 +63,9 @@ function onHandshake(event){ } var message = '💰 Captured ' + what + ':\n\n' + - 'Time: ' + event.time + "\n" + - 'GPS: lat=' + session.GPS.Latitude + " lon=" + session.GPS.Longitude + " updated_at=" + session.GPS.Updated.String() + "\n\n" + + //'Time: ' + event.time + "\n" + + //'GPS: lat=' + session.GPS.Latitude + " lon=" + session.GPS.Longitude + " updated_at=" + + //session.GPS.Updated.String() + "\n\n" + 'Station: ' + data.station + "\n" + 'AP: ' + data.ap; diff --git a/_example/telegram.js b/_example/telegram.js index 44db1ce9..6838333b 100644 --- a/_example/telegram.js +++ b/_example/telegram.js @@ -13,6 +13,6 @@ function sendMessage(message) { function sendPhoto(path) { var url = 'https://api.telegram.org/bot' + telegramToken + '/sendPhoto'; - var cmd = 'curl -s -X POST "' + url + '" -F chat_id=' + telegramChatId + ' -F photo="@' + path + '"'; + var cmd = 'curl -s -X POST "' + url + '" -F chat_id=' + telegramChatId + ' -F photo="@' + path + '" > /dev/null'; run("!"+cmd); } \ No newline at end of file diff --git a/modules/graph/dot.go b/modules/graph/dot.go index e80c8ddb..83c29e0b 100644 --- a/modules/graph/dot.go +++ b/modules/graph/dot.go @@ -7,6 +7,9 @@ import ( ) func (mod *Module) generateDotGraph(bssid string) error { + mod.wLock.Lock() + defer mod.wLock.Unlock() + start := time.Now() if err := mod.updateSettings(); err != nil { return err diff --git a/modules/graph/json.go b/modules/graph/json.go index f9562941..82521a0a 100644 --- a/modules/graph/json.go +++ b/modules/graph/json.go @@ -7,6 +7,9 @@ import ( ) func (mod *Module) generateJSONGraph(bssid string) error { + mod.wLock.Lock() + defer mod.wLock.Unlock() + start := time.Now() if err := mod.updateSettings(); err != nil { return err diff --git a/modules/graph/module.go b/modules/graph/module.go index 117e9dd0..14c49acd 100644 --- a/modules/graph/module.go +++ b/modules/graph/module.go @@ -10,6 +10,7 @@ import ( "os" "path/filepath" "regexp" + "sync" "time" ) @@ -46,6 +47,7 @@ type Module struct { gw *Node iface *Node eventBus session.EventBus + wLock sync.Mutex } func NewModule(s *session.Session) *Module {