diff --git a/Makefile b/Makefile index 58b0f20..ce94622 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ LIBS=-L../libbpf/src -l:libbpf.a -lelf -lz all: dns-trace.ebpf.o dns-trace dns-trace.ebpf.o: src/dns-trace.ebpf.c - $(CL) -Wall -g -O2 -target bpf -D __TARGET_ARCH_x86_64 -D __BPF_TRACING__ -L../libbpf/src -l:libbpf.a -c src/dns-trace.ebpf.c -o src/dns-trace.ebpf.o + $(CL) -Wall -g -O2 -target bpf -D __TARGET_ARCH_x86_64 -D __BPF_TRACING__ -c src/dns-trace.ebpf.c -o src/dns-trace.ebpf.o dns-trace: src/dns-trace.c $(GCC) $(CFLAGS) src/dns-trace.c -o dns-trace $(LIBS) diff --git a/cname.pcap b/cname.pcap deleted file mode 100644 index 185c6a8..0000000 Binary files a/cname.pcap and /dev/null differ diff --git a/dns-trace b/dns-trace index f05d610..c3076d2 100755 Binary files a/dns-trace and b/dns-trace differ diff --git a/dns-trace_2025-02-08.log b/dns-trace_2025-02-08.log new file mode 100644 index 0000000..aa9be6f --- /dev/null +++ b/dns-trace_2025-02-08.log @@ -0,0 +1,18 @@ +Feb 08 13:24:15 pc-geoffrey dns-trace: Query;tid=671c;192.168.1.37:53;class=IN;type=AAAA; +Feb 08 13:24:16 pc-geoffrey dns-trace: Query;tid=c537;192.168.1.37:53;class=IN;type=A; +Feb 08 13:24:17 pc-geoffrey dns-trace: Query;tid=12ba;192.168.1.37:53;class=IN;type=A; +Feb 08 14:17:10 pc-geoffrey dns-trace: Query;tid=fa8f;192.168.1.37:53;class=IN;type=A; +Feb 08 14:17:20 pc-geoffrey dns-trace: Query;tid=a417;192.168.1.37:53;class=IN;type=A; +Feb 08 14:21:36 pc-geoffrey dns-trace: Query;tid=34f;192.168.1.37:53;class=IN;type=A; +Feb 08 14:23:23 pc-geoffrey dns-trace: Query;tid=23c8;192.168.1.37:53;class=IN;type=A; +Feb 08 14:25:11 pc-geoffrey dns-trace: Query;tid=e74;192.168.1.37:53;class=IN;type=A; +Feb 08 14:25:21 pc-geoffrey dns-trace: Query;tid=3844;192.168.1.37:53;class=IN;type=A; +Feb 08 14:25:28 pc-geoffrey dns-trace: Query;tid=de58;192.168.1.37:53;class=IN;type=A; +Feb 08 14:27:39 pc-geoffrey dns-trace: Query;tid=4600;192.168.1.37:53;class=IN;type=A; +Feb 08 14:28:04 pc-geoffrey dns-trace: Query;tid=1f5a;192.168.1.37:53;class=IN;type=A; +Feb 08 14:29:20 pc-geoffrey dns-trace: Query;tid=3cc6;192.168.1.37:53;class=IN;type=A; +Feb 08 14:35:12 pc-geoffrey dns-trace: Query;tid=a8d2;192.168.1.37:53;class=IN;type=A; +Feb 08 14:35:12 pc-geoffrey dns-trace: Query;tid=e7ae;192.168.1.37:53;class=IN;type=AAAA; +Feb 08 14:35:16 pc-geoffrey dns-trace: Query;tid=ed16;192.168.1.37:53;class=IN;type=A; +Feb 08 14:35:31 pc-geoffrey dns-trace: Query;tid=28a6;192.168.1.37:53;class=IN;type=A; +Feb 08 14:50:39 pc-geoffrey dns-trace: Query;tid=b19f;192.168.1.37:53;class=IN;type=AAAA; diff --git a/dns.pcap b/dns.pcap deleted file mode 100644 index fc592d5..0000000 Binary files a/dns.pcap and /dev/null differ diff --git a/dns10.pcap b/dns10.pcap deleted file mode 100644 index 1214258..0000000 Binary files a/dns10.pcap and /dev/null differ diff --git a/dns2.pcap b/dns2.pcap deleted file mode 100644 index bfd1db0..0000000 Binary files a/dns2.pcap and /dev/null differ diff --git a/dns3.pcap b/dns3.pcap deleted file mode 100644 index f198ae5..0000000 Binary files a/dns3.pcap and /dev/null differ diff --git a/dns4.pcap b/dns4.pcap deleted file mode 100644 index 32adcb5..0000000 Binary files a/dns4.pcap and /dev/null differ diff --git a/exec.sh b/exec.sh index 0c2a450..b70fafb 100755 --- a/exec.sh +++ b/exec.sh @@ -3,4 +3,4 @@ #sudo bpftool btf dump file /sys/kernel/btf/vmlinux format c > src/vmlinux.h make clean -make all && sudo ./dns-trace -i enx98e743c667fc +make all && sudo ./dns-trace -i wlp0s20f3 -f dns-trace_`$(echo date '+%F')`.log diff --git a/jvetter.pcap b/jvetter.pcap deleted file mode 100644 index 050298c..0000000 Binary files a/jvetter.pcap and /dev/null differ diff --git a/src/.dns-trace.c.swp b/src/.dns-trace.c.swp new file mode 100644 index 0000000..1e43af8 Binary files /dev/null and b/src/.dns-trace.c.swp differ diff --git a/src/dns-trace.c b/src/dns-trace.c index 7a78401..5bedaab 100644 --- a/src/dns-trace.c +++ b/src/dns-trace.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include /* if_nametoindex */ #include @@ -17,8 +18,12 @@ #include "common.h" +/* Global variables */ static struct arguments arguments; static int running = 1; +static FILE *f; +static char hostname[127]; + struct arguments { char *interface; @@ -216,13 +221,38 @@ static char *mapType(const int type){ return tmp; } +/* + * This function get the localtime into the rsyslog format + */ +static int syslog_time(time_t ts, char t[32], size_t l){ + const char format[] = "%b %d %T"; + struct tm *lt = localtime(&ts); + if(strftime(t, l, format, lt) == 0) + return -1; + return 0; +} +static void get_hostname(){ + /* Get the hostname */ + if (gethostname(hostname, 127) == -1){ + printf("Failed to get the hostname\n"); + strncpy(hostname, "ubuntu", 7); + } +} +/* + * This function print to the stdout the query section + */ static void print_query(struct event *s_event){ char *req_type, *class, *type; + char t[32]; + time_t ts = time(NULL); + syslog_time(ts, t, sizeof(t)); + printf("%-20s", t); + req_type = mapReqType(s_event->req_type); printf("%s ", req_type); free(req_type); - printf("%5s:%d\t\t", inet_ntoa(*(struct in_addr*)&s_event->client), s_event->dport); + printf("%5s:%d\t", inet_ntoa(*(struct in_addr*)&s_event->client), s_event->dport); printf("%x\t", s_event->tid); class = mapClass(s_event->class); @@ -235,6 +265,53 @@ static void print_query(struct event *s_event){ printf("%s", s_event->qname); } +/* + * This function save to log file the query section in rsylog format + *