보안/android

[앱][리버싱] 앱 후킹 도구 frida 설치

y00&z1 2021. 10. 28. 15:39

https://frida.re/docs/installation/

 

Installation

Inject JavaScript to explore native apps on Windows, macOS, GNU/Linux, iOS, Android, and QNX

frida.re

 

1. 파이썬 설치 

저번에 drozer 설치하느라 파이썬2.7로 재설치를 하였는데, 

파이썬3이상 recommended라서 다시 재설치를 해준다. 

(혹시 몰라서 2.7버전은 삭제는 안했다)

 

파이썬 2.7 위치 - C:\Python27 

파이썬 3.9 위치 - C:\Users\[사용자명]\AppData\Local\Programs\Python\Python39

 

파이썬 2.7 사용 명령어

>py -2.7

파이썬 3.9 사용 명령어 

>py -3.9

 

 

 

 

2. pip로 설치

pip 사용할 때는 -m 옵션으로 py 명령라인에서 pip 실행하면 된다.

>py -3.9 -m pip install [packagename]

 

>py -3.9 -m pip install frida-tools

->이때 버전 확인도 같이 해준다. ; 15.1.3(추후에 frida agent 설치 시 필요함)

https://github.com/frida/frida

 

GitHub - frida/frida: Clone this repo to build Frida

Clone this repo to build Frida. Contribute to frida/frida development by creating an account on GitHub.

github.com

 

 

 

3.  추가 패키지 설치

>pip3 install colorama prompt-toolkit pygments

이미 다 설치되었다고 나온다! 

 

 

 

4. frida-server 다운로드 

핸드폰(에뮬레이터) 아키텍처 확인 하기

Bit : adb shell getprop ro.product.cpu.abi -> x86 

Type : adb shell getprop ro.product.cpu.abi2

 

아니면 ADB Maneger에서 확인 할 수 있음 (bit)

 

 

https://github.com/frida/frida/releases

 

Releases · frida/frida

Clone this repo to build Frida. Contribute to frida/frida development by creating an account on GitHub.

github.com

 

다운로드 한 후 압축을 풀어준다.

 

 

 

 

 

https://frida.re/docs/android/

 

Android

Inject JavaScript to explore native apps on Windows, macOS, GNU/Linux, iOS, Android, and QNX

frida.re

5. 공식 문서 순서대로 명령어 작업 진행

$ adb root # might be required 

-> adbd cannot run as root in production builds 오류 발생

https://mrdevelop.tistory.com/entry/SQLite-%EC%82%AC%EC%9A%A9%EC%8B%9C-root%EA%B6%8C%ED%95%9C-%ED%9A%8D%EB%93%9D-adbd-cannot-run-as-root-in-production-builds-Error

 

#SQLite 사용시 root권한 획득 adbd cannot run as root in production builds Error

안녕하세요! Hellow:) 입니다. 오늘은데이터베이스를 사용할 때 root권한을 획득해야 하는데 adbd cannot run as root in production builds 와 같은 메시지가 뜨면서 root권한으로 안되시는분들을 위해 글..

mrdevelop.tistory.com

위 블로그처럼 play store 아이콘 없는 에뮬레이터로 다시 구동하니 정상적으로 된다. 

 

$ adb push frida-server /data/local/tmp/

-> remote couldn't create file: Is a directory 오류 발생

 

>adb.exe push C:\Users\[사용자명]\Downloads\frida-server-15.1.3-android-x86/frida-server-15.1.3-android-x86 /data/local/tmp/

이렇게 입력했었는데, 환경변수 설정도 하고, frida-server에 있는 디렉토리로 옮겨서 명령어 실행했다. 

 

그냥 해본 건데 정상적으로 됐다.. 

 

 

$ adb shell chmod 755 /data/local/tmp/frida-server

위 명령어는 오류 발생. 그냥 따로 따로 실행했다. 

 

>adb shell

#cd /data/local/tmp

#ls -al

#chmod 777 frida-server

#ls -al

 

 

$ adb shell "/data/local/tmp/frida-server &"

-># ./frida-server-15.1.3-android-x86 & (현재디렉토리 . 빼먹지 않기!!!!)

 

#ps | grep frida

 

 

adb 쉘에서 나와서 명령어 입력해준다

>frida-ps -U

 

오류..

SyntaxError: Non-UTF-8 code starting with '\xc1' in file C:\Users\[사용자명]\AppData\Local\Programs\Python\Python39\Scripts\frida-ps-script.py on line 1, but no encoding declared; see https://python.org/dev/peps/pep-0263/ for details

=> 사용자명이 한글이라서 나는 오류인 듯하다. .. 

 

C:\Users\[사용자명]\AppData\Local\Programs\Python\Python39\Scripts\frida-ps-script.py 로 가서 idle로 열어서 맨 윗줄에 해당 문장을 추가한다. 

# -*- coding: cp949 -*- 

https://kunoo.tistory.com/entry/Python%ED%8C%8C%EC%9D%B4%EC%8D%AC-SyntaxError-NonUTF8-%EC%97%90%EB%9F%AC

 

Python(파이썬) SyntaxError Non-UTF-8 에러

파이썬 파일 한글부분을 명령 프롬프트를 이용하여 실행시 SyntaxError: Non-UTF-8 code starting with '\xb0' in file 파일명.py on line 오류줄번호 라는 오류가 출력될 때가 있다. 이럴때 코드의 맨 앞줄에 # -..

kunoo.tistory.com

 

됐다!! 

+)이외에 다른 스크립트 파일에도 추가하는 것이 좋다(아마 똑같은 오류 발생할 거임)