Flas
Well-Known Member
hallo, ich eier schon längere zeit mit nem kleinen sniffer rum, er soll die gefilterten packete auf das "PUSH" flag prüfen und dann (da es ja data enthält) die daten anzeigen, das heisst bei ner browser abfrage halt:
aber eben dieses anzeigen klappt bis dato nicht, desshalb wollt ich mal fragen ob einem von euch was dazu einfällt, denn google und zahlreiche irc channels konnten mir nicht helfen:
mfg und danke, flas!
Code:
"GET / HTTP/1.1\r\n
...
aber eben dieses anzeigen klappt bis dato nicht, desshalb wollt ich mal fragen ob einem von euch was dazu einfällt, denn google und zahlreiche irc channels konnten mir nicht helfen:
Code:
// mit "-lpcap" compilen
#include <pcap.h>
#include <stdio.h>
#include <netinet/ip.h>
#include <netinet/tcp.h>
#if !defined(__NetBSD__) || !defined(__OpenBSD__)
#include <net/ethernet.h>
#else
#include <netinet/if_ether.h>
#include <netinet/in.h>
#endif
#include <sys/types.h> /* \ */
#include <sys/socket.h> /* > for inet_ntop and its friends. */
#include <arpa/inet.h> /* / */
void my_callback(u_char*,const struct pcap_pkthdr*,const u_char*);
int main() {
pcap_t *descr; /* Session handle */
char dev[] = "rl0"; /* The device to sniff on */
char f[] = "tcp dst port 80";
char errbuf[PCAP_ERRBUF_SIZE]; /* Error string */
struct pcap_pkthdr header; /* The header that pcap gives us */
const u_char *packet; /* The actual packet */
struct bpf_program fp; /* hold compiled program */
bpf_u_int32 maskp; /* subnet mask */
bpf_u_int32 netp; /* ip */
pcap_lookupnet(dev,&netp,&maskp,errbuf);
if((descr = pcap_open_live(dev, BUFSIZ, 1, 1, errbuf)) == NULL) {
perror("[-] pcap_open_live() failed");
return 1;
}
if(pcap_compile(descr,&fp,f,0,netp) == -1) {
perror("[-] pcap_compile() failed");
return 2;
}
if(pcap_setfilter(descr,&fp) == -1) {
perror("[-] pcap_setfilter() failed");
return 3;
}
printf("starting sniffing...\n");
pcap_loop(descr,0,my_callback,NULL);
printf("finished sniffing\n");
pcap_close(descr);
return 0;
}
void my_callback(u_char *useless,const struct pcap_pkthdr* header,const u_char* packet) {
static int count = 1;
struct ip* ip_hdr;
struct tcphdr* tcp_hdr;
char src_ip[100], dst_ip[100];
int src_port, dst_port;
ip_hdr = (struct ip*) (packet + sizeof(struct ether_header));
inet_ntop(AF_INET, &ip_hdr->ip_src, src_ip, sizeof(src_ip));
inet_ntop(AF_INET, &ip_hdr->ip_dst, dst_ip, sizeof(dst_ip));
tcp_hdr = (struct tcphdr*)(packet + ip_hdr->ip_hl * 4 + sizeof(struct ether_header));
src_port = ntohs(tcp_hdr->th_sport);
dst_port = ntohs(tcp_hdr->th_dport);
printf("src %s:%d -> dst %s:%d\n",src_ip, src_port, dst_ip, dst_port);
//das:
if(tcp_hdr->th_flags & TH_PUSH) {
char *data = (char*) (packet + sizeof(tcp_hdr) + ip_hdr->ip_hl * 4 + sizeof(struct ether_header) );
printf("\ndata:\n%s\n\n",data);
}
//kommt nur mist
count++;
}
mfg und danke, flas!
Zuletzt bearbeitet: