diff --git a/app/src/main/cpp/native-lib.c b/app/src/main/cpp/native-lib.c index 6e3cbaf..21bb870 100644 --- a/app/src/main/cpp/native-lib.c +++ b/app/src/main/cpp/native-lib.c @@ -13,14 +13,22 @@ const enum demode DESYNC_METHODS[] = { DESYNC_NONE, DESYNC_SPLIT, DESYNC_DISORDER, - DESYNC_FAKE + DESYNC_FAKE, + DESYNC_OOB, }; extern int NOT_EXIT; -extern struct packet fake_tls, fake_http; + extern int get_default_ttl(); + extern int get_addr(const char *str, struct sockaddr_ina *addr); +JNIEXPORT jint JNICALL +Java_io_github_dovecoteescapee_byedpi_core_ByeDpiProxy_00024Companion_jniInit(JNIEnv *env, jobject thiz) { + oob_data.data = NULL; + return 0; +} + JNIEXPORT jint JNICALL Java_io_github_dovecoteescapee_byedpi_core_ByeDpiProxy_jniCreateSocket( JNIEnv *env, @@ -36,6 +44,8 @@ Java_io_github_dovecoteescapee_byedpi_core_ByeDpiProxy_jniCreateSocket( jint split_position, jboolean split_at_host, jint fake_ttl, + jstring fake_sni, + jstring custom_oob_data, jboolean host_mixed_case, jboolean domain_mixed_case, jboolean host_remove_spaces, @@ -52,6 +62,8 @@ Java_io_github_dovecoteescapee_byedpi_core_ByeDpiProxy_jniCreateSocket( if (get_addr(address, &s) < 0) { return -1; } + (*env)->ReleaseStringUTFChars(env, ip, address); + s.in.sin_port = htons(port); params.max_open = max_connections; @@ -83,6 +95,34 @@ Java_io_github_dovecoteescapee_byedpi_core_ByeDpiProxy_jniCreateSocket( return get_e(); } + if (params.attack == DESYNC_FAKE) { + const char *sni = (*env)->GetStringUTFChars(env, fake_sni, 0); + LOG(LOG_S, "fake_sni: %s", sni); + int res = change_tls_sni(sni, fake_tls.data, fake_tls.size); + (*env)->ReleaseStringUTFChars(env, fake_sni, sni); + if (res) { + fprintf(stderr, "error chsni\n"); + return -1; + } + } + + if (params.attack == DESYNC_OOB) { + const char *oob = (*env)->GetStringUTFChars(env, custom_oob_data, 0); + const size_t oob_len = strlen(oob); + LOG(LOG_L, "custom_oob_data: %s", oob); + oob_data.size = oob_len; + LOG(LOG_L, "before free"); + free(oob_data.data); + LOG(LOG_L, "after free"); + oob_data.data = malloc(oob_len); + if (oob_data.data == NULL) { + uniperror("malloc"); + return -1; + } + memcpy(oob_data.data, oob, oob_len); + (*env)->ReleaseStringUTFChars(env, custom_oob_data, oob); + } + LOG(LOG_S, "listen_socket, fd: %d", fd); return fd; } @@ -106,4 +146,4 @@ Java_io_github_dovecoteescapee_byedpi_core_ByeDpiProxy_jniStopProxy(JNIEnv *env, return get_e(); } return 0; -} \ No newline at end of file +} diff --git a/app/src/main/java/io/github/dovecoteescapee/byedpi/core/ByeDpiProxy.kt b/app/src/main/java/io/github/dovecoteescapee/byedpi/core/ByeDpiProxy.kt index 372eeb5..b85ef25 100644 --- a/app/src/main/java/io/github/dovecoteescapee/byedpi/core/ByeDpiProxy.kt +++ b/app/src/main/java/io/github/dovecoteescapee/byedpi/core/ByeDpiProxy.kt @@ -8,7 +8,10 @@ class ByeDpiProxy { companion object { init { System.loadLibrary("byedpi") + jniInit() } + + private external fun jniInit(): Int } private val mutex = Mutex() @@ -49,6 +52,8 @@ class ByeDpiProxy { splitPosition = preferences.splitPosition, splitAtHost = preferences.splitAtHost, fakeTtl = preferences.fakeTtl, + fakeSni = preferences.fakeSni, + oobData = preferences.oobData, hostMixedCase = preferences.hostMixedCase, domainMixedCase = preferences.domainMixedCase, hostRemoveSpaces = preferences.hostRemoveSpaces, @@ -77,6 +82,8 @@ class ByeDpiProxy { splitPosition: Int, splitAtHost: Boolean, fakeTtl: Int, + fakeSni: String, + oobData: String, hostMixedCase: Boolean, domainMixedCase: Boolean, hostRemoveSpaces: Boolean, diff --git a/app/src/main/java/io/github/dovecoteescapee/byedpi/core/ByeDpiProxyPreferences.kt b/app/src/main/java/io/github/dovecoteescapee/byedpi/core/ByeDpiProxyPreferences.kt index 5de1e64..cb33049 100644 --- a/app/src/main/java/io/github/dovecoteescapee/byedpi/core/ByeDpiProxyPreferences.kt +++ b/app/src/main/java/io/github/dovecoteescapee/byedpi/core/ByeDpiProxyPreferences.kt @@ -14,6 +14,8 @@ class ByeDpiProxyPreferences( splitPosition: Int? = null, splitAtHost: Boolean? = null, fakeTtl: Int? = null, + fakeSni: String? = null, + oobData: String? = null, hostMixedCase: Boolean? = null, domainMixedCase: Boolean? = null, hostRemoveSpaces: Boolean? = null, @@ -32,6 +34,8 @@ class ByeDpiProxyPreferences( val splitPosition: Int = splitPosition ?: 3 val splitAtHost: Boolean = splitAtHost ?: false val fakeTtl: Int = fakeTtl ?: 8 + val fakeSni: String = fakeSni ?: "www.w3c.org" + val oobData: String = oobData ?: "a" val hostMixedCase: Boolean = hostMixedCase ?: false val domainMixedCase: Boolean = domainMixedCase ?: false val hostRemoveSpaces: Boolean = hostRemoveSpaces ?: false @@ -52,6 +56,8 @@ class ByeDpiProxyPreferences( splitPosition = preferences.getString("byedpi_split_position", null)?.toIntOrNull(), splitAtHost = preferences.getBoolean("byedpi_split_at_host", false), fakeTtl = preferences.getString("byedpi_fake_ttl", null)?.toIntOrNull(), + fakeSni = preferences.getString("byedpi_fake_sni", null), + oobData = preferences.getString("byedpi_oob_data", null), hostMixedCase = preferences.getBoolean("byedpi_host_mixed_case", false), domainMixedCase = preferences.getBoolean("byedpi_domain_mixed_case", false), hostRemoveSpaces = preferences.getBoolean("byedpi_host_remove_spaces", false), @@ -64,7 +70,8 @@ class ByeDpiProxyPreferences( None, Split, Disorder, - Fake; + Fake, + OOB; companion object { fun fromName(name: String): DesyncMethod { @@ -73,6 +80,7 @@ class ByeDpiProxyPreferences( "split" -> Split "disorder" -> Disorder "fake" -> Fake + "oob" -> OOB else -> throw IllegalArgumentException("Unknown desync method: $name") } } diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index 6b27fa8..43c2f3c 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -25,11 +25,13 @@ Split Disorder Fake + Out-of-band none split disorder fake + oob diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index cd6688a..bc18012 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -49,4 +49,7 @@ ByeDPI VPN is running Proxy is running + General + ByeDPI + About \ No newline at end of file diff --git a/app/src/main/res/xml/settings.xml b/app/src/main/res/xml/settings.xml index 78d957a..f3fc482 100644 --- a/app/src/main/res/xml/settings.xml +++ b/app/src/main/res/xml/settings.xml @@ -4,8 +4,8 @@ xmlns:tools="http://schemas.android.com/tools" android:tag="settings_screen"> - + - + - + + + + + - + - + - +