{"id":18499,"date":"2015-03-23T22:12:17","date_gmt":"2015-03-23T16:42:17","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=18499"},"modified":"2015-09-15T10:52:39","modified_gmt":"2015-09-15T05:22:39","slug":"auditing-your-ubuntu-servers","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/auditing-your-ubuntu-servers\/","title":{"rendered":"Auditing Your Ubuntu Servers"},"content":{"rendered":"<p>You might be wondering how to audit your Ubuntu server \/ your Ubuntu local machine. Well, In this blog I will show you how easy it is do so. Auditing can be done by many ways of which few we shall discuss here. There are 3 following scenarios which we will be discussing :-<\/p>\n<h3><span style=\"font-family: 'DejaVu Sans', sans-serif\"><span style=\"font-size: large\"><b>1.<span style=\"text-decoration: underline\">Finding from where logins are done &amp; commands are executed<\/span><\/b><\/span><\/span><\/h3>\n<p>We can find the IP from where a ssh login has been done and commands have been executed. Also we can get the status of logins &amp; those commands.<\/p>\n<p><span style=\"text-decoration: underline\">Suppose a Server has 2 users<\/span> :-<br \/>\n1. Ubuntu which has sudo access.<br \/>\n2. ranvijay is a another user created by useradd.<br \/>\n(password login to server has been enabled)<\/p>\n<p>Login to your server using Ubuntu user.<br \/>\nAlso, login to server in with user ranvijay from another machine which might be running on the same or other network.<br \/>\nNow, if we want to check from where the ssh logins have been made<br \/>\nRun command -&gt;<\/p>\n<p>\u201c<strong>pstree -p<\/strong>\u201d and grep whatever command you want to audit<br \/>\nlike \u201c<strong>grep sshd<\/strong>\u201d<br \/>\nor simply \u201c<strong>ps -ef | grep sshd<\/strong>&#8221;<\/p>\n<p>This will return PIDs of ssh logins which have been processed till now.<br \/>\nLogs are stored in auth.log file<br \/>\nSo,<br \/>\n\u201c<strong>sudo grep 2448 \/var\/log\/auth.log<\/strong>\u201d ( 2248 is the process ID &amp; it may vary in your server)<\/p>\n<p>After running the above command, multiple PIDs will be shown, so you can filter the output according to your use.<br \/>\nYou would get a similar output :-<\/p>\n<p><a href=\"\/blog\/wp-ttn-blog\/uploads\/2015\/03\/Screenshot-from-2015-03-23-171259.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-18503\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/03\/Screenshot-from-2015-03-23-171259.png\" alt=\"Screenshot from 2015-03-23 17:12:59\" width=\"615\" height=\"139\" \/><\/a><\/p>\n<h3><\/h3>\n<h3><span style=\"font-family: 'DejaVu Sans', sans-serif\"><span style=\"font-size: large\"><b><span style=\"color: #000000\">2.<\/span><span style=\"text-decoration: underline;color: #000000\">For f<\/span><span style=\"color: #000000\"><span style=\"text-decoration: underline\">inding who changed \/ executed a particular file \/process \/system calls<\/span><\/span><\/b><\/span><\/span><\/h3>\n<p>For this, we have the auditd tool<br \/>\nInstall it by using the following command.<\/p>\n<p>\u201c<strong>apt-get install auditd audispd-plugins<\/strong>\u201d<\/p>\n<p>Auditd works on some user defined rules. So, now we have to set the rules.<br \/>\nThese rules specify for which file to &amp; the operations on the file to keep track of<br \/>\nNow run command -&gt;<br \/>\n\u201c<strong>vim \/etc\/audit\/audit.rules<\/strong>\u201d<\/p>\n<p><span style=\"text-decoration: underline\">Here write rules like below<\/span> :-<\/p>\n<p><a href=\"\/blog\/wp-ttn-blog\/uploads\/2015\/03\/4.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-18504\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/03\/4.png\" alt=\"4\" width=\"635\" height=\"540\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"text-decoration: underline\"><strong>Note<\/strong><\/span>:- When you write the line highlighted you wont be able to edit the audit.rules file again. There is an alternative to you opening the file and editing it. If you don&#8217;t want to edit the file you can directly define rules via command.<\/p>\n<p>\u201c<strong>auditctl -a exit,always -F path=\/etc\/passwd -F perm=wa<\/strong>\u201d<br \/>\nThis will append audit.rules file &amp; activate audit on passwd file.<\/p>\n<p><span style=\"text-decoration: underline\">A Few more auditctl commands<\/span>:-<br \/>\nTo see all system calls made by a program:<br \/>\n&#8220;<strong>auditctl -a entry,always -S all -F pid=1005<\/strong>&#8221;<\/p>\n<p>To see files opened by a specific user:<br \/>\n&#8220;<strong>auditctl -a exit,always -S open -F auid=510<\/strong>&#8221;<\/p>\n<p>To see unsuccessful open call\u2019s:<br \/>\n&#8220;<strong>auditctl -a exit,always -S open -F success!=0<\/strong>&#8221;<\/p>\n<p><span style=\"text-decoration: underline\">Here are a few switches<\/span> :-<br \/>\nr = read<br \/>\nw = write<br \/>\nx = execute<br \/>\na = attribute change<\/p>\n<p>Restart the service.<\/p>\n<p>\u201c<strong>sudo service auditd restart<\/strong>\u201d<\/p>\n<p>Now, run the below command with the file you want to edit.<\/p>\n<p>\u201c<strong>ausearch -f \/etc\/passwd<\/strong>\u201d<br \/>\nThis will audit file passwd and return results.<\/p>\n<p><a href=\"\/blog\/wp-ttn-blog\/uploads\/2015\/03\/2.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-18501\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/03\/2.png\" alt=\"2\" width=\"792\" height=\"147\" \/><\/a><\/p>\n<h3><\/h3>\n<h3><span style=\"font-family: 'DejaVu Sans', sans-serif\"><span style=\"font-size: large\"><b>3. <strong><span style=\"text-decoration: underline\">Now auditing User actions ( Who What ,How Much &amp; When)<\/span><\/strong><\/b><\/span><\/span><\/h3>\n<p>For this, we need to Install acct<\/p>\n<p>\u201c<strong>sudo apt-get install acct<\/strong>\u201d<br \/>\n<span style=\"text-decoration: underline\">This gives many commands few of which are<\/span> :-<br \/>\n<strong>ac<\/strong> : ac command prints the statistics of user logins\/logouts (connect time) in hours.<br \/>\n<strong>ac -d<\/strong> : Using command \u201cac -d\u201d will prints out the total login time in hours by day-wise.<br \/>\n<strong>ac ranvijay<\/strong> : To get the total login statistics time of user \u201cranvijay\u201d in hours, use the command as.<br \/>\n<strong>sa -c<\/strong> : The command \u201csa -c\u201d displays the highest memory percentage usage of users.<br \/>\n<strong>lastcomm<\/strong> : The &#8220;lastcomm&#8221; command is used to search and display previously executed user commands information. You can also search commands executed by individual usernames.<br \/>\nRun command -&gt;<br \/>\n\u201c<strong>lastcomm username<\/strong>\u201d<\/p>\n<p>or you can find which user ran a particular command &amp; when<br \/>\n\u201c<strong>lastcomm ls\u201cor \u201clastcomm rm<\/strong>\u201d<\/p>\n<p><a href=\"\/blog\/wp-ttn-blog\/uploads\/2015\/03\/3.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-18502\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/03\/3.png\" alt=\"3\" width=\"641\" height=\"268\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>All this will really help you keep track of the users, keep your server safe &amp; let you know who is responsible for which action.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>You might be wondering how to audit your Ubuntu server \/ your Ubuntu local machine. Well, In this blog I will show you how easy it is do so. Auditing can be done by many ways of which few we shall discuss here. There are 3 following scenarios which we will be discussing :- 1.Finding [&hellip;]<\/p>\n","protected":false},"author":174,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":55},"categories":[1174],"tags":[1711,751,248,528,590,1712,8],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/18499"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/174"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=18499"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/18499\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=18499"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=18499"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=18499"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}