ADB Commands

ゼロからヒーローまでAWSハッキングを学ぶ htARTE(HackTricks AWS Red Team Expert)

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

これにより、接続されたデバイスがリストされます。もし「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

ポートトンネリング

Androidデバイス内の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 [オプション] <パス>

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 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

スクリーンキャプチャ/スクリーンレコード

adb shell screencap <filename>

デバイスのディスプレイのスクリーンショットを撮影します。

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

プロセス

あなたのアプリケーションのプロセスのPIDを取得したい場合は、次のコマンドを実行できます:

adb shell ps

そして、アプリケーションを検索します

または、次の操作を行うことができます

adb shell pidof com.your.application

そして、アプリケーションのPIDを出力します

システム

adb root

再起動します。ルート権限でadbdデーモンを再起動します。その後、再度ADBサーバーに接続する必要があります。そうすれば、ルートユーザーになります(利用可能な場合)。

adb sideload <update.zip>

ログ

Logcat

特定のアプリケーションのメッセージをフィルタリングするには、アプリケーションのPIDを取得し、logcatの出力をフィルタリングするためにgrep(linux/macos)またはfindstr(windows)を使用します。

adb logcat | grep 4526
adb logcat | findstr 4526

adb logcat [オプション] [フィルタ仕様]

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 <Buffer>

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

注意事項: 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を使用してAndroidデバイスをバックアップします。
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 -
AWSハッキングをゼロからヒーローまで学ぶ htARTE(HackTricks AWS Red Team Expert)

HackTricksをサポートする他の方法:

Last updated