Unix Cheat Sheet

a. To look for unusual processes and services use the following commands:

i. ps -aux – displays running processes along with their process-id (PID), associated user-ids (UID #), name, and other pertinent information. Pay particular attention to any process that is using the UID 0 user-id, because those processes are running with root permissions.

ii. ps –ef – displays the full listing of all processes and can be useful for finding undesirable processes that are running.

iii. lsof –p (PID) – displays a specific process in more detail, by displaying the files and ports associated with that process. This is appropriate for examining any Trojan, worms, and other network based malware on a UNIX system.

iv. lsof +L1 – displays processes running from or accessing files that have been unlinked; basically it will show one to figure out if the attacker is hiding data or running a backdoor.

b. To look for unusual files the “find” command along with its various flags allows one to search a UNIX system for malware. A few examples are listed below:

i. find / -uid 0 -perm -4000 –print – searches for files that have root permissions.

ii.find / -size +50000k –print – searches for files of a specified or greater size. This is particularly useful for searching for files that may not belong on the system, like movies, games, et al.

c. To look for unusual network usage coming from a system’s network interface type in the following command: ip link | grep PROMISC – this command will display any network interfaces that are running in promiscuous mode, which can be a clear indication of an attacker running a packet sniffer.

d. Other useful commands to observe unusual network behavior are:

i. netstat –nap – this displays listening ports and in turn can be useful for finding backdoors. ii. arp –a – displays all MAC to IP address mappings of the system and can be useful for finding addresses of systems that are not part of the network (e.g. a rouge wireless access point that allows one to gain access into the internal network from the outside).

e. To look for scheduled jobs (i.e. tasks) by root or any other user, type in the following command: contrab –u root –l – this is useful for detecting logic bombs, scheduled connections to unknown hosts, and other potentially nefarious issues.

i. Two additional commands to display system-wide cron jobs are:

1. cat /etc/crontab – displays all jobs scheduled within the cron table.

2. ls etc/cron.* – lists files within the cron subdirectories.

f. To look for unusual accounts use the following commands to check the following files:

i. sort –nk3 –t: /etc/paswd | less – displays all accounts sorted by UID (e.g. UID0, etc), this is useful for finding accounts with root permissions or accounts that do not belong on the system.

ii. egrep ‘:0:’ /etc/passwd – displays only accounts with root permissions.

iii. getent passwd | grep ‘:0:’ – same as above, except for systems with multiple authentication mechanisms.

iv. find / -nouser –print – searches the entire system for orphaned files that may have been deleted by an attacker’s temporary account.

g. The best place to check for unusual system activity is the log files, especially in UNIX. Most log files are located in /var/log (or var/logs), or var/messages. A good command to use for viewing log files is: more –f /var/log/messages – this allows a page by page review of all logged events. Pay particular attention to user authentication logins and any unusual patterns such as missing entries and times that may indicate an intruder is trying to hide his/her tracks.

h. Other commands to check for possible clues are:

i. uptime – displays how long a system has been up and running. If the system’s uptime is shorter or longer than it should be, then it could be a clear indication that something has changed and therefore may need further review.

ii. free – is useful for checking how much ram is used. This is useful for detecting processes that are using a lot of memory (e.g. an attacker searching or modifying a database, etc).

iii. df – is useful for checking available disk space. This can provide a reliable indication as to whether an attacker is installing malware or removing files from a system.