{"id":12020,"date":"2019-03-21T03:13:27","date_gmt":"2019-03-21T03:13:27","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=12020"},"modified":"2019-03-21T03:13:27","modified_gmt":"2019-03-21T03:13:27","slug":"how-to-check-integrity-of-file-and-directory-using-aide-in-linux","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/21\/how-to-check-integrity-of-file-and-directory-using-aide-in-linux\/","title":{"rendered":"How to Check Integrity of File and Directory Using \u201cAIDE\u201d in Linux"},"content":{"rendered":"<p>In our mega guide to\u00a0<a href=\"https:\/\/www.tecmint.com\/security-and-hardening-centos-7-guide\/\" target=\"_blank\" rel=\"noopener\">hardening and securing CentOS 7<\/a>, under the section \u201c<strong>protect system internally<\/strong>\u201d, one of the useful security tools we listed for internal system protection against viruses, rootkits, malware, and detection of unauthorized activities is\u00a0<strong>AIDE<\/strong>.<\/p>\n<p><strong>AIDE<\/strong>\u00a0(<strong>Advanced Intrusion Detection Environment<\/strong>) is a small yet powerful, free open source intrusion detection tool, that uses predefined rules to check file and directory integrity in Unix-like operating systems such as Linux. It is an independent static binary for simplified client\/server monitoring configurations.<\/p>\n<p>It is feature-rich: uses plain text configuration files and database making it easy to use; supports several message digest algorithms such as but not limited to md5, sha1, rmd160, tiger; supports common file attributes; also supports powerful regular expressions to selectively include or exclude files and directories to be scanned.<\/p>\n<p>Also it can be compiled with exceptional support for Gzip compression, Posix ACL, SELinux, XAttrs and Extended file system attributes.<\/p>\n<p>Aide works by creating a database (which is simply a snapshot of selected parts of the file system), from the regular expression rules defined in the configuration file(s). Once this database is initialized, you can verify the integrity of the system files against it. This guide will show how to install and use aide in Linux.<\/p>\n<h3>How to Install AIDE in Linux<\/h3>\n<p>Aide is packaged in official repositories of mainstream Linux distributions, to install it run the command for your distribution using a package manager.<\/p>\n<pre># apt install aide \t   [On Debian\/Ubuntu]\r\n# yum install aide\t   [On RHEL\/CentOS] \t\r\n# dnf install aide\t   [On Fedora 22+]\r\n# zypper install aide\t   [On openSUSE]\r\n# emerge aide \t           [On Gentoo]\r\n<\/pre>\n<p>After installing it, the main configuration file is\u00a0<strong>\/etc\/aide.conf<\/strong>. To view the installed version as well as compile time parameters, run the command below on your terminal:<\/p>\n<pre># aide -v\r\n<\/pre>\n<h5>Sample Output<\/h5>\n<pre>Aide 0.14\r\n\r\nCompiled with the following options:\r\n\r\nWITH_MMAP\r\nWITH_POSIX_ACL\r\nWITH_SELINUX\r\nWITH_PRELINK\r\nWITH_XATTR\r\nWITH_LSTAT64\r\nWITH_READDIR64\r\nWITH_ZLIB\r\nWITH_GCRYPT\r\nWITH_AUDIT\r\nCONFIG_FILE = \"\/etc\/aide.conf\"\r\n<\/pre>\n<p>You can open the configuration using your favorite editor.<\/p>\n<pre># vi \/etc\/aide.conf\r\n<\/pre>\n<p>It has directives that define the database location, report location, default rules, the directories\/files to be included in the database.<\/p>\n<h4>Understanding Default Aide Rules<\/h4>\n<div id=\"attachment_28077\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/11\/AIDE-Default-Rules.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-28077\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/11\/AIDE-Default-Rules.png\" alt=\"AIDE Default Rules\" width=\"719\" height=\"629\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">AIDE Default Rules<\/p>\n<\/div>\n<p>Using the above default rules, you can define new custom rules in the\u00a0<strong>aide.conf<\/strong>\u00a0file for example.<\/p>\n<pre>PERMS = p+u+g+acl+selinux+xattrs\r\n<\/pre>\n<p>The\u00a0<strong>PERMS<\/strong>\u00a0rule is used for access control only, it will detect any changes to file or directories based on file\/directory permissions, user, group, access control permissions, SELinux context and file attributes.<\/p>\n<p>This will only check file content and file type.<\/p>\n<pre>CONTENT = sha256+ftype\r\n<\/pre>\n<p>This is an extended version of the previous rule, it checks extended content, file type and access.<\/p>\n<pre>CONTENT_EX = sha256+ftype+p+u+g+n+acl+selinux+xattrs\r\n<\/pre>\n<p>The\u00a0<strong>DATAONLY<\/strong>\u00a0rule below will help detect any changes in data inside all files\/directory.<\/p>\n<pre>DATAONLY =  p+n+u+g+s+acl+selinux+xattrs+sha256\r\n<\/pre>\n<div id=\"attachment_28079\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/11\/Configure-Aide-Rules.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-28079\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/11\/Configure-Aide-Rules.png\" alt=\"Configure Aide Rules\" width=\"712\" height=\"268\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Configure Aide Rules<\/p>\n<\/div>\n<h3>Defining Rules to Watch Files and Directories<\/h3>\n<p>Once you have defined rules, you can specify the file and directories to watch. Considering the PERMS rule above, this definition will check permissions for all files in root directory.<\/p>\n<pre>\/root\/\\..*  PERMS\r\n<\/pre>\n<p>This will check all files in the\u00a0<strong>\/root<\/strong>\u00a0directory for any changes.<\/p>\n<pre>\/root\/   CONTENT_EX\r\n<\/pre>\n<p>To help you detect any changes in data inside all files\/directory under\u00a0<strong>\/etc\/<\/strong>, use this.<\/p>\n<pre>\/etc\/   DATAONLY \r\n<\/pre>\n<div id=\"attachment_28080\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/11\/Configure-Aide-Rules-for-Filesystem.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-28080\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/11\/Configure-Aide-Rules-for-Filesystem.png\" alt=\"Configure Aide Rules for Filesystem\" width=\"672\" height=\"230\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Configure Aide Rules for Filesystem<\/p>\n<\/div>\n<h3>Using AIDE to Check File and Directory Integrity in Linux<\/h3>\n<p>Start by constructing a database against the checks that will be performed using\u00a0<code>--init<\/code>\u00a0flag. This is expected to be done before your system is connected to a network.<\/p>\n<p>The command below will create a database that contains all of the files that you selected in your configuration file.<\/p>\n<pre># aide --init\r\n<\/pre>\n<div id=\"attachment_28081\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/11\/Initialize-Aide-Database.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-28081\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/11\/Initialize-Aide-Database.png\" alt=\"Initialize Aide Database\" width=\"642\" height=\"135\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Initialize Aide Database<\/p>\n<\/div>\n<p>Then rename the database to<strong>\u00a0\/var\/lib\/aide\/aide.db.gz<\/strong>\u00a0before proceeding, using this command.<\/p>\n<pre># mv \/var\/lib\/aide\/aide.db.new.gz \/var\/lib\/aide\/aide.db.gz<\/pre>\n<p>It is recommended to move the database to a secure location possibly in a read-only media or on another machines, but ensure that you update the configuration file to read it from there.<\/p>\n<p>After the database is created, you can now check the integrity of the files and directories using the\u00a0<code>--check<\/code>flag.<\/p>\n<pre># aide --check\r\n<\/pre>\n<p>It will read the snapshot in the database and compares it to the files\/directories found you system disk. If it finds changes in places that you might not expect, it generates a report which you can then review.<\/p>\n<div id=\"attachment_28082\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/11\/Run-File-Integrity-Check.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-28082\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/11\/Run-File-Integrity-Check.png\" alt=\"Run File Integrity Check\" width=\"622\" height=\"135\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Run File Integrity Check<\/p>\n<\/div>\n<p>Since no changes have been made to the file system, you will only get an output similar to the one above. Now try to create some files in the file system, in areas defined in the configuration file.<\/p>\n<pre># vi \/etc\/script.sh\r\n# touch all.txt\r\n<\/pre>\n<p>Then run a check once more, which should report the files added above. The output of this command depends on the parts of the file system you configured for checking, it can be lengthy overtime.<\/p>\n<pre># aide --check\r\n<\/pre>\n<div id=\"attachment_28083\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/11\/Check-File-System-Changes.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-28083\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/11\/Check-File-System-Changes.png\" alt=\"Check File System Changes\" width=\"701\" height=\"346\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Check File System Changes<\/p>\n<\/div>\n<p>You need to run aide checks regularly, and in case of any changes to already selected files or addition of new file definitions in the configuration file, always update the database using the\u00a0<code>--update<\/code>\u00a0option:<\/p>\n<pre># aide --update\r\n<\/pre>\n<p>After running a database update, to use the new database for future scans, always rename it to\u00a0<strong>\/var\/lib\/aide\/aide.db.gz<\/strong>:<\/p>\n<pre># mv \/var\/lib\/aide\/aide.db.new.gz  \/var\/lib\/aide\/aide.db.gz<\/pre>\n<p>That\u2019s all for now! But take note of these important points:<\/p>\n<ul>\n<li>One characteristic of most intrusion detection systems AIDE inclusive, is that they will not provide solutions to most security loop holes on a system. They however, assist in easing the the intrusion response process by helping system administrators examine any changes to system files\/directories. So you should always be vigilant and keep updating your current security measures.<\/li>\n<li>It it highly recommended to keep the newly created database, the configuration file and the AIDE binary in a secure location such as read-only media (possible if you install from source).<\/li>\n<li>For additional security, consider signing the configuration and\/or database.<\/li>\n<\/ul>\n<p>For additional information and configurations, see its man page or check out the AIDE Homepage:\u00a0<a href=\"http:\/\/aide.sourceforge.net\/\" target=\"_blank\" rel=\"nofollow noopener\">http:\/\/aide.sourceforge.net\/<\/a><\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/check-integrity-of-file-and-directory-using-aide-in-linux\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In our mega guide to\u00a0hardening and securing CentOS 7, under the section \u201cprotect system internally\u201d, one of the useful security tools we listed for internal system protection against viruses, rootkits, malware, and detection of unauthorized activities is\u00a0AIDE. AIDE\u00a0(Advanced Intrusion Detection Environment) is a small yet powerful, free open source intrusion detection tool, that uses predefined &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/21\/how-to-check-integrity-of-file-and-directory-using-aide-in-linux\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to Check Integrity of File and Directory Using \u201cAIDE\u201d in Linux&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-12020","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12020","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=12020"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12020\/revisions"}],"predecessor-version":[{"id":12021,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12020\/revisions\/12021"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=12020"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=12020"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=12020"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}