ADB Commands

htARTE (HackTricks AWS Red Team Expert)를 통해 AWS 해킹을 처음부터 전문가까지 배워보세요!

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(Android Debug Bridge)는 안드로이드 기기와 컴퓨터 간의 연결을 제공하는 도구입니다. ADB를 사용하여 안드로이드 기기에 명령을 전송하고 기기에서 정보를 가져올 수 있습니다.

USB 연결

  1. 안드로이드 기기를 컴퓨터에 USB 케이블로 연결합니다.

  2. 안드로이드 기기에서 개발자 옵션을 활성화합니다. 이를 위해 기기 설정에서 "빌드 번호"를 7번 클릭합니다.

  3. 개발자 옵션으로 이동하여 "USB 디버깅"을 활성화합니다.

  4. 컴퓨터에서 터미널 또는 명령 프롬프트를 열고 다음 명령을 실행합니다.

adb devices
  1. 연결된 기기의 목록이 표시됩니다.

Wi-Fi 연결

  1. 안드로이드 기기를 USB로 컴퓨터에 연결합니다.

  2. 컴퓨터에서 터미널 또는 명령 프롬프트를 열고 다음 명령을 실행합니다.

adb tcpip 5555
  1. USB 연결을 해제합니다.

  2. 안드로이드 기기의 IP 주소를 확인합니다. 이를 위해 기기 설정에서 "Wi-Fi"로 이동하고 "고급" 또는 "추가 설정"을 선택합니다.

  3. "IP 주소"를 확인하고 다음 명령을 실행합니다.

adb connect <device-ip>:5555
  1. 연결된 기기의 목록이 표시됩니다.

연결 해제

adb disconnect

연결 상태 확인

adb devices
adb devices

다음은 연결된 장치 목록을 표시합니다. "unathorised"가 나타나면 모바일을 해제하고 연결을 수락해야 합니다.

이는 장치에 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

포트 터널링

만약 안드로이드 장치에서 adb 포트로컬호스트에서만 접근 가능하지만 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 [옵션] <경로>

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 [옵션] <패키지>

adb uninstall 명령은 Android 디바이스에서 특정 앱을 제거하는 데 사용됩니다.

옵션:

  • -k: 앱 데이터와 캐시를 유지한 채로 앱을 제거합니다.

사용법:

adb uninstall com.example.app

이 명령은 com.example.app이라는 패키지 이름을 가진 앱을 디바이스에서 제거합니다.

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 [옵션] <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>

주어진 <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 <로컬> <원격>

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

adb push test.apk /sdcard

스크린캡처/스크린레코드

adb shell screencap <파일명>

기기 화면의 스크린샷을 찍습니다.

adb shell screencap /sdcard/screen.png

adb shell screenrecord [옵션] <파일명>

Android 4.4 (API 레벨 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

(press Ctrl-C to stop recording)

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

adb shell

장치 내부에서 쉘을 얻습니다.

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

프로세스

애플리케이션의 프로세스 ID(PID)를 얻고 싶다면 다음을 실행할 수 있습니다:

adb shell ps

그리고 앱을 검색하세요.

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

adb shell pidof com.your.application

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

시스템

adb root

adbd 데몬을 루트 권한으로 다시 시작합니다. 그런 다음 ADB 서버에 다시 연결해야 합니다. 그러면 루트 권한을 얻을 수 있습니다 (사용 가능한 경우).

adb sideload <update.zip>

로그

로그캣

한 애플리케이션의 메시지만 필터링하려면 애플리케이션의 PID를 얻고 logcat의 출력을 필터링하기 위해 grep (linux/macos) 또는 findstr (windows)를 사용하십시오.

adb logcat | grep 4526
adb logcat | findstr 4526

adb logcat [옵션] [필터-사양]

adb logcat 명령은 Android 디바이스의 로그를 캡처하고 출력하는 데 사용됩니다. 이 명령은 앱의 디버깅, 오류 분석 및 성능 모니터링에 유용합니다.

옵션:

  • -d: 현재 로그를 캡처하고 출력한 후 종료합니다.

  • -f <file>: 로그를 지정된 파일에 기록합니다.

  • -r <kbytes>: 로그를 지정된 크기로 롤링합니다.

  • -n <count>: 롤링되는 로그 파일의 최대 개수를 지정합니다.

  • -v <format>: 출력 형식을 지정합니다. (brief, process, tag, thread, raw, time, threadtime, long)

  • -s <filter>: 지정된 필터로 로그를 제한합니다.

  • -e <regex>: 지정된 정규식과 일치하는 로그만 출력합니다.

  • -i: 로그를 무시합니다.

  • -c: 현재 로그를 지웁니다.

  • -t <count>: 최근 로그 항목의 개수를 지정합니다.

  • -T <count>: 최근 로그 항목의 시간 범위를 지정합니다.

  • -g: 로그 버퍼 크기를 출력합니다.

  • -b <buffer>: 지정된 로그 버퍼를 사용합니다. (main, system, radio, events, crash, default)

필터-사양:

  • <tag>[:priority]: 로그 태그와 우선순위를 지정합니다. (V, D, I, W, E, F, S)

  • *: 모든 로그를 포함합니다.

  • <tag>: 특정 태그의 로그를 포함합니다.

  • <tag>^: 특정 태그로 시작하는 로그를 포함합니다.

  • <tag>$: 특정 태그로 끝나는 로그를 포함합니다.

  • <tag>:<priority>: 특정 태그와 우선순위의 로그를 포함합니다.

adb logcat

노트: 모니터링을 중지하려면 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 <버퍼>

adb logcat -b <buffer> 명령은 Android 디바이스의 로그 버퍼에서 로그를 읽는 데 사용됩니다. 로그 버퍼는 시스템, 이벤트, 메인 및 라디오 버퍼로 구성됩니다. <buffer>는 읽을 로그 버퍼를 지정하는 데 사용되며, 다음과 같은 값 중 하나를 가질 수 있습니다:

  • main: 기본 로그 버퍼로, 앱 및 시스템 로그를 포함합니다.

  • system: 시스템 로그 버퍼로, Android 시스템 로그를 포함합니다.

  • radio: 라디오 로그 버퍼로, 라디오 인터페이스와 관련된 로그를 포함합니다.

  • events: 이벤트 로그 버퍼로, 이벤트 로그를 포함합니다.

예를 들어, adb logcat -b main 명령은 기본 로그 버퍼에서 로그를 읽습니다.

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 [옵션]

adb shell dumpsys

adb shell dumpsys meminfo

adb shell dumpsys battery

노트: Android 5.0 이상을 실행하는 개발자 옵션이 활성화된 모바일 장치.

adb shell dumpsys batterystats collects battery data from your device

노트: Battery Historian는 해당 데이터를 HTML 시각화로 변환합니다. 단계 1 adb shell dumpsys batterystats > batterystats.txt 단계 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 -
htARTE (HackTricks AWS Red Team Expert)를 통해 AWS 해킹을 처음부터 전문가까지 배워보세요!

HackTricks를 지원하는 다른 방법:

Last updated