Skip to content

Force Proxy to any Windows/MacOS/Linux Application TCP and UDP traffic

Bump version to 4.0.0; update marketing version in project files and build script; enhance IPV6 handling in proxy settings and rules

AnoF-Cyber1a48c66d9763
diff --git a/MacOS/ProxyBridge/ProxyBridge.xcodeproj/project.pbxproj b/MacOS/ProxyBridge/ProxyBridge.xcodeproj/project.pbxproj
index 5c36a5c..dc2ae95 100644
--- a/MacOS/ProxyBridge/ProxyBridge.xcodeproj/project.pbxproj
+++ b/MacOS/ProxyBridge/ProxyBridge.xcodeproj/project.pbxproj
@@ -411,7 +411,7 @@
"$(inherited)",
"@executable_path/../Frameworks",
);
- MARKETING_VERSION = 3.2.0;
+ MARKETING_VERSION = 4.0.0;
PRODUCT_BUNDLE_IDENTIFIER = com.interceptsuite.ProxyBridge;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
@@ -457,7 +457,7 @@
"$(inherited)",
"@executable_path/../Frameworks",
);
- MARKETING_VERSION = 3.2.0;
+ MARKETING_VERSION = 4.0.0;
"PROVISIONING_PROFILE_SPECIFIER[sdk=macosx*]" = "ProxyBridge Prod";
REGISTER_APP_GROUPS = YES;
STRING_CATALOG_GENERATE_SYMBOLS = YES;
@@ -498,7 +498,7 @@
"@executable_path/../Frameworks",
"@executable_path/../../../../Frameworks",
);
- MARKETING_VERSION = 3.2.0;
+ MARKETING_VERSION = 4.0.0;
PRODUCT_BUNDLE_IDENTIFIER = com.interceptsuite.ProxyBridge.extension;
PRODUCT_NAME = "$(inherited)";
REGISTER_APP_GROUPS = YES;
@@ -537,7 +537,7 @@
"@executable_path/../Frameworks",
"@executable_path/../../../../Frameworks",
);
- MARKETING_VERSION = 3.2.0;
+ MARKETING_VERSION = 4.0.0;
"PROVISIONING_PROFILE_SPECIFIER[sdk=macosx*]" = "ProxyBridge Extension Prod";
REGISTER_APP_GROUPS = YES;
SKIP_INSTALL = YES;
diff --git a/MacOS/ProxyBridge/ProxyBridge/ProxyRulesView.swift b/MacOS/ProxyBridge/ProxyBridge/ProxyRulesView.swift
index aa3b23a..c21d940 100644
--- a/MacOS/ProxyBridge/ProxyBridge/ProxyRulesView.swift
+++ b/MacOS/ProxyBridge/ProxyBridge/ProxyRulesView.swift
@@ -443,7 +443,7 @@ struct RuleEditorView: View {
label: "Target hosts",
placeholder: "*",
text: $targetHosts,
- hint: "Example: 127.0.0.1; 192.168.1.*; 10.0.0.1-10.0.0.254"
+ hint: "IPv4: 127.0.0.1; 192.168.1.*; 10.0.0.1-10.0.0.254 IPv6: ::1; 2001:db8:*; fe80::1-fe80::ff"
)
formField(
diff --git a/MacOS/ProxyBridge/ProxyBridge/ProxySettingsView.swift b/MacOS/ProxyBridge/ProxyBridge/ProxySettingsView.swift
index 8fc1b30..31c8811 100644
--- a/MacOS/ProxyBridge/ProxyBridge/ProxySettingsView.swift
+++ b/MacOS/ProxyBridge/ProxyBridge/ProxySettingsView.swift
@@ -184,20 +184,31 @@ struct ProxySettingsView: View {
}
private func checkTCPReachability(host: String, port: Int) -> Bool {
- let sock = socket(AF_INET, SOCK_STREAM, 0)
- guard sock >= 0 else { return false }
- defer { Darwin.close(sock) }
-
- var addr = sockaddr_in()
- addr.sin_family = sa_family_t(AF_INET)
- addr.sin_port = in_port_t(port).bigEndian
- inet_pton(AF_INET, host, &addr.sin_addr)
-
- return withUnsafePointer(to: &addr) { ptr in
- ptr.withMemoryRebound(to: sockaddr.self, capacity: 1) { sockPtr in
- connect(sock, sockPtr, socklen_t(MemoryLayout<sockaddr_in>.size)) == 0
+ // getaddrinfo handles ipv4, ipv6 and hostnames, so this works for any proxy
+ var hints = addrinfo()
+ hints.ai_family = AF_UNSPEC
+ hints.ai_socktype = SOCK_STREAM
+
+ var result: UnsafeMutablePointer<addrinfo>?
+ guard getaddrinfo(host, String(port), &hints, &result) == 0 else { return false }
+ defer { freeaddrinfo(result) }
+
+ var candidate = result
+ while let addr = candidate {
+ let sock = socket(addr.pointee.ai_family, addr.pointee.ai_socktype, addr.pointee.ai_protocol)
+ if sock >= 0 {
+ // bound connect time so an unreachable host doesn't hang the test
+ var timeout = timeval(tv_sec: 3, tv_usec: 0)
+ setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, &timeout, socklen_t(MemoryLayout<timeval>.size))
+ if connect(sock, addr.pointee.ai_addr, addr.pointee.ai_addrlen) == 0 {
+ Darwin.close(sock)
+ return true
+ }
+ Darwin.close(sock)
}
+ candidate = addr.pointee.ai_next
}
+ return false
}
}
diff --git a/MacOS/ProxyBridge/build.sh b/MacOS/ProxyBridge/build.sh
index 128bf30..4dc1d47 100755
--- a/MacOS/ProxyBridge/build.sh
+++ b/MacOS/ProxyBridge/build.sh
@@ -3,7 +3,7 @@
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
-VERSION="3.2.0"
+VERSION="4.0.0"
if [ -f "$SCRIPT_DIR/.env" ]; then
source "$SCRIPT_DIR/.env"
@@ -44,7 +44,7 @@ echo "Creating installer package..."
pkgbuild \
--root build/component \
--identifier com.interceptsuite.ProxyBridge \
- --version 3.2.0 \
+ --version "$VERSION" \
--install-location /Applications \
build/temp.pkg
@@ -63,7 +63,7 @@ cat > build/distribution.xml << 'EOF'
<choice id="com.interceptsuite.ProxyBridge" visible="false">
<pkg-ref id="com.interceptsuite.ProxyBridge"/>
</choice>
- <pkg-ref id="com.interceptsuite.ProxyBridge" version="3.2.0" onConclusion="none">temp.pkg</pkg-ref>
+ <pkg-ref id="com.interceptsuite.ProxyBridge" version="4.0.0" onConclusion="none">temp.pkg</pkg-ref>
</installer-gui-script>
EOF
diff --git a/MacOS/ProxyBridge/extension/AppProxyProvider.swift b/MacOS/ProxyBridge/extension/AppProxyProvider.swift
index 2076bde..d621251 100644
--- a/MacOS/ProxyBridge/extension/AppProxyProvider.swift
+++ b/MacOS/ProxyBridge/extension/AppProxyProvider.swift
@@ -130,57 +130,86 @@ struct ProxyRule: Codable {
return false
}
- private static func ipToInteger(_ ipString: String) -> UInt32? {
- let octets = ipString.components(separatedBy: ".")
- guard octets.count == 4 else { return nil }
-
- var result: UInt32 = 0
- for octet in octets {
- guard let value = UInt8(octet) else { return nil }
- result = (result << 8) | UInt32(value)
+ // raw bytes of a v4 (4) or v6 (16) address, nil if not an ip literal
+ private static func ipToBytes(_ ipString: String) -> [UInt8]? {
+ if let v4 = IPv4Address(ipString) { return Array(v4.rawValue) }
+ if let v6 = IPv6Address(ipString) { return Array(v6.rawValue) }
+ return nil
+ }
+
+ private static func compareBytes(_ a: [UInt8], _ b: [UInt8]) -> Int {
+ for i in 0..<min(a.count, b.count) where a[i] != b[i] {
+ return a[i] < b[i] ? -1 : 1
}
- return result
+ return 0
}
-
+
+ // full 8 hextet form of a v6 address, e.g. ["2001","db8","0",...]
+ private static func expandIPv6(_ ipString: String) -> [String]? {
+ guard let v6 = IPv6Address(ipString) else { return nil }
+ let bytes = Array(v6.rawValue)
+ var groups: [String] = []
+ for i in stride(from: 0, to: 16, by: 2) {
+ let value = (UInt16(bytes[i]) << 8) | UInt16(bytes[i + 1])
+ groups.append(String(format: "%x", value))
+ }
+ return groups
+ }
+
private static func matchIPPattern(_ pattern: String, ipString: String) -> Bool {
if pattern.isEmpty || pattern == "*" {
return true
}
-
- // ip range, e.g. 192.168.1.1-192.168.1.254
+
+ // range, works for v4 and v6, e.g. 10.0.0.1-10.0.0.254 or fe80::1-fe80::ff
if pattern.contains("-") {
let parts = pattern.components(separatedBy: "-")
- if parts.count == 2 {
- let startIP = parts[0].trimmingCharacters(in: .whitespaces)
- let endIP = parts[1].trimmingCharacters(in: .whitespaces)
-
- if let startInt = ipToInteger(startIP),
- let endInt = ipToInteger(endIP),
- let targetInt = ipToInteger(ipString) {
- return targetInt >= startInt && targetInt <= endInt
- }
+ guard parts.count == 2,
+ let lo = ipToBytes(parts[0].trimmingCharacters(in: .whitespaces)),
+ let hi = ipToBytes(parts[1].trimmingCharacters(in: .whitespaces)),
+ let target = ipToBytes(ipString),
+ lo.count == hi.count, target.count == lo.count else {
+ return false
}
- return false
+ return compareBytes(target, lo) >= 0 && compareBytes(target, hi) <= 0
}
-
- // wildcard, e.g. 192.168.1.*
+
+ // v6 pattern (contains a colon)
+ if pattern.contains(":") {
+ return matchIPv6Pattern(pattern, ipString: ipString)
+ }
+
+ // v4 wildcard, e.g. 192.168.1.*
let patternOctets = pattern.components(separatedBy: ".")
let ipOctets = ipString.components(separatedBy: ".")
-
if patternOctets.count != 4 || ipOctets.count != 4 {
return false
}
-
for i in 0..<4 {
- if patternOctets[i] == "*" {
- continue
- }
- if patternOctets[i] != ipOctets[i] {
- return false
- }
+ if patternOctets[i] == "*" { continue }
+ if patternOctets[i] != ipOctets[i] { return false }
}
return true
}
+
+ private static func matchIPv6Pattern(_ pattern: String, ipString: String) -> Bool {
+ // prefix wildcard on leading hextets, e.g. 2001:db8:* (no :: compression)
+ if pattern.hasSuffix("*") {
+ guard let target = expandIPv6(ipString) else { return false }
+ var groups = pattern.lowercased().dropLast()
+ .split(separator: ":", omittingEmptySubsequences: false).map(String.init)
+ if groups.last == "" { groups.removeLast() }
+ for (i, g) in groups.enumerated() {
+ guard i < 8, !g.isEmpty, let value = UInt16(g, radix: 16) else { return false }
+ if String(format: "%x", value) != target[i] { return false }
+ }
+ return true
+ }
+
+ // exact match, compared on normalized bytes so ::1 == 0:0:...:1
+ guard let p = ipToBytes(pattern), let t = ipToBytes(ipString) else { return false }
+ return p == t
+ }
private static func matchPortList(_ portList: String, port: UInt16) -> Bool {
if portList.isEmpty || portList == "*" {
@@ -1203,8 +1232,10 @@ class AppProxyProvider: NETransparentProxyProvider {
}
private func handleHTTPProxy(clientFlow: NEAppProxyTCPFlow, proxyConnection: NWTCPConnection, destination: String, port: UInt16, username: String?, password: String?) {
- var request = "CONNECT \(destination):\(port) HTTP/1.1\r\n"
- request += "Host: \(destination):\(port)\r\n"
+ // ipv6 literals must be bracketed in the request line and Host header
+ let host = IPv6Address(destination) != nil ? "[\(destination)]" : destination
+ var request = "CONNECT \(host):\(port) HTTP/1.1\r\n"
+ request += "Host: \(host):\(port)\r\n"
if let username = username, let password = password {
let credentials = "\(username):\(password)"