misc: small fix or general refactoring i did not bother commenting

This commit is contained in:
Simone Margaritelli 2021-04-08 22:38:28 +02:00
commit d5fb7b6754
5 changed files with 28 additions and 13 deletions

View file

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

View file

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

View file

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

View file

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

View file

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