Wireshark提供了许多Filter Expression,我们可以很轻松的过滤出FTP的用户名和密码。请看下图
Filter Expression为ftp.request.command=="USER" or ftp.request.command=="PASS"。具体为什么查找FTP连接的建立过程,而且点击Expression之后可以看到wireshark封装了许多过滤规则。Wireshark是基于winpcap的,但是自己编写winpcap程序的时候就没有这么多封装好的过滤规则了。
下面的代码是我尝试着写的可以过滤出USER和PASS的C语言代码,为什么我的程序总感觉很粗糙
#include <stdio.h>
#include <stdlib.h>
#define HAVE_REMOTE
#include "pcap.h"
#include <ws2tcpip.h>
#define LINE_LEN 16
/* 4字节的IP地址 */
typedef struct ip_address{
u_char byte1;
u_char byte2;
u_char byte3;
u_char byte4;
}ip_address;
/* IPv4 首部 ,20字节*/
typedef struct ip_header{
u_char ver_ihl; // 版本 (4 bits) + 首部长度 (4 bits)
u_char tos; // 服务类型(Type of service)
u_short tlen; // 总长(Total length)
u_short identification; // 标识(Identification)
u_short flags_fo; // 标志位(Flags) (3 bits) + 段偏移量(Fragment offset) (13 bits)
u_char ttl; // 存活时间(Time to live)
u_char proto; // 协议(Protocol)
u_short crc; // 首部校验和(Header checksum)
ip_addre