Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make cloud-init log line regex more strict #864

Merged
merged 3 commits into from
Oct 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 6 additions & 11 deletions dissect/target/plugins/os/unix/log/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from dissect.target.exceptions import UnsupportedPluginError
from dissect.target.helpers.record import TargetRecordDescriptor
from dissect.target.helpers.utils import year_rollover_helper
from dissect.target.plugin import Plugin, export
from dissect.target.plugin import Plugin, alias, export

MessagesRecord = TargetRecordDescriptor(
"linux/log/messages",
Expand All @@ -24,7 +24,9 @@
RE_DAEMON = re.compile(r"^[^:]+:\d+:\d+[^\[\]:]+\s([^\[:]+)[\[|:]{1}")
RE_PID = re.compile(r"\w\[(\d+)\]")
RE_MSG = re.compile(r"[^:]+:\d+:\d+[^:]+:\s(.*)$")
RE_CLOUD_INIT_LINE = re.compile(r"(?P<ts>.*) - (?P<daemon>.*)\[(?P<log_level>\w+)\]\: (?P<message>.*)$")
RE_CLOUD_INIT_LINE = re.compile(
r"^(?P<ts>\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2},\d{3}) - (?P<daemon>.*)\[(?P<log_level>\w+)\]\: (?P<message>.*)$"
)


class MessagesPlugin(Plugin):
Expand All @@ -43,19 +45,12 @@ def check_compatible(self) -> None:
if not self.log_files:
raise UnsupportedPluginError("No log files found")

@export(record=MessagesRecord)
def syslog(self) -> Iterator[MessagesRecord]:
"""Return contents of /var/log/messages*, /var/log/syslog* and cloud-init logs.

See ``messages`` for more information.
"""
return self.messages()

@alias("syslog")
@export(record=MessagesRecord)
def messages(self) -> Iterator[MessagesRecord]:
"""Return contents of /var/log/messages*, /var/log/syslog* and cloud-init logs.

Note: due to year rollover detection, the contents of the files are returned in reverse.
Due to year rollover detection, the contents of the files are returned in reverse.

The messages log file holds information about a variety of events such as the system error messages, system
startups and shutdowns, change in the network configuration, etc. Aims to store valuable, non-debug and
Expand Down