LINUX SYSTEMS SECURITY - GitHub Pages › NETS1028 › Presentations › NETS1028...Evidence of...

22
LINUX SYSTEMS SECURITY SYSTEM EXAMINATION AVAILABILITY, STABILITY, EVIDENCE OF COMPROMISE NETS1028 FALL 2019

Transcript of LINUX SYSTEMS SECURITY - GitHub Pages › NETS1028 › Presentations › NETS1028...Evidence of...

Page 1: LINUX SYSTEMS SECURITY - GitHub Pages › NETS1028 › Presentations › NETS1028...Evidence of Compromise Unexpected behaviour requires investigation e.g. resource usage spikes (up

LINUX SYSTEMS SECURITYSYSTEM EXAMINATION AVAILABILITY, STABILITY, EVIDENCE OF COMPROMISE NETS1028 FALL 2019

Page 2: LINUX SYSTEMS SECURITY - GitHub Pages › NETS1028 › Presentations › NETS1028...Evidence of Compromise Unexpected behaviour requires investigation e.g. resource usage spikes (up

AvailabilityComputer systems exist to satisfy an expectation of service

Expectations have multiple facets

Functionality

Features

Access consistency

Responsiveness

Support and recovery

Documentation and training usually define these, deviations from the norm can be indicative of system compromise

Examining running systems identifies deviations, users do it constantly as a byproduct of using the systems

Page 3: LINUX SYSTEMS SECURITY - GitHub Pages › NETS1028 › Presentations › NETS1028...Evidence of Compromise Unexpected behaviour requires investigation e.g. resource usage spikes (up

StabilityStability refers to the continued, consistent provision of expected services

Misconfigurations and bugs can introduce instability

Attacks can produce instabilities that look like bugs or misconfigurations, successful intruders may alter configurations

Normal operations and configurations must be clearly documented and well understood, to be able to identify abnormal situations

Instabilities are commonly flagged by users, but can also be identified by tools, logs, and reports

Page 4: LINUX SYSTEMS SECURITY - GitHub Pages › NETS1028 › Presentations › NETS1028...Evidence of Compromise Unexpected behaviour requires investigation e.g. resource usage spikes (up

Evidence of CompromiseUnexpected behaviour requires investigation e.g. resource usage spikes (up or down), inconsistent system responsiveness or responses, i/o irregularities

User problem reporting identifies symptoms, but not always causes

Monitoring systems can alert you to anomalous behaviour - sometimes only external monitoring will show anything, depending on the cause

Log files can be reviewed or analyzed for additional symptoms or root cause indicators

Simple examinations of critical services and files can provide evidence of compromise

Page 5: LINUX SYSTEMS SECURITY - GitHub Pages › NETS1028 › Presentations › NETS1028...Evidence of Compromise Unexpected behaviour requires investigation e.g. resource usage spikes (up

Documenting Normal

Manuals and business policy & procedure documents can define expected system operation

State information such as resource usage, change rates, resource consumption, current activity, past activity are all things to consider

Recording these things removes dependency on the guru

Page 6: LINUX SYSTEMS SECURITY - GitHub Pages › NETS1028 › Presentations › NETS1028...Evidence of Compromise Unexpected behaviour requires investigation e.g. resource usage spikes (up

System State - StaticSystem components (configuration and program files) should only change in a planned way

The state of these files can be compared to their expected state

rpm and debsums provide tools to check if program files have been modified other than by package installation and update procedures

rpm -qV packagename, dpkg -V packagename

debsums -s [packagename]

Neither can do much which is useful with generated files or configuration files, create your own methods, scripts for this

debsums does a different check from the rpm command which is more thorough

It is not uncommon for systems to have packages installed using more than one package management system (terrible very bad idea, IMHO), beware of snaps - read-only mounts are not a guarantee of integrity

Page 7: LINUX SYSTEMS SECURITY - GitHub Pages › NETS1028 › Presentations › NETS1028...Evidence of Compromise Unexpected behaviour requires investigation e.g. resource usage spikes (up

ExercisesInstall the debsums package

Use debsums to verify the files from your openssh-client package, check both the binaries and the config files

Use debsums to identify if you have any packages without checksums installed

Modify your /etc/ssh/ssh_config file and recheck with debsums to see the change in output

Rename your /usr/bin/scp program to something else, and see the change in debsums output, then put your scp program back

Page 8: LINUX SYSTEMS SECURITY - GitHub Pages › NETS1028 › Presentations › NETS1028...Evidence of Compromise Unexpected behaviour requires investigation e.g. resource usage spikes (up

State Verification - StaticCheck for setuid/setgid files not belonging to installed packages

Check for files in user directories not owned by those users

Check for files in system directories not belonging to installed packages

Check for files owned by system service daemons not belonging to installed packages

Pay particular attention to files and directories whose names start with a dot, especially if the files are executable

This is a good task for a script!

Page 9: LINUX SYSTEMS SECURITY - GitHub Pages › NETS1028 › Presentations › NETS1028...Evidence of Compromise Unexpected behaviour requires investigation e.g. resource usage spikes (up

File Integrity Toolsrkhunter is a tool which can look for a number of types of malicious files although development is sporadic so it shouldn’t be your only tool

Tripwire has been around for a long time and is a general purpose tool to identify file changes

Tripwire is available in both free and enterprise paid versions and has a GUI

Advanced Intrusion Detection Environment (AIDE) provides for comprehensive checks of your file stores to identify changes and was intended to be a replacement for Tripwire before Tripwire went commercial

Page 10: LINUX SYSTEMS SECURITY - GitHub Pages › NETS1028 › Presentations › NETS1028...Evidence of Compromise Unexpected behaviour requires investigation e.g. resource usage spikes (up

ExercisesCreate a script to find and list out setuid and setgid files on your system

Your script should separate out files that debsums says are ok

Add a listing of files in user directories not owned by those users

Add files in system directories which do not belong to installed packages

Add files owned by service daemons

Add dot files with execute permissions

Install rkhunter and compare its output with the output of your own script

Install AIDE and configure it to watch your system directories and email reports to you

Page 11: LINUX SYSTEMS SECURITY - GitHub Pages › NETS1028 › Presentations › NETS1028...Evidence of Compromise Unexpected behaviour requires investigation e.g. resource usage spikes (up

System State - DynamicDynamic state is

use of resources (cpu, memory, storage, network) - performance measurement

current access summary (who is on, what are they doing) - user access

service(s) status (running, stopped, degraded or normal) - service evaluation

external views of traffic flow (who/where from/to, what ports/services, volume, path taken) - unusual activity flagging

Check running system configuration with respect to time, timezone, resolver, network config, things that get set dynamically at boot or during normal operation

/proc filesystem provides lots of raw dynamic information when you need to dig down

Page 12: LINUX SYSTEMS SECURITY - GitHub Pages › NETS1028 › Presentations › NETS1028...Evidence of Compromise Unexpected behaviour requires investigation e.g. resource usage spikes (up

Performance MeasurementUse of resources

CPU/memory

top, htop can be used for simple overview of running system, or use a higher powered toolset like glances

ps, pidstat, vmstat, memstat, mpstat, free, pmap, pstree can be used to drill down and investigate things not running in a normal state

sar can be used to view historical data for comparison purposes, enable in /etc/default/sysstat and restart service to start data collection

ac (from psacct or acct) can also show summarized past usage info

Page 13: LINUX SYSTEMS SECURITY - GitHub Pages › NETS1028 › Presentations › NETS1028...Evidence of Compromise Unexpected behaviour requires investigation e.g. resource usage spikes (up

Files and Storageiotop, df, du, find can be used to check current activity and usage and detail it as necessary

mount/umount, automounting is often configured to permit end-user mounting of filesystems and should be investigated to ensure any user-mounted filesystems are nosetuid, and probably also noexec

swapon (free includes swap usage), lsof, iostat can be used to drill down to the details

world-writable directories, filesystem type-based limitations are potential attack vectors

Often, the worst thing that happens to a Linux server is that it gets misused to host Windows malware - clamav, bitdefender, and others can be used to actively scan your file stores for Windows malware

Page 14: LINUX SYSTEMS SECURITY - GitHub Pages › NETS1028 › Presentations › NETS1028...Evidence of Compromise Unexpected behaviour requires investigation e.g. resource usage spikes (up

Network ExaminationNetwork

ntopng, iptraf-ng, nethogs, iftop, arpwatch

netstat, route, ss

ifconfig, ethtool, ip

resolver configuration, might be a static verification

ping, traceroute, arp, nslookup, tcpdump, wireshark can all be used to drill down when investigating anomalies

Page 15: LINUX SYSTEMS SECURITY - GitHub Pages › NETS1028 › Presentations › NETS1028...Evidence of Compromise Unexpected behaviour requires investigation e.g. resource usage spikes (up

ExercisesEach of the tools mentioned on the previous pages has its uses. For each one that you may not be very familiar with already, install the package if necessary, review the description information on each one’s man page, and have a brief look at the options offered to customize the commands. Run each of the commands to view the default output and then try to get additional information using options. This is an exploration exercise.

While running the performance tools, create activity on your system in a second shell to see the impacts tasks can have on your system. You can use find to incur disk activity, curl or wget or netcat to incur network activity, zip to incur cpu and memory usage, or any other methods you like to cause your system to perform work.

Page 16: LINUX SYSTEMS SECURITY - GitHub Pages › NETS1028 › Presentations › NETS1028...Evidence of Compromise Unexpected behaviour requires investigation e.g. resource usage spikes (up

Performance Overview Tools

Glances is a tool that shows a summarized subset of information about the running system

KDE and Gnome have process monitoring tools that allow graphical process and performance exploration

Everybody and their sister writes custom tools for their own environment, many get published under GPL because they start with some other piece of GPL code

Check out monit, monitorix, nagios, nmon, collectl, web-vmstat for examples of real-time enhanced performance monitoring tools

No matter which tool(s) you use to become aware of anomalous conditions, there are plenty of commands to help dig into what is going on, and don’t forget about /proc which gives you a comprehensive view of what is going on inside your machine

Page 17: LINUX SYSTEMS SECURITY - GitHub Pages › NETS1028 › Presentations › NETS1028...Evidence of Compromise Unexpected behaviour requires investigation e.g. resource usage spikes (up

User AccessUnix users can be tracked or observed by a number of tools

who, whoami, id, w

last, lastcomm, history

various more comprehensive auditing tools

Most of the time, if you see users on that should not be on, or shouldn’t exist, you have already been broken into

Page 18: LINUX SYSTEMS SECURITY - GitHub Pages › NETS1028 › Presentations › NETS1028...Evidence of Compromise Unexpected behaviour requires investigation e.g. resource usage spikes (up

Services EvaluationServices can be checked in a number of simple ways

systemctl, service, ps, netstat, nmap

telnet, per-service access tools - connecting to a service is the only way to know for sure that it is responding normally

log entries - helpful for figuring out what went wrong (past tense) or just knowing something went wrong when all appears normal otherwise

Various services have more sophisticated built-in status inquiry mechanisms

apache has server-status module

mysql internal status commands and queries

cups lpadmin and web interface toolset

Some services are complex enough that there is software available to evaluate its status and manage the service - e.g. phpmyadmin for mysql-compatible database servers

Page 19: LINUX SYSTEMS SECURITY - GitHub Pages › NETS1028 › Presentations › NETS1028...Evidence of Compromise Unexpected behaviour requires investigation e.g. resource usage spikes (up

Performance Tools References• There are so many tools available, lists of tools are

also common

http://www.tecmint.com/command-line-tools-to-monitor-linux-performance/

http://www.tecmint.com/linux-performance-monitoring-tools/

http://www.cyberciti.biz/tips/top-linux-monitoring-tools.html

https://blog.serverdensity.com/80-linux-monitoring-tools-know/

Page 20: LINUX SYSTEMS SECURITY - GitHub Pages › NETS1028 › Presentations › NETS1028...Evidence of Compromise Unexpected behaviour requires investigation e.g. resource usage spikes (up

Log EntriesLogs are typically kept in /var/log as a default

Programs may directly write their own log files, or they may use the syslog service

Syslog can be configured to manage messages in custom ways, including sending them to a log server

Each program makes its own decisions about what to log, when to log it, and how usefully to describe whatever is being logged

Beware of sensitive information appearing in log files, they are not encrypted

Refer to the man pages or user guides for each service to see what is logged and how

Page 21: LINUX SYSTEMS SECURITY - GitHub Pages › NETS1028 › Presentations › NETS1028...Evidence of Compromise Unexpected behaviour requires investigation e.g. resource usage spikes (up

ExercisesReview the /var/log/auth.log file to see what sort of entries are present

Use su, sudo and login with invalid user names and wrong passwords to cause auth.log entries to be made and then see what got logged

Compare those entries with entries made by similar failed logins using ssh

Review the suggestions for things to consider when examining a Ubuntu system at https://wiki.ubuntu.com/BasicSecurity/DidIJustGetOwned

Page 22: LINUX SYSTEMS SECURITY - GitHub Pages › NETS1028 › Presentations › NETS1028...Evidence of Compromise Unexpected behaviour requires investigation e.g. resource usage spikes (up

LAB 02 SYSTEM EXAMINATIONTRY PRESENTATION EXERCISES BEGIN ON RESEARCH ASSIGNMENT