### Minimal Setup Configuration Example Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/README.md A basic configuration example for ciadpi. ```bash ciadpi -i 127.0.0.1 -p 1080 --split 3 ``` -------------------------------- ### run Function Example Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/api-reference/proxy-api.md Example showing how to start the proxy server's main event loop using the run function. ```c union sockaddr_u listen_addr; listen_addr.in.sin_family = AF_INET; listen_addr.in.sin_port = htons(1080); if (run(&listen_addr) < 0) { fprintf(stderr, "Proxy server failed\n"); return -1; } ``` -------------------------------- ### Fake Data Offset Example Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/configuration.md Example for setting the offset to start fake data. ```bash ciadpi --fake 100 --fake-offset 10 ``` -------------------------------- ### Timeout Example Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/configuration.md Examples for setting timeouts for server responses. ```bash ciadpi --timeout 5 ciadpi --timeout 3.5:2:10:1000 --auto=torst ``` -------------------------------- ### No UDP Example Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/configuration.md Example of disabling UDP support. ```bash ciadpi -U ``` -------------------------------- ### TCP Fast Open Example Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/configuration.md Example command to enable TCP Fast Open. ```bash ciadpi -F --split 3 ``` -------------------------------- ### OOB Data Example Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/configuration.md Examples for setting the byte value for OOB data. ```bash ciadpi --oob 3 --oob-data "x" ciadpi --oob 3 --oob-data "\x00" ``` -------------------------------- ### Listening Port Examples Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/configuration.md Examples of setting the TCP port for the proxy server. ```bash ciadpi -p 9050 ciadpi -i 127.0.0.1 -p 8080 ``` -------------------------------- ### Daemon Mode Example Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/configuration.md Example of running the proxy as a background daemon process. ```bash ciadpi -D -w /var/run/ciadpi.pid ``` -------------------------------- ### Output Redirection Examples Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/configuration.md Examples of redirecting connections using TCP or SOCKS5 modes. ```bash ciadpi -C tcp://127.0.0.1:3128 # Forward to HTTP proxy ciadpi -C socks5://10.0.0.1:1080 # Forward to SOCKS5 proxy ``` -------------------------------- ### Debug Logging Examples Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/configuration.md Examples of enabling and directing debug logging output. ```bash ciadpi -x 1 2>/tmp/ciadpi.log ciadpi -x 2 ``` -------------------------------- ### Usage example Source: https://github.com/hufrea/byedpi/blob/main/README.md The program is a local SOCKS proxy server. Usage examples for the ciadpi command. ```bash ciadpi --disorder 1 --auto=torst --tlsrec 1+s ciadpi --fake -1 --ttl 8 ``` -------------------------------- ### SS_PLUGIN_OPTIONS Example Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/configuration.md Example of setting SS_PLUGIN_OPTIONS for shadowsocks plugin usage. ```bash export SS_PLUGIN_OPTIONS="--split 3 --fake -1 --ttl 8" ./ciadpi ``` -------------------------------- ### Buffer Size Examples Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/configuration.md Examples of setting the maximum bytes per read/write operation. ```bash ciadpi -b 8192 ciadpi -b 32768 ``` -------------------------------- ### Disorder and OOB Combination Example Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/configuration.md Example of combining disorder and out-of-band techniques. ```bash ciadpi --disoob 3+s ``` -------------------------------- ### Hostname Whitelist/Blacklist Examples Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/configuration.md Examples demonstrating the use of --hosts for whitelisting or blacklisting hostnames. ```bash ciadpi --hosts /etc/hosts.txt --split 3 ciadpi --split 3 --auto=none --hosts ":example.com" # Only for example.com ciadpi --hosts ":example.com" --auto=none --split 3 # All except example.com ``` -------------------------------- ### Cache File Examples Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/configuration.md Examples demonstrating how to use --cache-file for loading and saving desync parameters. ```bash ciadpi --cache-file /var/cache/ciadpi.cache ciadpi --cache-file - --auto=torst --timeout 5 # Dump cache to console ``` -------------------------------- ### Building byedpi Source: https://github.com/hufrea/byedpi/blob/main/dist/bsd/README.md Steps to build and install byedpi from source on BSD systems. ```sh cd byedpi/ make sudo make install ``` -------------------------------- ### Protocol Whitelist Examples Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/configuration.md Examples of using the --proto flag to filter connections by protocol. ```bash ciadpi --proto=t,h --split 3 # HTTP and HTTPS only ciadpi --proto=t --fake -1 # HTTPS only ``` -------------------------------- ### Default TTL Example Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/configuration.md Example of setting the default TTL for all outgoing connections. ```bash ciadpi -g 64 ``` -------------------------------- ### TTL for Fake Packets Example Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/configuration.md Examples for setting the TTL for fake packets. ```bash ciadpi --fake -1 --ttl 8 ciadpi --fake 50 --ttl 3 ``` -------------------------------- ### Custom SNI Example Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/configuration.md Examples for using custom SNI in fake packets. ```bash ciadpi --fake -1 --fake-sni "example.com" ciadpi --fake -1 --fake-sni "random-?????.com" --fake-sni "test.com" ``` -------------------------------- ### HTTP Header Modification Example Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/configuration.md Examples for modifying HTTP headers. ```bash ciadpi --mod-http h,r ciadpi --mod-http d ``` -------------------------------- ### Cache TTL Example Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/configuration.md Example showing how to set the cache time-to-live using --cache-ttl. ```bash ciadpi --cache-ttl 3600 # 1 hour ciadpi --cache-ttl 86400 # 1 day ``` -------------------------------- ### Drop SACK Example Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/configuration.md Example command to ignore TCP SACK acknowledgments. ```bash ciadpi --split 1 --disorder 3 --drop-sack ``` -------------------------------- ### No Domain Example Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/configuration.md Example of rejecting connections that specify hostnames instead of IP addresses. ```bash ciadpi -N # Only accept IP addresses ``` -------------------------------- ### UDP Fake Packets Example Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/configuration.md Example for specifying the number of fake UDP packets. ```bash ciadpi --udp-fake 5 ``` -------------------------------- ### Fake Packets Example Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/configuration.md Examples for using the --fake option with different configurations. ```bash ciadpi --fake -1 --ttl 8 ciadpi --disorder 1 --fake -1 ``` -------------------------------- ### Configuring as a system service Source: https://github.com/hufrea/byedpi/blob/main/dist/bsd/README.md Instructions to copy the byedpi executable to the init.d directory and enable it as a system service. ```sh sudo cp byedpi /usr/local/etc/init.d sudo sysrc byedpi_enable="YES" ``` -------------------------------- ### TLS Record Splitting Example Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/configuration.md Examples for splitting TLS ClientHello into multiple TLS records. ```bash ciadpi --tlsrec 0+s ciadpi --auto=torst --timeout 3 --tlsrec 3+s ``` -------------------------------- ### Maximum Concurrent Connections Example Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/configuration.md Example of setting the maximum number of concurrent client connections. ```bash ciadpi -c 1024 ``` -------------------------------- ### mem_add example Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/api-reference/mpool-api.md Example of adding a hostname to the hosts pool. ```c struct mphdr *hosts = mem_pool(MF_STATIC, CMP_HOST); // Add a hostname struct elem *elem = mem_add(hosts, "example.com", 11, sizeof(struct elem)); if (!elem) { perror("Failed to add element"); } ``` -------------------------------- ### mem_get example Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/api-reference/mpool-api.md Example of searching for an element in the hosts pool. ```c struct mphdr *hosts = mem_pool(MF_STATIC, CMP_HOST); // Add "example.com" to the pool... // Later, search for it struct elem *found = mem_get(hosts, "example.com", 11); if (found) { printf("Found: %.*s\n", found->len, found->data); } ``` -------------------------------- ### mem_delete example Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/api-reference/mpool-api.md Example of removing a hostname from the pool. ```c // Remove a hostname from the pool mem_delete(hosts, "example.com", 11); ``` -------------------------------- ### MD5 Signature Example Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/configuration.md Example for adding TCP MD5 Signature to fake packets. ```bash ciadpi --fake -1 --md5sig ``` -------------------------------- ### Fake TLS ClientHello Modification Example Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/configuration.md Examples for modifying fake TLS ClientHello. ```bash ciadpi --fake -1 --fake-tls-mod rand ciadpi --fake -1 --fake-tls-mod orig ciadpi --fake -1 --fake-tls-mod msize=-20 ``` -------------------------------- ### Complete Configuration Example Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/configuration.md A complex DPI bypass configuration with multiple techniques. ```bash ciadpi \ -i 127.0.0.1 \ -p 1080 \ -c 1024 \ -x 1 \ --fake -1 --ttl 8 --md5sig \ --fake-sni "random-?????.com" \ --auto=torst --timeout 3 \ --split 1+s --disorder 3+s --fake -1 --ttl 5 \ --cache-file /var/cache/ciadpi.cache \ --cache-ttl 86400 \ --hosts /etc/ciadpi/bypass.hosts \ --proto=t,h \ -D \ -w /var/run/ciadpi.pid ``` -------------------------------- ### Filtered Application Configuration Example Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/README.md Configuration example for filtering applications. ```bash ciadpi \ --hosts /etc/blocked-hosts.txt \ --proto t,h \ --split 0+s --disorder 3 ``` -------------------------------- ### Out-of-Band Data Example Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/configuration.md Example of sending a part of the packet as out-of-band (urgent) data. ```bash ciadpi --oob 3+s ciadpi --oob 0+sh ``` -------------------------------- ### Port Range Whitelist Examples Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/configuration.md Examples illustrating the use of --pf to specify port ranges for desync. ```bash ciadpi --pf 443 --split 3 # Only port 443 ciadpi --pf 80-443 --fake -1 # Ports 80-443 ciadpi --pf 443 --split 3 --auto=none --pf 22,80 --split 1 ``` -------------------------------- ### struct part example 2 Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/types.md Example of splitting at multiple positions. ```c // Split at positions 3, 7, 11 (3 bytes, then skip 4, then skip 4) struct part multi_split = { .m = DESYNC_SPLIT, .pos = 3, .r = 3, .s = 4 }; ``` -------------------------------- ### Packet Splitting Examples Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/configuration.md Examples of splitting packets at specified positions with different flags and multiple splits. ```bash ciadpi --split 3+sm --split 10 ciadpi --split 0+s --split 3+h ``` -------------------------------- ### Auto-Fallback Configuration Example Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/README.md Configuration example demonstrating auto-fallback features. ```bash ciadpi \ --fake -1 --md5sig --ttl 8 \ --auto=torst --timeout 3 \ --split 1+s --disorder 3+s --ttl 5 ``` -------------------------------- ### udp_hook Example Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/api-reference/extend-api.md Example usage of the udp_hook function. ```c ssize_t sent = udp_hook(udp_event, dns_query, query_size, &dns_server); if (sent < 0) { perror("udp_hook"); } ``` -------------------------------- ### Bind Outgoing Connections Example Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/configuration.md Examples of binding outgoing connections to a specific IP address. ```bash ciadpi -I 192.168.1.100 ciadpi -I 2001:db8::1 ``` -------------------------------- ### Custom Fake Packet Data Example Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/configuration.md Examples for using custom fake packet data. ```bash ciadpi --fake 50 --fake-data ":/fake/http/request" ciadpi --fake -1 --fake-data "/etc/ciadpi/fake.bin" ``` -------------------------------- ### Listening IP Address Examples Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/configuration.md Examples of setting the listening IP address for the proxy server with different schemes. ```bash ciadpi -i 127.0.0.1 ciadpi -i ::1 ciadpi -i socks5://192.168.1.1 ``` -------------------------------- ### Daemonized Server Configuration Example Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/README.md Configuration example for running ciadpi as a daemonized server. ```bash ciadpi \ -i 0.0.0.0 -p 9050 \ -D -w /var/run/ciadpi.pid \ --cache-file /var/cache/ciadpi.cache \ --fake -1 --ttl 8 ``` -------------------------------- ### listen_socket Function Example Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/api-reference/proxy-api.md Example demonstrating how to initialize and bind a listening socket using the listen_socket function. ```c union sockaddr_u srv_addr; inet_pton(AF_INET, "0.0.0.0", &srv_addr.in.sin_addr); srv_addr.in.sin_family = AF_INET; srv_addr.in.sin_port = htons(1080); int listen_fd = listen_socket(&srv_addr); if (listen_fd < 0) { perror("listen_socket failed"); return -1; } ``` -------------------------------- ### IP/Subnet Whitelist/Blacklist Examples Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/configuration.md Examples showing the usage of --ipset for whitelisting or blacklisting IP addresses or subnets. ```bash ciadpi --ipset ":8.8.8.8 8.8.4.4" ciadpi --ipset /etc/blocklist.txt --disorder 1 ``` -------------------------------- ### tcp_recv_hook Example Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/api-reference/extend-api.md Example usage of the tcp_recv_hook function. ```c ssize_t processed = tcp_recv_hook(pool, server_event, buffer); if (processed < 0) { perror("tcp_recv_hook"); } ``` -------------------------------- ### mem_pool example Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/api-reference/mpool-api.md Example of creating memory pools for hosts and IPs. ```c // Create pool for hosts with static allocation struct mphdr *hosts_pool = mem_pool(MF_STATIC, CMP_HOST); if (!hosts_pool) { perror("Failed to create host pool"); return -1; } // Create pool for IPs with extra data struct mphdr *ip_pool = mem_pool(MF_EXTRA, CMP_BITS); ``` -------------------------------- ### Auto Mode Behavior Example Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/configuration.md Example showing how to use --auto-mode with --auto for controlling cache behavior. ```bash ciadpi --auto=torst --auto-mode o ``` -------------------------------- ### is_http_redirect example usage Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/api-reference/packets-api.md Example of how to use the is_http_redirect function. ```c if (is_http_redirect(request, req_size, response, resp_size)) { printf("DPI redirect detected - applying desync\n"); } ``` -------------------------------- ### is_http Example Usage Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/api-reference/packets-api.md Example of how to use the is_http function. ```c if (is_http(packet, size)) { printf("HTTP request detected\n"); } ``` -------------------------------- ### neq_tls_sid example usage Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/api-reference/packets-api.md Example of how to use the neq_tls_sid function. ```c if (neq_tls_sid(client_hello, ch_size, server_hello, sh_size)) { printf("TLS error detected - session_id mismatch\n"); } ``` -------------------------------- ### Disorder Examples Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/configuration.md Examples of splitting packets and sending parts in reverse order with low TTL, including platform-specific common values. ```bash ciadpi --disorder 1 ciadpi --split 7 --disorder 23 ``` -------------------------------- ### parse_http example usage Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/api-reference/packets-api.md Example of how to use the parse_http function. ```c char *hostname = NULL; uint16_t port = 0; int host_len = parse_http(http_data, http_size, &hostname, &port); if (host_len > 0) { printf("Host: %.*s:%d\n", host_len, hostname, port); } ``` -------------------------------- ### TLS Minor Version Override Example Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/configuration.md Example for overriding the TLS protocol minor version. ```bash ciadpi --tlsminor 3 ``` -------------------------------- ### desync_udp Example Usage Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/api-reference/desync-api.md Example demonstrating how to use the desync_udp function. ```c struct desync_params *dp = get_desync_params(); char udp_data[] = "query"; int result = desync_udp(udp_fd, udp_data, sizeof(udp_data), &server_addr, dp); if (result < 0) { perror("UDP desync failed"); } ``` -------------------------------- ### is_tls_shello Example Usage Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/api-reference/packets-api.md Example of how to use the is_tls_shello function. ```c if (is_tls_shello(response, resp_size)) { printf("TLS server confirmed connection\n"); } ``` -------------------------------- ### Shadowsocks Mode Environment Variable Example Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/configuration.md Example of setting the SS_LOCAL_PORT environment variable to enable Shadowsocks mode. ```bash export SS_LOCAL_PORT=1080 ./ciadpi ``` -------------------------------- ### Automatic Desync Triggering Examples Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/configuration.md Examples demonstrating the use of the --auto flag for automatic desync triggering with different detection methods. ```bash ciadpi --fake -1 --ttl 10 --auto=torst --fake -1 --ttl 5 ciadpi --auto=ssl_err --tlsrec 0+s ciadpi --proto=tls --disorder 1 --auto=none ``` -------------------------------- ### Log Macro Usage Examples Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/errors.md Examples demonstrating the usage of the LOG macro for different levels. ```c LOG(LOG_S, "Connection from %s port %d\n", ip, port); LOG(LOG_E, "Fatal error: %s\n", error_msg); ``` -------------------------------- ### Connection Redirection Example Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/api-reference/extend-api.md Example of redirecting connections using the connect-to option. ```c // Example command line: // ciadpi -C tcp://127.0.0.1:3128 ... // In connect_hook(): if (dp->out_type && dp->out_addr.in6.sin6_port) { // Redirect to output server *dst = dp->out_addr; // Change destination } ``` -------------------------------- ### s5_set_addr Example Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/api-reference/proxy-api.md Example usage of the s5_set_addr function to encode a server address. ```c union sockaddr_u server_addr; server_addr.in.sin_family = AF_INET; inet_pton(AF_INET, "10.0.0.1", &server_addr.in.sin_addr); server_addr.in.sin_port = htons(8080); char buffer[22]; // Enough for IPv4 + port int bytes = s5_set_addr(buffer, sizeof(buffer), &server_addr, 1); if (bytes > 0) { printf("Encoded %d bytes\n", bytes); } ``` -------------------------------- ### struct part example 1 Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/types.md Example of splitting at SNI middle position. ```c // Split at SNI middle position struct part split = { .m = DESYNC_SPLIT, .flag = OFFSET_SNI | OFFSET_MID, .pos = 0, .r = 1, .s = 0 }; ``` -------------------------------- ### is_tls_chello Example Usage Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/api-reference/packets-api.md Example of how to use the is_tls_chello function. ```c char packet[1024]; ssize_t received = recv(socket, packet, sizeof(packet), 0); if (is_tls_chello(packet, received)) { printf("Received TLS ClientHello\n"); } ``` -------------------------------- ### pre_desync Example Usage Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/api-reference/desync-api.md Example demonstrating the use of pre_desync before a desync operation. ```c struct desync_params *dp = val->dp; if (pre_desync(server_fd, dp) < 0) { perror("pre_desync failed"); close(server_fd); } ``` -------------------------------- ### mem_destroy example Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/api-reference/mpool-api.md Example of destroying the hosts_pool and setting the pointer to NULL. ```c mem_destroy(hosts_pool); hosts_pool = NULL; // Good practice ``` -------------------------------- ### next_event example Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/api-reference/conev-api.md Example usage of the next_event function with a 100ms timeout. ```c int offs = 0, event_type = 0; struct eval *event = next_event(pool, &offs, &event_type, 100); // 100ms timeout if (event) { printf("Event type: 0x%x\n", event_type); } ``` -------------------------------- ### Example Configuration for Connection Denied Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/errors.md Example configurations that would trigger a S_ER_DENY error due to filtering rules. ```bash // Connection to 10.0.0.2:80 denied because 10.0.0.0/8 is blacklisted --hosts /etc/whitelist.txt --auto=none --ipset ":10.0.0.0/8" --auto=none ``` -------------------------------- ### Basic Usage Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/README.md Basic command-line usage examples for byedpi. ```bash # Simple SOCKS5 proxy on 127.0.0.1:1080 ciadpi # With DPI evasion (packet splitting) ciadpi --split 3+sm # With fake packets and TTL ciadpi --fake -1 --ttl 8 # Auto-detect blocking and apply different technique ciadpi --fake -1 --ttl 10 --auto=torst --timeout 3 --split 1+s ``` -------------------------------- ### Docker Compose Up Source: https://github.com/hufrea/byedpi/blob/main/dist/docker/README.md Command to start Docker containers defined in compose.yaml. ```sh docker compose up -d ``` -------------------------------- ### create_conn Function Example Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/api-reference/proxy-api.md Example of initiating an outbound connection to a remote server using the create_conn function. ```c union sockaddr_u remote_addr; inet_pton(AF_INET, "192.0.2.1", &remote_addr.in.sin_addr); remote_addr.in.sin_family = AF_INET; remote_addr.in.sin_port = htons(443); int result = create_conn(pool, client_event, &remote_addr, on_tunnel); if (result < 0) { fprintf(stderr, "Failed to create connection\n"); } ``` -------------------------------- ### post_desync Example Usage Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/api-reference/desync-api.md Example of calling post_desync after desync operations. ```c // After desync operations complete if (post_desync(server_fd, dp) < 0) { perror("post_desync failed"); } ``` -------------------------------- ### desync Example Usage Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/api-reference/desync-api.md Example demonstrating how to use the desync function and handle its return values. ```c struct desync_params *dp = val->dp; bool should_wait = false; ssize_t sent = desync(pool, val, buffer, &size, &should_wait); if (sent < 0) { perror("desync failed"); } else if (should_wait) { // Delay next packet transmission } ``` -------------------------------- ### mod_etype example Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/api-reference/conev-api.md Example of switching to monitoring for write readiness using mod_etype. ```c // Switch to monitoring for write readiness if (mod_etype(pool, event, POLLOUT) < 0) { perror("Failed to modify event type"); } ``` -------------------------------- ### Cache Format Example Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/api-reference/mpool-api.md Example of cache file format for the --cache-file option. ```text 192.0.2.1 443 0 1653456789 example.com 10.0.0.1 80 1 1653456790 test.com ``` -------------------------------- ### init_pool example Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/api-reference/conev-api.md Example of initializing an event pool with a capacity for 512 concurrent connections. ```c struct poolhd *pool = init_pool(512); // Support 512 concurrent connections if (!pool) { perror("Failed to initialize event pool"); return -1; } // Use pool for managing connections... destroy_pool(pool); ``` -------------------------------- ### add_pair example Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/api-reference/conev-api.md Example of creating a bidirectional connection pair after accepting a client and establishing a server connection. ```c // After accepting a client connection and creating server connection struct eval *server_event = add_pair(pool, client_event, server_fd, POLLIN); if (!server_event) { perror("Failed to add pair"); close(server_fd); return -1; } // client_event->pair == server_event // server_event->pair == client_event ``` -------------------------------- ### part_tls example usage Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/api-reference/packets-api.md Example of how to use the part_tls function to split a TLS ClientHello. ```c char tls_buffer[2048]; memcpy(tls_buffer, original_tls, original_size); // Split at position 100 to confuse DPI int new_size = part_tls(tls_buffer, sizeof(tls_buffer), original_size, 100); if (new_size > 0) { send(socket, tls_buffer, new_size, 0); } ``` -------------------------------- ### HTTP CONNECT Response Example (Success) Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/endpoints.md Example of a successful HTTP CONNECT response. ```http HTTP/1.1 200 Connection Established ``` -------------------------------- ### Request Round Filter Examples Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/configuration.md Examples for using --round to filter desync application based on the request number. ```bash ciadpi --round 1 --split 3 # First request only ciadpi --round 2-10 --split 3 # Requests 2-10 ``` -------------------------------- ### resp_error Example Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/api-reference/proxy-api.md Example of sending a SOCKS5 connection refused error using resp_error. ```c // Send SOCKS5 connection refused error int result = resp_error(client_fd, S_ER_CONN, FLAG_S5); if (result < 0) { perror("Failed to send error response"); } ``` -------------------------------- ### HTTP CONNECT Request Example Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/endpoints.md Example of an HTTP CONNECT request for establishing a tunnel. ```http CONNECT example.com:443 HTTP/1.1 Host: example.com:443 Connection: close ``` -------------------------------- ### Checking service status Source: https://github.com/hufrea/byedpi/blob/main/dist/bsd/README.md Command to check the status of the byedpi system service. ```sh sudo service byedpi status ``` -------------------------------- ### Filter Checking Example Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/api-reference/extend-api.md Complete example showing filter evaluation using check_l34. ```c struct desync_params *dp = val->dp; int protocol_type = determine_protocol(buffer, size); if (!check_l34(dp, protocol_type, &val->addr)) { // Connection doesn't match filters - skip desync return 0; } // Connection matches filters - apply desync ssize_t sent = desync(pool, val, buff, &n, &wait); if (sent < 0) { perror("desync failed"); return -1; } ``` -------------------------------- ### setttl Example Usage Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/api-reference/desync-api.md Example demonstrating how to use the setttl function to set a low TTL for fake packets. ```c // Set TTL to 8 for fake packets if (setttl(socket_fd, 8) < 0) { perror("Failed to set TTL"); } // Now packets sent on this socket will have TTL=8 ``` -------------------------------- ### Configure as User Systemd Service Source: https://github.com/hufrea/byedpi/blob/main/dist/linux/README.md Instructions to set up byedpi as a user-specific systemd service. ```shell cp byedpi.service ~/.config/systemd/user/ cp byedpi.conf ~/.config/ systemctl --user enable --now byedpi.service ``` -------------------------------- ### Configure as System Systemd Service Source: https://github.com/hufrea/byedpi/blob/main/dist/linux/README.md Instructions to set up byedpi as a system-wide systemd service. ```shell sudo cp byedpi.service /etc/systemd/system/ sudo cp byedpi.conf /etc/ sudo systemctl enable --now byedpi.service ``` -------------------------------- ### struct eval Lifecycle - Creation Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/endpoints.md Code snippet showing the initial event setup for a client connection. ```c add_event(pool, on_request, client_fd, POLLIN) ``` -------------------------------- ### Part Structure Example Usage Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/api-reference/desync-api.md Example of defining a part for splitting at a specific position within the SNI. ```c // Split at position 3 within SNI struct part split_sni = { .m = DESYNC_SPLIT, .flag = OFFSET_SNI + OFFSET_MID, .pos = 3, .r = 1, .s = 0 }; ``` -------------------------------- ### parse_tls Example Usage Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/api-reference/packets-api.md Example of how to use the parse_tls function to extract SNI. ```c char *hostname = NULL; int host_len = parse_tls(tls_data, tls_size, &hostname); if (host_len > 0) { printf("SNI: %.*s\n", host_len, hostname); } ``` -------------------------------- ### add_event example Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/api-reference/conev-api.md Example of adding a new event to monitor a client file descriptor for incoming data (POLLIN). ```c struct eval *event = add_event(pool, on_client_request, client_fd, POLLIN); if (!event) { perror("Failed to add event"); close(client_fd); return -1; } ``` -------------------------------- ### Timeout-Based Error Recovery Example Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/errors.md Illustrates retry logic with --auto and --timeout parameters. ```bash Connect attempt 1 → Timeout → Retry with group 2 Connect attempt 2 → Timeout → Retry with group 3 ``` -------------------------------- ### load_cache example usage Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/api-reference/mpool-api.md Example of how to use the load_cache function to load cached desync parameters from a file. ```c FILE *cache_file = fopen("desync_cache.txt", "r"); if (cache_file) { load_cache(params.mempool, cache_file, params.dp); fclose(cache_file); } ``` -------------------------------- ### dump_cache example usage Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/api-reference/mpool-api.md Example of how to use the dump_cache function to export cached desync parameters to a file. ```c FILE *cache_file = fopen("desync_cache.txt", "w"); if (cache_file) { dump_cache(params.mempool, cache_file, NULL); fclose(cache_file); } ``` -------------------------------- ### destroy_pool example Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/api-reference/conev-api.md Example of destroying the event pool and setting the pointer to NULL. ```c destroy_pool(pool); pool = NULL; // Good practice to NULL the pointer ``` -------------------------------- ### Timeout-Based Error Recovery Configuration Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/errors.md Example configuration for timeout-based error recovery. ```bash --fake -1 --ttl 10 --auto=torst --timeout 3 \ --split 1 --disorder 3 --ttl 5 --auto=torst \ --tlsrec 0+s --auto=torst ``` -------------------------------- ### mod_http example usage Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/api-reference/packets-api.md Example of how to use the mod_http function with MH_HMIX and MH_SPACE flags. ```c char http_buffer[1024]; memcpy(http_buffer, original_http, http_size); // Randomize Host header and add space obfuscation if (mod_http(http_buffer, http_size, MH_HMIX | MH_SPACE) < 0) { perror("HTTP modification failed"); } ``` -------------------------------- ### Check User Systemd Service Status Source: https://github.com/hufrea/byedpi/blob/main/dist/linux/README.md Command to verify the status of the user systemd service. ```shell systemctl --user status byedpi.service ``` -------------------------------- ### Check System Systemd Service Status Source: https://github.com/hufrea/byedpi/blob/main/dist/linux/README.md Command to verify the status of the system systemd service. ```shell systemctl status byedpi.service ``` -------------------------------- ### map_fix Function Example Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/api-reference/proxy-api.md Example illustrating the conversion between IPv4 and IPv6-mapped IPv4 addresses using the map_fix function. ```c union sockaddr_u addr; addr.in.sin_family = AF_INET; inet_pton(AF_INET, "192.168.1.1", &addr.in.sin_addr); map_fix(&addr, 1); // Convert to IPv6-mapped format // Now addr.sa.sa_family == AF_INET6 map_fix(&addr, 0); // Convert back to IPv4 // Now addr.sa.sa_family == AF_INET ``` -------------------------------- ### SOCKS5 CONNECT Flow - Proxy → Client (Method Selection) Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/endpoints.md Example of the SOCKS5 method selection response from the proxy to the client. ```hex 05 00 (version 5, method 0 - no auth) ``` -------------------------------- ### SOCKS5 CONNECT Flow - Client → Proxy (Method Negotiation) Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/endpoints.md Example of the initial SOCKS5 method negotiation request from the client to the proxy. ```hex 05 01 00 (version 5, 1 method, no auth) ``` -------------------------------- ### SHTONA Macro Example Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/api-reference/packets-api.md Writes uint16_t value x in network byte order to bytes at position i. ```c uint16_t port = htons(443); SHTONA(buffer, 10, port); ``` -------------------------------- ### SOCKS5 CONNECT Flow - Proxy → Client (Success Response) Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/endpoints.md Example of the SOCKS5 success response from the proxy to the client after establishing the connection. ```hex 05 00 00 01 C0 A8 01 64 01 BB (v5, success, reserved, IPv4, address, port) ``` -------------------------------- ### SOCKS5 CONNECT Flow - Client → Proxy (Connect Request) Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/endpoints.md Example of the SOCKS5 CONNECT request from the client to the proxy, including target address and port. ```hex 05 01 00 01 C0 A8 01 64 01 BB (v5, connect, reserved, IPv4, 192.168.1.100, port 443) ``` -------------------------------- ### Build Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/README.md Build instructions for byedpi. ```bash make # Linux make windows # Windows with mingw ``` -------------------------------- ### change_tls_sni Example Usage Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/api-reference/packets-api.md Example of how to use the change_tls_sni function to modify SNI. ```c char tls_buffer[2048]; memcpy(tls_buffer, original_tls, original_size); int new_size = change_tls_sni("example.com", tls_buffer, 11, original_size); if (new_size > 0) { send(socket, tls_buffer, new_size, 0); } ``` -------------------------------- ### del_event example Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/api-reference/conev-api.md Example of closing a connection and cleaning up the associated event structure. ```c // Close connection and clean up event del_event(pool, client_event); // client_event->fd is now -1 ``` -------------------------------- ### struct params Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/types.md Global parameters and configuration. ```c struct params { int dp_n; struct desync_params *dp; uint64_t dp_full_mask; int await_int; bool wait_send; int def_ttl; bool custom_ttl; bool tfo; unsigned int timeout, ptimeout; int to_count_lim; int to_bytes_lim; char cache_pre; int mode; bool ipv6; bool resolve; bool udp; bool delay_conn; bool auto_reconnect; int max_open; int debug; size_t bfsize; union sockaddr_u baddr; union sockaddr_u laddr; struct mphdr *mempool; char **need_free; int need_free_n; const char *protect_path; bool daemonize; const char *pid_file; int pid_fd; }; ``` -------------------------------- ### Global Configuration Defaults Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/configuration.md Default parameters for the 'params' struct in C. ```c struct params params = { .await_int = 10, // Internal event loop interval (ms) .ipv6 = 1, // IPv6 support enabled .resolve = 1, // Domain name resolution enabled .udp = 1, // UDP support enabled .max_open = 512, // Max concurrent connections .bfsize = 16384, // Buffer size .debug = 0, // No debug output .laddr.in.sin_port = htons(1080), // Port 1080 }; ``` -------------------------------- ### Run Docker Container Source: https://github.com/hufrea/byedpi/blob/main/dist/docker/README.md Command to run the byedpi container and display help. ```sh docker run -it --rm hufrea/byedpi --help ``` -------------------------------- ### PID File Initialization Function Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/errors.md Function signature for initializing a PID file. ```c int init_pid_file(const char *fname) ``` -------------------------------- ### Build Docker Image Source: https://github.com/hufrea/byedpi/blob/main/dist/docker/README.md Command to build a Docker container image from the source. ```sh docker build . --tag my/byedpi ``` -------------------------------- ### ANTOHS Macro Example Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/api-reference/packets-api.md Converts two bytes at position i in data to network byte order uint16_t. ```c uint16_t port = ANTOHS(buffer, 10); ``` -------------------------------- ### Enable Debug Logging Command Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/errors.md Command to enable debug logging and redirect output to a file. ```bash ciadpi -x 2 2>&1 | tee ciadpi.log ``` -------------------------------- ### on_connect Function Signature Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/api-reference/proxy-api.md Handles successful connection events to remote servers. ```c int on_connect(struct poolhd *pool, struct eval *val, int et); ``` -------------------------------- ### SOCKS5 Authentication Negotiation - Client Initial Request Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/endpoints.md Client initial request for SOCKS5 authentication (Method Selection). ```protobuf +----+----------+----------+ |VER | NMETHODS | METHODS | +----+----------+----------+ | 1 | 1 | 1 to 255 | ``` -------------------------------- ### Common Patterns Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/README.md Common usage patterns for byedpi. ```bash #### Linux: Basic Evasion ```bash ciadpi --disorder 1 ``` #### Windows: Reliable Splitting ```bash ciadpi --split 1+s --disorder 3+s ``` #### Advanced: Multi-Strategy ```bash ciadpi \ --fake -1 --ttl 8 --md5sig \ --auto=torst --timeout 3 \ --split 1+s --disorder 3+s --fake -1 --ttl 5 \ --cache-file /tmp/cache.txt ``` -------------------------------- ### on_request Function Signature Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/api-reference/proxy-api.md Handles initial SOCKS protocol requests from clients. ```c int on_request(struct poolhd *pool, struct eval *val, int et); ``` -------------------------------- ### Pool Initialization Function Source: https://github.com/hufrea/byedpi/blob/main/_autodocs/errors.md Function signature for initializing an event pool. ```c struct poolhd *init_pool(int count) ```