289 lines
8.6 KiB
Markdown
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

**Adb는 일반적으로 다음 위치에 있습니다:**
```bash
#Windows
C:\Users\<username>\AppData\Local\Android\sdk\platform-tools\adb.exe
#MacOS
/Users/<username>/Library/Android/sdk/platform-tools/adb
```
**정보 출처:** [**http://adbshell.com/**](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 명령을 실행할 것인지 **지정해야 합니다**.
```bash
adb devices
List of devices attached
10.10.10.247:42135 offline
127.0.0.1:5555 device
```
```bash
adb -s 127.0.0.1:5555 shell
x86_64:/ # whoami
root
```
## 포트 터널링
안드로이드 장치에서 **adb** **포트**에 **로컬호스트**에서만 **접근할 수** 있지만 **SSH를 통해 접근할 수** 있는 경우, **포트 5555를 포워딩**하고 adb를 통해 연결할 수 있습니다:
```bash
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>
```bash
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>
```bash
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>
```bash
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의 경로를 출력합니다.
```bash
adb shell pm path com.android.phone
```
### adb shell pm clear \<PACKAGE>
패키지와 관련된 모든 데이터를 삭제합니다.
```bash
adb shell pm clear com.test.abc
```
# 파일 관리자
### adb pull \<remote> \[local]
지정된 파일을 에뮬레이터/장치에서 컴퓨터로 다운로드합니다.
```bash
adb pull /sdcard/demo.mp4 ./
```
### adb push \<local> \<remote>
지정된 파일을 컴퓨터에서 에뮬레이터/장치로 업로드합니다.
```bash
adb push test.apk /sdcard
```
# Screencapture/Screenrecord
### adb shell screencap \<filename>
디바이스 화면의 스크린샷을 찍습니다.
```bash
adb shell screencap /sdcard/screen.png
```
### adb shell screenrecord \[options] \<filename>
Android 4.4 (API 레벨 19) 이상에서 실행되는 장치의 화면을 녹화합니다.
```bash
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**_을 사용하여 다운로드할 수 있습니다.**
# Shell
### adb shell
장치 내부에서 셸을 가져옵니다.
```bash
adb shell
```
### adb shell \<CMD>
디바이스 내에서 명령을 실행합니다.
```bash
adb shell ls
```
## pm
다음 명령은 셸 내에서 실행됩니다.
```bash
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
```
# 프로세스
애플리케이션의 프로세스 PID를 얻으려면 다음을 실행할 수 있습니다:
```bash
adb shell ps
```
당신의 애플리케이션을 검색하세요
또는 다음을 수행할 수 있습니다
```bash
adb shell pidof com.your.application
```
애플리케이션의 PID를 출력합니다.
# 시스템
```bash
adb root
```
루트 권한으로 adbd 데몬을 재시작합니다. 그런 다음 ADB 서버에 다시 연결해야 하며, 루트 권한을 사용할 수 있습니다(가능한 경우).
```bash
adb sideload <update.zip>
```
플래싱/복원 Android update.zip 패키지.
# 로그
## Logcat
하나의 애플리케이션의 메시지만 **필터링하려면**, 애플리케이션의 PID를 가져오고 grep (linux/macos) 또는 findstr (windows)를 사용하여 logcat의 출력을 필터링합니다:
```bash
adb logcat | grep 4526
adb logcat | findstr 4526
```
### adb logcat \[option] \[filter-specs]
```bash
adb logcat
```
노트: 모니터를 중지하려면 Ctrl-C를 누르세요.
```bash
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>
```bash
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]
```bash
adb shell dumpsys
adb shell dumpsys meminfo
adb shell dumpsys battery
```
노트: Android 5.0 이상에서 개발자 옵션이 활성화된 모바일 장치.
```bash
adb shell dumpsys batterystats collects battery data from your device
```
노트: [Battery Historian](https://github.com/google/battery-historian)은 해당 데이터를 HTML 시각화로 변환합니다. **1단계** _adb shell dumpsys batterystats > batterystats.txt_ **2단계** _python historian.py batterystats.txt > batterystats.html_
```bash
adb shell dumpsys batterystats --reset erases old collection data
```
adb shell dumpsys activity
# 백업
adb를 사용하여 안드로이드 기기를 백업합니다.
```bash
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
```
백업의 내용을 검사하려면:
```bash
( printf "\x1f\x8b\x08\x00\x00\x00\x00\x00" ; tail -c +25 myapp_backup.ab ) | tar xfvz -
```
{{#include ../../banners/hacktricks-training.md}}