never lose a syslog message
play

Never Lose a Syslog Message Alexander Bluhm bluhm@openbsd.org - PowerPoint PPT Presentation

Motivation Starting Position Local Improvements Remote Logging Conclusion Never Lose a Syslog Message Alexander Bluhm bluhm@openbsd.org September 24, 2017 Motivation Starting Position Local Improvements Remote Logging Conclusion Agenda


  1. Motivation Starting Position Local Improvements Remote Logging Conclusion Never Lose a Syslog Message Alexander Bluhm bluhm@openbsd.org September 24, 2017

  2. Motivation Starting Position Local Improvements Remote Logging Conclusion Agenda Motivation 1 Starting Position 2 Local Improvements 3 Remote Logging 4 Conclusion 5

  3. Motivation Starting Position Local Improvements Remote Logging Conclusion Why reliable logging? system analysis attacker tries to prevent log required by common criteria

  4. Motivation Starting Position Local Improvements Remote Logging Conclusion What can go wrong? UDP for remote logs UNIX datagram for local logs file descriptors chroot environment timestamps and time zones

  5. Motivation Starting Position Local Improvements Remote Logging Conclusion Agenda Motivation 1 Starting Position 2 Local Improvements 3 Remote Logging 4 Conclusion 5

  6. Motivation Starting Position Local Improvements Remote Logging Conclusion Traditional Message Flow program syslog(LOG ERR, "message %d", 7) libc priority, timestamp, sprintf, send kernel /dev/log syslogd recv, log file, send UDP

  7. Motivation Starting Position Local Improvements Remote Logging Conclusion Priority, Facility, Level, Severity, Options openlog("ftpd", LOG PID|LOG CONS, LOG FTP) syslog(LOG INFO, "%s logged in", user) #define LOG FTP (11<<3) /* ftp daemon */ #define LOG INFO 6 /* informational */ <94>Sep 24 09:35:00 ftpd[4711]: bluhm logged in

  8. Motivation Starting Position Local Improvements Remote Logging Conclusion Agenda Motivation 1 Starting Position 2 Local Improvements 3 Remote Logging 4 Conclusion 5

  9. Motivation Starting Position Local Improvements Remote Logging Conclusion /dev/log Problems with /dev/log UNIX socket needs file descriptor use LOG NDELAY reconnect after SIGHUP syslogd needs UNIX socket in chroot needs pledge("unix") LOG CONS is even worse

  10. Motivation Starting Position Local Improvements Remote Logging Conclusion sendsyslog New system call sendsyslog(2) int sendsyslog(const void *msg, size t len, int flags) sendsyslog("<94>Sep 24 09:36:23 ftpd[4711]: bluhm logged in", 47, LOG CONS)

  11. Motivation Starting Position Local Improvements Remote Logging Conclusion Using sendsyslog Syslogd does create socketpair register one end with ioctl(LIOCSFD) receive form other end Kernel does send to syslogd’s socketpair write to console if necessary ktrace if activated count errors

  12. Motivation Starting Position Local Improvements Remote Logging Conclusion Error Handling void syslog(int prio, const char *msg, ...) libc cannot return error program cannot log error Kernel sendsyslog can do it count failures when sending to syslogd write message to syslog when it works again sendsyslog: dropped 2 messages, error 57

  13. Motivation Starting Position Local Improvements Remote Logging Conclusion Libc Timestamp Timestamp from syslog(3) needs /etc/localtime in every chroot no year no time zone no indication of daylight saving time insufficient precision does not work for kernel messages Sep 24 09:37:42

  14. Motivation Starting Position Local Improvements Remote Logging Conclusion Syslogd Timestamp Timestamp added by syslogd timestamp is optional in received message syslogd adds it if missing libc does not generate it syslogd -Z generates ISO format in UTC use millisecond precision 2017-09-24T07:38:59.333Z

  15. Motivation Starting Position Local Improvements Remote Logging Conclusion Logging without Libc System call sendsyslog allows logging from signal handler at memcpy overlap from stack protector handler from ld.so dynamic linker

  16. Motivation Starting Position Local Improvements Remote Logging Conclusion dmesg Overflow Detect dmesg overflow in log file ring buffer with kernel logs syslogd reads from /dev/klog messages may overwrite special kernel message at gap <4>klog: dropped 1243 bytes, message buffer full

  17. Motivation Starting Position Local Improvements Remote Logging Conclusion Agenda Motivation 1 Starting Position 2 Local Improvements 3 Remote Logging 4 Conclusion 5

  18. Motivation Starting Position Local Improvements Remote Logging Conclusion Possibilities tty user process wall console sender receiver syslogd loghost loghost memory buffer kernel pipe file

  19. Motivation Starting Position Local Improvements Remote Logging Conclusion Local Methods process sendsyslog /dev/log UNIX socket syslogd /dev/klog kernel

  20. Motivation Starting Position Local Improvements Remote Logging Conclusion Remote Methods UDP UDP TCP TCP sender TLS TLS receiver syslogd loghost loghost IPv4 IPv4 IPv6 IPv6

  21. Motivation Starting Position Local Improvements Remote Logging Conclusion UDP Format single UDP packet max 1180 bytes <94>Sep 24 10:07:13 80.154.94.47 ftpd[4711]: bluhm logged in

  22. Motivation Starting Position Local Improvements Remote Logging Conclusion TCP Format no proper RFC 6587 new line delimiter or NUL delimiter or octet counting 60 <94>Sep 24 10:08:52 80.154.94.47 ftpd[4711]: bluhm logged in

  23. Motivation Starting Position Local Improvements Remote Logging Conclusion TLS Format octet counting must support 2048 bytes should support 8192 bytes libevent and libtls

  24. Motivation Starting Position Local Improvements Remote Logging Conclusion Provide Server Certificate -T host:port sender syslogd loghost /etc/ssl/host.crt /etc/ssl/private/host.key syslogd must provide server certificate sender can identify syslogd attacker cannot see messages

  25. Motivation Starting Position Local Improvements Remote Logging Conclusion Validate Client Certificate -T host:port sender syslogd loghost client -K CAfile certificate sender may provide client certificate syslogd can identify sender attacker cannot inject messages

  26. Motivation Starting Position Local Improvements Remote Logging Conclusion Validate Server Certificate @tls://host:port receiver syslogd server loghost -C CAfile certificate /etc/ssl/cert.pem syslogd must know server CA hostname must be in server certificate syslogd can identify receiver attacker cannot see messages turn off with -V

  27. Motivation Starting Position Local Improvements Remote Logging Conclusion Provide Client Certificate @tls://host:port receiver syslogd loghost -c cert file -k key file syslogd may provide client certificate receiver can identify syslogd attacker cannot inject messages

  28. Motivation Starting Position Local Improvements Remote Logging Conclusion TCP/TLS Errors debug incoming connections log connection errors count dropped messages suppress “last message repeated” syslogd[17361]: dropped 2 messages to remote loghost

  29. Motivation Starting Position Local Improvements Remote Logging Conclusion Agenda Motivation 1 Starting Position 2 Local Improvements 3 Remote Logging 4 Conclusion 5

  30. Motivation Starting Position Local Improvements Remote Logging Conclusion OpenBSD Message Flow program syslog(LOG ERR, "message %d", 7) libc priority, sprintf, syscall kernel sendsyslog , error handling syslogd recv, timestamp , log file, send TLS

  31. Motivation Starting Position Local Improvements Remote Logging Conclusion Run and Log Reliably no fatal errors count dropped messages TCP and TLS transport libevent safe signal handlers file descriptor exhaustion privsep with re-exec pledge child and parent

  32. Motivation Starting Position Local Improvements Remote Logging Conclusion Tests 180 regression tests for almost everything config, start, log, stop, check stderr, client, server, file, pipe, console, user, ktrace, fstat

  33. Motivation Starting Position Local Improvements Remote Logging Conclusion TODO initialization errors to file continue after file system full log memory buffer overflow move format from RFC 3164 to 5424 fix bug found by mpi@openbsd ivadasz@dragonfly likes kernel timestamps

  34. Motivation Starting Position Local Improvements Remote Logging Conclusion Questions ?

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend