GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — 新增寄生功能 · magicjva/SKRoot-linuxKernelRoot@a9168ab

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • PermissionManager
    • .idea
      • misc.xml
    • app
      • appKey.jks
      • build.gradle
      • src/main
        • assets
          • su
        • cpp
          • CMakeLists.txt
          • root.cpp
          • urlEncodeUtils.h
        • java/com/linux/permissionmanager
          • Adapter
            • SelectAppRecyclerAdapter.java
            • SelectFileRecyclerAdapter.java
          • MainActivity.java
          • Model
            • SelectAppRecyclerItem.java
            • SelectFileRecyclerItem.java
        • res/layout
          • activity_main.xml
          • select_app_wnd.xml
          • select_file_recycler_item.xml
          • select_file_wnd.xml
  • README.md
  • testRoot
    • base64.h
    • jni
      • Android.mk
      • generate_source_file_kernel_root_kit_lib_root_server_data.bat
      • generate_source_file_kernel_root_kit_su_exec_data.bat
      • kernel_root_kit
        • file_convert_to_source_tools
          • file_convert_to_source_tools.cpp
          • file_convert_to_source_tools.exe
        • kernel_root_kit_command.h
        • kernel_root_kit_elf64_symbol_parser.h
        • kernel_root_kit_fork_helper.h
        • kernel_root_kit_init64_process_helper.h
        • kernel_root_kit_lib_root_server_data.h
        • kernel_root_kit_log.h
        • kernel_root_kit_maps_helper.h
        • kernel_root_kit_parasite_app.cpp
        • kernel_root_kit_parasite_app.h
        • kernel_root_kit_parasite_elf_def.h
        • kernel_root_kit_parasite_patch_elf.cpp
        • kernel_root_kit_parasite_patch_elf.h
        • kernel_root_kit_process64_inject.cpp
        • kernel_root_kit_process64_inject.h
        • kernel_root_kit_process_cmdline_utils.h
        • kernel_root_kit_ptrace_arm64_utils.cpp
        • kernel_root_kit_ptrace_arm64_utils.h
        • kernel_root_kit_su_exec_data.h
        • kernel_root_kit_su_install_helper.cpp
        • kernel_root_kit_su_install_helper.h
        • kernel_root_kit_umbrella.h
      • root_server
        • root_server.cpp
        • root_server.h
        • root_server_inline_key.h
        • root_server_inline_so_name.h
      • su
        • encryptor.h
        • su.cpp
        • su.h
        • su_hide_path_utils.h
        • su_log.h
      • testRoot.cpp
      • testRoot.h
      • utils
        • base64.h
        • cJSON.cpp
        • cJSON.h
        • jsonUtils.h
        • stringUtils.h
      • 编译流程.txt
    • kernel_root_kit
      • kernel_root_kit_fork_helper.h
      • kernel_root_kit_maps_helper.h
      • kernel_root_kit_process_cmdline_utils.h
      • kernel_root_kit_random.h
    • testRoot.cpp

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Dismiss banner
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎PermissionManager/.idea/misc.xml‎

Copy file name to clipboardExpand all lines: PermissionManager/.idea/misc.xml
+13-2Lines changed: 13 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Collapse file

‎PermissionManager/app/appKey.jks‎

Copy file name to clipboard
2.46 KB
Binary file not shown.
Collapse file

‎PermissionManager/app/build.gradle‎

