Category: Security

  • Securing Individual Files in Linux with Filesystem Attributes.

    Permissions-Reset-IconFilesystem attibutes can be used to enhance standard file security on ext4 and XFS filesystems by blocking users from being able to delete or override a file. 

    In order to get started you first must see if your filesystem supports the user_xattr mount option. To do this you can use the tune2fs command. Use the '-l' option to list options.

    # tune2fs -l /dev/xvda1

     

    As shown in the section below, the filesystem that I am working with on my virtual machine supports ext_attr and has been mounted with the user_xattr option (as well as the acl option)

    Filesystem features:      has_journal ext_attr resize_inode dir_index filetype needs_recovery extent flex_bg sparse_super large_file huge_file uninit_bg dir_nlink extra_isize
    Filesystem flags:         signed_directory_hash
    Default mount options:    user_xattr acl

     

    Alternatively, you can bypass mounting a filesystem with the user_xattr option by simply making user_xattr a default mounting option for the filesystem. You accompish this formidable task with the tune2fs command. For example.

    [root@localhost ~]# tune2fs -o user_xattr /dev/sda1
    tune2fs 1.42.8 (20-Jun-2013)

     

    Now lets start messing around with a couple of the more common options. I have listed them below.

    a Append Only – sets the file to append only
    i Immutable – prevents deletion
    d Do not back up with the dump command

     

    To set the options show above you use the chattr command, and to view these options you use the lsattr command. Lets try it out. In this exmaple I am setting the immutable flag to that the file cannot be removed, renamed, or overwritten.

    [root@localhost ~]# touch testfile
    [root@localhost ~]# lsattr testfile
    —————- testfile
    [root@localhost ~]# chattr +i testfile
    [root@localhost ~]# lsattr testfile
    —-i———– testfile

     

    Ok now lets remove the 'i' option..

    [root@localhost ~]# chattr -i testfile
    [root@localhost ~]# lsattr testfile
    —————- testfile

     

    See this is pretty simple stuff, however since these options are rarely set, not to many people know about them.

     

     

     

     

  • 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
  • Quick and Dirty Yum Security Plugin Overview

    Maneki-neko-mountain-tummy-13745890The YUM security plugin is a package that allows you to search specifically for security patches applicable to a Redhat/Centos server.  This functionality comes in very handy when having to cross reference CVEs to Redhat Security Advisories (RHSAs). If you work closely with anyone in an information security role, you already know how vital functionality is.

    Before you can begin you need to make sure that you have the plugin installed.  Use the command below to install it.

    # yum -y install yum-plugin-security

     

    Then you can use the plugin to get a overview of the security updates availible for your system.

    # yum updateinfo
        
    Updates Information Summary: available
    3 Security notice(s)
             1 Important Security notice(s)
             2 Moderate Security notice(s)
    12 Bugfix notice(s)
    1 Enhancement notice(s)

     

    You can get a specific list of updates, sorted by security advisories, bug fixes, and enhancement advisories.

    # yum updateinfo list

     

    To get more specific information on a RHSA and the CVEs that it applies to, you can search by RHSA as seen below.

    # yum updateinfo RHSA-2014:0771

     

    Need to see what patches are required to address a certain CVE, then this next command is for you. Trust me this one is useful as it gives you a list of all required packages that address that CVE.

    # yum updateinfo list –cve=CVE-2013-6378
    Loaded plugins: amazon-id, rhui-lb, security
    RHSA-2014:0771 Important/Sec. kernel-2.6.32-431.20.3.el6.x86_64
    RHSA-2014:0771 Important/Sec. kernel-firmware-2.6.32-431.20.3.el6.noarch
    RHSA-2014:0771 Important/Sec. kernel-headers-2.6.32-431.20.3.el6.x86_64
    RHSA-2014:0771 Important/Sec. perf-2.6.32-431.20.3.el6.x86_64

     

    Want to see a list of all fixes by severity. Then you can use the command below. Note that I am using important as my severity as there are no critical updates that are applicable to my test system at this time.

    yum updateinfo list –sec-severity=Important
    RHSA-2014:0771 Important/Sec. kernel-2.6.32-431.20.3.el6.x86_64
    RHSA-2014:0771 Important/Sec. kernel-firmware-2.6.32-431.20.3.el6.noarch
    RHSA-2014:0771 Important/Sec. kernel-headers-2.6.32-431.20.3.el6.x86_64
    RHSA-2014:0771 Important/Sec. perf-2.6.32-431.20.3.el6.x86_64

     

    You can also search for security fixes by package name as shown below.

    # yum updateinfo list kernel
    RHSA-2014:0771 Important/Sec. kernel-2.6.32-431.20.3.el6.x86_64

     

    You can also use YUM to apply only security related updates. See below. This is useful if you are in a pinch and need to quickly apply all security updates to make your Infosec Team happy.

    # yum –security update

    Related articles

    Using Yum Update to Apply Security Patches Only
    SCAP CVE Audit
    YFD plugin updated
  • RHEL6 – SELinux Troubleshooting II: Electric Boogaloo

    Little_Miss_Trouble_by_Percyfan94So a good while back I posted an article on how to troubleshoot SELinux violations and after reviewing that article as part of a troubleshooting exercise, I realized that I left out a few details. Needless to say my original article was not as clear as it should be. Anyway I wanted to use up a few more bytes of the internet to clarify.

    When the package setroubleshoot-server is installed, SELinux violations will be sent to /var/log/messages, which makes it fairly easy to troubleshoot SELinux issues.

    So first lets install setroubleshoot and all its parts

    # yum install setroubleshoot*

    In my case on RHEL6, the following packages were installed

    setroubleshoot-plugins-3.0.40-1.el6.noarch
    setroubleshoot-server-3.0.47-3.el6_3.x86_64
    setroubleshoot-3.0.47-3.el6_3.x86_64

    Note that the setroubleshoot-server is the one that you need to troubleshoot via the command line.

    Now lets generate a violation. In this case I am just dropping a file with the wrong selinux context into /var/www/html and am trying to access it.

    # touch /root/file3 && cp /root/index.html /var/www/html/file3

    Check the context if you must to make sure that its not correct for httpd content. In this case you can see that it is not.

    # ls -lZ /var/www/html/file3
    -rwxrwxrwx. root root system_u:object_r:admin_home_t:s0 /var/www/html/file3

    Now start Apache and try to access the file via elinks or a browser. You will get a Forbidden error, which I have omitted below.

    # elinks -dump http://localhost/file3

    Note that you may need to restart auditd if your message does not show up in the messages file.

    Aug 11 17:08:39 vfatmin01 setroubleshoot: SELinux is preventing /usr/sbin/httpd from getattr access on the file /var/www/html/file3. For complete SELinux messages. run sealert -l 5a413022-af89-4222-b055-0cc1edc4bbad

    Note: You will also find a the same error in /var/log/audit/audit.log, albeit in a bit less friendly format.

    type=AVC msg=audit(1344719319.890:7196): avc:  denied  { getattr } for  pid=6765 comm=”httpd” path=”/var/www/html/file3″ dev=dm-1 ino=656718 scontext=unconfined_u:system_r:httpd_t:s0 tcontext=unconfined_u:object_r:admin_home_t:s0 tclass=file

    Anyway back to the error from the messages file. At the end of the error you are shown the UUID of the error and the sealert command to run to get more information on the error.

    # sealert -l 5a413022-af89-4222-b055-0cc1edc4bbad

    Output below:

    SELinux is preventing /usr/sbin/httpd from getattr access on the file /var/www/html/file3.

    *****  Plugin restorecon (99.5 confidence) suggests  *************************

    If you want to fix the label.
    /var/www/html/file3 default label should be httpd_sys_content_t.
    Then you can run restorecon.
    Do
    # /sbin/restorecon -v /var/www/html/file3

    Wow, sealert actually tells you why the file is being blocked and the commands that you should run to fix the problem. Nice!

  • Finding / Eliminating rogue NFS mounts in Mac OS X

    LionThere is a handy utility called Directory Utility which allows you to configure connections to directory servers.  It also contains information for persistent NFS mounts across reboots.  If you ever wondered where these phantom mounts came from or you are trying to eliminate a mount that no longer exists go to /System/Library/CoreServices/Directory Utility.

    From within Directory utility, click on Directory Editor and then select Mounts from the Viewing categories.  There you will find all mounts and add/remove as required.

     

  • RHEL6 – More on Cryptsetup and Luks — Removing Encryption

    Old-lockWay back in the day — back in March of two thousand-naught-eleven, I added a blog post on how to encrypt a partion using crypsetup and luks on RHEL. Its title, ironically enought was, RHEL, How to Encrypt a Partition Using Cryptsetup and Luks.

    Today we are going to talk about how to revert an encyrpted partion back to its unencrypted state so that i can use my usb drive normally again.

    # cryptsetup status freeagent
    /dev/mapper/freeagent is active.
      type:    LUKS1
      cipher:  aes-cbc-essiv:sha256
      keysize: 256 bits
      device:  /dev/sdd1
      offset:  4096 sectors
      size:    2930267906 sectors
      mode:    read/write

    First take note of the device name and the name the dev mapper has given the device. The former is /dev/sdd1 and the latter is /dev/mapper/freeagent.

    So first lets remove the key file mapping. You will be prompted for your LUKS passphrase

    #cryptsetup luksRemoveKey /dev/sdd1
    Enter LUKS passphrase to be deleted:

    Then lets remove the dev/mapper mapping for /dev/sdd1. Once complete we are free to create a new filesystem on the disk as needed.

    #cryptsetup remove /dev/mapper/freeagent /dev/sdd1

     
    Disk Encryption: High-impact Strategies – What You Need to Know: Definitions, Adoptions, Impact, Benefits, Maturity, Vendors