Moe*_*oeb 6 encryption networking tcp tcpdump wireshark
我使用的工具之一使用加密/解密来通过网络发送数据.我正在修改该工具,我需要确保数据实际上是以加密形式发送的.
osg*_*sgx 12
简短回答:数据包在软件网络堆栈的最末端被窃听(例如在Linux中).
在tcpdump,libpcap和linux内核3.12中挖掘代码的长答案:
例如,Wireshark和tcpdump都使用libpcap,
http://sources.debian.net/src/tcpdump/4.5.1-2/tcpdump.c#L1472
if (pcap_setfilter(pd, &fcode) < 0)
Run Code Online (Sandbox Code Playgroud)
然后通过setfilter_op和activate_op安装数据包过滤器.这些操作有很多实现,我认为在最近的Linux PF_PACKET
上将使用pcap_activate_linux
libpcap-1.5.3-2/pcap-linux.c#L1287:
/*
* Current Linux kernels use the protocol family PF_PACKET to
* allow direct access to all packets on the network while
* older kernels had a special socket type SOCK_PACKET to
* implement this feature.
* While this old implementation is kind of obsolete we need
* to be compatible with older kernels for a while so we are
* trying both methods with the newer method preferred.
*/
status = activate_new(handle);
...
activate_new(pcap_t *handle)
...
/*
* Open a socket with protocol family packet. If the
* "any" device was specified, we open a SOCK_DGRAM
* socket for the cooked interface, otherwise we first
* try a SOCK_RAW socket for the raw interface.
*/
sock_fd = is_any_device ?
socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_ALL)) :
socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
Run Code Online (Sandbox Code Playgroud)
PF_PACKET在内核中实现,文件为net/packet/af_packet.c.PF_SOCKET的初始化在完成packet_do_bind
与register_prot_hook(sk)
功能(如果该装置处于UP状态),它调用 dev_add_pack
从净/芯/ dev.c注册钩:
370 /**
371 * dev_add_pack - add packet handler
372 * @pt: packet type declaration
373 *
374 * Add a protocol handler to the networking stack. The passed &packet_type
375 * is linked into kernel lists and may not be freed until it has been
376 * removed from the kernel lists.
377 *
378 * This call does not sleep therefore it can not
379 * guarantee all CPU's that are in middle of receiving packets
380 * will see the new packet type (until the next received packet).
381 */
382
383 void dev_add_pack(struct packet_type *pt)
384 {
385 struct list_head *head = ptype_head(pt);
386
387 spin_lock(&ptype_lock);
388 list_add_rcu(&pt->list, head);
389 spin_unlock(&ptype_lock);
390 }
Run Code Online (Sandbox Code Playgroud)
我认为,pf_packet处理程序 - tpacket_rcv(...)
函数 - 将在ptype_all中注册.
注册的挂钩ptype_all
被称为传出数据包 dev_queue_xmit_nit
("支持例程.将传出帧发送到当前正在使用的任何网络抽头.")list_for_each_entry_rcu(ptype, &ptype_all, list) { ... deliver_skb ...} .. func
,deliver_skb调用tpacket_rcv
用于libpcap 的func .
dev_queue_xmit_nit从dev_hard_start_xmit
(网络/核心/ dev.c中的第2539行)调用,这是AFAIK,是Linux网络堆栈中与设备无关的数据包处理的最后一个阶段(用于传出数据包).
传入数据包的历史记录相同,注册的ptype_all
挂钩也是__netif_receive_skb_core
相同的list_for_each_entry_rcu(ptype, &ptype_all, list) {.. deliver_skb..}
. 在处理传入数据包的最开始__netif_receive_skb_core
调用__netif_receive_skb
Linux基金会对网络堆栈有很好的描述(http://www.linuxfoundation.org/collaborate/workgroups/networking/kernel_flow),你可以dev_hard_start_xmit
在图片上看到http://www.linuxfoundation.org/images/1/1c/ Network_data_flow_through_kernel.png(警告,它很大)位于图例下方的左侧.并且netif_receive_skb
位于最右下方("net/core/dev.c")内,它从IRQ输入,然后是NAPI poll或netif_rx,这里唯一的退出是netif_receive_skb
.
图片甚至显示了两个pf_packet挂钩中的一个 - 传说中最左边的方块("net/packet/af_packet.c") - 用于传出数据包.
你的工具是什么?它如何连接到网络堆栈?如果您可以在Network_data_flow图片中找到该工具,您将得到答案.例如,Netfilter NF_HOOK
仅在ip_rcv
(传入)ip_output
(本地传出)和ip_forward
(从路由传出)中挂钩() - 就在之后netif_receive_skb
和之前dev_queue_xmit
.
这两种工具都可以捕获数据,就像它通过网络传输一样.(将其视为输出的"tee"等同于屏幕和文件的输出;同样,数据也会输出到套接字以及tcpdump或其他任何内容.)
所以,是的,如果您的工具在发送之前正确配置以加密数据,那么tcpdump或Wireshark应该在其数据包捕获中反映出来.
归档时间: |
|
查看次数: |
5281 次 |
最近记录: |