From d0ece1d0c80d0e449d361f8f2aa395362026084d Mon Sep 17 00:00:00 2001 From: abcz316 Date: Fri, 3 Sep 2021 20:32:25 +0800 Subject: [PATCH 01/29] first commit --- README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 00000000..117e997d --- /dev/null +++ b/README.md @@ -0,0 +1,13 @@ + printf( + "======================================================\n" + "本工具名称: Linux ARM64 完美隐藏ROOT演示\n" + "本工具功能列表:\n" + "\t1.显示自身权限信息\n" + "\t2.获取ROOT权限\n" + "\t3.绕过SELinux\n" + "\t4.还原SELinux\n" + "\t5.执行ROOT权限级别的Shell命令\n" + "\t6.赋予ADB最高级别权限\n" + "\t新一代root,跟面具完全不同思路,摆脱面具被检测的弱点,完美隐藏root功能,挑战全网root检测手段,兼容安卓APP直接JNI调用,稳定、流畅、不闪退。\n" + "======================================================\n" + ); From 21a47a6bbd44ff2558aea8f87950f7847eb09fba Mon Sep 17 00:00:00 2001 From: abcz316 Date: Sat, 25 Sep 2021 00:51:39 +0800 Subject: [PATCH 02/29] fix error --- testRoot/main.cpp | 103 ++++++++++++++++++++++------------------------ 1 file changed, 50 insertions(+), 53 deletions(-) diff --git a/testRoot/main.cpp b/testRoot/main.cpp index ca905fee..f3731c22 100644 --- a/testRoot/main.cpp +++ b/testRoot/main.cpp @@ -1,4 +1,5 @@ #include +#include #include #include "super_root.h" @@ -27,11 +28,11 @@ void show_capability_info() FILE * fp = popen("getenforce", "r"); if (fp) { - char cmd[512] = { 0 }; - fread(cmd, 1, sizeof(cmd), fp); + char shell[512] = { 0 }; + fread(shell, 1, sizeof(shell), fp); pclose(fp); - printf("SELinux status: %s\n", cmd); + printf("SELinux status: %s\n", shell); } } void test_root() @@ -68,12 +69,20 @@ void test_enable_selinux() } -void test_run_cmd(char * cmd, bool bKeepAdbRoot = false) { - printf("inject_cmd_remote_process(%s)\n", cmd); +void test_run_adb_shell(char * shell, bool bKeepAdbRoot = false) { + printf("inject_shell_remote_process(%s)\n", shell); char szResult[0x1000] = { 0 }; - ssize_t ret = safe_inject_adb_process_run_cmd_wrapper(ROOT_KEY, cmd, bKeepAdbRoot, szResult, sizeof(szResult)); - printf("inject_cmd_remote_process ret val:%zd\n", ret); - printf("inject_cmd_remote_process result:%s\n", szResult); + ssize_t ret = safe_inject_adb_process_run_shell_wrapper(ROOT_KEY, shell, bKeepAdbRoot, szResult, sizeof(szResult)); + printf("inject_shell_remote_process ret val:%zd\n", ret); + printf("inject_shell_remote_process result:%s\n", szResult); +} + +void test_run_shell(char * shell) { + printf("test_run_shell(%s)\n", shell); + char szResult[0x1000] = { 0 }; + ssize_t ret = safe_run_shell(ROOT_KEY, shell, szResult, sizeof(szResult)); + printf("test_run_shell ret val:%zd\n", ret); + printf("test_run_shell result:%s\n", szResult); } int main(int argc, char *argv[]) @@ -86,8 +95,9 @@ int main(int argc, char *argv[]) "\t2.获取ROOT权限\n" "\t3.绕过SELinux\n" "\t4.还原SELinux\n" - "\t5.执行ROOT权限级别的Shell命令\n" - "\t6.赋予ADB最高级别权限\n" + "\t5.执行ROOT Shell命令\n" + "\t6.执行ADBShell命令\n" + "\t7.赋予ADB最高级别权限\n" "\t新一代root,跟面具完全不同思路,摆脱面具被检测的弱点,完美隐藏root功能,挑战全网root检测手段,兼容安卓APP直接JNI调用,稳定、流畅、不闪退。\n" "======================================================\n" ); @@ -97,51 +107,38 @@ int main(int argc, char *argv[]) --argc; - int cmdc; - char *cmdv[6]; - - while (argc) { - // Clean up - cmdc = 0; - memset(cmdv, 0, sizeof(cmdv)); - - // Split the commands - for (char *tok = strtok(argv[0], " "); tok; tok = strtok(nullptr, " ")) - { - cmdv[cmdc++] = tok; - if (cmdc == 0) - { - continue; - } - } - - - if (strcmp(cmdv[0], "show") == 0) { - show_capability_info(); - } - else if (strcmp(cmdv[0], "root") == 0) { - test_root(); - } - else if (strcmp(cmdv[0], "disable") == 0) { - test_disable_selinux(); - } - else if (strcmp(cmdv[0], "enable") == 0) { - test_enable_selinux(); - } - else if (strcmp(cmdv[0], "cmd") == 0) { - test_run_cmd("id"); - //test_run_cmd("id > /sdcard/run.txt"); - //test_run_cmd("insmod rwProcMem37.ko > /sdcard/run.txt"); - } - else if (strcmp(cmdv[0], "adb") == 0) { - test_run_cmd("id", true); + if (strcmp(argv[0], "show") == 0) { + show_capability_info(); + } + else if (strcmp(argv[0], "root") == 0) { + test_root(); + } + else if (argc >=2 && strcmp(argv[0], "selinux") == 0 && strcmp(argv[1], "disable") == 0) { + test_disable_selinux(); + } + else if (argc >= 2 && strcmp(argv[0], "selinux") == 0 && strcmp(argv[1], "enable") == 0) { + test_enable_selinux(); + } + else if (argc >= 2 && strcmp(argv[0], "shell") == 0) { + std::stringstream sstrCmd; + for (int i = 1; i < argc; i++) { + sstrCmd << argv[i]; } - else { - return 1; + test_run_shell((char*)sstrCmd.str().c_str()); + } + else if (argc > 2 && strcmp(argv[0], "adb") == 0 && strcmp(argv[1], "shell") == 0) { + std::stringstream sstrCmd; + for (int i = 2; i < argc; i++) { + sstrCmd << argv[i]; } - - --argc; - ++argv; + test_run_adb_shell((char*)sstrCmd.str().c_str()); + } + else if (argc >= 2 && strcmp(argv[0], "adb") == 0 && strcmp(argv[1], "root") == 0) { + test_run_adb_shell("id", true); } + else { + return 1; + } + return 0; } \ No newline at end of file From 7d5743373cad0f4a3c0e9fedfc348eecf57a4659 Mon Sep 17 00:00:00 2001 From: abcz316 Date: Sat, 25 Sep 2021 00:56:06 +0800 Subject: [PATCH 03/29] add --- find_kernel_func/empty | 0 ida_patch_cmd_creator/empty | 0 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 find_kernel_func/empty create mode 100644 ida_patch_cmd_creator/empty diff --git a/find_kernel_func/empty b/find_kernel_func/empty new file mode 100644 index 00000000..e69de29b diff --git a/ida_patch_cmd_creator/empty b/ida_patch_cmd_creator/empty new file mode 100644 index 00000000..e69de29b From 00e2d1b89a7fecd50c4957bf6deb99411a22f1f4 Mon Sep 17 00:00:00 2001 From: abcz316 Date: Sat, 25 Sep 2021 01:46:35 +0800 Subject: [PATCH 04/29] fix error --- testRoot/main.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/testRoot/main.cpp b/testRoot/main.cpp index f3731c22..066e52a0 100644 --- a/testRoot/main.cpp +++ b/testRoot/main.cpp @@ -77,10 +77,10 @@ void test_run_adb_shell(char * shell, bool bKeepAdbRoot = false) { printf("inject_shell_remote_process result:%s\n", szResult); } -void test_run_shell(char * shell) { +void test_run_root_shell(char * shell) { printf("test_run_shell(%s)\n", shell); char szResult[0x1000] = { 0 }; - ssize_t ret = safe_run_shell(ROOT_KEY, shell, szResult, sizeof(szResult)); + ssize_t ret = run_root_shell(ROOT_KEY, shell, szResult, sizeof(szResult)); printf("test_run_shell ret val:%zd\n", ret); printf("test_run_shell result:%s\n", szResult); } @@ -96,7 +96,7 @@ int main(int argc, char *argv[]) "\t3.绕过SELinux\n" "\t4.还原SELinux\n" "\t5.执行ROOT Shell命令\n" - "\t6.执行ADBShell命令\n" + "\t6.执行ADB Shell命令\n" "\t7.赋予ADB最高级别权限\n" "\t新一代root,跟面具完全不同思路,摆脱面具被检测的弱点,完美隐藏root功能,挑战全网root检测手段,兼容安卓APP直接JNI调用,稳定、流畅、不闪退。\n" "======================================================\n" @@ -124,7 +124,7 @@ int main(int argc, char *argv[]) for (int i = 1; i < argc; i++) { sstrCmd << argv[i]; } - test_run_shell((char*)sstrCmd.str().c_str()); + test_run_root_shell((char*)sstrCmd.str().c_str()); } else if (argc > 2 && strcmp(argv[0], "adb") == 0 && strcmp(argv[1], "shell") == 0) { std::stringstream sstrCmd; From 37f5533b6aa78f0f5c593b1c186e275cf626956d Mon Sep 17 00:00:00 2001 From: abcz316 Date: Sun, 10 Oct 2021 20:47:30 +0800 Subject: [PATCH 05/29] =?UTF-8?q?=E8=A1=A5=E5=85=85=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PermissionManager/.gitignore | 15 + PermissionManager/app/.gitignore | 1 + PermissionManager/app/build.gradle | 51 +++ PermissionManager/app/proguard-rules.pro | 21 ++ .../ExampleInstrumentedTest.java | 26 ++ .../app/src/main/AndroidManifest.xml | 21 ++ .../app/src/main/cpp/CMakeLists.txt | 50 +++ PermissionManager/app/src/main/cpp/root.cpp | 112 +++++++ .../linux/permissionmanager/MainActivity.java | 279 +++++++++++++++++ .../UsbDebugSwitchHelper.java | 41 +++ .../drawable-v24/ic_launcher_foreground.xml | 30 ++ .../res/drawable/ic_launcher_background.xml | 170 ++++++++++ .../app/src/main/res/layout/activity_main.xml | 169 ++++++++++ .../res/mipmap-anydpi-v26/ic_launcher.xml | 5 + .../mipmap-anydpi-v26/ic_launcher_round.xml | 5 + .../src/main/res/mipmap-hdpi/ic_launcher.png | Bin 0 -> 3593 bytes .../res/mipmap-hdpi/ic_launcher_round.png | Bin 0 -> 5339 bytes .../src/main/res/mipmap-mdpi/ic_launcher.png | Bin 0 -> 2636 bytes .../res/mipmap-mdpi/ic_launcher_round.png | Bin 0 -> 3388 bytes .../src/main/res/mipmap-xhdpi/ic_launcher.png | Bin 0 -> 4926 bytes .../res/mipmap-xhdpi/ic_launcher_round.png | Bin 0 -> 7472 bytes .../main/res/mipmap-xxhdpi/ic_launcher.png | Bin 0 -> 7909 bytes .../res/mipmap-xxhdpi/ic_launcher_round.png | Bin 0 -> 11873 bytes .../main/res/mipmap-xxxhdpi/ic_launcher.png | Bin 0 -> 10652 bytes .../res/mipmap-xxxhdpi/ic_launcher_round.png | Bin 0 -> 16570 bytes .../app/src/main/res/values-night/themes.xml | 16 + .../app/src/main/res/values/colors.xml | 10 + .../app/src/main/res/values/strings.xml | 3 + .../app/src/main/res/values/themes.xml | 16 + .../permissionmanager/ExampleUnitTest.java | 17 + PermissionManager/appKey.jks | Bin 0 -> 2192 bytes PermissionManager/build.gradle | 24 ++ PermissionManager/gradle.properties | 19 ++ .../gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 54329 bytes .../gradle/wrapper/gradle-wrapper.properties | 6 + PermissionManager/gradlew | 172 +++++++++++ PermissionManager/gradlew.bat | 84 +++++ PermissionManager/settings.gradle | 2 + README.md | 10 +- su/jni/Android.mk | 11 + su/jni/Application.mk | 2 + su/pts.cpp | 290 ++++++++++++++++++ su/pts.hpp | 99 ++++++ su/simple_su.cpp | 45 +++ su/socket.cpp | 183 +++++++++++ su/socket.hpp | 19 ++ su/su.cpp | 12 + su/su.h | 30 ++ su/su.vcxproj | 97 ++++++ su/su.vcxproj.filters | 26 ++ su/su.vcxproj.user | 4 + su/su_client.h | 197 ++++++++++++ su/su_daemon.h | 245 +++++++++++++++ suTest/.gitignore | 15 + suTest/app/.gitignore | 1 + suTest/app/build.gradle | 41 +++ suTest/app/proguard-rules.pro | 21 ++ .../linux/sutest/ExampleInstrumentedTest.java | 26 ++ suTest/app/src/main/AndroidManifest.xml | 24 ++ .../java/com/linux/sutest/MainActivity.java | 117 +++++++ .../drawable-v24/ic_launcher_foreground.xml | 30 ++ .../res/drawable/ic_launcher_background.xml | 170 ++++++++++ .../app/src/main/res/layout/activity_main.xml | 43 +++ suTest/app/src/main/res/menu/menu_main.xml | 10 + .../res/mipmap-anydpi-v26/ic_launcher.xml | 5 + .../mipmap-anydpi-v26/ic_launcher_round.xml | 5 + .../src/main/res/mipmap-hdpi/ic_launcher.png | Bin 0 -> 3593 bytes .../res/mipmap-hdpi/ic_launcher_round.png | Bin 0 -> 5339 bytes .../src/main/res/mipmap-mdpi/ic_launcher.png | Bin 0 -> 2636 bytes .../res/mipmap-mdpi/ic_launcher_round.png | Bin 0 -> 3388 bytes .../src/main/res/mipmap-xhdpi/ic_launcher.png | Bin 0 -> 4926 bytes .../res/mipmap-xhdpi/ic_launcher_round.png | Bin 0 -> 7472 bytes .../main/res/mipmap-xxhdpi/ic_launcher.png | Bin 0 -> 7909 bytes .../res/mipmap-xxhdpi/ic_launcher_round.png | Bin 0 -> 11873 bytes .../main/res/mipmap-xxxhdpi/ic_launcher.png | Bin 0 -> 10652 bytes .../res/mipmap-xxxhdpi/ic_launcher_round.png | Bin 0 -> 16570 bytes .../app/src/main/res/navigation/nav_graph.xml | 28 ++ .../app/src/main/res/values-night/themes.xml | 16 + suTest/app/src/main/res/values/colors.xml | 10 + suTest/app/src/main/res/values/dimens.xml | 3 + suTest/app/src/main/res/values/strings.xml | 12 + suTest/app/src/main/res/values/themes.xml | 25 ++ .../com/linux/sutest/ExampleUnitTest.java | 17 + suTest/build.gradle | 24 ++ suTest/gradle.properties | 19 ++ suTest/gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 54329 bytes .../gradle/wrapper/gradle-wrapper.properties | 6 + suTest/gradlew | 172 +++++++++++ suTest/gradlew.bat | 84 +++++ suTest/settings.gradle | 2 + testRoot/README.md | 10 +- testRoot/adb64_inject.h | 18 ++ testRoot/env64_inject.cpp | 231 ++++++++++++++ testRoot/env64_inject.h | 18 ++ testRoot/jni/Android.mk | 2 +- testRoot/maps_helper.cpp | 74 +++++ testRoot/maps_helper.h | 18 ++ testRoot/ptrace_arm64_utils.cpp | 3 +- testRoot/ptrace_arm64_utils.h | 6 +- testRoot/{main.cpp => testRoot.cpp} | 89 ++++-- testRoot/testRoot.h | 50 +++ testRoot/testRoot.vcxproj | 11 +- testRoot/testRoot.vcxproj.filters | 11 +- 103 files changed, 4060 insertions(+), 42 deletions(-) create mode 100644 PermissionManager/.gitignore create mode 100644 PermissionManager/app/.gitignore create mode 100644 PermissionManager/app/build.gradle create mode 100644 PermissionManager/app/proguard-rules.pro create mode 100644 PermissionManager/app/src/androidTest/java/com/linux/permissionmanager/ExampleInstrumentedTest.java create mode 100644 PermissionManager/app/src/main/AndroidManifest.xml create mode 100644 PermissionManager/app/src/main/cpp/CMakeLists.txt create mode 100644 PermissionManager/app/src/main/cpp/root.cpp create mode 100644 PermissionManager/app/src/main/java/com/linux/permissionmanager/MainActivity.java create mode 100644 PermissionManager/app/src/main/java/com/linux/permissionmanager/UsbDebugSwitchHelper.java create mode 100644 PermissionManager/app/src/main/res/drawable-v24/ic_launcher_foreground.xml create mode 100644 PermissionManager/app/src/main/res/drawable/ic_launcher_background.xml create mode 100644 PermissionManager/app/src/main/res/layout/activity_main.xml create mode 100644 PermissionManager/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml create mode 100644 PermissionManager/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml create mode 100644 PermissionManager/app/src/main/res/mipmap-hdpi/ic_launcher.png create mode 100644 PermissionManager/app/src/main/res/mipmap-hdpi/ic_launcher_round.png create mode 100644 PermissionManager/app/src/main/res/mipmap-mdpi/ic_launcher.png create mode 100644 PermissionManager/app/src/main/res/mipmap-mdpi/ic_launcher_round.png create mode 100644 PermissionManager/app/src/main/res/mipmap-xhdpi/ic_launcher.png create mode 100644 PermissionManager/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png create mode 100644 PermissionManager/app/src/main/res/mipmap-xxhdpi/ic_launcher.png create mode 100644 PermissionManager/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png create mode 100644 PermissionManager/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png create mode 100644 PermissionManager/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png create mode 100644 PermissionManager/app/src/main/res/values-night/themes.xml create mode 100644 PermissionManager/app/src/main/res/values/colors.xml create mode 100644 PermissionManager/app/src/main/res/values/strings.xml create mode 100644 PermissionManager/app/src/main/res/values/themes.xml create mode 100644 PermissionManager/app/src/test/java/com/linux/permissionmanager/ExampleUnitTest.java create mode 100644 PermissionManager/appKey.jks create mode 100644 PermissionManager/build.gradle create mode 100644 PermissionManager/gradle.properties create mode 100644 PermissionManager/gradle/wrapper/gradle-wrapper.jar create mode 100644 PermissionManager/gradle/wrapper/gradle-wrapper.properties create mode 100644 PermissionManager/gradlew create mode 100644 PermissionManager/gradlew.bat create mode 100644 PermissionManager/settings.gradle create mode 100644 su/jni/Android.mk create mode 100644 su/jni/Application.mk create mode 100644 su/pts.cpp create mode 100644 su/pts.hpp create mode 100644 su/simple_su.cpp create mode 100644 su/socket.cpp create mode 100644 su/socket.hpp create mode 100644 su/su.cpp create mode 100644 su/su.h create mode 100644 su/su.vcxproj create mode 100644 su/su.vcxproj.filters create mode 100644 su/su.vcxproj.user create mode 100644 su/su_client.h create mode 100644 su/su_daemon.h create mode 100644 suTest/.gitignore create mode 100644 suTest/app/.gitignore create mode 100644 suTest/app/build.gradle create mode 100644 suTest/app/proguard-rules.pro create mode 100644 suTest/app/src/androidTest/java/com/linux/sutest/ExampleInstrumentedTest.java create mode 100644 suTest/app/src/main/AndroidManifest.xml create mode 100644 suTest/app/src/main/java/com/linux/sutest/MainActivity.java create mode 100644 suTest/app/src/main/res/drawable-v24/ic_launcher_foreground.xml create mode 100644 suTest/app/src/main/res/drawable/ic_launcher_background.xml create mode 100644 suTest/app/src/main/res/layout/activity_main.xml create mode 100644 suTest/app/src/main/res/menu/menu_main.xml create mode 100644 suTest/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml create mode 100644 suTest/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml create mode 100644 suTest/app/src/main/res/mipmap-hdpi/ic_launcher.png create mode 100644 suTest/app/src/main/res/mipmap-hdpi/ic_launcher_round.png create mode 100644 suTest/app/src/main/res/mipmap-mdpi/ic_launcher.png create mode 100644 suTest/app/src/main/res/mipmap-mdpi/ic_launcher_round.png create mode 100644 suTest/app/src/main/res/mipmap-xhdpi/ic_launcher.png create mode 100644 suTest/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png create mode 100644 suTest/app/src/main/res/mipmap-xxhdpi/ic_launcher.png create mode 100644 suTest/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png create mode 100644 suTest/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png create mode 100644 suTest/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png create mode 100644 suTest/app/src/main/res/navigation/nav_graph.xml create mode 100644 suTest/app/src/main/res/values-night/themes.xml create mode 100644 suTest/app/src/main/res/values/colors.xml create mode 100644 suTest/app/src/main/res/values/dimens.xml create mode 100644 suTest/app/src/main/res/values/strings.xml create mode 100644 suTest/app/src/main/res/values/themes.xml create mode 100644 suTest/app/src/test/java/com/linux/sutest/ExampleUnitTest.java create mode 100644 suTest/build.gradle create mode 100644 suTest/gradle.properties create mode 100644 suTest/gradle/wrapper/gradle-wrapper.jar create mode 100644 suTest/gradle/wrapper/gradle-wrapper.properties create mode 100644 suTest/gradlew create mode 100644 suTest/gradlew.bat create mode 100644 suTest/settings.gradle create mode 100644 testRoot/adb64_inject.h create mode 100644 testRoot/env64_inject.cpp create mode 100644 testRoot/env64_inject.h create mode 100644 testRoot/maps_helper.cpp create mode 100644 testRoot/maps_helper.h rename testRoot/{main.cpp => testRoot.cpp} (51%) create mode 100644 testRoot/testRoot.h diff --git a/PermissionManager/.gitignore b/PermissionManager/.gitignore new file mode 100644 index 00000000..643d213c --- /dev/null +++ b/PermissionManager/.gitignore @@ -0,0 +1,15 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +.cxx +local.properties diff --git a/PermissionManager/app/.gitignore b/PermissionManager/app/.gitignore new file mode 100644 index 00000000..42afabfd --- /dev/null +++ b/PermissionManager/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/PermissionManager/app/build.gradle b/PermissionManager/app/build.gradle new file mode 100644 index 00000000..4a6c8874 --- /dev/null +++ b/PermissionManager/app/build.gradle @@ -0,0 +1,51 @@ +plugins { + id 'com.android.application' +} + +android { + compileSdkVersion 29 + buildToolsVersion "29.0.3" + + defaultConfig { + applicationId "com.linux.permissionmanager" + minSdkVersion 26 + targetSdkVersion 29 + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + externalNativeBuild { + cmake { + cppFlags "-std=c++17" + abiFilters "arm64-v8a" //需要什么构架的so,就在这边添加即 + } + } + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + externalNativeBuild { + cmake { + path "src/main/cpp/CMakeLists.txt" + version "3.10.2" + } + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } +} + +dependencies { + + implementation 'androidx.appcompat:appcompat:1.2.0' + implementation 'com.google.android.material:material:1.3.0' + implementation 'androidx.constraintlayout:constraintlayout:2.0.4' + testImplementation 'junit:junit:4.+' + androidTestImplementation 'androidx.test.ext:junit:1.1.2' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' +} \ No newline at end of file diff --git a/PermissionManager/app/proguard-rules.pro b/PermissionManager/app/proguard-rules.pro new file mode 100644 index 00000000..64b4a059 --- /dev/null +++ b/PermissionManager/app/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/PermissionManager/app/src/androidTest/java/com/linux/permissionmanager/ExampleInstrumentedTest.java b/PermissionManager/app/src/androidTest/java/com/linux/permissionmanager/ExampleInstrumentedTest.java new file mode 100644 index 00000000..d7eca3a4 --- /dev/null +++ b/PermissionManager/app/src/androidTest/java/com/linux/permissionmanager/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.linux.permissionmanager; + +import android.content.Context; + +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.ext.junit.runners.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); + assertEquals("com.linux.permissionmanager", appContext.getPackageName()); + } +} \ No newline at end of file diff --git a/PermissionManager/app/src/main/AndroidManifest.xml b/PermissionManager/app/src/main/AndroidManifest.xml new file mode 100644 index 00000000..37686dd9 --- /dev/null +++ b/PermissionManager/app/src/main/AndroidManifest.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/PermissionManager/app/src/main/cpp/CMakeLists.txt b/PermissionManager/app/src/main/cpp/CMakeLists.txt new file mode 100644 index 00000000..4bbb8fd2 --- /dev/null +++ b/PermissionManager/app/src/main/cpp/CMakeLists.txt @@ -0,0 +1,50 @@ +# For more information about using CMake with Android Studio, read the +# documentation: https://d.android.com/studio/projects/add-native-code.html + +# Sets the minimum version of CMake required to build the native library. + +cmake_minimum_required(VERSION 3.10.2) + +# Declares and names the project. + +project("permissionmanager") + +# Creates and names a library, sets it as either STATIC +# or SHARED, and provides the relative paths to its source code. +# You can define multiple libraries, and CMake builds them for you. +# Gradle automatically packages shared libraries with your APK. + +add_library( # Sets the name of the library. + root + + # Sets the library as a shared library. + SHARED + + # Provides a relative path to your source file(s). + ../../../../../testRoot/adb_inject.cpp + ../../../../../testRoot/ptrace_arm64_utils.cpp + root.cpp) + +# Searches for a specified prebuilt library and stores the path as a +# variable. Because CMake includes system libraries in the search path by +# default, you only need to specify the name of the public NDK library +# you want to add. CMake verifies that the library exists before +# completing its build. + +find_library( # Sets the name of the path variable. + log-lib + + # Specifies the name of the NDK library that + # you want CMake to locate. + log ) + +# Specifies libraries CMake should link to your target library. You +# can link multiple libraries, such as libraries you define in this +# build script, prebuilt third-party libraries, or system libraries. + +target_link_libraries( # Specifies the target library. + root + + # Links the target library to the log library + # included in the NDK. + ${log-lib} ) \ No newline at end of file diff --git a/PermissionManager/app/src/main/cpp/root.cpp b/PermissionManager/app/src/main/cpp/root.cpp new file mode 100644 index 00000000..72f5f86e --- /dev/null +++ b/PermissionManager/app/src/main/cpp/root.cpp @@ -0,0 +1,112 @@ +#include +#include +#include +#include +#include +#include +#include + +#include "../../../../../testRoot/super_root.h" +#include "../../../../../testRoot/adb_inject.h" + +using namespace std; +string getCapabilityInfo() +{ + struct __user_cap_header_struct cap_header_data; + cap_user_header_t cap_header = &cap_header_data; + + struct __user_cap_data_struct cap_data_data; + cap_user_data_t cap_data = &cap_data_data; + + cap_header->pid = getpid(); + cap_header->version = _LINUX_CAPABILITY_VERSION_3; //_1、_2、_3 + + if (capget(cap_header, cap_data) < 0) { + return "FAILED capget()"; + // perror("FAILED capget()"); + //exit(1); + } + stringstream sstrCapInfo; + sstrCapInfo << "Cap data effective:"<<(uint64_t *) cap_data->effective<<", permitted:"<<(uint64_t *) cap_data->permitted<<", inheritable:"<<(uint64_t *) cap_data->inheritable<<"\n"; + sstrCapInfo << "now getuid()="<< getuid() <<",geteuid()="<< geteuid() <<",getgid()="<< getgid() <<",getegid()="<< getegid() << "\n"; + + FILE * fp = popen("getenforce", "r"); + if (fp) + { + char cmd[512] = { 0 }; + fread(cmd, 1, sizeof(cmd), fp); + pclose(fp); + + sstrCapInfo<< "SELinux status: "<< cmd; + } + + return sstrCapInfo.str(); +} + +extern "C" JNIEXPORT jstring JNICALL +Java_com_linux_permissionmanager_MainActivity_getCapabilityInfo( + JNIEnv* env, + jobject /* this */) { + return env->NewStringUTF(getCapabilityInfo().c_str()); +} + +extern "C" JNIEXPORT jint JNICALL +Java_com_linux_permissionmanager_MainActivity_getRoot( + JNIEnv* env, + jobject /* this */, + jlong rootKey) { + return get_root(rootKey); +} +extern "C" JNIEXPORT jint JNICALL +Java_com_linux_permissionmanager_MainActivity_disableSElinux( + JNIEnv* env, + jobject /* this */, + jlong rootKey) { + return safe_disable_selinux(rootKey); +} + +extern "C" JNIEXPORT jint JNICALL +Java_com_linux_permissionmanager_MainActivity_enableSElinux( + JNIEnv* env, + jobject /* this */, + jlong rootKey) { + return safe_enable_selinux(rootKey); +} + +extern "C" JNIEXPORT jstring JNICALL +Java_com_linux_permissionmanager_MainActivity_runRootCmd( + JNIEnv* env, + jobject /* this */, + jlong rootKey, + jstring cmd) { + + const char *str1 = env->GetStringUTFChars(cmd, 0); + string strCmd= str1; + env->ReleaseStringUTFChars(cmd, str1); + + char szResult[0x1000] = {0}; + ssize_t ret = safe_run_root_cmd(rootKey, strCmd.c_str(), szResult, sizeof(szResult)); + stringstream sstr; + sstr << "runRootCmd ret val:" << ret << ", result:" << szResult; + return env->NewStringUTF(sstr.str().c_str()); +} + +extern "C" JNIEXPORT jstring JNICALL +Java_com_linux_permissionmanager_MainActivity_runAdbShell( + JNIEnv* env, + jobject /* this */, + jlong rootKey, + jstring shell, + jboolean keepAdbRoot) { + + const char *str1 = env->GetStringUTFChars(shell, 0); + string strShell= str1; + env->ReleaseStringUTFChars(shell, str1); + + char szResult[0x1000] = {0}; + ssize_t inject = safe_inject_adb_process_run_shell_wrapper(rootKey, strShell.c_str(), keepAdbRoot, szResult, sizeof(szResult)); + //ssize_t inject = safe_inject_adb_process_run_shell_wrapper(rootKey, strShell.c_str(), NULL, 0); + stringstream sstr; + sstr << "runAdbShell ret val:" << inject << ", result:" << szResult; + return env->NewStringUTF(sstr.str().c_str()); +} diff --git a/PermissionManager/app/src/main/java/com/linux/permissionmanager/MainActivity.java b/PermissionManager/app/src/main/java/com/linux/permissionmanager/MainActivity.java new file mode 100644 index 00000000..d63a93b2 --- /dev/null +++ b/PermissionManager/app/src/main/java/com/linux/permissionmanager/MainActivity.java @@ -0,0 +1,279 @@ +package com.linux.permissionmanager; + +import androidx.appcompat.app.AppCompatActivity; + +import android.app.AlertDialog; +import android.content.ClipData; +import android.content.ClipboardManager; +import android.content.Context; +import android.content.DialogInterface; +import android.content.SharedPreferences; +import android.graphics.Color; +import android.os.Bundle; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.Toast; + +public class MainActivity extends AppCompatActivity { + + private long rootKey = 0x7F6766F8; + //保存的本地配置信息 + private SharedPreferences m_shareSave; + + // Used to load the 'native-lib' library on application startup. + static { + System.loadLibrary("root"); + } + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + + m_shareSave = getSharedPreferences("zhcs", Context.MODE_PRIVATE); + try{ rootKey = m_shareSave.getLong("rootKey",rootKey );}catch(Exception e){} + + //验证用户的KEY + final EditText inputKey = new EditText(MainActivity.this); + inputKey.setText(Long.toHexString(rootKey)); + inputKey.setSelection(inputKey.length(),0); + AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); + builder.setTitle("请输入ROOT权限的KEY").setIcon(android.R.drawable.ic_dialog_info).setView(inputKey) + .setPositiveButton("确定", new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + rootKey = Long.valueOf(inputKey.getText().toString(),16); + //数值保存到本地 + SharedPreferences.Editor mEdit = m_shareSave.edit(); + mEdit.putLong("rootKey",rootKey); + mEdit.commit(); + }; + }); + builder.show(); + + + + Button show_myself_info_btn = findViewById(R.id.show_myself_info_btn); + show_myself_info_btn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + showConsoleMsg(getCapabilityInfo()); + } + }); + + Button get_root_btn = findViewById(R.id.get_root_btn); + get_root_btn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + int ret = getRoot(rootKey); + showConsoleMsg("getRoot: " +ret); + } + }); + + Button disable_selinux_btn = findViewById(R.id.disable_selinux_btn); + disable_selinux_btn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + int ret = disableSElinux(rootKey); + showConsoleMsg("disableSElinux: " +ret); + } + }); + + Button enable_selinux_btn = findViewById(R.id.enable_selinux_btn); + enable_selinux_btn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + int ret = enableSElinux(rootKey); + showConsoleMsg("enableSElinux: " +ret); + } + }); + + Button run_root_cmd_btn = findViewById(R.id.run_root_cmd_btn); + run_root_cmd_btn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + + final EditText inputCMD = new EditText(MainActivity.this); + inputCMD.setText("id"); + inputCMD.setSelection(inputCMD.length(),0); + AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); + builder.setTitle("输入ROOT命令").setIcon(android.R.drawable.ic_dialog_info).setView(inputCMD) + .setNegativeButton("取消", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + dialog.dismiss(); + } + }); + builder.setPositiveButton("确定", new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + String text = inputCMD.getText().toString(); + showConsoleMsg(text+"\n"+runRootCmd(rootKey, text)); + }; + }); + builder.show(); + + } + }); + Button run_adb_shell_btn = findViewById(R.id.run_adb_shell_btn); + run_adb_shell_btn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + + if(!guideOpenUsbDebugSwitch()) { + return; + } + + final EditText inputShell = new EditText(MainActivity.this); + inputShell.setText("id"); + inputShell.setSelection(inputShell.length(),0); + AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); + builder.setTitle("输入shell命令").setIcon(android.R.drawable.ic_dialog_info).setView(inputShell) + .setNegativeButton("取消", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + dialog.dismiss(); + } + }); + builder.setPositiveButton("确定", new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + String text = inputShell.getText().toString(); + showConsoleMsg(text+"\n"+runAdbShell(rootKey, text, false)); + }; + }); + builder.show(); + + } + }); + + Button keep_adb_root_btn = findViewById(R.id.keep_adb_root_btn); + keep_adb_root_btn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + + if(!guideOpenUsbDebugSwitch()) { + return; + } + showConsoleMsg("id\n"+runAdbShell(rootKey, "id", true)); + } + }); + Button su_install_btn = findViewById(R.id.su_install_btn); + keep_adb_root_btn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + + + } + }); + + Button copy_info_btn = findViewById(R.id.copy_info_btn); + copy_info_btn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + copyConsoleMsg(); + Toast.makeText(v.getContext(), "复制成功" , Toast.LENGTH_SHORT).show(); + + } + }); + Button clean_info_btn = findViewById(R.id.clean_info_btn); + clean_info_btn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + cleanConsoleMsg(); + } + }); + } + public void showConsoleMsg(String msg){ + EditText console_edit = findViewById(R.id.console_edit); + StringBuffer txt = new StringBuffer(); + txt.append(console_edit.getText().toString()); + if (txt.length() != 0) { + txt.append("\n"); + } + txt.append(msg); + txt.append("\n"); + console_edit.setText(txt.toString()); + console_edit.setSelection(txt.length()); + } + public void cleanConsoleMsg(){ + EditText console_edit = findViewById(R.id.console_edit); + console_edit.setText(""); + } + public void copyConsoleMsg(){ + EditText console_edit = findViewById(R.id.console_edit); + //获取剪贴板管理器: + ClipboardManager cm = (ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE); + // 创建普通字符型ClipData + ClipData mClipData = ClipData.newPlainText("Label", console_edit.getText()); + // 将ClipData内容放到系统剪贴板里。 + cm.setPrimaryClip(mClipData); + + } + + public boolean guideOpenUsbDebugSwitch(){ + //检查USB调试开关是否打开 + if(!UsbDebugSwitchHelper.checkUsbDebugSwitch(MainActivity.this)){ + + AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this) + .setTitle("提示") + .setMessage("请先到开发者选项页面里打开【USB调试】开关(提示:在手机关于页面里连续点击系统版本号可启用开发者选项页面)") + .setOnDismissListener(new DialogInterface.OnDismissListener() { + @Override + public void onDismiss(DialogInterface dialog) { + dialog.dismiss(); + UsbDebugSwitchHelper.startDevelopmentActivity(MainActivity.this); //转到开发者页面 + } + }) + .setNegativeButton("确定", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + dialog.dismiss(); + UsbDebugSwitchHelper.startDevelopmentActivity(MainActivity.this); //转到开发者页面 + + } + }); + AlertDialog dialog = builder.create(); + dialog.show(); + dialog.getButton(AlertDialog.BUTTON_NEGATIVE).setTextColor(Color.BLACK); + + return false; + } + return true; + } + public boolean guideCloseUsbDebugSwitch(){ + //检查USB调试开关是否打开 + if(UsbDebugSwitchHelper.checkUsbDebugSwitch(MainActivity.this)){ + + AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this) + .setTitle("提示") + .setMessage("请先到开发者选项页面里关闭【USB调试】开关") + .setOnDismissListener(new DialogInterface.OnDismissListener() { + @Override + public void onDismiss(DialogInterface dialog) { + dialog.dismiss(); + UsbDebugSwitchHelper.startDevelopmentActivity(MainActivity.this); //转到开发者页面 + } + }) + .setNegativeButton("确定", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + dialog.dismiss(); + UsbDebugSwitchHelper.startDevelopmentActivity(MainActivity.this); //转到开发者页面 + + } + }); + AlertDialog dialog = builder.create(); + dialog.show(); + dialog.getButton(AlertDialog.BUTTON_NEGATIVE).setTextColor(Color.BLACK); + return false; + } + return true; + } + + public native String getCapabilityInfo(); + public native int getRoot(long rootKey); + public native int disableSElinux(long rootKey); + public native int enableSElinux(long rootKey); + public native String runRootCmd(long rootKey, String cmd); + public native String runAdbShell(long rootKey, String shell,boolean keepAdbRoot); +} \ No newline at end of file diff --git a/PermissionManager/app/src/main/java/com/linux/permissionmanager/UsbDebugSwitchHelper.java b/PermissionManager/app/src/main/java/com/linux/permissionmanager/UsbDebugSwitchHelper.java new file mode 100644 index 00000000..53e1f489 --- /dev/null +++ b/PermissionManager/app/src/main/java/com/linux/permissionmanager/UsbDebugSwitchHelper.java @@ -0,0 +1,41 @@ +package com.linux.permissionmanager; + +import android.content.ComponentName; +import android.content.Context; +import android.content.Intent; +import android.provider.Settings; + +public class UsbDebugSwitchHelper { + public static boolean checkUsbDebugSwitch(Context ctx) { + //检查USB调试是否被打开 + boolean enableAdb = (Settings.Secure.getInt(ctx.getContentResolver(), Settings.Secure.ADB_ENABLED, 0) > 0);//判断adb调试模式是否打开 + return enableAdb; + } + + /** + * 打开开发者模式界面 + */ + public static void startDevelopmentActivity(Context ctx) { + try { + Intent intent = new Intent(Settings.ACTION_APPLICATION_DEVELOPMENT_SETTINGS); + ctx.startActivity(intent); + } catch (Exception e) { + try { + ComponentName componentName = new ComponentName("com.android.settings", "com.android.settings.DevelopmentSettings"); + Intent intent = new Intent(); + intent.setComponent(componentName); + intent.setAction("android.intent.action.View"); + ctx.startActivity(intent); + } catch (Exception e1) { + try { + Intent intent = new Intent("com.android.settings.APPLICATION_DEVELOPMENT_SETTINGS");//部分小米手机采用这种方式跳转 + ctx.startActivity(intent); + } catch (Exception e2) { + + } + + } + } + } + +} diff --git a/PermissionManager/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/PermissionManager/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 00000000..cc14f035 --- /dev/null +++ b/PermissionManager/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/PermissionManager/app/src/main/res/drawable/ic_launcher_background.xml b/PermissionManager/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 00000000..a4f78de5 --- /dev/null +++ b/PermissionManager/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/PermissionManager/app/src/main/res/layout/activity_main.xml b/PermissionManager/app/src/main/res/layout/activity_main.xml new file mode 100644 index 00000000..6a12bb89 --- /dev/null +++ b/PermissionManager/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,169 @@ + + + + + + + + + + + + + + +