我正在尝试为基于 Wireshark 命令行的 TShark 编写一个过滤器。 我想将这些选项添加到命令中:
-i 2 (interface with index n°2)
-a duration:60 (the "scan" should last 60 seconds)
-v (print the result and exit)
-x (print an ASCII dump in the file)
以及一个仅捕获具有这些特殊性的数据包的过滤器:
"ip" (only IP packets)
"ip.src == 192.168.0.1" (source IP adress should be 192.168.0.1)
"ip.dst == 111.222.111.222" (destination IP adress should be 111.222.111.222)
"port == 80 or port == 443" (port should be http or https)
"http.request.method == 'GET'" (it should be a GET request)
然后我希望将结果保存在文件“test.txt”中。 所以最终的命令应该是这样的:
tshark -i 2 -a duration:60 -vx -f "ip" && "ip.src == 192.168.0.1" && "ip.dst == 111.222.111.222" && "port == 80 or port == 443" && "http.request.method == 'GET'" > test.txt
但我不断收到来自 Windows 的错误消息,指出 '"ip.src == 192.168.0.1"
不是可识别的内部或外部命令。我尝试过使用空格、不使用空格等,但无法找到一种方法来完成这项工作。
问题可能来自于我“链接”条件的方式。
- 还想询问是否有某种“停止执行”命令可以停止当前捕获,但仍将结果保存在 .txt 文件中。
最佳答案
and a filter that only captures packets with these particularities
...
"http.request.method == 'GET'" (it should be a GET request)
最后一部分使用捕获过滤器极其很难完成。如果您可以避免这种情况,那么使用捕获过滤器就可以相对容易地完成其余:
"ip src 192.168.0.1 && ip dst 111.222.111.222 && (tcp port 80 or tcp port == 443)"
并且您可能能够使用整个*shark过滤器作为读取过滤器:
-r "ip && ip.src == 192.168.0.1 && ip.dst == 111.222.111.222 && (tcp.port == 80 or tcp.port == 443) && http.request.method == 'GET'"
(请注意,它是 tcp.port
,而不仅仅是 port
)。
但是,请注意,对于 HTTP-over-SSL/TLS,如果请求已加密,您必须安排解密这些请求,以便 http.request.method = = 'GET'
即可工作。
(“or”子句周围的括号可能不是必需的,但我更喜欢它们只是让表达式的含义更加明显。)
关于windows - Wireshark 过滤器语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10288908/