You can also use these pipelines for other data sources. The ""cat access.log | sed 's/.*"\([^"]*\)"$/\1/'" is how I'm extracting the user agent strings from the Apache log format. Everything after that is shell idioms you can apply to any data.
Encoded #log4j user agents are longer than normal user agent strings:
"cat access.log | sed 's/.*"\([^"]*\)"$/\1/' | sort -u | while read str; do len=$(echo $str | wc -c); echo -e $len\\t$str; done | sort -n"
Sort unique user agent strings by length, ascending
Looking for #log4j encoded user agents in Apache "combined" access log format:
"cat access.log | sed 's/.*"\([^"]*\)"$/\1/' | sort | uniq -c | sort -rn"
Histogram of all user agents in descending order (unique encoded user agents right above your shell prompt)
You want to see what LD_PRELOAD is set to?
"grep -l LD_PRELOAD /proc/[0-9]*/environ | while read file; do echo $file:; cat $file | tr \\000 \\n | grep LD_PRELOAD; echo; done"
Haven't yet been seeing this with #log4j but be aware that LD_PRELOAD rootkits are circulating in the wild. Use of LD_PRELOAD is uncommon, so spot suspicious processes with "grep -l LD_PRELOAD /proc/[0-9]*/environ"
Or just try:
"ls -l /proc/[0-9]*/exe 2>/dev/null | awk '/ -> / {print $NF}' | sort"
Shows all EXE paths in sorted order making it easier to spot outliers #log4j
Another fun Linux command line:
"sudo ls -l /proc/[0-9]*/exe 2>/dev/null | awk '/ -> / && !/\/usr\/(lib(exec)?|s?bin)\// {print $9, $10, $11}' | sed 's,/proc/\([0-9]*\)/exe,\1,'"
Display PIDs with non-standard EXE paths
Another vuln where strict egress filtering would have greatly reduced possible impact to your environment. Make sure implementing egress filtering is part of your recovery plan. #log4j
Helpful Linux command-lines:
“find /tmp /var/tmp /dev/shm -type f \( -perm -0100 -o -perm -0001 \)”
Looks through tmpdirs for files with execute set for self or others—coin miners, install scripts, etc. #log4j
If you’re struggling with the Linux forensics in the wake of #log4j, archive.org/details/HalLinux… may help. As always, feel free to reach out—I’m here to help with everything from simple syntax questions all the way up to full consulting engagements.
There may be earlier exploitation, but “find / -mtime -4” is a good way to look for weekend #log4j carnage on your Linux servers. RCE is likely unprivileged, so focus first on [/var]/tmp, /dev/shm, and similar world-write directories.
Instead of vilifying those who don’t vaccinate, we need to document them as human beings, interconnected with family and friends, who leave huge voids when they pass. If we create a library of these very human stories, maybe we can shift the conversation.
I mentioned to @JBeanDesign that I was feeling a bit punky after my booster. We’re both old enough that the obvious “Punky Booster” joke is hilarious to us.