mirror of
https://github.com/bettercap/bettercap
synced 2025-07-08 05:51:37 -07:00
new: exposing the graph object to js
This commit is contained in:
parent
0042b77c36
commit
93b7e7f2ed
8 changed files with 48 additions and 13 deletions
|
@ -4,7 +4,7 @@ require("telegram")
|
||||||
var fakeESSID = random.String(16, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ');
|
var fakeESSID = random.String(16, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ');
|
||||||
var fakeBSSID = random.Mac()
|
var fakeBSSID = random.Mac()
|
||||||
|
|
||||||
function graph(who, where) {
|
function createGraph(who, where) {
|
||||||
// generates a .dot file with the graph for this mac
|
// generates a .dot file with the graph for this mac
|
||||||
run('graph.to_dot ' + who);
|
run('graph.to_dot ' + who);
|
||||||
// uses graphviz to make a png of it
|
// uses graphviz to make a png of it
|
||||||
|
@ -14,7 +14,7 @@ function graph(who, where) {
|
||||||
function onDeauthentication(event) {
|
function onDeauthentication(event) {
|
||||||
var data = event.data;
|
var data = event.data;
|
||||||
|
|
||||||
graph(data.address1, '/tmp/graph_deauth.png');
|
createGraph(data.address1, '/tmp/graph_deauth.png');
|
||||||
|
|
||||||
var message = '🚨 Detected deauthentication frame:\n\n' +
|
var message = '🚨 Detected deauthentication frame:\n\n' +
|
||||||
// 'Time: ' + event.time + "\n" +
|
// 'Time: ' + event.time + "\n" +
|
||||||
|
@ -34,7 +34,7 @@ function onDeauthentication(event) {
|
||||||
function onNewAP(event){
|
function onNewAP(event){
|
||||||
var ap = event.data;
|
var ap = event.data;
|
||||||
if(ap.hostname == fakeESSID) {
|
if(ap.hostname == fakeESSID) {
|
||||||
graph(ap.mac, '/tmp/graph_ap.png');
|
createGraph(ap.mac, '/tmp/graph_ap.png');
|
||||||
|
|
||||||
var message = '🦠 Detected rogue AP:\n\n' +
|
var message = '🦠 Detected rogue AP:\n\n' +
|
||||||
// 'Time: ' + event.time + "\n" +
|
// 'Time: ' + event.time + "\n" +
|
||||||
|
@ -52,7 +52,7 @@ function onHandshake(event){
|
||||||
var data = event.data;
|
var data = event.data;
|
||||||
var what = 'handshake';
|
var what = 'handshake';
|
||||||
|
|
||||||
graph(data.station, '/tmp/graph_handshake.png');
|
createGraph(data.station, '/tmp/graph_handshake.png');
|
||||||
|
|
||||||
if(data.pmkid != null) {
|
if(data.pmkid != null) {
|
||||||
what = "RSN PMKID";
|
what = "RSN PMKID";
|
||||||
|
@ -77,8 +77,8 @@ function onHandshake(event){
|
||||||
function onNewNode(event) {
|
function onNewNode(event) {
|
||||||
var node = event.data;
|
var node = event.data;
|
||||||
|
|
||||||
if(node.type != 'ssid' && node.type != 'ble_server') {
|
if(node.type != 'ssid' && node.type != 'ble_server' && graph.IsConnected(node.type, node.id)) {
|
||||||
graph(node.id, '/tmp/graph_node.png');
|
createGraph(node.id, '/tmp/graph_node.png');
|
||||||
|
|
||||||
var message = '🖥️ Detected previously unknown ' + node.type + ':\n\n' +
|
var message = '🖥️ Detected previously unknown ' + node.type + ':\n\n' +
|
||||||
'Type: ' + node.type + "\n" +
|
'Type: ' + node.type + "\n" +
|
||||||
|
|
|
@ -10,6 +10,8 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var Loaded = (* Graph)(nil)
|
||||||
|
|
||||||
type NodeCallback func(*Node)
|
type NodeCallback func(*Node)
|
||||||
type EdgeCallback func(*Node, []Edge, *Node)
|
type EdgeCallback func(*Node, []Edge, *Node)
|
||||||
|
|
||||||
|
@ -24,10 +26,11 @@ func NewGraph(path string) (*Graph, error) {
|
||||||
if edges, err := LoadEdges(path); err != nil {
|
if edges, err := LoadEdges(path); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
} else {
|
} else {
|
||||||
return &Graph{
|
Loaded = &Graph{
|
||||||
path: path,
|
path: path,
|
||||||
edges: edges,
|
edges: edges,
|
||||||
}, nil
|
}
|
||||||
|
return Loaded, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -147,6 +150,10 @@ func (g *Graph) Traverse(root string, onNode NodeCallback, onEdge EdgeCallback)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (g *Graph) IsConnected(nodeType string, nodeID string) bool {
|
||||||
|
return g.edges.IsConnected(fmt.Sprintf("%s_%s", nodeType, nodeID))
|
||||||
|
}
|
||||||
|
|
||||||
func (g *Graph) Dot(filter, layout, name string, disconnected bool) (string, int, int, error) {
|
func (g *Graph) Dot(filter, layout, name string, disconnected bool) (string, int, int, error) {
|
||||||
size := 0
|
size := 0
|
||||||
discarded := 0
|
discarded := 0
|
||||||
|
|
15
modules/graph/js_builtin.go
Normal file
15
modules/graph/js_builtin.go
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
package graph
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/bettercap/bettercap/log"
|
||||||
|
)
|
||||||
|
|
||||||
|
type graphPackage struct{}
|
||||||
|
|
||||||
|
func (g graphPackage) IsConnected(nodeType, nodeID string) bool {
|
||||||
|
if Loaded == nil {
|
||||||
|
log.Error("graph.IsConnected: graph not loaded")
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return Loaded.IsConnected(nodeType, nodeID)
|
||||||
|
}
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"github.com/bettercap/bettercap/network"
|
"github.com/bettercap/bettercap/network"
|
||||||
"github.com/bettercap/bettercap/session"
|
"github.com/bettercap/bettercap/session"
|
||||||
"github.com/evilsocket/islazy/fs"
|
"github.com/evilsocket/islazy/fs"
|
||||||
|
"github.com/evilsocket/islazy/plugin"
|
||||||
"github.com/evilsocket/islazy/str"
|
"github.com/evilsocket/islazy/str"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -50,6 +51,10 @@ type Module struct {
|
||||||
wLock sync.Mutex
|
wLock sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
plugin.Defines["graph"] = graphPackage{}
|
||||||
|
}
|
||||||
|
|
||||||
func NewModule(s *session.Session) *Module {
|
func NewModule(s *session.Session) *Module {
|
||||||
mod := &Module{
|
mod := &Module{
|
||||||
SessionModule: session.NewSessionModule("graph", s),
|
SessionModule: session.NewSessionModule("graph", s),
|
||||||
|
@ -173,9 +178,16 @@ func (mod *Module) updateSettings() error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// only reload if needed
|
||||||
|
if mod.db != nil && mod.db.path != mod.settings.path {
|
||||||
|
mod.db = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if mod.db == nil {
|
||||||
if mod.db, err = NewGraph(mod.settings.path); err != nil {
|
if mod.db, err = NewGraph(mod.settings.path); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
"unicode"
|
"unicode"
|
||||||
)
|
)
|
||||||
|
@ -153,7 +154,7 @@ func (n Node) Dot(isTarget bool) string {
|
||||||
return fmt.Sprintf("\"%s\" [%s, label=\"%s\"];",
|
return fmt.Sprintf("\"%s\" [%s, label=\"%s\"];",
|
||||||
n.String(),
|
n.String(),
|
||||||
style,
|
style,
|
||||||
n.Label())
|
strings.ReplaceAll(n.Label(), "\"", "\\\""))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n Node) ToMap() (map[string]interface{}, error) {
|
func (n Node) ToMap() (map[string]interface{}, error) {
|
||||||
|
|
|
@ -3,7 +3,6 @@ package session
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/evilsocket/islazy/plugin"
|
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
@ -25,6 +24,7 @@ import (
|
||||||
"github.com/evilsocket/islazy/fs"
|
"github.com/evilsocket/islazy/fs"
|
||||||
"github.com/evilsocket/islazy/log"
|
"github.com/evilsocket/islazy/log"
|
||||||
"github.com/evilsocket/islazy/ops"
|
"github.com/evilsocket/islazy/ops"
|
||||||
|
"github.com/evilsocket/islazy/plugin"
|
||||||
"github.com/evilsocket/islazy/str"
|
"github.com/evilsocket/islazy/str"
|
||||||
"github.com/evilsocket/islazy/tui"
|
"github.com/evilsocket/islazy/tui"
|
||||||
)
|
)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue