Useful commands

Useful built-in commands for Linux reconnaissance

  • cat /etc/issue
  • cat /etc/passwd
  • cat /proc/version
  • env
  • dpkg -l — list installed packages on Debian derived systems
  • find
  • getcap — find and list executable capabilities
  • history
  • hostname
  • id
  • ifconfig
  • ip route
  • last — display recently logged-in users (including IP addresses for network users)
  • ls
  • lsof -i — list programs using given network ports (use with netstat)
  • netstat -ano — list all listening parts and established connections, no domain resolution
  • netstat -i — list per interface statistics
  • netstat -l — list only listening ports
  • netstat -p — list protocol and service information (requires root to see everything)
  • netstat -s — list protocol statistics
  • ps auxfww — show process tree
  • ps auxww — show lots and lots of process info
  • rpm -qa — list installed packages on Red Hat derived systems
  • sudo -l
  • uname -a
  • w — list all currently logged-in users and their current program
  • who — list all currently logged-in users (including IP addresses for network users)
Link to original

Package enumeration

How to match files to packages

Debian

How to match files to packages in Debian-based operating systems

# List all installed packages
#
dpkg-query -l
 
# List files in an installed package
#
dpkg-query -L $PACKAGE_NAME
 
# List the package that owns a particular file
#
dpkg-query -S $FULL_PATH_TO_FILE
Link to original

Red Hat

How to match files to packages in Red Hat-based operating systems

# List all installed packages
#
rpm -qa
 
# List files in an installed package
#
rpm -ql $PACKAGE_NAME
 
# List the package that owns a particular file
#
rpm -qf $FULL_PATH_TO_FILE
Link to original

Link to original

Finding potentially interesting files

find file metadata flags

Some useful find flags related to file metadata.

Ownership

Filter files based on ownership in find

The -user and -group flags match files and folders owned by a particular user or group (both numeric and symbolic-readable names are allowed).

Link to original

File size

Filter files based on size in find

The -size flag matches files of size n.

Prefix n with + or - to match files strictly greater than or less than n in size. To specify useful sizes, use a suffix.

  • c — Bytes
  • k — Kilobytes
  • M — Megabytes
  • G — Gigabytes

For example, use -size +4G to find files over 4 GB (i.e., those that can’t be written to a FAT32 file system).

Link to original

Permissions

Filter files based on file permissions in find

The -perm flag matches files and folders with a given permission. Both numeric and symbolic permissions are allowed.

Use the / or - prefix to match files with any of the specified permissions or at least the specified permissions. For example, -perm -644 will match any file where the current user has at least read + write access and any other user has at least read access (so, - requires the specified permissions, but is agnostic as to the presence/absence of additional permissions). Likewise, -perm /666 will match files where the current user has read + write access and/or the current group has read + write access and/or everyone has read + write access (so, / requires that at least one of the specified permissions groups matches exactly, but is agnostic to the state of any other group outside of that match).

Link to original

Timestamps

Filter files based on timestamp in find

The -Xmin and -Xtime flags match files accessed (a), had their contents modified (m), or had their inode changed (c) n minutes (-Xmin) or days (-Xtime) ago.

All mtime changes are ctime changes, but the reverse is not necessarily true.

Prefix n with + or - to match files strictly before or after the specified time in the past.

For example:

# Matches files accessed *more* than 30 minutes ago
#
find . -type f -amin +30
 
# Matches files modified *less* than 7 days ago
#
find . -type f -mtime -7
 
# Matches files modified *today*
#
find . -type f -mtime 0
Link to original

Link to original

Finding SUID “capable” files

How to find executables with SUID capabilities

Executables can also have an SUID “capability” set in Linux, which is not the same as the SUID permission!

The getcap command displays a binary’s capabilities (if there are any), and can even be used to perform a search for such binaries using getcap -r $PATH 2> /dev/null.

Link to original

Useful scripts