<p dir="ltr">Hello Burn, </p>
<p dir="ltr">Thank you very much for your patience. </p>
<p dir="ltr">I can follow your instructions, and yes I can review the code on the server, I have root access. </p>
<p dir="ltr">I will try this tomorrow. <br>
Thank you very much again, <br>
Kind regards, <br>
Stefano </p>
<div class="gmail_quote">On Dec 22, 2013 10:53 PM, "Burn Alting" <<a href="mailto:burn@swtf.dyndns.org">burn@swtf.dyndns.org</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Stefano,<br>
<br>
Just add the lines to /etc/audit/audit.rules after your directory<br>
watches<br>
<br>
-a always,exit -F arch=b32 -S chmod -S fchmod -S fchmodat -S chown -S<br>
fchown -S fchownat -S lchown -S setxattr -S lsetxattr -S fsetxattr -S<br>
removexattr -S lremovexattr -S fremovexattr -F auid!=0 -F auid!<br>
=4294967295 -k perm_mod<br>
-a always,exit -F arch=b64 -S chmod -S fchmod -S fchmodat -S chown -S<br>
fchown -S fchownat -S lchown -S setxattr -S lsetxattr -S fsetxattr -S<br>
removexattr -S lremovexattr -S fremovexattr -F auid!=0 -F auid!<br>
=4294967295 -k perm_mod<br>
<br>
-a exit,always -F arch=b32 -S execve -k cmds<br>
-a exit,always -F arch=b64 -S execve -k cmds<br>
<br>
Then reload the audit service with<br>
        service auditd reload<br>
or<br>
        /etc/init.d/auditd reload<br>
