From a732dfb80788e5e55d01823a43a4b2f9f9eb34e3 Mon Sep 17 00:00:00 2001 From: alterdekim Date: Mon, 30 Sep 2024 03:33:59 +0300 Subject: [PATCH] First commit --- build.gradle | 69 +++++++ proguard-rules.pro | 21 +++ src/main/AndroidManifest.xml | 44 +++++ .../com/alterdekim/fridaapp/MainActivity.java | 52 ++++++ .../fridaapp/service/FridaService.java | 82 +++++++++ .../service/NativeBinaryConnection.java | 47 +++++ .../drawable-v24/ic_launcher_foreground.xml | 30 ++++ .../res/drawable/ic_launcher_background.xml | 170 ++++++++++++++++++ src/main/res/layout/activity_main.xml | 19 ++ .../res/mipmap-anydpi-v26/ic_launcher.xml | 6 + .../mipmap-anydpi-v26/ic_launcher_round.xml | 6 + src/main/res/mipmap-hdpi/ic_launcher.webp | Bin 0 -> 1404 bytes .../res/mipmap-hdpi/ic_launcher_round.webp | Bin 0 -> 2898 bytes src/main/res/mipmap-mdpi/ic_launcher.webp | Bin 0 -> 982 bytes .../res/mipmap-mdpi/ic_launcher_round.webp | Bin 0 -> 1772 bytes src/main/res/mipmap-xhdpi/ic_launcher.webp | Bin 0 -> 1900 bytes .../res/mipmap-xhdpi/ic_launcher_round.webp | Bin 0 -> 3918 bytes src/main/res/mipmap-xxhdpi/ic_launcher.webp | Bin 0 -> 2884 bytes .../res/mipmap-xxhdpi/ic_launcher_round.webp | Bin 0 -> 5914 bytes src/main/res/mipmap-xxxhdpi/ic_launcher.webp | Bin 0 -> 3844 bytes .../res/mipmap-xxxhdpi/ic_launcher_round.webp | Bin 0 -> 7778 bytes src/main/res/values-night/themes.xml | 7 + src/main/res/values/colors.xml | 5 + src/main/res/values/strings.xml | 3 + src/main/res/values/themes.xml | 9 + src/main/res/xml/backup_rules.xml | 13 ++ src/main/res/xml/data_extraction_rules.xml | 19 ++ 27 files changed, 602 insertions(+) create mode 100644 build.gradle create mode 100644 proguard-rules.pro create mode 100644 src/main/AndroidManifest.xml create mode 100644 src/main/java/com/alterdekim/fridaapp/MainActivity.java create mode 100644 src/main/java/com/alterdekim/fridaapp/service/FridaService.java create mode 100644 src/main/java/com/alterdekim/fridaapp/service/NativeBinaryConnection.java create mode 100644 src/main/res/drawable-v24/ic_launcher_foreground.xml create mode 100644 src/main/res/drawable/ic_launcher_background.xml create mode 100644 src/main/res/layout/activity_main.xml create mode 100644 src/main/res/mipmap-anydpi-v26/ic_launcher.xml create mode 100644 src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml create mode 100644 src/main/res/mipmap-hdpi/ic_launcher.webp create mode 100644 src/main/res/mipmap-hdpi/ic_launcher_round.webp create mode 100644 src/main/res/mipmap-mdpi/ic_launcher.webp create mode 100644 src/main/res/mipmap-mdpi/ic_launcher_round.webp create mode 100644 src/main/res/mipmap-xhdpi/ic_launcher.webp create mode 100644 src/main/res/mipmap-xhdpi/ic_launcher_round.webp create mode 100644 src/main/res/mipmap-xxhdpi/ic_launcher.webp create mode 100644 src/main/res/mipmap-xxhdpi/ic_launcher_round.webp create mode 100644 src/main/res/mipmap-xxxhdpi/ic_launcher.webp create mode 100644 src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp create mode 100644 src/main/res/values-night/themes.xml create mode 100644 src/main/res/values/colors.xml create mode 100644 src/main/res/values/strings.xml create mode 100644 src/main/res/values/themes.xml create mode 100644 src/main/res/xml/backup_rules.xml create mode 100644 src/main/res/xml/data_extraction_rules.xml diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..ed36812 --- /dev/null +++ b/build.gradle @@ -0,0 +1,69 @@ +plugins { + id "de.undercouch.download" version "5.6.0" + alias(libs.plugins.androidApplication) +} + +android { + namespace 'com.alterdekim.fridaapp' + compileSdk 34 + + defaultConfig { + applicationId "com.alterdekim.fridaapp" + minSdk 21 + targetSdk 34 + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + + packagingOptions.doNotStrip "**/*.so" +} + +tasks.withType(JavaCompile) { + compileTask -> + { + compileTask.dependsOn(downloadAarch) + compileTask.dependsOn(downloadArmeabi) + compileTask.dependsOn(downloadx86) + } +} + +task downloadAarch(type: Download) { + src 'https://jenkins.awain.net/job/Frida-android-binaries/lastSuccessfulBuild/artifact/jniLibs/arm64-v8a/frida.so' + dest layout.projectDirectory.file('jniLibs/arm64-v8a/frida.so') +} + +task downloadArmeabi(type: Download) { + src 'https://jenkins.awain.net/job/Frida-android-binaries/lastSuccessfulBuild/artifact/jniLibs/armeabi-v7a/frida.so' + dest layout.projectDirectory.file('jniLibs/armeabi-v7a/frida.so') +} + +task downloadx86(type: Download) { + src 'https://jenkins.awain.net/job/Frida-android-binaries/lastSuccessfulBuild/artifact/jniLibs/x86/frida.so' + dest layout.projectDirectory.file('jniLibs/x86/frida.so') +} + +dependencies { + implementation libs.okhttp + implementation libs.ground.crockford32 + implementation libs.ktsh + implementation libs.appcompat + implementation libs.material + implementation libs.activity + implementation libs.constraintlayout + testImplementation libs.junit + androidTestImplementation libs.ext.junit + androidTestImplementation libs.espresso.core +} \ No newline at end of file diff --git a/proguard-rules.pro b/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml new file mode 100644 index 0000000..9f7dc8b --- /dev/null +++ b/src/main/AndroidManifest.xml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/java/com/alterdekim/fridaapp/MainActivity.java b/src/main/java/com/alterdekim/fridaapp/MainActivity.java new file mode 100644 index 0000000..5d3cb9c --- /dev/null +++ b/src/main/java/com/alterdekim/fridaapp/MainActivity.java @@ -0,0 +1,52 @@ +package com.alterdekim.fridaapp; + +import android.content.Intent; +import android.net.VpnService; +import android.os.Bundle; +import android.view.View; + +import androidx.activity.EdgeToEdge; +import androidx.activity.result.ActivityResultLauncher; +import androidx.activity.result.contract.ActivityResultContracts; +import androidx.appcompat.app.AppCompatActivity; +import androidx.core.graphics.Insets; +import androidx.core.view.ViewCompat; +import androidx.core.view.WindowInsetsCompat; + +import com.alterdekim.fridaapp.service.FridaService; + +public class MainActivity extends AppCompatActivity { + private static final String TAG = MainActivity.class.getSimpleName(); + + private final ActivityResultLauncher launcher = registerForActivityResult( + new ActivityResultContracts.StartActivityForResult(), + result -> { + if (result.getResultCode() == RESULT_OK) { + startService(new Intent(this, FridaService.class)); + } + } + ); + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + EdgeToEdge.enable(this); + setContentView(R.layout.activity_main); + ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> { + Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars()); + v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom); + return insets; + }); + + findViewById(R.id.start_btn).setOnClickListener(view -> startVpn()); + } + + private void startVpn() { + Intent intent = VpnService.prepare(MainActivity.this); + if (intent != null) { + launcher.launch(intent); + } else { + onActivityResult(0, RESULT_OK, null); + } + } +} \ No newline at end of file diff --git a/src/main/java/com/alterdekim/fridaapp/service/FridaService.java b/src/main/java/com/alterdekim/fridaapp/service/FridaService.java new file mode 100644 index 0000000..ba38ea7 --- /dev/null +++ b/src/main/java/com/alterdekim/fridaapp/service/FridaService.java @@ -0,0 +1,82 @@ +package com.alterdekim.fridaapp.service; + +import android.app.PendingIntent; +import android.content.Intent; +import android.net.VpnService; +import android.os.ParcelFileDescriptor; +import android.util.Log; + +import com.alterdekim.fridaapp.R; + +import java.io.IOException; +import java.util.Objects; + +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.Response; + +public class FridaService extends VpnService { + private static final String TAG = FridaService.class.getSimpleName(); + private static final String VPN_ADDRESS = "10.66.66.6"; // Only IPv4 support for now + private static final String VPN_ROUTE = "0.0.0.0"; // Intercept everything + + private ParcelFileDescriptor vpnInterface = null; + private PendingIntent pendingIntent; + + + @Override + public void onCreate() { + setupVPN(); + Log.i(TAG, "Started"); + + Thread t = new Thread(new NativeBinaryConnection(vpnInterface.detachFd(), getApplicationContext().getApplicationInfo().nativeLibraryDir)); + t.start(); + + new Thread(new Runnable() { + @Override + public void run() { + OkHttpClient client = new OkHttpClient(); + + + Request request = new Request.Builder() + .url("https://google.com") + .build(); + try { + try (Response response = client.newCall(request).execute()) { + Log.i(TAG, "Response code: " + response.code()); + if (response.body() != null) { + Log.i(TAG, "Response body: " + response.body().string()); + } else { + Log.i(TAG, "Response body: null"); + } + } + } catch (IOException e) { + Log.e(TAG, Objects.requireNonNull(e.getMessage())); + } + } + }).start(); + } + + private void setupVPN() { + try { + //if (vpnInterface == null) { + Builder builder = new Builder(); + builder.addAddress(VPN_ADDRESS, 32); + builder.addRoute(VPN_ROUTE, 0); + //builder.addDnsServer("1.1.1.1"); + //builder.setMtu(1400); + //builder.addAllowedApplication(); + //builder.addDisallowedApplication(); + + vpnInterface = builder.setSession(getString(R.string.app_name)).setConfigureIntent(pendingIntent).establish(); + // } + } catch (Exception e) { + Log.e(TAG, "error", e); + } + } + + @Override + public int onStartCommand(Intent intent, int flags, int startId) { + return START_STICKY; + } +} diff --git a/src/main/java/com/alterdekim/fridaapp/service/NativeBinaryConnection.java b/src/main/java/com/alterdekim/fridaapp/service/NativeBinaryConnection.java new file mode 100644 index 0000000..347dcd5 --- /dev/null +++ b/src/main/java/com/alterdekim/fridaapp/service/NativeBinaryConnection.java @@ -0,0 +1,47 @@ +package com.alterdekim.fridaapp.service; + +import android.util.Log; + +import com.jaredrummler.ktsh.Shell; + +import java.io.BufferedReader; +import java.io.File; +import java.io.InputStreamReader; + +public class NativeBinaryConnection implements Runnable { + private static final String TAG = NativeBinaryConnection.class.getSimpleName(); + + private int fd = 0; + private String baseDir; + + public NativeBinaryConnection(int fd, String baseDir) { + this.fd = fd; + this.baseDir = baseDir; + } + + @Override + public void run() { + try { + Log.i(TAG, "FD: " + this.fd); + /* Shell shell = new Shell("sh"); + Shell.Command.Result result = shell.run(command); + Log.i(TAG, result.stdout()); + Log.i(TAG, result.stderr());*/ + ProcessBuilder p = new ProcessBuilder("./frida.so", "--fd", fd+"", "--config", "MNWGSZLOOQ5A2CRAEBYHE2LWMF2GKX3LMV4TUIDPMIYTKOBRNFVTMNZSGNTU6ZTKJ4XXS3DIO44WIVZLNRLTE2LCI5ZXISDVIJKVG42MK5MT2DIKEAQHA5LCNRUWGX3LMV4TUIDEMRBWGSSYIFIVS4SRHFWVIRTJOB2HOK3OK5WXOUJXG5IESSSQOAYEU3SLJ5GU6NCLIMYD2DIKEAQGCZDEOJSXG4Z2EAYTALRWGYXDMNROGYGQU43FOJ3GK4R2BUFCAIDQOVRGY2LDL5VWK6J2EBCUUTSROIZVUNKKJBWC65CDLFNC6UDDJZGGWTLTKMYGCS3OMZVGINCKMJ3DMVDVHE3EKTJ5BUFCAIDFNZSHA33JNZ2DUIBRGU4S4MJQGAXDCOBOHA4DUOBXHEZQ2CRAEBVWKZLQMFWGS5TFHIQDEMANBI======").directory(new File(baseDir)); + p.redirectErrorStream(true); + + Process pr = p.start(); + + BufferedReader in = new BufferedReader(new InputStreamReader(pr.getInputStream())); + String line; + while ((line = in.readLine()) != null) { + Log.i(TAG, line); + } + pr.waitFor(); + Log.i(TAG, "ok!"); + in.close(); + } catch (Exception e) { + Log.e(TAG, e.getMessage()); + } + } +} diff --git a/src/main/res/drawable-v24/ic_launcher_foreground.xml b/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000..2b068d1 --- /dev/null +++ b/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/res/drawable/ic_launcher_background.xml b/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..07d5da9 --- /dev/null +++ b/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/res/layout/activity_main.xml b/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..fab63b4 --- /dev/null +++ b/src/main/res/layout/activity_main.xml @@ -0,0 +1,19 @@ + + + +