From cb5f7679d883c76398610eb405547e6670365cf6 Mon Sep 17 00:00:00 2001 From: Sniffleupagus <129890632+Sniffleupagus@users.noreply.github.com> Date: Wed, 13 Nov 2024 11:33:25 -0800 Subject: [PATCH] Improve backwards compatibility with getHandshakeFileFor The getHandshakeFile function was using "path.Dir(shakesFileName)", which drops the last element of the path. This is not backwards compatible with prior versions that used the variable as the dir name. In particular this change causes pwnagotchi to store handshakes in /root instead of /root/handshakes. This commit checks for an existing directory at shakesFileName and will use that as the path instead of taking the parent directory of the path. --- modules/wifi/wifi_recon_handshakes.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/modules/wifi/wifi_recon_handshakes.go b/modules/wifi/wifi_recon_handshakes.go index ac5b52dd..5b949231 100644 --- a/modules/wifi/wifi_recon_handshakes.go +++ b/modules/wifi/wifi_recon_handshakes.go @@ -4,6 +4,7 @@ import ( "bytes" "fmt" "net" + "os" "path" "github.com/bettercap/bettercap/v2/network" @@ -27,6 +28,11 @@ func (mod *WiFiModule) getHandshakeFileFor(ap *network.AccessPoint) string { shakesFileName := mod.shakesFile if !mod.shakesAggregate { parentDir := path.Dir(shakesFileName) + // check for existing directory at "shakesFileName" for backwards compatibility + fileInfo, err := os.Stat(shakesFileName) + if (err == nil) && (fileInfo.IsDir()) { + parentDir = shakesFileName + } shakesFileName = path.Join(parentDir, fmt.Sprintf("%s.pcap", ap.PathFriendlyName())) } return shakesFileName