From 9a0d000ec4b6c06128795eb00f14175cf21210e0 Mon Sep 17 00:00:00 2001 From: DoronZ Date: Thu, 10 Feb 2022 17:27:06 +0200 Subject: [PATCH] rpcclient: add darwin_network for wifi scan --- .../rpcclient/client/darwin_client.py | 2 ++ src/rpcclient/rpcclient/darwin_network.py | 29 +++++++++++++++++++ src/rpcclient/rpcclient/symbol.py | 2 +- 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 src/rpcclient/rpcclient/darwin_network.py diff --git a/src/rpcclient/rpcclient/client/darwin_client.py b/src/rpcclient/rpcclient/client/darwin_client.py index 58d3abb4..46f400f2 100644 --- a/src/rpcclient/rpcclient/client/darwin_client.py +++ b/src/rpcclient/rpcclient/client/darwin_client.py @@ -6,6 +6,7 @@ from rpcclient.client.client import Client from rpcclient.darwin_fs import DarwinFs from rpcclient.darwin_media import DarwinMedia +from rpcclient.darwin_network import DarwinNetwork from rpcclient.darwin_processes import DarwinProcesses from rpcclient.exceptions import RpcClientException from rpcclient.preferences import Preferences @@ -40,6 +41,7 @@ def __init__(self, sock, sysname: str, hostname: str, port: int = None): self.prefs = Preferences(self) self.processes = DarwinProcesses(self) self.media = DarwinMedia(self) + self.network = DarwinNetwork(self) @property def modules(self) -> typing.List[str]: diff --git a/src/rpcclient/rpcclient/darwin_network.py b/src/rpcclient/rpcclient/darwin_network.py new file mode 100644 index 00000000..db85e746 --- /dev/null +++ b/src/rpcclient/rpcclient/darwin_network.py @@ -0,0 +1,29 @@ +from collections import namedtuple +from typing import List + +from rpcclient.exceptions import RpcClientException +from rpcclient.network import Network + +WifiNetwork = namedtuple('WifiNetwork', 'ssid bssid rssi') + + +class DarwinNetwork(Network): + def __init__(self, client): + super().__init__(client) + + if 0 == client.dlopen('/System/Library/Frameworks/CoreWLAN.framework/Versions/A/CoreWLAN', 2): + raise RpcClientException('failed to load CoreWLAN') + + def scan(self, iface: str) -> List[WifiNetwork]: + """ perform wifi scan on selected interface """ + result = [] + CWInterface = self._client.symbols.objc_getClass('CWInterface') + iface = CWInterface.objc_call('alloc').objc_call('initWithInterfaceName:', self._client.cf(iface)) + networks = iface.objc_call('scanForNetworksWithName:error:', 0, 0).objc_call('allObjects') + + for i in range(networks.objc_call('count')): + network = networks.objc_call('objectAtIndex:', i) + result.append(WifiNetwork(ssid=network.objc_call('ssidData').py, bssid=network.objc_call('bssid').py, + rssi=network.objc_call('rssiValue').c_int64)) + + return result diff --git a/src/rpcclient/rpcclient/symbol.py b/src/rpcclient/rpcclient/symbol.py index 4d65a096..61045dd1 100644 --- a/src/rpcclient/rpcclient/symbol.py +++ b/src/rpcclient/rpcclient/symbol.py @@ -209,7 +209,7 @@ def cfdesc(self): """ if self == 0: return None - return self._client.symbols.CFCopyDescription(self).cfstr.peek_str() + return self._client.symbols.CFCopyDescription(self).py @property def py(self):