Tag: centos

  • 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
  • What the Heck is a Linux Container, and Who the Hell is Docker?

    Docker-whaleA Linux Container is an Operating System level virtualization method for running isolated Linux environments on a single base install of Linux. Linux containers are not virtual machines, rather they are isolated virtual environments with dedicated CPU, memory, I/O, and network. One can think of a Linux Container as a light, virtual OS instance. At first glance one hearkens back to the time of Solaris Containers, but there is a lot more going on here then first meets the eye, especially when we throw Docker in the mix.

     

    But first, lets focus on Linux Containers…

     

    The technologies behind Linux Containers are Control Groups and Name Spaces. Control Groups manage and monitor resource allocation for processes and process groups such as CPU, Memory, and I/O. Name Spaces help isolate processes, in something akin to a chrooted environment, making processes running within them invisible to other processes in other Name Spaces.

     

    So why would you possibly want to run a Linux Container?

     

    Well for one you can consolidate multiple Linux servers into one Machine, therefor reducing the number of management points in your environment. Instead of having to patch 6 Virtual Machines, you now only have to patch one.

     

    Linux Containers can also be used to quickly spin up sandbox environments for development and testing so that you no longer need to spin up a new VM for each individual project. As we all know, this is how we end up with Virtual Sprawl. You create someone a Virtual Machine, with the intention of reclaiming it after a short period of time and all of a sudden that Virtual Machine becomes a permanent fixture in your environment. In the case of Linux Containers, you just tear down the instance and toss it away.

     

    Also, Linux Containers can be used to allow you to run multiple instances of the same application in parallel. Think of Apache virtual servers, running separately, independent and isolated from each other. Each with its own dedicated CPU, Memory, and I/O, and never stepping on each others toes.

     

    Linux Containers also provide an added layer of security. Just because a Container on a server is compromised, it does not mean that any other local Containers, or the base system itself is compromised in the least.

     

    Finally Linux Containers are efficient. First and foremost, they boot faster than traditional Virtual Machines. They also offer better performance over Virtual Machines as there is no hardware abstraction layer in the form of a hypervisor.

     

    So what is Docker then, you ask? Docker is an open source project that streamlines the deployment of an application (or OS) inside a Linux Container. Its designed to make the creation and management of Linux Containers simple as Docker can create and share disk images with ease.

     

    Here are just a few of the images available from the Docker Hub.

    • Apache CouchDB

    • PostgreSQL

    • Memcached

    • Mongo DB

    • NGINX

    • Mysql

    • WordPress

    • Centos

    • Ubuntu

    Whats amazing is that any dockerized image can run on any machine that is running docker. Imagine an Ubuntu docker image running on Centos. Weird huh?

     

    Have yourself a perfect OS image for your in-house java app? How about you dockerize that and use Docker as a revision control system for your application/OS. Sounds interesting, doesn't it.

     

    I have heard it said that Docker is not just Platform as a Service (PAAS) , its possibly could be much more than that. Right now Docker only works with Linux Containers, but imagine if it worked with KVM or Xen.

     

    Not sure about you but I look forward to getting deploy it in my lab.

    Related articles

    libswarm – Docker Orchestration Announced
    Docker 1.0 Provides Enterprise Support for Container Virtualization
    Docker 1.0 Backed By IBM, Red Hat, Rackspace
    Docker all geared up for the enterprise
    Docker: Lightweight Linux Containers for Consistent Development and Deployment
    Docker Software Containers Go Commercial
  • I have no name! – RHEL 6 and SSSD Issue.

    Cartoon_horses_st5This is an interesting one that I ran into today on an RHEL 6.3 VM that is using SSSD for authentication against LDAP.

    User contacted me stating that he was unable to su to a particual user.

    # su – app
    cannot find name for user ID 650
    [I have no name!@localhost ~]

    So I jumped on the box and attempted to "finger" the user "app". This command retured the expected output, as did the "id" command. Thinking that the issue was a temporary failure for the server to connect to the ldap server, I figured we were probably fine now. But when I attempted to su to the user above, I ran into the same issue that the user ran into. So I restarted sssd and tried again. Same issue. So in order to isolate the issue a bit more I then attempted to su to another user, and was successful.

    Huh?

    Remebering that I had run into a similar issue before I decided to stop sssd and then delete its cache

    service sssd stop ; cd /var/lib/sss/db ;rm cache_default.ldb; service sssd start.

    Boom, su now works like a charm.

    A bit of research shows that this is a known issue. See bugzilla here.

    Also I could have used the ldbsearch command to verify that the particular users database/cache entry was corrupt.

    ldbsearch -H /var/lib/sss/db/cache_default.ldb uidNumber=650

     

  • 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!

  • RHEL6 – Using htpasswd to Create a Secure Apache Directory

    Bank-vaultThe process of setting up a simple password protected web directory on an Apache server is rather easy. The simplest way to accomplish this task is to use flat-file user authentication. Disclaimer, I am not claiming that the directions below are the most complete, or the most secure. However they work and are probably the most simple.

    The first thing that you need to do is to create a "secret" directory. In this instance my web root is /var/www2/html, so I will create my secure directory under that tree.

    #mkdir /var/www2/html/secret

    Now lets create an index.html inside our secret directory for the purpose of testing.

    #echo "Secret Directory Working" > /var/www2/html/secret/index.html

    This way we have something to look at when we actually are able to get this working correctly.

    Now using the htpasswd command we need to create an htpasswd file and add a user that will have access to our top secret directory. Note that you should not create this file inside your web-root.

    #htpasswd -c /etc/httpd/.htpasswd fatmin

    In the example above the "-c" option creates our htpasswd file, fatmin is the user that we want to grant access to. You will be prompted for a password.

    Now add the following stanza to your httpd.conf. Note that AuthName is the text that will display when the user is prompted for a password. AuthUserFile is the location of the password file. Basic is pretty much the only auth method that anyone uses.

    <Directory /var/www2/html/secret>
    AuthName "Secret Directory"
    AuthType basic
    AuthUserFile /etc/httpd/.htpasswd
    Require valid-user
    </Directory>

    Now restart apache, and when you navigate to http://www.mysite.com/secret you should be prompted for a userid and password.

     

     

  • SELinux – Invalid Regex in /etc/selinux/targeted/contexts/files/file_context

    EnikSo I have been doing my best to better understand SELinux as of late, and last night when I was practicing I ran into an issue that had me banging my head against by desk.

    Specifically I was playing around with the semanage command and working on defining a particular context to a directory that I had just created. However I was not exactly quite sure of the exact regex to use (or even if I needed to use a regex)

    The specific command that I ran was…

    #semanage fcontext -a -t httpd_sys_content_t /var/www2

    Now my concern was that this was not the correct command for me to run since www2 was a directory and I wanted to make sure that appropriate SELinux contexts were applied recursively as new files/directories were created. So I ran the following command that I found in my RHEL book.

    #semanage fcontext -a -t httpd_sys_content_t ‘/var/www2/html(*,/)’

    which spits out this….

    /etc/selinux/targeted/contexts/files/file_contexts.local:  line 13 has invalid regex /var/www2/html(*,/):  Invalid preceding regular expression

    Oops, wait I entered the command wrong. Its a period and the end not a comma, so I run the command again with a period this time and get the following error.

    # semanage fcontext -a -t httpd_sys_content_t ‘/var/www2/html(*./)’
    /etc/selinux/targeted/contexts/files/file_contexts.local:  line 13 has invalid regex /var/www2/html(*,/):  Invalid preceding regular expression
    /etc/selinux/targeted/contexts/files/file_contexts.local:  line 14 has invalid regex /var/www2/html(*./):  Invalid preceding regular expression

    Well crap, its still not correct. So I enter this command and get another error.

    #semanage fcontext -a -t httpd_sys_content_t “/var/www2/html(/.*)?“

    So at this point I start running all sorts of variations of the command with minor syntax changes each time, each time getting an error and each time getting more and more frustrated thinking that I am still not running the command correctly.

    However this is not actually the case.

    After I take a step back and cool off I actually take the time to read the error message which is pointing me t the file, file_contexts.local. Which upon further inspection actually contains each and every regex that I just ran regardless of the fact that the regex was correct.

    # cat /etc/selinux/targeted/contexts/files/file_contexts.local | grep www2
    /var/www2    system_u:object_r:httpd_sys_content_t:s0
    /var/www2/html(/,*)?    system_u:object_r:httpd_sys_content_t:s0
    /var/www2/html(/,*)    system_u:object_r:httpd_sys_content_t:s0
    /var/www2/html    system_u:object_r:httpd_sys_content_t:s0
    /var/www2(/.*)?    system_u:object_r:httpd_sys_content_t:s0
    /var/www2/html(*,/)    system_u:object_r:httpd_sys_content_t:s0
    /var/www2/html(*./)    system_u:object_r:httpd_sys_content_t:s0
    /var/www2/html(/.*)?    system_u:object_r:httpd_sys_content_t:s0

    In a nutshell.. the semanage command added each and context to file/directory mapping despite the fact that my regex was not correct, and then it gave me an error. So each time I ran the command with the an invalid regex, another entry was added and the error message grew. One would think that it would detect the regex error first and not add it to the file.

    Anwyway the fix was to identify all the bad lines in the file from the error message and run the following command against each entry.

    #semanage fcontext -d “/var/www2/html(*,/)?”

    Once I cleaned out the file of the offending entries I was able to run the command one last time, this time using the correct syntax and was error free

  • RHEL6 – Display and Modify SELinux Modes

    There are three basic commands that you can use to display and modify SELinux modes. They are as follows

    • getenforce

    • setenforce

    • sestatus

    The first two are installed as part of the package, libselinux-utils. The sestatus is installed as part of policycoreutils.

    Setenforce will enable or disable SELinux temporarily. Use 0 to disable and 1 to enable as shown below.

    #setenforce 0

    #setenforce 1

    If you need need your change to be persistent across reboots edit /etc/selinux/config.

    # This file controls the state of SELinux on the system.
    # SELINUX= can take one of these three values:
    #       enforcing - SELinux security policy is enforced.
    #       permissive - SELinux prints warnings instead of enforcing.
    #       disabled - SELinux is fully disabled.
    SELINUX=enforcing
    # SELINUXTYPE= type of policy in use. Possible values are:
    #       targeted - Only targeted network daemons are protected.
    #       strict - Full SELinux protection.
    SELINUXTYPE=targeted

    Getenforce is used to query your SELinux Status as seen below

    [root@vpaquin01 selinux]# getenforce 
    Enforcing

    Sestatus give you the same information as getenforce but in a bit more detail

    [root@vpaquin01 selinux]# /usr/sbin/sestatus
    SELinux status:                 enabled
    SELinuxfs mount:                /selinux
    Current mode:                   enforcing
    Mode from config file:          enforcing
    Policy version:                 24
    Policy from config file:        targeted