에러 유형은 dmesg에서 확인할 수 있다.

./insmod 1.ko

1) 에러 유형: 커널 컴파일 시 컴파일러를 android-aach64를 사용하여야 한다. android용이 아니면 에러가 발생한다.

2) 에러 유형: 커널 모듈과 커널 버전이 완전히 일치하여야 한다.

- lkm 버전 확인 : modinfo [lkm.ko]

- 리눅스 커널 버전 확인 : cat /proc/version

insmod: failed to load 1.ko: Invalid argument

(dmesg) 1.ko : disagrees about version of symbol printk

(demsg) 1.ko : Unknown symbol printk (err -22)

 

에러 유형: 커널 모듈과 커널 버전이 완전히 일치하여야 한다.

insmod: failed to load 1.ko: Exec format error

(dmesg) 1.ko : disagrees about version of symbol module_layout

 

에러 유형 : 삼성 단말기에선 LKM을 허용하지 않음 -> 이 경우, 우회하거나 커스텀 os를 새로 설치하여야 한다.

insmod: failed to load 1.ko: Exec format error

(dmesg) LKM is not allowed by Samsung security policy.

0. ubuntu 20.04.4 LTS x64

1. 의존 패키지 설치 Install Dependent Packages (defconfig 및 menuconfig 빌드를 위함)
sudo apt-get install build-essential libncurses5-dev python

2. 커널 소스 다운로드 Download the appropriate kernel source for your device.
Galaxy Tab S6 Lite : git clone https://github.com/LineageOS/android_kernel_samsung_gta4xl

3. 크로스 컴파일러 다운로드 후 경로 설정 Set path after downloading cross-compiler
git clone https://github.com/Shubhamvis98/toolchains

export PATH="/home/code/toolchains/clang-r428724/bin:/home/code/toolchains/aarch64-linux-android-4.9/bin:$PATH"
export ARCH=arm64
export CROSS_COMPILE=aarch64-linux-android-
export CLANG_TRIPLE=aarch64-linux-gnu-

4. 커널 소스 디렉토리로 이동 Go to the kernel source path
make clean
make mrproper
make exynos9611-gta4xlwifi_defconfig
make menuconfig  -> 실행 후 <Save> 클릭 

5. 컴파일 Build it
make -j16 CC=clang

6. 커널 소스 수정 (오류 발생 시) Modifying kernel sources (in case of error)
Open Makefile


KBUILD_CFLAGS   := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
   -fno-strict-aliasing -fno-common -fshort-wchar \
   -Werror-implicit-function-declaration \
   -Wno-format-security \
   -Werror \    <------------- 해당 라인 삭제 delete this line
   -std=gnu89

    private boolean checkRootMethod1() {
        for (String str : new String[]{"/system/app/Superuser.apk", "/sbin/su", "/system/bin/su", "/system/xbin/su", "/data/local/xbin/su", "/data/local/bin/su", "/system/sd/xbin/su", "/system/bin/failsafe/su", "/data/local/su"}) {
            if (new File(str).exists()) {
                return true;
            }
        }
        return false;
    }

exist() -> /apex/com.android.art/lib64/libjavacore.so에서 access()를 호출함

access() 후킹 코드 작성으로 우회 가능

int (*Org_access)(const char* __path, int __mode);
int hook_access(const char* __path, int __mode)
{
    register uint64_t result;

    __asm volatile ("MOV %0, LR\n" : "=r" (result));

    LOG("access path - %s %lx", __path, result);
    if (strstr(__path, "su"))
    {
        return -1;
    }
    return Org_access(__path, __mode);
}
A64HookFunction((void*)access, (void*)hook_access, (void**)&Org_access);

https://github.com/codetronik/AArch64Hook_android

+ Recent posts