网站首页置顶是怎么做,上海工商网查询营业执照,沭阳县城乡建设局网站,盗版网站是如何做的原文链接 本文原文来自#xff1a; A tcpdump Tutorial with Examples — 50 Ways to Isolate Traffic TCPDUMP 简介 TCPDUMP 在一个界面中既提供了强大的功能又简单易用#xff0c;无疑已经是网络分析工具中的老大。 本教程将介绍如何以各种方式隔离流量#xff1a;从IP A tcpdump Tutorial with Examples — 50 Ways to Isolate Traffic TCPDUMP 简介 TCPDUMP 在一个界面中既提供了强大的功能又简单易用无疑已经是网络分析工具中的老大。 本教程将介绍如何以各种方式隔离流量从IP端口到协议再到应用层流量。以确使用者保能够尽快找到所需内容。 查看所有流量 查看指定接口上的所有流量 tcpdump -i eth0 查看所有接口上的所有流量 tcpdump -i any 通过IP找流量 这是最常用的查询之一使用 host 指定主机就会看到 从指定IP的进流量和出流量 tcpdump host 1.1.1.1 -i ens33 通过源地址和/或目的地址进行过滤 如果你只想一个方向上的流量可以使用 src 或 dst 指定。 tcpdump src 192.168.27.100 -i ens33
tcpdump dst 192.168.27.100 -i ens33 通过网段过滤流量 使用 net 选项查看进出一个网段或子网的进出流量。 tcpdump net 1.2.3.0/24 使用十六进制输出流量包的内容 当要对一些包进行仔细审查其内容的时候使用十六进制输出的方式来查看包就很有用了。 tcpdump -c 1 -X icmp -i ens33
tcpdump -c 1 -X tcp port 443 -i ens33 -c 1 是指定只抓取一个包。 [rootcentos7 ~]#tcpdump -c 1 -X icmp -i ens33
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on ens33, link-type EN10MB (Ethernet), capture size 262144 bytes
15:25:37.519985 IP ming-machine centos7-scm: ICMP echo request, id 40906, seq 1154, length 640x0000: 4500 0054 61af 4000 4001 20c8 c0a8 1b7d E..Ta........}0x0010: c0a8 1b64 0800 5ec2 9fca 0482 007a f35c ...d..^......z.\0x0020: 0000 0000 3547 0d00 0000 0000 1011 1213 ....5G..........0x0030: 1415 1617 1819 1a1b 1c1d 1e1f 2021 2223 .............!#0x0040: 2425 2627 2829 2a2b 2c2d 2e2f 3031 3233 $%()*,-./01230x0050: 3435 3637 4567
1 packet captured
2 packets received by filter
0 packets dropped by kernel [rootcentos7-scm ~]#tcpdump -c 1 -X tcp port 443 -i ens33
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on ens33, link-type EN10MB (Ethernet), capture size 262144 bytes
15:25:40.084912 IP ming-machine.53006 tsa03s01-in-f14.1e100.net.https: Flags [S], seq 908528803, win 29200, options [mss 1460,sackOK,TS val 4054248663 ecr 0,nop,wscale 7], length 00x0000: 4500 003c 747a 4000 4006 48f3 c0a8 1b7d E..tz..H....}0x0010: d83a c8ee cf0e 01bb 3627 0ca3 0000 0000 .:......6......0x0020: a002 7210 668e 0000 0204 05b4 0402 080a ..r.f...........0x0030: f1a6 ecd7 0000 0000 0103 0307 ............
1 packet captured
1 packet received by filter
0 packets dropped by kernel
[rootcentos7-scm ~]# 查看指定端口上的流量 通过 port 选项可以找到指定端口上的进出流量。 tcpdump port 3389 -i ens33 # 3389 是 windows 远程链接的端口
tcpdump src port 1025 -i ens33 查看指定协议类型的流量 如果想要查看某一种类型协议的流量可以通过 tcp、 udp、 icmo 或其他协议类型。 tcpdump icmp 只查看 IPv6 流量 https://hauweele.net/~gawen/blog/?p1053 tcpdump src fe80::1e55:bb34:ae1:fd08 -i ens33
tcpdump dst fe80::1e55:bb34:ae1:fd08 -i ens33 抓包示例 [rootcentos7 ~]#tcpdump -nn dst fe80::1e55:bb34:ae1:fd08 -i ens33 -c 2
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on ens33, link-type EN10MB (Ethernet), capture size 262144 bytes
16:04:08.318748 IP6 fe80::20c:29ff:fe20:a3f5 fe80::1e55:bb34:ae1:fd08: ICMP6, echo request, seq 250, length 64
16:04:09.342193 IP6 fe80::20c:29ff:fe20:a3f5 fe80::1e55:bb34:ae1:fd08: ICMP6, echo request, seq 251, length 64
2 packets captured
2 packets received by filter
0 packets dropped by kernel 使用 ipv6 地址ping使用的是 ping6 命令 命令格式为 ping6 ipv6地址%网卡名 #要通过 % 指定网卡名
ping -6 ipv6地址%网卡名 #要通过 % 指定网卡名, ping -6 在ubuntu上无效需要使用ping6 示例 [rootcentos7 ~]#ping6 fe80::20c:29ff:fe20:a3f5%ens33
PING fe80::20c:29ff:fe20:a3f5%ens33(fe80::20c:29ff:fe20:a3f5%ens33) 56 data bytes
64 bytes from fe80::20c:29ff:fe20:a3f5%ens33: icmp_seq1 ttl64 time0.265 ms
64 bytes from fe80::20c:29ff:fe20:a3f5%ens33: icmp_seq2 ttl64 time0.319 ms
64 bytes from fe80::20c:29ff:fe20:a3f5%ens33: icmp_seq3 ttl64 time0.510 ms [rootcentos7 ~]#ping -6 fe80::20c:29ff:fe20:a3f5%ens33 -c 2
PING fe80::20c:29ff:fe20:a3f5%ens33(fe80::20c:29ff:fe20:a3f5%ens33) 56 data bytes
64 bytes from fe80::20c:29ff:fe20:a3f5%ens33: icmp_seq1 ttl64 time0.231 ms
64 bytes from fe80::20c:29ff:fe20:a3f5%ens33: icmp_seq2 ttl64 time0.402 ms 通过端口范围过滤 tcpdump portrange 21-23 查看指定大小的数据包 可以查看指定大小的数据包指定数据包的大小的时候还可以使用比较运算符。 tcpdump less 32
tcpdump greater 64
tcpdump 128 读/写抓取的信息从/到文件 将抓取到的数据包信息存储到文件以便将来进行分析是很必要的。文件格式为 PCAP (PEE-cap) files格式。这种文件可以被众多的应用程序解析包括网络分析工具、入侵检测系统、当然还有tcpdump自己。 保存抓包信息到文件 使用 -w 选项写入文件(后缀是 .cap 就可以使用 wireshark 识别分析) sudo tcpdump -i eth0 -c 100 -w catcher.cap $ sudo tcpdump -i eth0 -c 100 -w catcher.cap
tcpdump: listening on eth0, link-type EN10MB (Ethernet), capture size 262144 bytes
100 packets captured
213 packets received by filter
0 packets dropped by kernel
$ 从文件中读取抓包信息 使用 -r 选项从文件中读取在读取文件的时候我们可以像正常抓包时一样使用tcpdump.需要注意的是文件中不存在的数据是抓取不到和解析的。 tcpdump -r capture_file 示例 tcpdump -r capture_file dst 192.168.27.125
tcpdump -r capture_file src 192.168.27.100
tcpdump -r capture_file -i ens33 icmp6 以下是进阶内容 下面是 tcpdump 的一些其他进阶选项工抓包时候进行进一步调整。 -A : Print each packet (minus its link level header) in ASCII. Handy for capturing web pages.-X : 十六进制的ASCII编码方式输出显示包内容-XX : 同 -X , 但是同时显示一台帧头部信息。-D : 显示可用的接口列表。-l : 显示行号输出。-q : 静默输出显示最少的信息。-t : 输出的时间戳为人类可读格式经实验无时间戳输出。-tttt : 输出最详细的时间戳为人类可读格式。-i eth0 : 监听 eth0 网卡抓包。-vv : 比 -v 有更详细的输出。-c : 指定的抓包的数量之后停止。-s : 指定每个抓取的数据包的字节长度默认是262144字节. 使用 -s0 获取整个数据包的内容。-S : 输出绝对数据包的绝对序列号。-e : 同时获取以太帧头信息。-E : 通过给定的密钥解密 IPSEC 数据流。关于组合(或与非) tcpdump 除了支持上面的单独的功能还提供了更加强大的组合功能可以让我们创造出各种组合形式来得到我们想要的结果。如果学习果编程你会发现下面的内容似曾相识。 ANDand or ORor or ||EXCEPTnot or !裸视图输出 下面的组合输出的是没有主机名和端口解析、使用绝对序号、人类可读时间戳的详细输出。 [rootcentos7 ~]#tcpdump -ttnnvvS -i ens33 -c 1
tcpdump: listening on ens33, link-type EN10MB (Ethernet), capture size 262144 bytes
1559468718.414926 IP (tos 0x10, ttl 64, id 35965, offset 0, flags [DF], proto TCP (6), length 216)192.168.27.100.22 192.168.27.2.14154: Flags [P.], cksum 0xb881 (incorrect - 0x7999), seq 580563511:580563687, ack 2138271063, win 339, length 176 指定源IP和目的端口的流量 tcpdump -nnvvS src 10.5.2.3 and dst port 3389 网段到网段的流量 下面阿组合输出为从源为192.168.0.0/16目的为10.0.0.0/8或172.16.0.0/16、不解析主机名、十六进制格式、详细级别为-v级别的抓包信息。 tcpdump -nvX src net 192.168.0.0/16 and dst net 10.0.0.0/8 or 172.16.0.0/16 到指定地址的非ICMP的流量 tcpdump dst 192.168.0.2 and src net and not icmp 指定源主机和排除目的端口的流量 下面的输出为源为指定的主机 mars, 目的端口不是 22 端口的流量信息。 tcpdump -vv src mars and not dst port 22 关于分组的小结 我们可以看到通过合理的组合我们就可以得到任何想要的结果关键是要搞清楚想要的信心并且构建合适的查询语法。 在构建复杂查询时可能必须使用单引号对选项进行分组在下例中是在“()”括号下面。单引号用于告诉tcpdump忽略某些特殊字符。同样的技术也可以用于使用其他表达式(如host、port、net等)进行分组。 tcpdump src 10.0.2.4 and (dst port 3389 or 22) 隔离指定TCP标记的流量 TCP 报头 # TCP 报头简图 一个 TCP 头为 20 字节0 15 31
-----------------------------------------------------------------
| source port | destination port |
-----------------------------------------------------------------
| sequence number |
-----------------------------------------------------------------
| acknowledgment number |
-----------------------------------------------------------------
| HL | rsvd |C|E|U|A|P|R|S|F| window size |
-----------------------------------------------------------------
| TCP checksum | urgent pointer |
-----------------------------------------------------------------# 下面是标志位的部分位置处在包头20字节中的第 13 字节的位置。0 7| 15| 23| 31
----------------|---------------|---------------|----------------
| HL | rsvd |C|E|U|A|P|R|S|F| window size |
----------------|---------------|---------------|----------------
| | 13th octet | | | 通过二进制计算可以得到 FIN 的值为 1 2^0SYN 的值为 2 2^1RST 的值为 4 2^2PSH 的值为 8 2^3ACK 的值为 162^4URG 的值为 322^5ECE 的值为 642^6CWR 的值为 1282^7TCP RST 标记的隔离 tcpdump tcp[13] 4!0
tcpdump tcp[tcpflags] tcp-rst TCP SYN 标记的隔离 tcpdump tcp[13] 2!0
tcpdump tcp[tcpflags] tcp-syn TCP ACK 和 SYN 标记的隔离 tcpdump tcp[13]18 TCP URG 标记的隔离 tcpdump tcp[13] 32!0
tcpdump tcp[tcpflags] tcp-urg TCP ACK 标记的隔离 tcpdump tcp[13] 16!0
tcpdump tcp[tcpflags] tcp-ack TCP PSH 标记的隔离 tcpdump tcp[13] 8!0
tcpdump tcp[tcpflags] tcp-psh TCP FIN 标记的隔离 tcpdump tcp[13] 1!0
tcpdump tcp[tcpflags] tcp-fin 快速过滤 TCP FLAG 可以通过上文中计算出的各个标志位的对应值直接计算出组合的值来设置组合对应的值。 Both SYN and RST Set SYN 的值为 2 2^1RST 的值为 4 2^2tcpdump tcp[13] 6 过滤 HTTP的 User Agents tcpdump -vvAls0 -i ens33| grep User-Agent: [rootcentos7-scm ~]#curl --head www.baidu.com
HTTP/1.1 200 OK
Accept-Ranges: bytes
Cache-Control: private, no-cache, no-store, proxy-revalidate, no-transform
Connection: Keep-Alive
Content-Length: 277
Content-Type: text/html
Date: Sun, 02 Jun 2019 10:42:35 GMT
Etag: 575e1f60-115
Last-Modified: Mon, 13 Jun 2016 02:50:08 GMT
Pragma: no-cache
Server: bfe/1.0.8.18 [rootcentos7-scm ~]#tcpdump -vvAls0 -i ens33| grep User-Agent:
tcpdump: listening on ens33, link-type EN10MB (Ethernet), capture size 262144 bytesUser-Agent: curl/7.29.0
User-Agent: curl/7.29.0 过滤 HTTP的 明文 HTTP 请求头 tcpdump -vvAls0 -i ens33 | grep GET [rootcentos7-scm ~]#curl -X GET www.baidu.com
!DOCTYPE html
!--STATUS OK--html headmeta http-equivcontent-type contenttext/html;charsetutf-8meta http-equivX-UA-Compatible contentIEEdgemeta contentalways namereferrerlink relstylesheet typetext/css hrefhttp://s1.bdstatic.com/r/www/cache/bdorz/baidu.min.csstitle百度一下你就知道/title/head body link#0000cc div idwrapper div idhead div classhead_wrapper div classs_form div classs_form_wrapper div idlg img hidefocustrue src//www.baidu.com/img/bd_logo1.png width270 height129 /div form idform namef action//www.baidu.com/s classfm input typehidden namebdorz_come value1 input typehidden nameie valueutf-8 input typehidden namef value8 input typehidden namersv_bp value1 input typehidden namersv_idx value1 input typehidden nametn valuebaiduspan classbg s_ipt_wrinput idkw namewd classs_ipt value maxlength255 autocompleteoff autofocus/spanspan classbg s_btn_wrinput typesubmit idsu value百度一下 classbg s_btn/span /form /div /div div idu1 a hrefhttp://news.baidu.com nametj_trnews classmnav新闻/a a hrefhttp://www.hao123.com nametj_trhao123 classmnavhao123/a a hrefhttp://map.baidu.com nametj_trmap classmnav地图/a a hrefhttp://v.baidu.com nametj_trvideo classmnav视频/a a hrefhttp://tieba.baidu.com nametj_trtieba classmnav贴吧/a noscript a hrefhttp://www.baidu.com/bdorz/login.gif?loginamp;tplmnamp;uhttp%3A%2F%2Fwww.baidu.com%2f%3fbdorz_come%3d1 nametj_login classlb登录/a /noscript scriptdocument.write(a hrefhttp://www.baidu.com/bdorz/login.gif?logintplmnu encodeURIComponent(window.location.href (window.location.search ? ? : ) bdorz_come1) nametj_login classlb登录/a);/script a href//www.baidu.com/more/ nametj_briicon classbri styledisplay: block;更多产品/a /div /div /div div idftCon div idftConw p idlh a hrefhttp://home.baidu.com关于百度/a a hrefhttp://ir.baidu.comAbout Baidu/a /p p idcpcopy;2017nbsp;Baidunbsp;a hrefhttp://www.baidu.com/duty/使用百度前必读/anbsp; a hrefhttp://jianyi.baidu.com/ classcp-feedback意见反馈/anbsp;京ICP证030173号nbsp; img src//www.baidu.com/img/gs.gif /p /div /div /div /body /html [rootcentos7-scm ~]#tcpdump -vvAls0 -i ens33 | grep GET
tcpdump: listening on ens33, link-type EN10MB (Ethernet), capture size 262144 bytesGET / HTTP/1.1
E..u|.......dg.....P601.....P...r...GET / HTTP/1.1 过滤 HTTP的 Hosts tcpdump -vvAls0 -i ens33 | grep Host: [rootcentos7-scm ~]#curl -I www.baidu.com
HTTP/1.1 200 OK
Accept-Ranges: bytes
Cache-Control: private, no-cache, no-store, proxy-revalidate, no-transform
Connection: Keep-Alive
Content-Length: 277
Content-Type: text/html
Date: Sun, 02 Jun 2019 10:48:40 GMT
Etag: 575e1f60-115
Last-Modified: Mon, 13 Jun 2016 02:50:08 GMT
Pragma: no-cache
Server: bfe/1.0.8.18 [rootcentos7-scm ~]#tcpdump -vvAls0 -i ens33 | grep Host:
tcpdump: listening on ens33, link-type EN10MB (Ethernet), capture size 262144 bytesHost: www.baidu.com
Host: www.baidu.com 过滤 HTTP Cookies tcpdump -vvAls0 -i ens33 | grep -E Set-Cookie:|Host:|Cookie: [rootcentos7-scm ~]#wget www.baidu.com
--2019-06-02 19:34:49-- http://www.baidu.com/
Resolving www.baidu.com (www.baidu.com)... 220.181.38.149, 220.181.38.150
Connecting to www.baidu.com (www.baidu.com)|220.181.38.149|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2381 (2.3K) [text/html]
Saving to: ‘index.html.5’100%[] 2,381 --.-K/s in 0s 2019-06-02 19:34:49 (191 MB/s) - ‘index.html.5’ saved [2381/2381] [rootcentos7-scm ~]#tcpdump -vvAls0 -i ens33 | grep -E Set-Cookie:|Host:|Cookie:
tcpdump: listening on ens33, link-type EN10MB (Ethernet), capture size 262144 bytesHost: www.baidu.com
Host: www.baidu.comSet-Cookie: BDORZ27315; max-age86400; domain.baidu.com; path/
Set-Cookie: BDORZ27315; max-age86400; domain.baidu.com; path/ 过滤 SSH Connections This one works regardless of what port the connection comes in on, because it’s getting the banner response. tcpdump tcp[(tcp[12]2):4] 0x5353482D -i ens33 [rootcentos7 ~]#tcpdump tcp[(tcp[12]2):4] 0x5353482D -i ens33
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on ens33, link-type EN10MB (Ethernet), capture size 262144 bytes
18:36:23.490464 IP gateway.fronet centos7.ssh: Flags [P.], seq 960612390:960612432, ack 497953643, win 2053, length 42
18:36:23.502672 IP centos7.ssh gateway.fronet: Flags [P.], seq 1:22, ack 42, win 229, length 21 过滤 DNS 流量 tcpdump -vvAs0 port 53 -i ens33 [rootcentos7-scm ~]#ping www.google.com
PING www.google.com (74.86.235.236) 56(84) bytes of dat [rootcentos7-scm ~]#tcpdump -vvAs0 port 53 -i ens33
tcpdump: listening on ens33, link-type EN10MB (Ethernet), capture size 262144 bytes
19:39:12.520747 IP (tos 0x0, ttl 64, id 6789, offset 0, flags [DF], proto UDP (17), length 60)centos7-scm.40966 google-public-dns-a.google.com.domain: [bad udp cksum 0xec55 - 0xbfb1!] 9453 A? www.google.com. (32)
E......4....d.......5.(.U$............www.google.com.....
19:39:12.521795 IP (tos 0x0, ttl 64, id 6790, offset 0, flags [DF], proto UDP (17), length 66)centos7-scm.59105 google-public-dns-a.google.com.domain: [bad udp cksum 0xec5b - 0x3a7d!] 55476 PTR? 8.8.8.8.in-addr.arpa. (38)
E..B....4 ...d.......5...[.............8.8.8.8.in-addr.arpa.....
19:39:12.537071 IP (tos 0x0, ttl 60, id 27911, offset 0, flags [DF], proto UDP (17), length 76)google-public-dns-a.google.com.domain centos7-scm.40966: [udp sum ok] 9453 q: A? www.google.com. 1/0/0 www.google.com. A 74.86.235.236 (48)
E..Lm....}.......d.5...8G.$............www.google.com.................JV..
19:39:12.537087 IP (tos 0x0, ttl 48, id 0, offset 0, flags [none], proto UDP (17), length 76)google-public-dns-a.google.com.domain centos7-scm.40966: [udp sum ok] 9453 q: A? www.google.com. 1/0/0 www.google.com. A 69.63.186.30 (48)
E..L....0..........d.5...8~.$............www.google.com.................E?.. 过滤 FTP 流量 tcpdump -vvAs0 port ftp or ftp-data -i ens33 过滤NTP流量 tcpdump -vvAs0 port 123 -i ens33 过滤明文密码 tcpdump port http or port ftp or port smtp or port imap or port pop3 or port telnet -lA | egrep -i -B5 pass|pwd|log|login|user|username|pw|passw|passwd |password|pass:|user:|username:|password:|login:|pass |user testmachine:~$ curl -X GET http://www.baidu.com/?pass123456
!DOCTYPE html
!--STATUS OK--html ... /html testmachine:~$ sudo tcpdump port http or port ftp or port smtp or port imap or port pop3 or port telnet -lA | egrep -i -B5 pass|pwd|log|login|user|username|pw|passw|passwd |password|pass:|user:|username:|password:|login:|pass |user
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 262144 bytes
.Q.!........
19:49:57.328294 IP 103.235.46.39.http 192.168.27.125.47334: Flags [S.], seq 2439930931, ack 2291696402, win 8192, options [mss 1440,sackOK,nop,nop,nop,nop,nop,nop,nop,nop,nop,nop,nop,wscale 5], length 0
E..d*.,.xZg.....}.P...nd3...... ..O......................
19:49:57.328365 IP 192.168.27.125.47334 103.235.46.39.http: Flags [.], ack 1, win 229, length 0
E..(d..dm...}g.....P.....nd4P...rR..
19:49:57.328474 IP 192.168.27.125.47334 103.235.46.39.http: Flags [P.], seq 1:90, ack 1, win 229, length 89: HTTP: GET /?pass123456 HTTP/1.1
E...d,..d....}g.....P.....nd4P...r...GET /?pass123456 HTTP/1.1 过滤包含邪恶位的包 IP 包头中有 3个bit的标志位Flag3bit的标识字段每一位都有特定的含义该字段主要用来分片和重组。第1个bit为保留位Reserved Bit一般置位0。第2个bit为不分片位Don’t ragment该位在置1时表示不分片。第3个bit为更多片位More Fragment该位表示后面是否还有更多的分片置位1时表示后面还有所以除了最后一片报文其他分片报文该位全部置1。 这里指的邪恶位就是第一个bit的位置。 处在IP包头中的第6个字节位置。 tcpdump ip[6] 128 ! 0 几种重要流量的抓取 本节内容参考自 tcpdump简明教程: https://github.com/mylxsw/growing-up/blob/master/doc/tcpdump%E7%AE%80%E6%98%8E%E6%95%99%E7%A8%8B.md 这里有一些重要的代码片段你可能需要它们用于过滤指定的流量例如畸形的或者恶意的流量。 过滤同时设置SYN和RST标识的包这在正常情况下不应该发生 tcpdump tcp[13] 6 过滤明文的HTTP GET请求 tcpdump tcp[32:4] 0x47455420 通过横幅文本过滤任意端口的SSH连接 tcpdump tcp[(tcp[12]2):4] 0x5353482D 过滤TTL小于10的包通常情况下是存在问题或者在使用traceroute tcpdump ip[8] 10 过滤恶意的包 tcpdump ip[6] 128 ! 0 可能出现问题的解决 在RHEL7下如果不用-i参数指定网络接口则会报如下错误tcpdump: Bluetooth link-layer type filtering not implemented 转载于:https://www.cnblogs.com/shichangming/p/10964238.html