Copy file name to clipboardExpand all lines: PermissionManager/app/build.gradle
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ android {
77

88
defaultConfig {
99
applicationId "com.linux.permissionmanager"
10-
minSdk 23
10+
minSdk 26
1111
targetSdk 31
1212
versionCode 1
1313
versionName "1.0"
Collapse file

‎PermissionManager/app/src/main/assets/su‎

Copy file name to clipboard
-189 KB
Binary file not shown.
Collapse file

‎PermissionManager/app/src/main/cpp/CMakeLists.txt‎

Copy file name to clipboardExpand all lines: PermissionManager/app/src/main/cpp/CMakeLists.txt
+5-4Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ add_library( # Sets the name of the library.
2121
SHARED
2222

2323
# Provides a relative path to your source file(s).
24-
../../../../../testRoot/kernel_root_kit/kernel_root_kit_process64_inject.cpp
25-
../../../../../testRoot/kernel_root_kit/kernel_root_kit_ptrace_arm64_utils.cpp
26-
../../../../../testRoot/kernel_root_kit/kernel_root_kit_su_install_helper.cpp
27-
../../../../../testRoot/base64.cpp
24+
../../../../../testRoot/jni/kernel_root_kit/kernel_root_kit_process64_inject.cpp
25+
../../../../../testRoot/jni/kernel_root_kit/kernel_root_kit_ptrace_arm64_utils.cpp
26+
../../../../../testRoot/jni/kernel_root_kit/kernel_root_kit_su_install_helper.cpp
27+
../../../../../testRoot/jni/kernel_root_kit/kernel_root_kit_parasite_app.cpp
28+
../../../../../testRoot/jni/kernel_root_kit/kernel_root_kit_parasite_patch_elf.cpp
2829
root.cpp)
2930

3031
# Searches for a specified prebuilt library and stores the path as a
Collapse file

‎PermissionManager/app/src/main/cpp/root.cpp‎

Copy file name to clipboardExpand all lines: PermissionManager/app/src/main/cpp/root.cpp
+139-65Lines changed: 139 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -7,61 +7,13 @@
77
#include <thread>
88
#include <sys/capability.h>
99

10-
#include "../../../../../testRoot/kernel_root_kit/kernel_root_kit_umbrella.h"
11-
10+
#include "../../../../../testRoot/jni/kernel_root_kit/kernel_root_kit_umbrella.h"
11+
#include "../../../../../testRoot/jni/testRoot.h"
12+
#include "urlEncodeUtils.h"
1213
using namespace std;
1314

1415
std::string g_last_su_full_path;
1516

16-
string getCapabilityInfo()
17-
{
18-
__uid_t now_uid, now_euid, now_suid;
19-
if (getresuid(&now_uid, &now_euid, &now_suid)) {
20-
return "FAILED getresuid()";
21-
}
22-
23-
24-
__gid_t now_gid, now_egid, now_sgid;
25-
if (getresgid(&now_gid, &now_egid, &now_sgid)) {
26-
return "FAILED getresgid()";
27-
}
28-
29-
stringstream sstrCapInfo;
30-
sstrCapInfo<< "Current process information:\n";
31-
sstrCapInfo<< "uid:"<<now_uid <<"," << std::endl <<"euid:"<< now_euid <<"," << std::endl
32-
<<"suid:"<< now_suid <<"," << std::endl <<"gid:"<< now_gid <<"," << std::endl
33-
<<"egid:"<< now_egid <<"," << std::endl <<"sgid:"<< now_sgid <<"\n";
34-
35-
struct __user_cap_header_struct cap_header_data;
36-
cap_user_header_t cap_header = &cap_header_data;
37-
38-
struct __user_cap_data_struct cap_data_data;
39-
cap_user_data_t cap_data = &cap_data_data;
40-
41-
cap_header->pid = getpid();
42-
cap_header->version = _LINUX_CAPABILITY_VERSION_3; //_1、_2、_3
43-
44-
if (capget(cap_header, cap_data) < 0) {
45-
return "FAILED capget()";
46-
// perror("FAILED capget()");
47-
//exit(1);
48-
}
49-
sstrCapInfo << "cap effective:" << hex <<cap_data->effective << "," << std::endl
50-
<<"cap permitted:"<< hex << cap_data->permitted<< "," << std::endl
51-
<<"cap inheritable:"<< hex <<cap_data->inheritable<< std::endl;
52-
FILE * fp = popen("getenforce", "r");
53-
if (fp)
54-
{
55-
char cmd[512] = { 0 };
56-
fread(cmd, 1, sizeof(cmd), fp);
57-
pclose(fp);
58-
59-
sstrCapInfo<< "read system SELinux status:"<< cmd;
60-
}
61-
62-
return sstrCapInfo.str();
63-
}
64-
6517
extern "C" JNIEXPORT jstring JNICALL
6618
Java_com_linux_permissionmanager_MainActivity_testRoot(
6719
JNIEnv* env,
@@ -80,11 +32,11 @@ Java_com_linux_permissionmanager_MainActivity_testRoot(
8032
result += std::to_string(err);
8133
result += "\n\n";
8234
if(err == 0) {
83-
result += getCapabilityInfo();
35+
result += get_capability_info();
8436
result += "\n\n";
8537
}
86-
write_errcode_to_father(finfo, err);
87-
write_string_to_father(finfo, result);
38+
write_errcode_from_child(finfo, err);
39+
write_string_from_child(finfo, result);
8840
_exit(0);
8941
return 0;
9042
}
@@ -152,8 +104,7 @@ Java_com_linux_permissionmanager_MainActivity_installSu(
152104
JNIEnv* env,
153105
jobject /* this */,
154106
jstring rootKey,
155-
jstring basePath,
156-
jstring originSuFullPath) {
107+
jstring basePath) {
157108

158109
const char *str1 = env->GetStringUTFChars(rootKey, 0);
159110
string strRootKey= str1;
@@ -163,14 +114,10 @@ Java_com_linux_permissionmanager_MainActivity_installSu(
163114
string strBasePath= str1;
164115
env->ReleaseStringUTFChars(basePath, str1);
165116

166-
str1 = env->GetStringUTFChars(originSuFullPath, 0);
167-
string strOriginSuFullPath= str1;
168-
env->ReleaseStringUTFChars(originSuFullPath, str1);
169-
170117
stringstream sstr;
171118
//安装su工具套件
172119
ssize_t err;
173-
std::string su_hide_full_path = kernel_root::safe_install_su(strRootKey.c_str(), strBasePath.c_str(), strOriginSuFullPath.c_str(), err);
120+
std::string su_hide_full_path = kernel_root::safe_install_su(strRootKey.c_str(), strBasePath.c_str(), err);
174121
sstr << "install su err:" << err<<", su_hide_full_path:" << su_hide_full_path << std::endl;
175122
g_last_su_full_path = su_hide_full_path;
176123
if (err == 0) {
@@ -234,14 +181,14 @@ Java_com_linux_permissionmanager_MainActivity_autoSuEnvInject(
234181
stringstream sstr;
235182

236183
//杀光所有历史进程
237-
std::vector<pid_t> vOut;
238-
ssize_t err = kernel_root::safe_find_all_cmdline_process(strRootKey.c_str(), strTargetProcessCmdline.c_str(), vOut);
239-
sstr << "find_all_cmdline_process err:"<< err<<", cnt:"<<vOut.size() << std::endl;
184+
std::set<pid_t> out;
185+
ssize_t err = kernel_root::safe_find_all_cmdline_process(strRootKey.c_str(), strTargetProcessCmdline.c_str(), out);
186+
sstr << "find_all_cmdline_process err:"<< err<<", cnt:"<<out.size() << std::endl;
240187
if (err != 0) {
241188
return env->NewStringUTF(sstr.str().c_str());
242189
}
243190
std::string kill_cmd;
244-
for (pid_t t : vOut) {
191+
for (pid_t t : out) {
245192
err = kernel_root::safe_kill_process(strRootKey.c_str(), t);
246193
sstr << "kill_ret err:"<< err << std::endl;
247194
if (err != 0) {
@@ -268,3 +215,130 @@ Java_com_linux_permissionmanager_MainActivity_autoSuEnvInject(
268215
sstr << "autoSuEnvInject done.";
269216
return env->NewStringUTF(sstr.str().c_str());
270217
}
218+
219+
220+
221+
extern "C" JNIEXPORT jstring JNICALL
222+
Java_com_linux_permissionmanager_MainActivity_getAllCmdlineProcess(
223+
JNIEnv* env,
224+
jobject /* this */,
225+
jstring rootKey) {
226+
std::stringstream ss;
227+
228+
const char *str1 = env->GetStringUTFChars(rootKey, 0);
229+
std::string strRootKey = str1;
230+
env->ReleaseStringUTFChars(rootKey, str1);
231+
232+
std::map<pid_t, std::string> pid_map;
233+
ssize_t err = kernel_root::safe_get_all_cmdline_process(strRootKey.c_str(), pid_map);
234+
if(err != 0) {
235+
ss << "get_all_cmdline_process err:"<< err<< std::endl;
236+
return env->NewStringUTF(ss.str().c_str());
237+
}
238+
239+
ss << "{\"data\":[";
240+
for (auto iter = pid_map.begin(); iter != pid_map.end(); ) {
241+
size_t len = iter->second.length();
242+
size_t max_encoded_len = 3 * len + 1;
243+
shared_ptr<char> spData(new (std::nothrow) char[max_encoded_len], std::default_delete<char[]>());
244+
memset(spData.get(), 0, max_encoded_len);
245+
url_encode(const_cast<char*>(iter->second.c_str()), spData.get());
246+
ss << "{\"" << iter->first << "\":\"" << spData.get() << "\"}";
247+
if (++iter != pid_map.end()) {
248+
ss << ",";
249+
}
250+
}
251+
ss << "]}";
252+
return env->NewStringUTF(ss.str().c_str());
253+
}
254+
255+
extern "C" JNIEXPORT jstring JNICALL
256+
Java_com_linux_permissionmanager_MainActivity_parasitePrecheckApp(
257+
JNIEnv* env,
258+
jobject /* this */,
259+
jstring rootKey,
260+
jstring targetProcessCmdline) {
261+
262+
const char *str1 = env->GetStringUTFChars(rootKey, 0);
263+
string strRootKey= str1;
264+
env->ReleaseStringUTFChars(rootKey, str1);
265+
266+
str1 = env->GetStringUTFChars(targetProcessCmdline, 0);
267+
string strTargetProcessCmdline = str1;
268+
env->ReleaseStringUTFChars(targetProcessCmdline, str1);
269+
270+
stringstream sstr;
271+
std::set<pid_t> test_pid;
272+
ssize_t err = kernel_root::safe_find_all_cmdline_process(strRootKey.c_str(), strTargetProcessCmdline.c_str(), test_pid);
273+
if (err != 0) {
274+
sstr << "find_all_cmdline_process err:"<< err<<", cnt:"<< test_pid.size() << std::endl;
275+
return env->NewStringUTF(sstr.str().c_str());
276+
}
277+
if (test_pid.size() == 0) {
278+
sstr << "目标进程不存在" << std::endl;
279+
return env->NewStringUTF(sstr.str().c_str());
280+
}
281+
282+
std::set<std::string> so_path_list;
283+
err = kernel_root::safe_parasite_precheck_app(strRootKey.c_str(), strTargetProcessCmdline.c_str(), so_path_list);
284+
if (err) {
285+
sstr << "parasite_precheck_app ret val:" << err << std::endl;
286+
if(err == -9903) {
287+
sstr << "此目标APP为32位应用,无法寄生" << err << std::endl;
288+
}
289+
return env->NewStringUTF(sstr.str().c_str());
290+
}
291+
292+
if (!so_path_list.size()) {
293+
sstr << "目标APP无法寄生:无法检测到目标APP的JNI环境,您可尝试重启目标APP后再试" << std::endl;
294+
return env->NewStringUTF(sstr.str().c_str());
295+
}
296+
297+
sstr << "{\"soPaths\":[";
298+
for (auto iter = so_path_list.begin(); iter != so_path_list.end(); ) {
299+
size_t len = iter->length();
300+
size_t max_encoded_len = 3 * len + 1;
301+
std::shared_ptr<char> spData(new (std::nothrow) char[max_encoded_len], std::default_delete<char[]>());
302+
memset(spData.get(), 0, max_encoded_len);
303+
url_encode(const_cast<char*>(iter->c_str()), spData.get());
304+
sstr << "\"" << spData.get() << "\"";
305+
if (++iter != so_path_list.end()) {
306+
sstr << ",";
307+
}
308+
}
309+
sstr << "]}";
310+
return env->NewStringUTF(sstr.str().c_str());
311+
312+
}
313+
314+
extern "C" JNIEXPORT jstring JNICALL
315+
Java_com_linux_permissionmanager_MainActivity_parasiteImplantApp(
316+
JNIEnv* env,
317+
jobject /* this */,
318+
jstring rootKey,
319+
jstring targetProcessCmdline,
320+
jstring targetSoFullPath) {
321+
322+
const char *str1 = env->GetStringUTFChars(rootKey, 0);
323+
string strRootKey= str1;
324+
env->ReleaseStringUTFChars(rootKey, str1);
325+
326+
str1 = env->GetStringUTFChars(targetProcessCmdline, 0);
327+
string strTargetProcessCmdline = str1;
328+
env->ReleaseStringUTFChars(targetProcessCmdline, str1);
329+
330+
str1 = env->GetStringUTFChars(targetSoFullPath, 0);
331+
string strTargetSoFullPath = str1;
332+
env->ReleaseStringUTFChars(targetSoFullPath, str1);
333+
334+
stringstream sstr;
335+
ssize_t err = kernel_root::safe_parasite_implant_app(strRootKey.c_str(), strTargetProcessCmdline.c_str(), strTargetSoFullPath.c_str());
336+
if (err != 0) {
337+
sstr << "parasite_implant_app err:"<< err << std::endl;
338+
return env->NewStringUTF(sstr.str().c_str());
339+
}
340+
sstr << "parasiteImplantApp done.";
341+
return env->NewStringUTF(sstr.str().c_str());
342+
343+
}
344+
Collapse file

‎PermissionManager/app/src/main/cpp/urlEncodeUtils.h‎

Copy file name to clipboard
+74Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#ifndef URL_ENCODE_UTILS_H_
2+
#define URL_ENCODE_UTILS_H_
3+
#include <ctype.h>
4+
#include <stdio.h>
5+
6+
static inline char to_hex(char code) {
7+
static char hex[] = "0123456789ABCDEF";
8+
return hex[code & 15];
9+
}
10+
static inline char from_hex(char ch) {
11+
return isdigit(ch) ? ch - '0' : tolower(ch) - 'a' + 10;
12+
}
13+
14+
/*
15+
//使用例子
16+
int main() {
17+
char str[] = "你好,世界";
18+
char encoded_str[256];
19+
url_encode(str, encoded_str);
20+
printf("Encoded URL: %s\n", encoded_str);
21+
return 0;
22+
}
23+
*/
24+
static void url_encode(char *str, char *encoded_str) {
25+
char *pstr = str, *buf = encoded_str;
26+
while (*pstr) {
27+
unsigned char c = *pstr;
28+
if (c <= 0x7F) { // ASCII
29+
if (isalnum(c) || c == '-' || c == '_' || c == '.' || c == '~') {
30+
*buf++ = c;
31+
} else if (c == ' ') {
32+
*buf++ = '+';
33+
} else {
34+
*buf++ = '%', *buf++ = to_hex(c >> 4), *buf++ = to_hex(c & 15);
35+
}
36+
} else { // Non-ASCII
37+
while (c) {
38+
*buf++ = '%', *buf++ = to_hex(c >> 4), *buf++ = to_hex(c & 15);
39+
c = *(++pstr);
40+
}
41+
continue;
42+
}
43+
pstr++;
44+
}
45+
*buf = '\0';
46+
}
47+
/*
48+
//使用例子
49+
int main() {
50+
char url[] = "%E4%BD%A0%E5%A5%BD%EF%BC%8C%E4%B8%96%E7%95%8C"; // "你好,世界"的URL编码
51+
char decoded_str[256];
52+
url_decode(url, decoded_str);
53+
printf("Decoded URL: %s\n", decoded_str);
54+
return 0;
55+
}
56+
*/
57+
static void url_decode(char *str, char *decoded_str) {
58+
char *pstr = str, *buf = decoded_str;
59+
while (*pstr) {
60+
if (*pstr == '%') {
61+
if (pstr[1] && pstr[2]) {
62+
*buf++ = from_hex(pstr[1]) << 4 | from_hex(pstr[2]);
63+
pstr += 2;
64+
}
65+
} else if (*pstr == '+') {
66+
*buf++ = ' ';
67+
} else {
68+
*buf++ = *pstr;
69+
}
70+
pstr++;
71+
}
72+
*buf = '\0';
73+
}
74+
#endif

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.