美文网首页
Android tcpdump TCP 抓包

Android tcpdump TCP 抓包

作者: 木猫尾巴 | 来源:发表于2017-06-20 16:13 被阅读3497次

[TOC]

常用抓取命令

adb shell rm /sdcard/capture.pcap
adb shell  /data/local/tcpdump -i any -p -s 0 -w /sdcard/capture.pcap
adb pull /sdcard/capture.pcap capture.pcap

安装

使用准备

  • 设备需要root权限
  • tcpdump 二进制文件
  • wireshark 分析工具

https://www.wireshark.org/
tcpdump for android 说明
http://www.androidtcpdump.com/

安装tcpdump到设备

adb shell, su获得root权限

tcpdump 需要在命令行运行目录中存在

adb push tcpdump /data/local/tcpdump
adb shell chmod 6755 /data/local/tcpdump

使用 tcpdump

cd /data/local
./tcpdump -i any -p -s 0 -w /sdcard/capture.pcap

拉取抓获的tcp/udp包

adb pull /sdcard/capture.pcap

用wireshark打开capture.pcap即可分析log

  • tcpdump 参数说明
        # "-i any": listen on any network interface
  # "-p": disable promiscuous mode (doesn't work anyway)
  # "-s 0": capture the entire packet
  # "-w": write packets to a file (rather than printing to stdout)
  ... do whatever you want to capture, then ^C to stop it ...

错误处理

Android5.0系统下用tcpdump抓包失败

在Android5.0系统下用tcpdump抓包失败,但是在5.0之前的系统上可以正常抓包

error: only position independent executables (PIE) are supported.

这是由于PIE安全机制所引起的,从Android4.1开始引入该机制

PIE机制它会随机分配程序的内存地址从而令攻击者更难发现程序的溢出漏洞

PIE机制详细介绍 https://en.wikipedia.org/wiki/Position-independent_code

Android L之前的系统版本并不会去检验可执行文件是否基于PIE编译出的

因此低于Android L 以前不会报错

但是Android L已经开启验证,如果调用的可执行文件不是基于PIE方式编译的,则无法运行

编译的时候加上如下的flag就行

LOCAL_CFLAGS += -pie -fPIE
LOCAL_LDFLAGS += -pie -fPIE

adb shell 不是root用户

有些机器root后通过adb shell 后,默认不是root用户,需要输入 su才能切换到root

安装 su 需要自己破解root

adb shell "su -c 'sleep 1'"
adb start-server
adb push tcpdump /data/local/tcpdump
adb shell su -c "/data/local/tmp/tcpdump -i any -p -s 0 -w /sdcard/netCapture.pcap"

安装脚本

使用脚本前,需要注意这个脚本要求 adb 进入就是root权限,你可以使用adb root获取

#!/bin/bash

shell_script_path=$(cd `dirname $0`; pwd)

tcpdump_local_path="${shell_script_path}/tcpdump"

if [ ! -f "${tcpdump_local_path}" ]; then
  cd ${shell_script_path}
  curl -O http://www.androidtcpdump.com/download/4.9.0/tcpdump
  echo -e "download tcpdump at path ${shell_script_path}"
fi

if [ -f "${tcpdump_local_path}" ]; then
    echo -e "findout tcpdump ${tcpdump_local_path}"
else
    echo -e "download tcpdump fail"
    exit 1
fi
adb push "${tcpdump_local_path}" /data/local/tcpdump
adb shell chmod 6755 /data/local/tcpdump
echo -e "install tcpdump success"
echo -e "You can use like
adb shell as root!
cd /data/local/
./tcpdump -i any -p -s 0 -w /sdcard/capture.pcap

Then exit shell
adb pull /sdcard/capture.pcap .
"

echo -e "Do you want delete tcpdump file (y) ?"
read isDeleteDownload
if [ ${isDeleteDownload} == "y" ]; then
  rm -f ${tcpdump_local_path}
  echo -e "success remove ${tcpdump_local_path}"
fi

相关文章

  • Android tcpdump TCP 抓包

    [TOC] 常用抓取命令 安装 使用准备 设备需要root权限 tcpdump 二进制文件 wireshark 分...

  • tcpdump小黑板抓包

    Linux、Unix默认安装了tcpdump纯字符抓包工具 抓包 抓包筛选 高级筛选 这里tcp[13]是指下图里...

  • 应用抓包之Fiddler抓包

    抓包前准备 tcpdump抓包:应用抓包之tcpdump命令抓包 原料 1.抓包工具Fiddler(Windows...

  • Tcpdump 抓包教程 用 WireShark 抓取 4G下的

    tcpdump网上教程 iOS,Android网络抓包教程之tcpdumpWireshark抓包iOS入门教程 i...

  • Android tcpdump 抓包

    1.手机必须root 2.下载tcpdump 5.1以后的 有安全验证 https://raw.githubu...

  • 手机抓包

    【】非常实用的博客 tcpdump for Android 移动端抓包 https://blog.csdn.net...

  • tcpdump命令

    1. tcpdump用途 抓包 2. tcpdump用法 tcpdump [option] expression...

  • tcpdump抓包分析

    tcpdump抓包,加上-X选项后,会打印出包的具体内容, 其中有个tcp Flags 的标志,就是tcp包头中的...

  • Android端抓包(tcpdump)

    抓包准备 Android手机需要先获得root权限。一种是否获得root权限的检验方法:安装并打开终端模拟器(可通...

  • Android通过tcpdump抓包

    1 手机要有root权限 2 下载tcpdump android模拟器上linux里面有的会自带。 3 adb p...

网友评论

      本文标题:Android tcpdump TCP 抓包

      本文链接:https://www.haomeiwen.com/subject/hdfaqxtx.html