Tag: centos

  • Mastering Auditd: A Guide to Linux Auditing

    Mastering Auditd: A Guide to Linux Auditing

    Auditd is the userland piece of the RHEL audit tool suite. When its up and running, audit messages sent by the kernel will be send to log files that you have configured. By default, only a small and limited number of messages will be picked up by Auditd; these are mostly messages related to authentication and authorization.

    Auditd has three main config files as shown below

    • /etc/sysconfig/auditd – basic configuration options
    • /etc/audit/auditd.conf – main config file
    • /etc/audit/audit.rules – auditing rules

    Auditd and Syslog:

    Its possible to send audit messages to a syslog. By setting active=yes in /etc/audisp/plugins.d/syslog.conf you can send all your audit messages to syslog. If your system is setup to log to a remote syslog server, then your audit messages will go along for the ride as well. Note that you can also send audit messages to a remote logging server via native audit protocol over TCP. I am not going to go into this option, but I want to make sure that we are aware that it exists.

     

    Looking for Audit Events in All the Wrong Places:

    Auditd includes a handy-dandy tool for searching audit logs. Ausearch. You can check out all your current audit log messages using the command below.

    [root@ip-172-31-21-28 ~]# ausearch -l

    Viewing audit logs in their raw format can be accomplished with the command below

    [root@ip-172-31-21-28 ~]# ausearch --raw

    The -a option allows you to search by audit event ids

    [root@ip-172-31-21-28 ~]# ausearch -a 282

    Auditd also includes ausearch, which allows you to get a quick summary of audit events, rather than trying to view massive audit logs. Usage and output shown below.

    root@ip-172-31-21-28 ~]# aureport
    Summary Report
    ======================
    Range of time in logs: 07/17/2014 10:21:36.438 - 07/17/2014 19:52:49.556
    Selected time for report: 07/17/2014 10:21:36 - 07/17/2014 19:52:49.556
    Number of changes in configuration: 4
    Number of changes to accounts, groups, or roles: 24
    Number of logins: 20
    Number of failed logins: 4
    Number of authentications: 75
    Number of failed authentications: 3
    Number of users: 3
    Number of terminals: 18
    Number of host names: 19
    Number of executables: 14
    Number of files: 0
    Number of AVC's: 10
    Number of MAC events: 20
    Number of failed syscalls: 10
    Number of anomaly events: 0
    Number of responses to anomaly events: 0
    Number of crypto events: 244
    Number of keys: 0
    Number of process IDs: 203
    Number of events: 1132

    You can also use aureport and ausearch together. Simliar to the powerfull partnership between Batman and Robin, these two tools complement each other in ways that you can only imagine. Check out my sexy bits below.

    [root@ip-172-31-21-28 ~]# ausearch --start today --raw | aureport
    Summary Report
    ======================
    Range of time in logs: 07/17/2014 10:21:36.438 - 07/17/2014 20:01:01.911
    Selected time for report: 07/17/2014 10:21:36 - 07/17/2014 20:01:01.911
    Number of changes in configuration: 4
    Number of changes to accounts, groups, or roles: 24
    Number of logins: 20
    Number of failed logins: 4
    Number of authentications: 75
    Number of failed authentications: 3
    Number of users: 3
    Number of terminals: 18
    Number of host names: 19
    Number of executables: 14
    Number of files: 0
    Number of AVC's: 10
    Number of MAC events: 20
    Number of failed syscalls: 10
    Number of anomaly events: 0
    Number of responses to anomaly events: 0
    Number of crypto events: 244
    Number of keys: 0
    Number of process IDs: 205
    Number of events: 1144

    Want to know another cool tool that is part of auditd? I know, its a lot to take in at one time, but I am sure that you can handle it. Using autrace you can trace and investigate system calls made by a process. 

    Want to see everything that nslookup is doing? Then run the command below.

    [root@ip-172-31-21-28 ~]# autrace /usr/bin/nslookup google.com

    This will output a pid for you to trace with ausearch.

    Trace complete. You can locate the records with 'ausearch -i -p 3359'

     
    Related articles

    RHEL6- Getting Up Close and Personal With Rsyslog
    Linux audit files to see who made changes to a file
  • RHEL6: Using Advanced Log File Filtering in Rsyslog

    100-8591So by default when you forward logs to a syslog/rsyslog server all the logs end up in the same file (ususally configured to go to the messages file). Sometimes one may prefer to forward logs from a particular server to a separate logfile. I know for a fact that my sometimes friends in our info-sec group prefers this setup.

    While managing such a setup for more than a handful of hosts would probably be a nightmare, its not actaually hard to setup on the most basic level.

    First create a custom filters.conf (or whatever you want to name it) in your /etc/rsyslog.d directory. Below is the file that I created.

    [root@ip-172-31-21-28 rsyslog.d]# cat filters.conf
    :fromhost, isequal, "ip-172-31-25-104.ec2.internal" /var/log/ip-172-31-25-104.ec2.internal/messages
    :fromhost, isequal, "ip-172-31-25-104.ec2.internal" ~

    Note that you will need to include two lines in your file for each host, one with the specific file/location that you want to send your filtered log messages, and a second line that directs rsyslog to discard any messages from the specified hosts once they have been logged to the specified locations. This keeps these messages from ending up in the messages file as well as the file defined in your filter file.

     
    Related articles

    RHEL6 – Introduction to IPtables, Part II
    HomeLab: Basic Syslog Configuration on Cisco Catalyst Devices
    RHEL6- Getting Up Close and Personal With Rsyslog
  • Disabling Ctrl+Alt+Delete in RHEL 6

    Ctrl-Alt-Del-Cup-Set

    Let me start off by saying that I am not a fan of disabling ctrl+alt+delete, especially if you do not have physical access to a server.

    Sometimes the old three finger salute is the best and quickest method to reboot a locked and unresponsive Operating System.

    Regardless of this fact, some Info Sec folks think that disabling this functionality is a good idea for security.

    So for their sake, I will show you how to do it.


    First ssh into your server and become root and change directory to what is shown below.

    [root@ip-172-31-22-45 ~]# cd /etc/init

    Now copy the file below exactly as I have illustrated. You do not want to try to modify the original file as it could be overwritten by Upstart.

    [root@ip-172-31-22-45 init]# cp control-alt-delete.conf control-alt-delete.override

    Now modify the line below and change it to run a command that will exit with an exit code of 0.

    exec /sbin/shutdown -r now "Control-Alt-Delete pressed"

    Something like /bin/true will work, although I am sure that you can come up with more creative ideas.

    exec /bin/true

    Now try ctrl+atl+delete, nothing should happen.

  • Introduction to AIDE – Advanced Intrusion Detection Environment

    Wally_Gator_PhotoEver heard of AIDE, neither had I. Apparently its a simple intrusion detection application that can be used to monitor file changes.  It can be confired to monitor permission, ownership, timestamp, or content changes.

    Lets install it. Its in the stock Redhat repos, so its a piece of cake to install via yum.

     

    [root@localhost ~]# yum -y install aide

    Once installed, you can tweak the config file (/etc/aide.conf) to your liking. The stock config is pretty robust, so I am going to trim it down a bit and just monitor /etc for permission changes, and /bin for what are defined as normal changes. Normal looks at file hashes to see if the files have been modified.

    /bin    NORMAL
    /etc    PERMS
     

    Now lets start aide

    [root@localhost ~]# aide –init

    AIDE, version 0.15.1

    ### AIDE database at /var/lib/aide/aide.db.new.gz initialized.

     

    Now this part is silly, we need to rename the database created above to the name that aide is configured to use.

    [root@localhost ~]# cp /var/lib/aide/aide.db.new.gz /var/lib/aide/aide.db.gz

     

    Now lets check for changes.

    [root@localhost ~]# aide –check

    AIDE, version 0.15.1

    ### All files match AIDE database. Looks okay!

    Hey no changes. Now lets monkey with something and see if aide catches it. In this example we are creating a new file in /etc. As seen below aide catches the new file and reports on it.

     

    [root@localhost ~]# touch /etc/aide.test.change
    [root@localhost ~]# aide –check
    AIDE 0.15.1 found differences between database and filesystem!!
    Start timestamp: 2014-07-15 19:51:14

    Summary:
      Total number of files:        5054
      Added files:                  1
      Removed files:                0
      Changed files:                0

    —————————————————
    Added files:
    —————————————————

    added: /etc/aide.test.change

     

    So now lets re-initialize the database, which is pretty much a snapshot.

    [root@localhost ~]# aide –init

    AIDE, version 0.15.1

    ### AIDE database at /var/lib/aide/aide.db.new.gz initialized.

     

    Don't forget to overwrite the old database.

    [root@localhost ~]# cp /var/lib/aide/aide.db.new.gz /var/lib/aide/aide.db.gz
    cp: overwrite ‘/var/lib/aide/aide.db.gz’? yes

    Now lets change the permissions on our test file and see if aide catches the change.  I'll spare you the suspense and let you know that aide did its job. See below.

     

    [root@localhost ~]# chmod 777 /etc/aide.test.change
    [root@localhost ~]# aide –check                    
    AIDE 0.15.1 found differences between database and filesystem!!
    Start timestamp: 2014-07-15 19:54:09

    Summary:
      Total number of files:        5054
      Added files:                  0
      Removed files:                0
      Changed files:                2

    —————————————————
    Changed files:
    —————————————————

    changed: /etc/aide.test.change
    changed: /root/.mozilla/firefox/8u03e3hs.default/sessionstore.js

    —————————————————
    Detailed information about changes:
    —————————————————

    File: /etc/aide.test.change
     Perm     : -rw-r–r–                       , -rwxrwxrwx
     ACL      : old = A:
    —-
    user::rw-
    group::r–
    other::r–
    —-
                      D: <NONE>
                new = A:
    —-
    user::rwx
    group::rwx
    other::rwx
    —-
                      D: <NONE>

    Now aide on its own is just a simple tool, but run via cron with a bit of tuning and a bit more logic behind it and I can see it being a very useful tool. Looking forward to playing with it more.
    Related articles

    How To Install Aide on a DigitalOcean VPS
    RHEL6 – How to Setup an Anonymous Download Only FTP Server
  • Working With Extended Filesystem Attributes in Linux

    GarfatIn my previous post I went over standard filesystem attibutes in Linux, and how to set and view those attibutes with lsattr and chattr. You can view that post here if you are interested.

    In this post we are going to go over extended filesystem attibutes. Now there is not much to this as you are probably not going to ever have to use these settings. That being said, its not a bad thing to be aware of.

    Attribute names are strings that can be set and configured at will using the setfatr command. They can be viewed with the getfattr command. There are 4 namespaces of attibutes, security, system, trusted, and user.

    When using getfattr ( which I pronounce as getfatter) the -d option dumps only user namespace attibutes. The rest of the namespace attributes can be viewed by using the -m option along with the namespace name. In the example below you can see that there are no user namespace attibutes set on my anaconda-ks.cfg file, however there are attibutes set in the security namespace.

    [root@localhost ~]# getfattr -d anaconda-ks.cfg
    [root@localhost ~]# getfattr -d -m security anaconda-ks.cfg
    # file: anaconda-ks.cfg
    security.selinux="unconfined_u:object_r:admin_home_t:s0"

     

    Using setfattr you can define and set custom attributes. See the useless example below.

    [root@localhost ~]# setfattr -n user.example -v example anaconda-ks.cfg
    [root@localhost ~]# getfattr -d anaconda-ks.cfg
    # file: anaconda-ks.cfg
    user.example="example"

    However this could be cool if you got an md5 sum on a file and dumped it into a file attibute. You could, in theory, use this process to see if someone has messed with one of your config files.

     

    [root@localhost ~]# md5sum anaconda-ks.cfg
    fda1aa550d3cf82423d1b1ad1ae53a13  anaconda-ks.cfg
    [root@localhost ~]# setfattr -n user.md5sum -v fda1aa550d3cf82423d1b1ad1ae53a13 anaconda-ks.cfg
    [root@localhost ~]# getfattr -d anaconda-ks.cfg
    # file: anaconda-ks.cfg
    user.example="example"
    user.md5sum="fda1aa550d3cf82423d1b1ad1ae53a13"

     
    Related articles

    Why Extended Attributes are Coming to HDFS
    Advanced Filesystem Attributes in Linux
    How to create a file that root user also can't delete?
  • Yum: Under the Covers with GPG Keys

    Skeleton_key_1_keychain_sculpture_photo_cut_outs-r558fef9b275d4609b522ac07970a6af6_x7sa6_8byvr_324Hey look at this spooky key. Don't be frightened little one. Nothing scary is going to happen to you here. This is a safe place. As a matter of fact, if you stick around you might just learn a thing or two. A thing or two about GPG!

    First off do any of us really know what GPG stands for? Well yes we do! It stands for GNU Privacy Guard. RPM Package creators use GPG to apply a digital signature to their packages. If a package was tampered with, then its GPG signature will no longer match what was placed in the original package.

    First off to check what keys you have installed on your Linux server you can run the following rpm command as show in the example below.

    [root@ip-172-31-22-45 ~]# rpm -qa gpg-pubkey
    gpg-pubkey-0608b895-4bd22942
    gpg-pubkey-fd431d51-4ae0493b
    gpg-pubkey-2fa658e0-45700c69

     

    Neet I have three keys installed. But lets say want to install another one. Well I can do so with the command below. In this example I have navigated to /etc/pki/rpm-gpg and am going to install the redhat beta key on my server.

    [root@ip-172-31-22-45 rpm-gpg]# rpm –import RPM-GPG-KEY-redhat-beta

    Hey that was fun. Now lets get our hands a bit dirtier.

    Want to get more information on a specific key. Then this command is your huckleberry. Here you can see that this is the pubkey for the EPEL repo.

    [root@ip-172-31-22-45 rpm-gpg]# rpm -qi gpg-pubkey-0608b895-4bd22942
    Name        : gpg-pubkey                   Relocations: (not relocatable)
    Version     : 0608b895                          Vendor: (none)
    Release     : 4bd22942                      Build Date: Sat 14 Jun 2014 09:13:58 AM EDT
    Install Date: Sat 14 Jun 2014 09:13:58 AM EDT      Build Host: localhost
    Group       : Public Keys                   Source RPM: (none)
    Size        : 0                                License: pubkey
    Signature   : (none)
    Summary     : gpg(EPEL (6) <epel@fedoraproject.org>)
    Description :

     

    To verify signature of a downloaded package, use the rpm command as shown below. In this example I have highlighted the key that was used to sign this package.

    # rpm -vK nautilus-dropbox-1.6.0-1.fedora.i386.rpm
    nautilus-dropbox-1.6.0-1.fedora.i386.rpm:
        Header V3 RSA/SHA1 Signature, key ID 5044912e: OK
        Header SHA1 digest: OK (a4d51906633f92913db075ba33946f50999c245e)
        V3 RSA/SHA1 Signature, key ID 5044912e: OK
        MD5 digest: OK (1b8ff7abc18f68bf274e24fc57fd3a87)

     

    Using the bolded information in the example above, I can then use this information to track down the exact key that was used to sign the package.

    [root@localhost Downloads]# rpm -qa | grep 5044912e
    gpg-pubkey-5044912e-4b7489b1

     

    Is this awesome, well not really, but you never know when you might need to use this information. Like on a test. Wink Wink.
    Related articles

    Using Yum Update to Apply Security Patches Only
    How to Enable EPEL Repository on CentOs for Yum
    Signing rpm packages with GPG
  • RPM Package Inspection for Fun and Profit

    6a00d8341c562c53ef01538f8abd65970b-800wi"Whats in the box" — David Mills

    Lets face it, one of your users needs to have a package installed on a system, you tend to do it for them. That is, as long as the package looks safe. Sure, your not going to install an rpm that is clearly dangerous, but as long as the package name looks reasonable and you trust the user, you might actually just go ahead an install it for them without thinking much about it. Hell, I know that I have done the exact same thing from time to time. And I have done it with an unsigned package.

    "Sure you need this Oracle thing installed on this database server?"

     "You got it directly from Oracle right?"

    But honestly, this is a very bad practice as you have no idea what the RPM is installing, and what its pre and post scripts might be doing to your system. Using the command below, you can inspect a packages post and pre install scripts to see if they are doing anything funny. In this instance I am taking a look at the dropbox package for my little Eeepc.

    [root@localhost ~]# rpm -qp –scripts /root/Downloads/nautilus-dropbox-1.6.0-1.fedora.i386.rpm

    If you have already installed a package and want to see what its pre and post install scripts did. You can run the command above using the installed package name. Note that you will drop the "P" from the command. See my sendmail example below.

    [root@localhost ~]#rpm -q –scripts sendmail-8.14.8-2.fc20.i686

     

    In addition to checking the pre and post scripts, you also want to check to see if the rpm has any triggers. What are triggers you ask? Well they are extensions to the normal install scripts, and they may often call for the installation of another package or the execution of a command. Just look at all the triggers that fire when you install sendmail.

    [root@localhost ~]# rpm -q –triggers sendmail-8.14.8-2.fc20.i686
    triggerun scriptlet (using /bin/sh) — sendmail < 8.14.5-3
    /usr/bin/systemd-sysv-convert –save sendmail >/dev/null 2>&1 ||:
    /bin/systemctl enable sendmail.service >/dev/null 2>&1
    /bin/systemctl enable sm-client.service >/dev/null 2>&1
    /sbin/chkconfig –del sendmail >/dev/null 2>&1 || :
    /bin/systemctl try-restart sendmail.service >/dev/null 2>&1 || :
    /bin/systemctl try-restart sm-client.service >/dev/null 2>&1 || :
    # workaround for systemd rhbz#738022
    /bin/systemctl is-active sendmail.service >/dev/null 2>&1 && \
            ! /bin/systemctl is-active sm-client.service >/dev/null 2>&1 && \
            /bin/systemctl start sm-client.service >/dev/null 2>&1 || :

    Obviously you also want to check to see what files are actually part of a package. This can be accomplished with the query and list arguments seen below. Add the "P" argument if the rpm is not already installed. In this case I have already installed sendmail, so I exclude the "P" from the command.

     

    [root@localhost ~]# rpm -ql sendmail-8.14.8-2.fc20.i686
    /etc/NetworkManager/dispatcher.d/10-sendmail
    /etc/mail
    /etc/mail/Makefile
    /etc/mail/access
    /etc/mail/access.db
    /etc/mail/aliasesdb-stamp
    /etc/mail/domaintable
    /etc/mail/domaintable.db
    /etc/mail/helpfile
    /etc/mail/local-host-names
    ..truncated…

     

    So whats the moral of the story here. Well its really not that hard to take a minute and look under the covers and make sure that the packages that you are installing are not harming your systems. Is definetly worth 5 minutes of your time. Might just save your behind.

     
    Related articles

    RHEL6 – Simple Postfix Configuration
    RHEL6 – Common Postfix Server Roles
    Configure sendmail as a client for SMTPs
    Sendmail Server