<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>

<channel>
	<title>Snagg in progress</title>
	<atom:link href="http://blogs.freebsdish.org/snagg/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.freebsdish.org/snagg</link>
	<description>Just another FreeBSD Committers Blogs weblog</description>
	<pubDate>Sat, 16 Aug 2008 19:11:49 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6</generator>
	<language>en</language>
			<item>
		<title>Final results</title>
		<link>http://blogs.freebsdish.org/snagg/2008/08/16/final-results/</link>
		<comments>http://blogs.freebsdish.org/snagg/2008/08/16/final-results/#comments</comments>
		<pubDate>Sat, 16 Aug 2008 19:08:17 +0000</pubDate>
		<dc:creator>snagg</dc:creator>
		
		<category><![CDATA[Project]]></category>

		<guid isPermaLink="false">http://blogs.freebsdish.org/snagg/2008/08/16/final-results/</guid>
		<description><![CDATA[Hi all, it has been a long time since my last post. Due to some problems I didn&#8217;t have the chance to update this blog. Anyhow before the end of the soc, I&#8217;m here to speak about what I did in this period.First of all my auditpipe patch changed a bit: it supports only pid-based subscription [...]]]></description>
			<content:encoded><![CDATA[<p>Hi all, it has been a long time since my last post. Due to some problems I didn&#8217;t have the chance to update this blog. Anyhow before the end of the soc, I&#8217;m here to speak about what I did in this period.First of all my auditpipe patch changed a bit: it supports only pid-based subscription to events due to internal decision taken by me and other developers. How to use it then?<br />
fd = open(&#8221;/dev/auditpipe&#8221;, O_RDONLY);<br />
	if (fd &lt; 0)<br />
		err(-1, &#8220;/dev/auditpipe&#8221;);</p>
<p>	entry = malloc(sizeof(struct auditpipe_ioctl_preselect_proc));<br />
	if(entry == NULL)<br />
		err(-1, &#8220;MALLOC&#8221;);</p>
<p>	value = AUDITPIPE_PRESELECT_MODE_PROC;<br />
	if (ioctl(fd, AUDITPIPE_SET_PRESELECT_MODE, &amp;value) aipp_pid = pid;</p>
<p>	if (ioctl(fd, AUDITPIPE_SET_PRESELECT_PROC, entry) &lt; 0)<br />
			err(-1, &#8220;AUDITPIPE_SET_PRESELECT_EVENTS&#8221;);</p>
<p>What it does is to open auditpipe, change the preselection mode to AUDITPIPE_PRESELECT_MODE_PROC and set up an entry with a specific pid. From there on auditpipe will trace that specific pid. Clean and concise:P   Now the second half of the project. I ought to write a regression test framework. After several unsuccessful attempts, I figured out how to make it works with a bit of shared memory. The general idea is to have a testing function/process which communicates with a parent process and exchange runtime information in order to run the test.  The testing function will take read records from auditpipe and compare them with runtime information collected before. If some inconsistencies are found they are reported. More in details, here is a sample testing module:<br />
/*-<br />
 * Copyright (c) 2008 Vincenzo Iozzo<br />
 * All rights reserved.<br />
 *<br />
 * Redistribution and use in source and binary forms, with or without<br />
 * modification, are permitted provided that the following conditions<br />
 * are met:<br />
 * 1. Redistributions of source code must retain the above copyright<br />
 *    notice, this list of conditions and the following disclaimer.<br />
 * 2. Redistributions in binary form must reproduce the above copyright<br />
 *    notice, this list of conditions and the following disclaimer in the<br />
 *    documentation and/or other materials provided with the distribution.<br />
 *<br />
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS &#8220;AS IS&#8221; AND<br />
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br />
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br />
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE<br />
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL<br />
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS<br />
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)<br />
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT<br />
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY<br />
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF<br />
 * SUCH DAMAGE.<br />
 *<br />
 */</p>
<p>#include &#8220;audit_pipe_regression_test_utils.h&#8221;</p>
<p>struct sysctl_record<br />
{<br />
	int mib[6];<br />
	char err_val[256];<br />
	int ret;<br />
	int index;<br />
	struct sysctl_record *next;<br />
};</p>
<p>struct sysctl_record *<br />
add_field(struct sysctl_record *head, struct sysctl_record *new)<br />
{<br />
	struct sysctl_record *tmp;</p>
<p>	tmp = head;<br />
	if(tmp == NULL) {<br />
		new-&gt;next = NULL;<br />
		return (new);<br />
	}</p>
<p>	/* Reach the last element of the list*/<br />
	for(; tmp-&gt;next != NULL;tmp = tmp-&gt;next);</p>
<p>	new-&gt;index = tmp-&gt;index +1;<br />
	tmp-&gt;next= new;<br />
	new-&gt;next = NULL;</p>
<p>	return (head);<br />
}</p>
<p>void test_sysctl()<br />
{<br />
	int mib[2];<br />
	int ret, val;</p>
<p>	init_channel_primary();</p>
<p>	mib[0] = CTL_KERN;<br />
	mib[1] = KERN_SECURELVL;<br />
	val = 2;<br />
	ret = sysctl(&amp;mib, 2, NULL, NULL, &amp;val, sizeof(int));</p>
<p>	write_int(mib[0], &#8220;arg&#8221;);<br />
	write_int(mib[1], &#8220;arg1&#8243;);<br />
	write_int(ret, &#8220;ret&#8221;);<br />
	if (ret == -1)<br />
		write_string(strerror(errno), &#8220;ret_val&#8221;);<br />
	else<br />
		write_string(&#8221;success&#8221;, &#8220;ret_val&#8221;);<br />
	write_end();</p>
<p>	val = 1;<br />
	ret = sysctl(&amp;mib, 2, NULL, NULL, &amp;val, sizeof(int));<br />
	write_int(mib[0], &#8220;arg&#8221;);<br />
	write_int(mib[1], &#8220;arg1&#8243;);<br />
	write_int(ret, &#8220;ret&#8221;);<br />
	if (ret == -1)<br />
		write_string(strerror(errno), &#8220;ret_val&#8221;);<br />
	else<br />
		write_string(&#8221;success&#8221;, &#8220;ret_val&#8221;);<br />
	write_end();</p>
<p>	end_channel();</p>
<p>	/* Let auditsysctl flush all data */<br />
	sleep(5);<br />
	return;<br />
}</p>
<p>void validate(FILE *f, struct sysctl_record *head, char *path, pid_t pid)<br />
{<br />
	int i, ret, reclen, bytesread, to_parse, arg_counter;<br />
	struct sysctl_record *tmp, *elem;<br />
	int err = -1;<br />
	tokenstr_t tok;<br />
	u_char *buf;<br />
	u_char type = 0;<br />
	FILE *fp;<br />
	long control_flag;</p>
<p>	to_parse = WAITING;<br />
	arg_counter = 0;<br />
	control_flag = 0;</p>
<p>	fp = fopen(path, &#8220;r&#8221;);<br />
	if(fp == NULL)<br />
		return;</p>
<p>	tmp = head;<br />
	if(tmp == NULL)<br />
		return;</p>
<p>	while(1) {</p>
<p>		to_parse = WAITING;<br />
		if(!err || reclen == -1)<br />
			break;</p>
<p>		/* Record must begin with a header token. */<br />
		do {<br />
			type = fgetc(fp);<br />
		} while(type != AU_HEADER_32_TOKEN);<br />
		ungetc(type, fp);</p>
<p>		while ((reclen = au_read_rec(fp, &amp;buf)) != -1) {<br />
			bytesread = 0;<br />
			while (bytesread mib[0]);<br />
						else<br />
							ret = check_arg(tok.tt.arg32, tmp-&gt;mib[1]);</p>
<p>						if(!ret)<br />
							report_error(tok, f);<br />
						break;</p>
<p>					case AUT_RETURN32:<br />
						TOKEN_FLAG_SET(control_flag, TOKEN_RETURN);<br />
						ret = check_ret(tok.tt.ret32, tmp-&gt;ret, tmp-&gt;err_val);<br />
						if(!ret)<br />
							report_error(tok, f);<br />
						break;</p>
<p>					case AUT_TRAILER:<br />
						to_parse = WAITING;<br />
						if(!TOKEN_FLAG_ISSET(control_flag, TOKEN_SUBJECT))<br />
							report_error_string(&#8221;Missing Subject token&#8221;, f);<br />
						if (!TOKEN_FLAG_ISSET(control_flag, TOKEN_ARG) || arg_counter != 2)<br />
							report_error_string(&#8221;Missing Argument token&#8221;, f);<br />
						if(!TOKEN_FLAG_ISSET(control_flag, TOKEN_RETURN))<br />
							report_error_string(&#8221;Missing Return token&#8221;, f);<br />
						control_flag = 0;<br />
						arg_counter = 0;<br />
						if(tmp-&gt;next != NULL)<br />
							tmp = tmp-&gt;next;<br />
						break;</p>
<p>					default:<br />
						break;<br />
					}<br />
				}<br />
			}<br />
		}<br />
	}</p>
<p>free(buf);<br />
fclose(fp);<br />
}</p>
<p>int<br />
main(int argc, char *argv[])<br />
{<br />
	int i, quit, fd, value, index, fdout, count;<br />
	char *shared_string, *descr, path[512];<br />
	pid_t pid;<br />
	struct sysctl_record *head, *elem;<br />
	FILE *f;</p>
<p>	index = 0;<br />
	head = NULL;</p>
<p>	init_channel();</p>
<p>	pid = fork();<br />
	if(!pid) {<br />
		sleep(15);<br />
		test_sysctl();<br />
	} else {<br />
		fd = setup_auditpipe(pid);<br />
		snprintf(path, 512, &#8220;/tmp/audit-%d&#8221;, pid);</p>
<p>		fdout = open(path, O_RDWR | O_CREAT);<br />
		if(fdout == -1)<br />
			err(-1, &#8220;OPEN&#8221;);</p>
<p>		quit = 0;<br />
		while (!waitpid(pid, &amp;quit, WNOHANG)) {</p>
<p>			/* Audit pipe input. */<br />
			read_auditpipe(fd, fdout);</p>
<p>			/*<br />
			 * See whether is there anything on the shared-memory,<br />
			 * if so build a structure<br />
			 */<br />
			sem_getvalue(mutex, &amp;count);<br />
			if(count) {<br />
				shared_string = read_string();<br />
				elem = malloc(sizeof(struct sysctl_record));<br />
				if(elem == NULL)<br />
						err(-1, &#8220;MALLOC&#8221;);</p>
<p>				while((count = parse_string(shared_string)) != -1) {<br />
					descr = get_descr(shared_string);<br />
					if(count == INT_TYPE) {<br />
						if(!strncmp(descr, &#8220;arg1&#8243;, 4))<br />
							elem-&gt;mib[1] = get_int(shared_string);<br />
						else if (!strncmp(descr, &#8220;arg&#8221;, 3))<br />
							elem-&gt;mib[0] = get_int(shared_string);<br />
						else<br />
							elem-&gt;ret = get_int(shared_string);<br />
					}<br />
					else if ( count == STRING_TYPE) {<br />
						snprintf(elem-&gt;err_val, sizeof(elem-&gt;err_val) &gt;<br />
								strlen(shared_string) +1 ?<br />
								strlen(shared_string) +1 :<br />
								sizeof(elem-&gt;err_val), &#8220;%s&#8221;,<br />
								shared_string);<br />
					}<br />
					shared_string = read_string();<br />
				}<br />
				head = add_field(head, elem);<br />
				if(head == NULL)<br />
					err(-1, &#8220;List error&#8221;);<br />
			}<br />
		}<br />
	}<br />
	close_auditpipe(fd, fdout);<br />
	end_channel();<br />
	f = init_log(pid);<br />
	validate(f, head, path, pid);<br />
	fclose(f);<br />
	return (0);<br />
}</p>
<p>As you might see, the validate() function will compare records against collected data, whereas the test_sysctl() will send  to the parent, using shared memory, information regarding the events. You might see a sort of  &#8221;API&#8221; here, those functions were provided in order to ease tests writing. They are somehow commented, so you might find useful to take a look at the code. I wrote tests for 20 events, but theoretically they are 500+, so we need your help. As usual if you have any kind of suggestions or comments feel free to contact me. Here: http://www1.autistici.org/snagg/final.zip you can find the whole code.  Cheers,Snagg </p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.freebsdish.org/snagg/2008/08/16/final-results/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Some results</title>
		<link>http://blogs.freebsdish.org/snagg/2008/06/01/some-results/</link>
		<comments>http://blogs.freebsdish.org/snagg/2008/06/01/some-results/#comments</comments>
		<pubDate>Sun, 01 Jun 2008 11:14:15 +0000</pubDate>
		<dc:creator>snagg</dc:creator>
		
		<category><![CDATA[Project]]></category>

		<guid isPermaLink="false">http://blogs.freebsdish.org/snagg/2008/06/01/some-results/</guid>
		<description><![CDATA[I was a bit talkish in the last days but still I didn&#8217;t provide anything practical to my &#8220;two&#8221; readers.
So here we go:
I&#8217;ve decided to let auditpipe trace a small program:

int main(){
    gid_t *gid;
    int i;
    gid = malloc(25);
    memset(gid, 15*4, 0x41);
  [...]]]></description>
			<content:encoded><![CDATA[<p>I was a bit talkish in the last days but still I didn&#8217;t provide anything practical to my &#8220;two&#8221; readers.<br />
So here we go:<br />
I&#8217;ve decided to let auditpipe trace a small program:<br />
<code><br />
int main(){<br />
    gid_t *gid;<br />
    int i;</p>
<p>    gid = malloc(25);<br />
    memset(gid, 15*4, 0x41);<br />
    setgroups(15, gid);</p>
<p>    printf("%s\n", strerror(errno));<br />
    return 0;<br />
}</code><br />
The code needed was just:<br />
<code><br />
value = 4;<br />
if(ioctl(fd, AUDITPIPE_SET_PRESELECT_MODE, &amp;value) &lt; 0)<br />
    err(-1, "AUDITPIPE_SET_PRESELECT_MODE");<br />
</code><br />
<code><br />
entry-&gt;app_pid = pid;<br />
entry-&gt;app_event_len = 0;<br />
if(ioctl(fd, AUDITPIPE_SET_PRESELECT_EVENTS) &lt; 0)<br />
   err(-1, "AUDITPIPE_SET_PRESELECT_EVENTS");<br />
</code><br />
After that I just needed to read from /dev/auditpipe.<br />
<a href="http://www.autistici.org/snagg/audit-823">The results</a> (in a xml-readable form).<br />
As you can see the whole execution flow for a given pid (823) was traced.<br />
So you don&#8217;t have to use some complex regex to take out from a very huge auditd log file the record you&#8217;re interested in.<br />
Hope it will help you.<br />
Snagg</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.freebsdish.org/snagg/2008/06/01/some-results/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Patch Published</title>
		<link>http://blogs.freebsdish.org/snagg/2008/05/30/patch-published/</link>
		<comments>http://blogs.freebsdish.org/snagg/2008/05/30/patch-published/#comments</comments>
		<pubDate>Fri, 30 May 2008 19:36:55 +0000</pubDate>
		<dc:creator>snagg</dc:creator>
		
		<category><![CDATA[Project]]></category>

		<guid isPermaLink="false">http://blogs.freebsdish.org/snagg/2008/05/30/patch-published/</guid>
		<description><![CDATA[Here you can find my patch for auditpipe. If you ever have the chance to try it, please let me know. Feel free to  mail me for comments, suggestions and bug-fixes. 
]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.autistici.org/snagg/auditpipe.patch">Here</a> you can find my patch for auditpipe. If you ever have the chance to try it, please let me know. Feel free to  mail me for comments, suggestions and bug-fixes. </p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.freebsdish.org/snagg/2008/05/30/patch-published/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Kernel part finished</title>
		<link>http://blogs.freebsdish.org/snagg/2008/05/28/kernel-part-finished/</link>
		<comments>http://blogs.freebsdish.org/snagg/2008/05/28/kernel-part-finished/#comments</comments>
		<pubDate>Wed, 28 May 2008 19:35:37 +0000</pubDate>
		<dc:creator>snagg</dc:creator>
		
		<category><![CDATA[Project]]></category>

		<guid isPermaLink="false">http://blogs.freebsdish.org/snagg/2008/05/28/kernel-part-finished/</guid>
		<description><![CDATA[Hi,I&#8217;ve just finished with the kernel part of my project. I&#8217;ve introduced some new features to auditpipe. Specifically, it&#8217;s now possibile to set up a trail which will trace by pid or by an events&#8217; list associated to a specific pid. To specify which of the tracing capability you&#8217;d like to have in your trail [...]]]></description>
			<content:encoded><![CDATA[<p>Hi,I&#8217;ve just finished with the kernel part of my project. I&#8217;ve introduced some new features to auditpipe. Specifically, it&#8217;s now possibile to set up a trail which will trace by pid or by an events&#8217; list associated to a specific pid. To specify which of the tracing capability you&#8217;d like to have in your trail you just have to select it with ioctl. Now it&#8217;s also possible to retrieve information about pid and events for a specific trail. To manage the events array I&#8217;ve used qsort to sort in ascending order the array and binary search to performe searches for specific events. If you like to see the code you&#8217;ll find it in my perforce repository.From now on I will mainly focus on regression tests. When I have something done, I&#8217;ll leave a post here. </p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.freebsdish.org/snagg/2008/05/28/kernel-part-finished/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Some news</title>
		<link>http://blogs.freebsdish.org/snagg/2008/05/12/some-news/</link>
		<comments>http://blogs.freebsdish.org/snagg/2008/05/12/some-news/#comments</comments>
		<pubDate>Mon, 12 May 2008 23:59:56 +0000</pubDate>
		<dc:creator>snagg</dc:creator>
		
		<category><![CDATA[Project]]></category>

		<guid isPermaLink="false">http://blogs.freebsdish.org/snagg/2008/05/12/some-news/</guid>
		<description><![CDATA[I&#8217;ve just finished to upload the code onto my perforce branch. At the moment the whole code is ready for testing, which means that, now, should be possibile to audit events one-by-one. Specifically I&#8217;ve added some functionalities to audit_pipe_ioctl which allow to do the same operation done before but on events list instead of audit [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve just finished to upload the code onto my perforce branch. At the moment the whole code is ready for testing, which means that, now, should be possibile to audit events one-by-one. Specifically I&#8217;ve added some functionalities to audit_pipe_ioctl which allow to do the same operation done before but on events list instead of audit classes. Also all the functions needed to manage the events list were made up. The audit_pipe_preselect structure was modified, adding a pid field and a dynamic array of structs which hold the events&#8217; list.  The KPI now has two new prototype for audit_pipe_preselect and audit_pipe_submit in order to allow event matching by pid. As soon as the testing period is finished maybe new features will be added. All the code could be found on my perforce branch. I&#8217;d really appreciate if anyone willing to help will test the code and give me some feedback. Also please note that the whole code is in a really alpha-stage.That&#8217;s all folks,Snagg </p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.freebsdish.org/snagg/2008/05/12/some-news/feed/</wfw:commentRss>
		</item>
		<item>
		<title>First post, me and my project</title>
		<link>http://blogs.freebsdish.org/snagg/2008/05/01/first-post-me-and-my-project/</link>
		<comments>http://blogs.freebsdish.org/snagg/2008/05/01/first-post-me-and-my-project/#comments</comments>
		<pubDate>Thu, 01 May 2008 16:59:43 +0000</pubDate>
		<dc:creator>snagg</dc:creator>
		
		<category><![CDATA[Project]]></category>

		<guid isPermaLink="false">http://blogs.freebsdish.org/snagg/2008/05/01/first-post-me-and-my-project/</guid>
		<description><![CDATA[Hi all,I&#8217;m Vincenzo Iozzo, currently I&#8217;m studying computer engineering at the Politecnico di Milano. I also work for Secure Network srl. And in the spare time I do some research for my university. I&#8217;m mainly involved in IT Security.   Now, after this brief presentation, I&#8217;d like to spend a few words on my project for this [...]]]></description>
			<content:encoded><![CDATA[<p>Hi all,I&#8217;m Vincenzo Iozzo, currently I&#8217;m studying computer engineering at the Politecnico di Milano. I also work for <a href="http://www.securenetwork.it">Secure Network srl</a>. And in the spare time I do some research for my university. I&#8217;m mainly involved in IT Security.   Now, after this brief presentation, I&#8217;d like to spend a few words on my project for this Summer Of Code.  I will modify the FreeBSD auditpipe support in order to provide more granularity while auditing syscalls. In fact, at the present time, your choice on what to audit is limited to default classes. With my patch it would be possible to select every syscall by its own. The second half of the project will consist of creating a framework for testing the correct behavior of the auditing system and, if needed, patching it.Finally the whole auditing system will be checked in order to see whether or not is vulnerable at some anti-forensics techiniques.  <a href="http://www1.autistici.org/snagg/proposal-soc.pdf">Here</a> you can find a detailed description of the first part of the project.Snagg</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.freebsdish.org/snagg/2008/05/01/first-post-me-and-my-project/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