<br>
At this point you should start seeing more events in<br>
your /var/log/audit/audit.log files.<br>
<br>
Then monitor your filesystem or audit till you see the 777 change again.<br>
<br>
Can you review your web server code? In effect, auditd has already<br>
informed you that a php process executed the chmod system call ... the<br>
execve monitoring will just help with the arguments to the program and<br>
the parent processes (and their arguements).<br>
<br>
The bottom line is that you will still need to be able to review your<br>
php code.<br>
<br>
Rgds<br>
Burn<br>
<br>
<br>
<br>
On Sun, 2013-12-22 at 22:41 +0100, Stefano Schiavi wrote:<br>
> Hello and thank you very much for your responses!<br>
><br>
> You have to forgive me but it's a tad hard for me to follow.<br>
><br>
> I am not sure I can trace down the process by the pid since the incident<br>
> happened about 8 days ago. Please correct me if wrong.<br>
><br>
> I have the following rules setup:<br>
><br>
> -a exit,always  -F dir=/home/lanogbar/public_html -F perm=war -F<br>
> key=lanogbar-pubhtmlwatch<br>
><br>
> -a exit,always  -F path=/home/lanogbar/public_html -F perm=war -F<br>
> key=lanogbar-pubhtmlwatch<br>
><br>
> I only watch directories not files.<br>
> Specifically the public_html whcih is the one causing the troubles.<br>
><br>
> Because I don't have much experience with this, would it be possible for<br>
> you to suggest me how to change the above rules or what commands to run now?<br>
><br>
> Apologies for being unable to follow your guidance.<br>
><br>
> Please let me know anything else I can do.<br>
> It would be really great to finally nail down what is causing the<br>
> website to break out of the blue every now and then.<br>
><br>
> Thank you again.<br>
> Kind regards,<br>
> Stefano<br>
><br>
><br>
><br>
><br>
> On 12/22/13, 10:00 PM, Burn Alting wrote:<br>
> > Stefano,<br>
> ><br>
> > I assume your rules are file watches. Yes, on the surface, it looks like<br>
> > a service user, lanogbar, is running a php application which has make<br>
> > the chmod  system call making the change to 777 (ie a1=1ff in the second<br>
> > event shown).<br>
> ><br>
> > You could check the process id's (the one which does the chmod - pid =<br>
> > 8804, or the parent process id - ppid = 27717) although these might be<br>
> > temporary processes ... perhaps you could turn on execution audit<br>
> ><br>
> > -a exit,always -F arch=b32 -S execve -k cmds<br>
> > -a exit,always -F arch=b64 -S execve -k cmds<br>
> ><br>
> ><br>
> > perhaps also specific chmods also ...<br>
> ><br>
> > -a always,exit -F arch=b32 -S chmod -S fchmod -S fchmodat -S chown -S<br>
> > fchown -S fchownat -S lchown -S setxattr -S lsetxattr -S fsetxattr -S<br>
> > removexattr -S lremovexattr -S fremovexattr -F auid!=0 -F auid!<br>
> > =4294967295 -k perm_mod<br>
> > -a always,exit -F arch=b64 -S chmod -S fchmod -S fchmodat -S chown -S<br>
> > fchown -S fchownat -S lchown -S setxattr -S lsetxattr -S fsetxattr -S<br>
> > removexattr -S lremovexattr -S fremovexattr -F auid!=0 -F auid!<br>
> > =4294967295 -k perm_mod<br>
> ><br>
> > Also, as Peter suggests it does help if you present the output from<br>
> > ausearch -i rather than the raw data from /var/log/audit/audit.log.<br>
> ><br>
> ><br>
> ><br>
> ><br>
> > On Sun, 2013-12-22 at 09:05 -0800, Peter Moody wrote:<br>
> >> What's the actual rule? On my system, syscall 88 is either symlink (64 bit) or reboot (32 bit).<br>
> >><br>
> >> On Sat, Dec 21 2013 at 04:48, Stefano Schiavi wrote:<br>
> >>> Hello,<br>
> >>><br>
> >>> Could anyone help with this? I really don't know where else to ask.<br>
> >>><br>
> >>> Thank you very much.<br>
> >>> Stefano<br>
> >>><br>
> >>><br>
> >>> On 12/15/13, 12:19 AM, Stefano Schiavi wrote:<br>
> >>>> Hello,<br>
> >>>><br>
> >>>> Thank you Steve and all for keeping up the great work here.<br>
> >>>><br>
> >>>> Some time ago I setup some audit rules to monitor what would change the permissions of the<br>
> >>>> public_html directory since we found that once in a while it would change to 777 out of the<br>
> >>>> blue.<br>
> >>>><br>
> >>>> It happened again yesterday and I believe these parts of the log represent when the issue<br>
> >>>> happened:<br>
> >>>><br>
> >>>> type=PATH msg=audit(1386933561.795:7958476): item=2 name="./www" inode=4980752 dev=08:08<br>
> >>>> mode=0120777 ouid=501 ogid=501 rdev=00:00<br>
> >>>> type=PATH msg=audit(1386933561.795:7958476): item=1 name="./" inode=4980737 dev=08:08<br>
> >>>> mode=040711 ouid=501 ogid=501 rdev=00:00<br>
> >>>> type=PATH msg=audit(1386933561.795:7958476): item=0 name="public_html"<br>
> >>>> type=CWD msg=audit(1386933561.795:7958476):  cwd="/home/lanogbar"<br>
> >>>> type=SYSCALL msg=audit(1386933561.795:7958476): arch=c000003e syscall=88 success=yes exit=0<br>
> >>>> a0=1306d160 a1=1306d200 a2=11 a3=0 items=3 ppid=18728 pid=18731 auid=0 uid=501 gid=501<br>
> >>>> euid=501 suid=501 fsuid=501 egid=501 sgid=501 fsgid=501 tty=(none) ses=117304 comm="gtar"<br>
> >>>> exe="/bin/tar" key="lanogbar-www"<br>
> >>>><br>
> >>>><br>
> >>>> This is just a guess though and I can not be sure as I have no experience parsing the<br>
> >>>> logs. Looking through with the I flag we can see the following::<br>
> >>>><br>
> >>>> type=PATH msg=audit(12/13/2013 15:00:03.759:7970202) : item=0<br>
> >>>> name=/home/lanogbar/public_html/ inode=4980744 dev=08:08 mode=dir,750 ouid=lanogbar<br>
> >>>> ogid=nobody rdev=00:00<br>
> >>>> type=CWD msg=audit(12/13/2013 15:00:03.759:7970202) : cwd=/home/lanogbar/public_html<br>
> >>>> type=SYSCALL msg=audit(12/13/2013 15:00:03.759:7970202) : arch=x86_64 syscall=chmod<br>
> >>>> success=yes exit=0 a0=1585e520 a1=1ff a2=2f a3=146c1d40 items=1 ppid=27717 pid=8804 auid=root<br>
> >>>> uid=lanogbar gid=lanogbar euid=lanogbar suid=lanogbar fsuid=lanogbar egid=lanogbar<br>
> >>>> sgid=lanogbar fsgid=lanogbar tty=(none) ses=117304 comm=php exe=/usr/bin/php<br>
> >>>> key=lanogbar-public_html<br>
> >>>><br>
> >>>> Do you think this is relevant?<br>
> >>>> If so it would seem a php script was responsible.<br>
> >>>><br>
> >>>> Would you have any suggestion on how to identify the script?<br>
> >>>><br>
> >>>> Thank you very much for the very valuable help.<br>
> >>>> Kind regards,<br>
> >>>> Stefano<br>
> >>> --<br>
> >>> Linux-audit mailing list<br>
> >>> <a href="mailto:Linux-audit@redhat.com">Linux-audit@redhat.com</a><br>
> >>> <a href="https://www.redhat.com/mailman/listinfo/linux-audit" target="_blank">https://www.redhat.com/mailman/listinfo/linux-audit</a><br>
> >> --<br>
> >> Linux-audit mailing list<br>
> >> <a href="mailto:Linux-audit@redhat.com">Linux-audit@redhat.com</a><br>
> >> <a href="https://www.redhat.com/mailman/listinfo/linux-audit" target="_blank">https://www.redhat.com/mailman/listinfo/linux-audit</a><br>
> ><br>
><br>
<br>
<br>
</blockquote></div>