Skip to content

Commit 7eab8fc

Browse files
ProxymanBotgitbook-bot
authored andcommitted
GITBOOK-692: No subject
1 parent a7871b3 commit 7eab8fc

4 files changed

Lines changed: 28 additions & 14 deletions

File tree

855 KB
Loading
76.8 KB
Loading

advanced-features/websocket.md

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
description: Capture and decrypt WS/WSS with Proxyman
2+
description: Capture and debug Websocket from iOS devices / simulators with Proxyman
33
---
44

55
# WebSocket
@@ -22,17 +22,24 @@ Proxyman could capture WebSocket (WS) and Secure WebSocket (WSS) traffic and eas
2222

2323
If your iOS app is using **URLSessionWebSocketTask** or iOS WebSocket libraries, e.g. Starscream, SocketRocket, etc. Proxyman might not be able to capture WS/WSS traffic.
2424

25-
Reason: It's an intention of Apple. **URLSessionWebSocketTask** doesn't respect the System HTTP Proxy. All WS/WSS traffic goes directly to the Internet. Thus, Proxyman or Charles Proxy can't capture it.
25+
* **Reason**: Apple's intention. **URLSessionWebSocketTask** doesn't respect the System HTTP Proxy. All WS/WSS traffic goes directly to the Internet. Thus, Proxyman or Charles Proxy can't capture it.
26+
* Example Ap: [https://github.com/ProxymanApp/websocket-example-ios-app](https://github.com/ProxymanApp/websocket-example-ios-app)
2627

2728
### ✅ Solution 1 (Recommended for iOS 17 or later)
2829

29-
1. Proxyman Setup:\
30-
Tools > Proxy Settings > SOCKS Proxy settings -> Enable it (Take note of the port)
31-
2. App Setup:\
32-
Configure a Socksv5Proxy in your App, make sure this is only available for debug builds by implementing a switch or something, you might not want your release build with this configuration.
30+
1. Follow the Setup guide for your [iOS Devices](../debug-devices/ios-device.md) or [iOS Simulators](../debug-devices/ios-simulator.md) (Make sure we installed and trusted the certificate on your device)
31+
2. Proxyman Setup: Tools > Proxy Settings > SOCKS Proxy settings -> Enable it (Take note of the port)
32+
3. On the main Proxyman app -> Take note of a current IP in the Proxyman Tools bar
33+
34+
<figure><img src="../.gitbook/assets/proxyman_capture_websocket_4.jpeg" alt=""><figcaption><p>Get Proxyman current IP</p></figcaption></figure>
35+
36+
37+
38+
4. On your app: Configure a SOCK Proxy in your App, make sure this is only available for debug builds by implementing a switch or something, you might not want your release build with this configuration.
3339

3440
* For NWConnection
3541

42+
{% code overflow="wrap" fullWidth="false" %}
3643
```swift
3744
let parameters = webSocketURL.scheme == "wss" ? NWParameters.tls : NWParameters.tcp
3845

@@ -42,7 +49,7 @@ options.autoReplyPing = true
4249
parameters.defaultProtocolStack.applicationProtocols.insert(options, at: 0)
4350

4451
if #available(iOS 17.0, *) {
45-
let socksv5Proxy = NWEndpoint.hostPort(host: "192.168.1.4", port: 8889) // Use proxyman socksv5 port
52+
let socksv5Proxy = NWEndpoint.hostPort(host: "x.x.x.x", port: 8889) // Please x.x.x.x with a real Proxyman IP
4653
let config = ProxyConfiguration.init(socksv5Proxy: socksv5Proxy)
4754
let context = NWParameters.PrivacyContext(description: "my socksv5Proxy")
4855
context.proxyConfigurations = [config]
@@ -53,24 +60,31 @@ if #available(iOS 17.0, *) {
5360
let connection = NWConnection(to: .url(webSocketURL), using: parameters)
5461
connection.start(queue: .main)
5562
```
63+
{% endcode %}
5664

57-
* For URLSession
65+
* For URLSession and URLSessionWebSocketTask
5866

67+
{% code overflow="wrap" fullWidth="false" %}
5968
```swift
6069
private lazy var urlSession: URLSession = {
6170
let config = URLSessionConfiguration.default
6271
if #available(iOS 17.0, *) {
63-
let socksv5Proxy = NWEndpoint.hostPort(host: "192.168.1.4", port: 8889) // Use proxyman socksv5 port
72+
let socksv5Proxy = NWEndpoint.hostPort(host: "x.x.x.x", port: 8889) // Please x.x.x.x with a real Proxyman IP
6473
let proxyConfig = ProxyConfiguration.init(socksv5Proxy: socksv5Proxy)
65-
6674
config.proxyConfigurations = [proxyConfig]
6775
}
6876

69-
return URLSession(configuration: config, delegate: self, delegateQueue: operationQueue)
77+
return URLSession(configuration: config, delegate: nil, delegateQueue: nil)
7078
}()
7179
```
80+
{% endcode %}
81+
82+
5. Done ✅
83+
84+
<figure><img src="../.gitbook/assets/Screenshot 2024-11-29 at 1.17.23 PM.jpg" alt=""><figcaption><p>Capture Websocket from iOS with Proxyman</p></figcaption></figure>
7285

73-
Credit to [**FranklinSamboni**](https://github.com/FranklinSamboni) **->** [https://github.com/ProxymanApp/Proxyman/issues/586#issuecomment-2125082129](https://github.com/ProxymanApp/Proxyman/issues/586#issuecomment-2125082129)
86+
* Credit to [**FranklinSamboni**](https://github.com/FranklinSamboni) **->** [https://github.com/ProxymanApp/Proxyman/issues/586#issuecomment-2125082129](https://github.com/ProxymanApp/Proxyman/issues/586#issuecomment-2125082129)
87+
* Tutorial: [https://proxyman.io/posts/2019-10-18-WebSocket-Debugging](https://proxyman.io/posts/2019-10-18-WebSocket-Debugging)
7488

7589
### ✅ Solution 2
7690

scripting/environment-variables.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ From Proxyman 2.25.0+, the **sharedState** is available across different scripts
4949
{% endhint %}
5050
5151
{% hint style="info" %}
52-
Prior to Proxyman 2.24.0**,** the **sharedState** is only alive on the current flow that executes the script and it's released when the script is run over.&#x20;
52+
Prior to Proxyman 2.24.&#x30;**,** the **sharedState** is only alive on the current flow that executes the script and it's released when the script is run over.&#x20;
5353
{% endhint %}
5454
5555
To clear all data, please consider using \`clearSharedState\` function.
@@ -79,7 +79,7 @@ export PROXYMAN_PATH=/Users/my_user/Desktop/file-mapper
7979
8080
3\. Reload the ENV to get the env update.
8181
82-
![Enable env on scripts](../.gitbook/assets/Screen\_Shot\_2022-07-31\_at\_10\_48\_26.jpg)
82+
![Enable env on scripts](../.gitbook/assets/Screen_Shot_2022-07-31_at_10_48_26.jpg)
8383
8484
4\. Access env from your script with a prefix `$`
8585

0 commit comments

Comments
 (0)