From 23042901c2adc1e83d9e339752d81e833600f8db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Regu=C5=82a?= Date: Mon, 20 May 2024 14:32:48 +0200 Subject: [PATCH] VPN detection added --- IOSSecuritySuite/ProxyChecker.swift | 46 +++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/IOSSecuritySuite/ProxyChecker.swift b/IOSSecuritySuite/ProxyChecker.swift index 35c738a..7712349 100644 --- a/IOSSecuritySuite/ProxyChecker.swift +++ b/IOSSecuritySuite/ProxyChecker.swift @@ -9,17 +9,39 @@ import Foundation internal class ProxyChecker { - static func amIProxied() -> Bool { - guard let unmanagedSettings = CFNetworkCopySystemProxySettings() else { - return false + static func amIProxied(considerVPNConnectionAsProxy: Bool = false) -> Bool { + guard let unmanagedSettings = CFNetworkCopySystemProxySettings() else { + return false + } + + let settingsOptional = unmanagedSettings.takeRetainedValue() as? [String: Any] + + guard let settings = settingsOptional else { + return false + } + + if(considerVPNConnectionAsProxy) { + if let scoped = settings["__SCOPED__"] as? [String: Any] { + for interface in scoped.keys { + + let names = [ + "tap", + "tun", + "ppp", + "ipsec", + "utun" + ] + + for name in names { + if(interface.contains(name)) { + print("detected: \(interface)") + return true + } + } + } + } + } + + return (settings.keys.contains("HTTPProxy") || settings.keys.contains("HTTPSProxy")) } - - let settingsOptional = unmanagedSettings.takeRetainedValue() as? [String: Any] - - guard let settings = settingsOptional else { - return false - } - - return (settings.keys.contains("HTTPProxy") || settings.keys.contains("HTTPSProxy")) - } }