12 #include <sys/types.h> 14 #include <netinet/in.h> 29 static u_char
buf[BUFSIZ];
38 fprintf(stderr,
"Version: " VERSION "\n" 39 "Usage: filenamesnarf [-i interface] expression\n");
44 ftp_parse(
struct libnet_ipv4_hdr *ip,
struct libnet_tcp_hdr *tcp,
int pkt_len) {
49 data_len = pkt_len - (ip->ip_hl + tcp->th_off)*4;
50 unsigned int a1, a2, a3, a4, p1, p2;
58 if ((strcmp(
"RETR ",tmp) == 0) || (strcmp(
"STORE",tmp) == 0) ||(strcmp(
"226 T",tmp) == 0) ||(strcmp(
"450 ",tmp)
61 memcpy(command,
buf,data_len -1);
62 command[data_len -1] = 0x00;
63 printf(
"FTP [%s:%d] > [%s:%d] - %s\n",
64 libnet_addr2name4(ip->ip_src.s_addr, 0), ntohs(tcp->th_sport),
65 libnet_addr2name4(ip->ip_dst.s_addr, 0), ntohs(tcp->th_dport),
67 }
else if (strcmp(
"PORT ",tmp) == 0) {
69 memcpy(command,
buf + 5,data_len - 6);
70 command[data_len - 6] = 0x00;
71 sscanf(command,
"%u,%u,%u,%u,%u,%u",
72 &a1, &a2, &a3, &a4, &p1, &p2);
73 port_no = (p1 << 8) | p2;
74 printf(
"Conversion done\n");
75 printf(
"FTP [%s:%d] > [%s:%d] - PORT %u.%u.%u.%u:%u\n",
76 libnet_addr2name4(ip->ip_src.s_addr, 0), ntohs(tcp->th_sport),
77 libnet_addr2name4(ip->ip_dst.s_addr, 0), ntohs(tcp->th_dport),
78 a1, a2, a3, a4, port_no);
87 struct libnet_ipv4_hdr *ip;
88 struct libnet_tcp_hdr *tcp;
93 ip = (
struct libnet_ipv4_hdr *)
pkt;
95 if (ip->ip_p == IPPROTO_TCP) {
97 tcp = (
struct libnet_tcp_hdr *)(
pkt + ip->ip_hl * 4);
99 if (!(tcp->th_flags & TH_PUSH))
101 memset(
buf,0x00,BUFSIZ);
102 memcpy(
buf,
pkt + ip->ip_hl*4 + tcp->th_off*4,len - ip->ip_hl*4 + tcp->th_off*4);
106 }
else if (ip->ip_p == IPPROTO_UDP) {
122 char *
intf, *filter, ebuf[PCAP_ERRBUF_SIZE];
128 char errbuf[LIBNET_ERRBUF_SIZE];
134 ip_id = LIBNET_PTAG_INITIALIZER;
136 while ((c = getopt(argc, argv,
"i:")) != -1) {
146 if (
intf == NULL && (
intf = pcap_lookupdev(ebuf)) == NULL)
158 errx(1,
"couldn't initialize sniffing");
161 errx(1,
"couldn't determine link layer offset");
163 libnet_seed_prand(
l);
165 warnx(
"listening on %s [%s]",
intf, filter);