ADB Commands

Support HackTricks

Adb는 일반적으로 다음 위치에 있습니다:

#Windows
C:\Users\<username>\AppData\Local\Android\sdk\platform-tools\adb.exe

#MacOS
/Users/<username>/Library/Android/sdk/platform-tools/adb

정보 출처: http://adbshell.com/

연결

adb devices

이 명령은 연결된 장치를 나열합니다. "unauthorized"가 나타나면, 이는 모바일의 잠금을 해제하고 연결을 수락해야 함을 의미합니다.

이는 장치에 포트 5555에서 adb 서버를 시작해야 함을 나타냅니다:

adb tcpip 5555

해당 IP와 포트에 연결:

adb connect <IP>:<PORT>

가상 Android 소프트웨어(예: Genymotion)에서 다음과 같은 오류가 발생하면:

adb server version (41) doesn't match this client (36); killing...

ADB 서버에 다른 버전으로 연결하려고 하기 때문입니다. 소프트웨어가 사용하는 adb 바이너리를 찾아보세요 (C:\Program Files\Genymobile\Genymotion로 가서 adb.exe를 검색하세요).

여러 장치

여러 장치가 귀하의 머신에 연결되어 있는 경우 어떤 장치에서 adb 명령을 실행할 것인지 지정해야 합니다.

adb devices
List of devices attached
10.10.10.247:42135	offline
127.0.0.1:5555	device
adb -s 127.0.0.1:5555 shell
x86_64:/ # whoami
root

Port Tunneling

안드로이드 장치에서 adb 포트localhost에서만 접근 가능하지만 SSH를 통해 접근할 수 있는 경우, 포트 5555를 포워딩하고 adb를 통해 연결할 수 있습니다:

ssh -i ssh_key username@10.10.10.10 -L 5555:127.0.0.1:5555 -p 2222
adb connect 127.0.0.1:5555

패킷 관리자

설치/제거

adb install [option] <path>

adb install test.apk

adb install -l test.apk # forward lock application

adb install -r test.apk # replace existing application

adb install -t test.apk # allow test packages

adb install -s test.apk # install application on sdcard

adb install -d test.apk # allow version code downgrade

adb install -p test.apk # partial application install

adb uninstall [options] <PACKAGE>

adb uninstall com.test.app

adb uninstall -k com.test.app Keep the data and cache directories around after package removal.

패키지

모든 패키지를 출력하며, 선택적으로 패키지 이름에 <FILTER> 텍스트가 포함된 패키지만 출력합니다.

adb shell pm list packages [options] <FILTER-STR>

adb shell pm list packages <FILTER-STR>

adb shell pm list packages -f <FILTER-STR> #See their associated file.

adb shell pm list packages -d <FILTER-STR> #Filter to only show disabled packages.

adb shell pm list packages -e <FILTER-STR> #Filter to only show enabled packages.

adb shell pm list packages -s <FILTER-STR> #Filter to only show system packages.

adb shell pm list packages -3 <FILTER-STR> #Filter to only show third party packages.

adb shell pm list packages -i <FILTER-STR> #See the installer for the packages.

adb shell pm list packages -u <FILTER-STR> #Also include uninstalled packages.

adb shell pm list packages --user <USER_ID> <FILTER-STR> #The user space to query.

adb shell pm path <PACKAGE>

주어진 APK의 경로를 출력합니다.

adb shell pm path com.android.phone

adb shell pm clear <PACKAGE>

패키지와 관련된 모든 데이터를 삭제합니다.

adb shell pm clear com.test.abc

파일 관리자

adb pull <remote> [local]

지정된 파일을 에뮬레이터/장치에서 컴퓨터로 다운로드합니다.

adb pull /sdcard/demo.mp4 ./

adb push <local> <remote>

지정된 파일을 컴퓨터에서 에뮬레이터/장치로 업로드합니다.

adb push test.apk /sdcard

Screencapture/Screenrecord

adb shell screencap <filename>

디바이스 화면의 스크린샷을 찍습니다.

adb shell screencap /sdcard/screen.png

adb shell screenrecord [options] <filename>

Android 4.4 (API level 19) 이상에서 실행되는 장치의 화면을 녹화합니다.

