{{ v.name }}
{{ v.cls }}类
{{ v.price }} ¥{{ v.price }}
wireshark针对unixlike系统的gui发行版界面采用的是xwindow(1987年更改x版本到x11)。macosx在mountainlion之后放弃x11,取而代之的是开源的xquartz(x11.app)。因此,在macosx上安装wireshark之前,需要先下载安装quartz。
xquartz(xquartz-2.7.6.dmg)安装完成后,按照提示需要注销重新登录,以使xquartz作为默认的x11server。
安装成功后,在终端输入“xterm--help”可查看命令行帮助,输入“xterm-version”可查看xterm版本信息。在终端输入“xterm”或通过菜单“applications->terminal”可启动xwindow(xquartz)的终端(xterm)。
安装osx10.6andlaterintel64-bit版本(wireshark1.12.0intel64.dmg)。
安装成功后,在终端输入“wireshark--help”可查看命令行帮助,输入“wireshark--v”可查看wireshark版本信息。
首次启动wireshark,提示通过前端x11窗口可以操控wireshark;由于需要编译字体包,可能需要耗费几分钟。
如果事先没有安装x11(xquartz),则会提示引导安装x11。
如果事先已经安装好xquartz(x11),则会引导选择x11.app所在路径。——最新版本的wireshark1.12.4intel64.dmg貌似会自动识别已安装的x11路径而无需手动指定。
点击browse到“/applications/utilities/xquartz.app”,将xquartz作为wireshark的x11前端。——最新版本的wireshark1.12.4intel64.dmg貌似会自动识别已安装的x11路径而无需手动指定。
如果不出意外的话,wireshark将成功启动。
关于macosx升级yosemite后无法启动wireshark的问题
macosx升级yosemite后,无法启动wireshark,是因为yosemite将x11外链文件夹从原来的/usr移动到了/opt下。可通过以下三种方式解决:
-解决方法1:重装或升级xquartz
-解决方法2:将/opt/x11拷贝一份到/usr/x11:sudomv/opt/x11/usr/x11
-解决方法3:将/opt/x11软链一份到/usr/x11:sudoln-s/opt/x11/usr/x11
点击启动首页中的“interfacelist”(相当于菜单“capture->interfaces”),可以查看本机活跃网卡(通过系统菜单apple->aboutthismac->moreinfo->overview->systemreport或终端命令ifconfig也可查看)。
由于本人imac使用无线接入,故en1(wirelessnic)和lo0(本机环路)活跃(active),有线网卡en0(wirednic)未使用(inactive)。注意:mbp上没有有线网卡,en0即为无线网卡,可通过ifconfig命令自行识别。
这里可以直接勾选en1,点击start按钮使用默认captureoptions(默认勾选了混杂模式[promiscuousmode])进行抓包;可以在启动首页点选“wi-fi:en1”打开“editinterfacesettings”,设置(例如可配置capturefilters只捕捉指定类型或条件的数据包)或使用默认captureoptions开始抓包;也可以从菜单“capture->options”着手,选择网卡设置选项开始抓包。
这里选择了无线网卡(wi-fi:en1),怎么抓到的是以太网包(ethernetpacket)呢?实际上它是某些bsd提供的伪以太网头(fakeethernetheaders)。如果要抓取ieee802.11无线包(beaconframe等),则需要开启监听模式[monitormode],并且将link-layerheadertype选为802.11系列选项。
另外,在displayfilters中填写了“http”,将从捕捉到的数据包中过滤出并只显示http协议包。
在“editinterfacesettings”或“captureoptions”中勾选“capturepacketsinmonitormode”开启监听模式,然后勾选link-layerheadertype为“802.11”开始抓取无线包。
说明:
(1)imac开启monitormode时,可能会阻塞网卡导致上不了网,参见下文相关说明。
(2)windows下抓取802.11无线帧(management/control/dataframe),需要wireshark配合airpcap或使用omnipeek。
(1)managementframe:
type/subtype:beaconframe(0x0008,bit[5:0]=00,1000b)
type/subtype:proberesponse(0x0005,bit[5:0]=00,0101b)
(2)controlframe:
type/subtype:802.11blockack(0x0019,bit[5:0]=01,1001b)
type/subtype:request-to-send(0x001b,bit[5:0]=01,1011b)
type/subtype:clear-to-send(0x001c,bit[5:0]=01,1100b)
type/subtype:acknowledgement(0x001d,bit[5:0]=01,1101b)
(3)dataframe:
type/subtype:data(0x0020,bit[5:0]=10,0000b)
type/subtype:nullfunction(nodata)(0x0024,bit[5:0]=10,0100b)
type/subtype:qosdata(0x0028,bit[5:0]=10,1000b)
type/subtype:qosdata+cf-ack+cf-poll(0x002b,bit[5:0]=10,1011b)
(1)rvi简介
使用mac抓取iphone数据包可通过共享和代理两种方式:
这两种方式都是将iphone的网络流量导入到mac电脑中,通过mac连接互联网。这就要求mac本身是联网的,对于网络共享的方式还要求mac本身的网络不能使用wifi,而且在iphone上只能使用wifi连接,无法抓取到xg(2g/3g/4g)网络包。
苹果在ios5中新引入了“远程虚拟接口(remotevirtualinterface,rvi)”的特性,可以在mac中建立一个虚拟网络接口来作为ios设备的网络栈,这样所有经过ios设备的流量都会经过此虚拟接口。此虚拟接口只是监听ios设备本身的协议栈(但并没有将网络流量中转到mac本身的网络连接上),所有网络连接都是ios设备本身的,与mac电脑本身联不联网或者联网类型无关。ios设备本身可以为任意网络类型(wifi/xg),这样在mac电脑上使用任意抓包工具(tcpdump、wireshark、cpa)抓取rvi接口上的数据包就实现了对iphone的抓包。
macosx对rvi的支持是通过终端命令rvictl提供的,在终端(terminal)中输入“rvictl?”命令可查看帮助:
==================================================
rvictloptions:
-l,-llistcurrentlyactivedevices
-s,-sstartadeviceorsetofdevices
-x,-xstopadeviceorsetofdevices
==================================================
(2)使用“rvictl-s”命令创建虚拟接口
首先,通过mfiusb数据线将iphone连接到安装了macos+xcode4.2(orlater)的mac机上。ios7以上需要搭配xcode5.0(orlater),抓包过程中必须保持连接。
然后,通过itunes->summary或者xcode->organizer->devices获取iphone的udid(identifier)。
接着,使用“rvictl-s”命令创建rvi接口,使用iphone的udid作为参数。
==================================================
$rvictl-s
==================================================
创建成功后,在终端通过ifconfig命令可以看到多了一个rvi0接口。当有多个ios设备连接imac时,依次是rvi1,rvi2…,使用“rvictl-l”命令可以列出所有挂接的虚拟接口。
在wireshark首页选择rvi0,使用默认的captureoptions即可开始对iphone进行抓包。
下图为抓取的wifi数据包:
其中iphone手机连接wifi动态获取的ip地址为192.168.199.230。
下图为抓取的3g数据包:
说明:联通3g上网动态分配的都是172.20网段(例如172.20.124.251)的这种b类私网地址(172.16.0.0~172.32.255.255)。手机百度中输入ip,ip138中显示112.97.24.178是深圳联通附近基站对外的公网网关ip地址。
(3)使用“rvictl-x”命令删除虚拟接口
使用rvictl-x命令删除rvi接口,使用iphone的udid作为参数。
==================================================
$rvictl-x
==================================================
(1)《wiresharkfaq》:q10.1:howcanicaptureraw802.11frames,includingnon-data(management,beacon)frames?
note:aninterfacerunninginmonitormodewill,onmostifnotallplatforms,notbeabletoactasaregularnetworkinterface;puttingitintomonitormodewill,ineffect,takeyourmachineoffofwhatevernetworkit'sonaslongastheinterfaceisinmonitormode,allowingitonlytopassivelycapturepackets.
thismeansthatyoushoulddisablenameresolutionwhencapturinginmonitormode;otherwise,whenwireshark(ortshark,ortcpdump)triestodisplayipaddressesashostnames,itwillprobablyblockforalongtimetryingtoresolvethenamebecauseitwillnotbeabletocommunicatewithanydnsornisservers.
(2)《airsnortfaq》:q3:whatisthedifferencebetwenmonitorandpromiscuousmode?
monitormodeenablesawirelessnictocapturepacketswithoutassociatingwithanaccesspointorad-hocnetwork.thisisdesirableinthatyoucanchooseto"monitor"aspecificchannel,andyouneednevertransmitanypackets.infacttransmitingissometimesnotpossiblewhileinmonitormode(driverdependent).anotheraspectofmonitormodeisthatthenicdoesnotcarewhetherthecrcvaluesarecorrectforpacketscapturedinmonitormode,sosomepacketsthatyouseemayinfactbecorrupted.
实际上,我在osx10.9.4上安装xquartz+wireshark非常顺利,没有出现什么诸如无法发现网卡(nointerfaceavailable)的权限问题。
安装前执行“ls-l/dev/bpf*”,bpf0/bpf1/bpf2/bpf3只有“rw-------”权限;安装完成时,再次执行“ls-l/dev/bpf*”,发现权限已经升级为了“rw-rw----”,即wireshark已经给当前安装使用wireshark的user(administrator)所在的group配置了rw权限。相当于执行过“sudochmodg+rw/dev/bpf*”,并且已经被配置到随机启动,下次开机不用重新执行该命令。
--------------------------------------------------------------------------------
/captureprivileges-youmusthavesufficientprivilegestocapturepackets,e.g.specialprivilegesallowingcapturingasanormaluser(preferred)orroot/administratorprivileges.
inordertocapturepacketsunderbsd(includingmacosx),youmusthavereadaccesstothebpfdevicesin/dev/bpf*.
enablingandusingthe"root"userinmacosx
platform-specificinformationaboutcaptureprivileges。
howtosecurelyconfiguremacosxfornetworkpacketsniffingwithwireshark
--------------------------------------------------------------------------------
上文主要讲解的是在不越狱正常权限情况下,通过rvi虚拟接口挂钩抓取iphone数据包,一台iphone通常只对应一个rvi虚拟接口。但是iphone本身支持两种上网模式——wifi/xg(类似pc工作站多网卡情形),当xg和wifi同时活跃时(en0为无线网卡,pdp_ip0为3g网卡),ios将wifi作为优先默认路由通道。
那么,当需要调试分析xg/wifi切换或并存时的一些路由策略或临界流量问题时,如何抓取指定通道(wifi/xg)的数据包呢?使用rvi通过包源ip可能可以区分,但是由于权限等问题,总是不那么方便。此时,通过越狱,在iphone上安装远程登录工具包(openssh)、网络诊断分析命令行工具network-cmds(arp,ifconfig,ping,traceroute,netstat),然后在winpc或imac上通过ssh隧道发送tcpdump命令可指定wifi/xg网卡进行抓包(ssh远程控制iphone运行tcpdump抓包),最后通过wireshark对pcap文件进行分析或统计。
以第4节中gethttp://blog.csdn.net/phunxm为例,仅做简单的分析。
###############################################################
no148:发包的源mac/ip地址为本机mac/ip地址。(1)destinationmac为00:00:0c:07:ac:24(ciscoall-hsrp-routers_24)socket编程通常在ip层以上进行,一般不关心mac地址。我们的电脑也不可能与csdn博客服务器直接相连,一般要经过很多中间节点(hops)。根据邻居协议,目的mac地址为下一跳(nexthop,[default]gateway/router)的mac地址。通过networkutility或“route-ngetdefault”或“netstat-rn”命令可获得默认网关为10.64.66.1。通过“arp-a”显示“?(10.64.66.1)at0:0:c:7:ac:24onen1ifscope[ethernet]”。
(2)destinationip为10.14.36.100按道理,目的ip地址应该为csdn博客服务器(blog.csdn.net)主机的ip(117.79.157.201),为什么这里的却为a类私网地址(10.14.36.100)呢?
这是因为内网使用了httpproxy,10.14.36.100是proxy.pac(参考:原理、脚本、设置、自动化)基于域名判断出口返回的proxyserver的ip地址。
###############################################################
no251:收包(http/1.1200ok)的目的mac/ip地址为接收方(本机)的mac/ip地址。
(1)源ip地址为proxyserver的ip地址,同上。
(2)源mac地址一般应为【默认】网关的mac地址(进出都要过关),实际抓包却发现mac地址并非【默认】网关的mac地址,这是什么情况呢?
通过windows的“routeprint”或macosx/unix下的“netstat-r”命令可查看路由表(routingtables)信息。通过windows下的“tracert10.14.36.100”或macosx/unix下的“traceroute10.14.36.100”命令可查看本机到代理10.14.36.100之间的路由信息,第一跳并非默认网关(10.64.66.1),而是10.64.66.2!
这是因为采用了热备路由(hsrp),hsrp协议利用优先级决定哪个路由器成为活动路由器,收包的那个陌生源mac地址即是热备路由(10.64.66.2)的mac地址!
升级到xquartz-2.7.8后,貌似wireshark出现了无法发现网卡的问题,索性卸载了之前通过dmgwithpkg安装的wireshark1.12.0,完整的卸载指令可参考completeuninstallinstructions。
wireshark官网于18november,2015发布了stablerelease(2.0.0),可前往下载osx10.6andlaterintel64-bit.dmg安装包进行安装体验。这次,我使用brew-cask来安装wireshark软件,完整的安装日志可参考《brew-caskinstallwireshark.log》。
鉴于macosx在mountainlion之后已不再自带x11,新版的wireshark2.0.0也摒弃了陈旧的gtk+/x11界面,取而代之的是与windows版保持一致的qt界面,简洁清爽。
“wireshark’sdebian-andrpm-basedpackagedefinitionsprovidethenewinterfaceinthe“wireshark-qt”packageandtheoldinterfaceinthe“wireshark-gtk”package.
theosxinstalleronlyprovidesthenewinterface.”
——wireshark2.0.0releasenotes-what’snew