Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
technical:remote_syslog_setup [2025/06/04 01:04] – super_stunder | technical:remote_syslog_setup [2025/06/11 04:45] (current) – [Going against the Linux Gods] super_stunder | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Remote Syslog - IPTables - Tigers and Bears OH MY ====== | ||
+ | |||
+ | |||
I have been working on a simple SYSLOG project to gather scanning data off of host around the internet and centralize it. The no telling what I will do with the data at that point. | I have been working on a simple SYSLOG project to gather scanning data off of host around the internet and centralize it. The no telling what I will do with the data at that point. | ||
< | < | ||
digraph MyGraph { | digraph MyGraph { | ||
- | | + | |
- | | + | |
+ | label = "Basic Concept" | ||
} | } | ||
</ | </ | ||
Line 13: | Line 17: | ||
I had worked on a project like this a couple of years/ | I had worked on a project like this a couple of years/ | ||
- | I am going to move the sidebar conversation to the [[blog: | + | I am going to move the sidebar conversation to the [[blog: |
- | < | + | ---- |
- | root@syslog01:/ | + | ===== Configuring iptables (the hell of logging denies) ===== |
- | README | + | |
- | alternatives.log | + | |
- | apt dpkg.log | + | |
- | btmp | + | |
- | </ | + | |
- | Well it looks like a lot of things have changed in the logging world since Debian 9. I know people have had their [[https:// | ||
- | <code> | + | <del>So I am going to start this off and load rsyslog and UFW on the logger servers then I will go from there. I am using UFW for basic firewall configs it makes things way easier when building basic rules. |
- | root@syslog01:/ | + | |
- | You are looking for the traditional text log files in / | + | |
- | gone? | + | |
- | Here's an explanation on what's going on: | + | < |
- | You are running a systemd-based OS where traditional syslog has been replaced | + | I started this with the plans of using UFW to keep it simple things got pretty detailed pretty quick so I ended up switching directly to iptables. I may end up doing another install with netfilter |
- | with the Journal. The journal stores the same (and more) information as classic | + | |
- | syslog. To make use of the journal and access the collected log data simply | + | |
- | invoke " | + | |
- | format the syslog files in /var/log used to be. For further details, please | + | |
- | refer to journalctl(1). | + | |
- | Alternatively, | + | Alright so now I am actually going to use a little bit of help from Google Gemini. |
- | implementations available for your distribution, | + | |
- | classic log files for you. Syslog implementations such as syslog-ng or rsyslog | + | |
- | may be installed side-by-side with the journal | + | |
- | the way they always did. | + | |
- | Thank you! | + | < |
+ | -A INPUT -m state --state RELATED, | ||
+ | -A INPUT -p tcp -m tcp --dport 22 -j LOG --log-prefix " | ||
+ | -A INPUT -p tcp -m tcp --dport 22 -j ACCEPT | ||
+ | -A INPUT -i lo -j ACCEPT | ||
+ | -A INPUT -j LOG --log-prefix " | ||
+ | -A OUTPUT -o lo -j ACCEPT | ||
+ | </ | ||
- | Further reading: | + | ==== Saving iptables config and setting persistence after reboots ==== |
- | man:journalctl(1) | + | |
- | | + | After you have tested access back into your device over SSH you can now issue the persistent command to maintain the rules at startup. Turns on iptables-persistent isn't installed by default. |
- | man: | + | |
- | | + | < |
- | README | + | apt install iptables-persistent |
+ | </ | ||
+ | |||
+ | After iptables-persistent is install you can now run iptables-save to your policy file and it will load again after reboots. | ||
+ | |||
+ | < | ||
+ | root@logger02:~# iptables-save > / | ||
+ | </ | ||
+ | |||
+ | ==== Displaying iptables rules ==== | ||
+ | While digging into the rules I was just using the iptables -L command to list the policy. | ||
+ | |||
+ | |||
+ | < | ||
+ | Chain INPUT (policy DROP 14136 packets, 706K bytes) | ||
+ | pkts bytes target | ||
+ | 19294 4901K ACCEPT | ||
+ | | ||
+ | | ||
+ | | ||
+ | 247 11960 LOG all -- any any | ||
+ | |||
+ | Chain FORWARD | ||
+ | pkts bytes target | ||
+ | |||
+ | Chain OUTPUT (policy ACCEPT 21944 packets, 5353K bytes) | ||
+ | pkts bytes target | ||
+ | | ||
+ | root@logger02:~# | ||
+ | |||
+ | </ | ||
+ | |||
+ | ===== The drama of logging in Linux ===== | ||
+ | I didn't know in this journey to consolidate logs to a centralized server I was going to end up blogging so much. Turns out I needed to start another post to talk about the usage of systemd' | ||
+ | |||
+ | ==== Going against the Linux Gods ==== | ||
+ | Now we need to shut off kernel logging in the journald. I go into details about this in the blog posting mentioned above, but I don't like the idea of cutting off kernel logs going to journald. | ||
+ | |||
+ | === Install rsyslog and disable kernal logging in journald === | ||
+ | Basic rsyslog install is fine | ||
+ | < | ||
+ | apt install rsyslog | ||
+ | </ | ||
+ | |||
+ | Here is a my / | ||
+ | < | ||
+ | # /etc/rsyslog.conf configuration file for rsyslog | ||
+ | # | ||
+ | # For more information install rsyslog-doc and see | ||
+ | # /usr/share/doc/ | ||
+ | |||
+ | |||
+ | ################# | ||
+ | #### MODULES #### | ||
+ | ################# | ||
+ | |||
+ | module(load=" | ||
+ | module(load=" | ||
+ | # | ||
+ | |||
+ | # provides UDP syslog reception | ||
+ | # | ||
+ | # | ||
+ | |||
+ | # provides TCP syslog reception | ||
+ | # | ||
+ | # | ||
+ | |||
+ | |||
+ | ########################### | ||
+ | #### GLOBAL DIRECTIVES #### | ||
+ | ########################### | ||
+ | |||
+ | # | ||
+ | # Set the default permissions for all log files. | ||
+ | # | ||
+ | $FileOwner root | ||
+ | $FileGroup adm | ||
+ | $FileCreateMode 0640 | ||
+ | $DirCreateMode 0755 | ||
+ | $Umask 0022 | ||
+ | |||
+ | # | ||
+ | # Where to place spool and state files | ||
+ | # | ||
+ | $WorkDirectory / | ||
+ | |||
+ | # | ||
+ | # Include all config files in / | ||
+ | # | ||
+ | $IncludeConfig / | ||
+ | |||
+ | |||
+ | ############### | ||
+ | #### RULES #### | ||
+ | ############### | ||
+ | |||
+ | # Forward messages with " | ||
+ | :msg, contains, " | ||
+ | |||
+ | # This will forward all of the Firewall Logs to the syslog01 server from /etc/hosts over UDP 514 | ||
+ | :msg, contains, " | ||
+ | |||
+ | # Discard messages with the " | ||
+ | :msg, contains, " | ||
+ | |||
+ | # Send all other messages to the journald socket | ||
+ | *.* action(type=" | ||
+ | |||
+ | # | ||
+ | # Log anything besides private authentication messages to a single log file | ||
+ | # | ||
+ | *.*; | ||
+ | |||
+ | # | ||
+ | # Log commonly used facilities to their own log file | ||
+ | # | ||
+ | auth, | ||
+ | cron.* -/ | ||
+ | kern.* -/ | ||
+ | mail.* -/ | ||
+ | user.* -/ | ||
+ | |||
+ | # | ||
+ | # Emergencies are sent to everybody logged in. | ||
+ | # | ||
+ | *.emerg : | ||
+ | </ | ||
+ | |||
+ | |||
+ | Then edit / | ||
+ | |||
+ | < | ||
+ | root@logger02: | ||
+ | </ | ||
+ | |||
+ | <code title=journald.conf el=true hl=34> | ||
+ | # Use ' | ||
+ | # | ||
+ | # See journald.conf(5) for details. | ||
+ | |||
+ | [Journal] | ||
+ | # | ||
+ | # | ||
+ | #Seal=yes | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | ForwardToSyslog=yes | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | MaxLevelSyslog=warn | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | ReadKMsg=no | ||
+ | #Audit=no | ||
</ | </ | ||
- | Now after some reading I believe I will keep using rsyslog | + | Once you have rsyslog |
+ | |||
+ | < | ||
+ | systemctl restart systemd-journald.service | ||
+ | systemctl restart rsyslog.service | ||
+ | </ | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | Alright | ||
+ | |||
+ | === The Syslog Server - syslog01 === | ||
+ | FIXME | ||
+ | |||
+ | Now you should see both servers " | ||
+ | < | ||
+ | 2025-06-11T04: | ||
+ | 2025-06-11T04: | ||
+ | </file> | ||
+ | |||
+ | - < | ||
+ | - Even though I have loaded RSYSLOG all logs are still going to the systemd logs. I want to keep the system logs pointed to systemd (let it do its thing) and have all of the firewalls logs sent to /var/log for text based processing. :!: I thought this was going to be an option, turns out log flexibility has gone away now that the world of Linux has push to systemd | ||
+ | |||
+ | FIXME | ||
+ | Important considerations: | ||
+ | |||
+ | Order of rules: The LOG rule must be at the very beginning of the chain to log all packets. | ||
+ | Log level: Adjust the --log-level to suit your needs and logging system. Levels range from 0 (highest severity) to 7 (debug). | ||
+ | Rate limiting: Logging all packets can generate a lot of log data. Use the --limit and --limit-burst options to rate-limit logging if needed. | ||
+ | |||
+ | By implementing this iptables policy, a firewall that allows SSH on port 22, denies all other inbound traffic, and logs both accepted and denied packets with the desired prefix can be created. | ||
+ | |||
+ | [[:about|CONTACT ME:]] if you think I missed something, need to update anything, or you just have questions. Follow the contact rules or spam filters will get you. | ||
+ | |||
+ | |||
+ |