adb shell screenrecord /sdcard/demo.mp4
adb shell screenrecord --size <WIDTHxHEIGHT>
adb shell screenrecord --bit-rate <RATE>
adb shell screenrecord --time-limit <TIME> #Sets the maximum recording time, in seconds. The default and maximum value is 180 (3 minutes).
adb shell screenrecord --rotate # Rotates 90 degrees
adb shell screenrecord --verbose

(녹화를 중지하려면 Ctrl-C를 누르세요)

_adb pull_을 사용하여 파일(이미지 및 비디오)을 다운로드할 수 있습니다.

adb 셸

장치 내부에서 셸을 가져옵니다.

adb shell

adb shell <CMD>

디바이스 내에서 명령을 실행합니다.

adb shell ls

pm

다음 명령은 셸 내에서 실행됩니다.

pm list packages #List installed packages
pm path <package name> #Get the path to the apk file of tha package
am start [<options>] #Start an activity. Whiout options you can see the help menu
am startservice [<options>] #Start a service. Whiout options you can see the help menu
am broadcast [<options>] #Send a broadcast. Whiout options you can see the help menu
input [text|keyevent] #Send keystrokes to device

Processes

애플리케이션의 프로세스 PID를 얻으려면 다음을 실행할 수 있습니다:

adb shell ps

그리고 애플리케이션을 검색하세요

또는 다음을 수행할 수 있습니다

adb shell pidof com.your.application

그리고 애플리케이션의 PID를 출력합니다.

시스템

adb root

adbd 데몬을 루트 권한으로 재시작합니다. 그런 다음, ADB 서버에 다시 연결해야 하며, 루트 권한을 가질 수 있습니다(가능한 경우).

adb sideload <update.zip>

flashing/restoring Android update.zip 패키지.

Logs

Logcat

하나의 애플리케이션의 메시지만 필터링하려면, 애플리케이션의 PID를 가져오고 grep (linux/macos) 또는 findstr (windows)를 사용하여 logcat의 출력을 필터링하십시오:

adb logcat | grep 4526
adb logcat | findstr 4526

adb logcat [option] [filter-specs]

adb logcat

Notes: 모니터를 중지하려면 Ctrl-C를 누르세요.

adb logcat *:V # lowest priority, filter to only show Verbose level

adb logcat *:D # filter to only show Debug level

adb logcat *:I # filter to only show Info level

adb logcat *:W # filter to only show Warning level

adb logcat *:E # filter to only show Error level

adb logcat *:F # filter to only show Fatal level

adb logcat *:S # Silent, highest priority, on which nothing is ever printed

adb logcat -b <Buffer>

adb logcat -b # radio View the buffer that contains radio/telephony related messages.

adb logcat -b # event View the buffer containing events-related messages.

adb logcat -b # main default

adb logcat -c # Clears the entire log and exits.

adb logcat -d # Dumps the log to the screen and exits.

adb logcat -f test.logs # Writes log message output to test.logs .

adb logcat -g # Prints the size of the specified log buffer and exits.

adb logcat -n <count> # Sets the maximum number of rotated logs to <count>.

dumpsys

시스템 데이터 덤프

adb shell dumpsys [options]

adb shell dumpsys

adb shell dumpsys meminfo

adb shell dumpsys battery

Notes: Android 5.0 이상에서 Developer Options가 활성화된 모바일 장치.

adb shell dumpsys batterystats collects battery data from your device

Notes: Battery Historian는 해당 데이터를 HTML 시각화로 변환합니다. STEP 1 adb shell dumpsys batterystats > batterystats.txt STEP 2 python historian.py batterystats.txt > batterystats.html

adb shell dumpsys batterystats --reset erases old collection data

adb shell dumpsys activity

백업

adb를 통해 안드로이드 기기를 백업합니다.

adb backup [-apk] [-shared] [-system] [-all] -f file.backup
# -apk -- Include APK from Third partie's applications
# -shared -- Include removable storage
# -system -- Include system Applciations
# -all -- Include all the applications

adb shell pm list packages -f -3      #List packages
adb backup -f myapp_backup.ab -apk com.myapp # backup on one device
adb restore myapp_backup.ab                  # restore to the same or any other device

백업의 내용을 검사하려면:

( printf "\x1f\x8b\x08\x00\x00\x00\x00\x00" ; tail -c +25 myapp_backup.ab ) |  tar xfvz -
HackTricks 지원하기

Last updated