<?xml version='1.0' encoding='utf-8' ?>
<!--  If you are running a bot please visit this policy page outlining rules you must respect. http://www.livejournal.com/bots/  -->
<rss version='2.0' xmlns:lj='http://www.livejournal.org/rss/lj/1.0/' xmlns:media='http://search.yahoo.com/mrss/' xmlns:atom10='http://www.w3.org/2005/Atom'>
<channel>
  <title>gamesfairy</title>
  <link>http://gamesfairy.livejournal.com/</link>
  <description>gamesfairy - LiveJournal.com</description>
  <lastBuildDate>Tue, 27 Oct 2009 10:29:13 GMT</lastBuildDate>
  <generator>LiveJournal / LiveJournal.com</generator>
  <lj:journal>gamesfairy</lj:journal>
  <lj:journalid>8161861</lj:journalid>
  <lj:journaltype>personal</lj:journaltype>
  <atom10:link rel='hub' href='http://pubsubhubbub.appspot.com/' />
  <image>
    <url>http://l-userpic.livejournal.com/34541996/8161861</url>
    <title>gamesfairy</title>
    <link>http://gamesfairy.livejournal.com/</link>
    <width>89</width>
    <height>98</height>
  </image>

<item>
  <guid isPermaLink='true'>http://gamesfairy.livejournal.com/23277.html</guid>
  <pubDate>Tue, 27 Oct 2009 10:29:13 GMT</pubDate>
  <link>http://gamesfairy.livejournal.com/23277.html</link>
  <description>So. Another post about the security scanner.&lt;br /&gt;&lt;br /&gt;I&apos;ve spent (most of) the last two days playing, in some way or another, with memory breakpoints.&lt;br /&gt;&lt;br /&gt;The scanner requires that it be able to set breakpoints on memory accesses. It needs to be able to say &quot;Tell me when memory at XXXX is accessed&quot; and run the target code otherwise unsupervised. This is a common feature in debuggers - so common that Intel added the feature in hardware.&lt;br /&gt;&lt;br /&gt;So, the CPU itself is capable of performing memory breakpointing. However, it has a couple of downsides - firstly, we&apos;re limited to four memory breakpoints, and secondly, the CPU only tells us _after_ memory has been accessed, not before. So, for example, if we set a memory breakpoint at some location and the program writes to it, there&apos;s no way of getting the data back.&lt;br /&gt;&lt;br /&gt;OK. So we can&apos;t use hardware breakpoints. But that&apos;s no real biggie - we can just use the software breakpoints that the debugger provides (the security scanner operates in parallel with a well-known debugger package). So I went about doing this, and after a lot of headscratching, realised that - bizarrely - the debugger package I use notifies me _after_ memory accesses too. Odd. &lt;br /&gt;I figure, OK. Fair enough. I&apos;ll just write my own memory-breakpointing system. All I have to do is mark pages as guard pages, and catch the exception that gets thrown when that page is accessed. An exception will be thrown for every hit on the _page_, so I&apos;ll filter them by address. It&apos;ll be slow, but it&apos;s cool. No problem. So I implement that.&lt;br /&gt;&lt;br /&gt;And it works. Oddly, though, the exception info I get passed by the debugger looks like random crap from the heap. No amount of playing about will get a sensible result. Unfortunately, I kinda need that information - one thing it contains is the memory address which was hit. I play with it for a bit more (the debugger I&apos;m building around is a bit finnicky) and still can&apos;t coax anything out.&lt;br /&gt;&lt;br /&gt;Eventually I find a line in a changelog of v5.2 of the software. &quot;BUGFIX: SDK: dbg_exception event parameters were wrong&quot;. I&apos;m using 4.8. The reason I&apos;m using 4.8 is because there&apos;s a not-for-profit version of 4.8 available free. 5.2 costs around 300 GBP.&lt;br /&gt;&lt;br /&gt;I eventually cave. I&apos;ll pirate a version of 5.2. So I do. And it doesn&apos;t co-operate with my plugin at all. Things &lt;i&gt;just don&apos;t work&lt;/i&gt;. I realise that there&apos;s going to be a lot of time spent effectively porting it to the newer version of the debugger, before I even get to see if my problem is fixed.&lt;br /&gt;&lt;br /&gt;I spend a lot of time trying to coax the debugger in to doing what I want to do. Perhaps it&apos;s time to ditch it for another?&lt;br /&gt;&lt;br /&gt;It&apos;d be an amount of work to adapt the scanner to use GDB instead, but GDB has a couple advantages:&lt;br /&gt;&lt;br /&gt;* Free-as-in-money to use&lt;br /&gt;* Dead easy to replace with scripts, in order to test the scanner&apos;s response to various debugger behaviours (a BIG THING)&lt;br /&gt;&lt;br /&gt;I&apos;m loathed to sink more dev time in to doing _more_ stuff, but I think this is the best way forward. Better tests would make me happy.</description>
  <comments>http://gamesfairy.livejournal.com/23277.html</comments>
  <category>security scanner</category>
  <category>ida</category>
  <category>gdb</category>
  <lj:mood>aggravated</lj:mood>
  <lj:security>public</lj:security>
  <lj:reply-count>4</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://gamesfairy.livejournal.com/22955.html</guid>
  <pubDate>Sun, 25 Oct 2009 00:27:16 GMT</pubDate>
  <title>STP caching</title>
  <link>http://gamesfairy.livejournal.com/22955.html</link>
  <description>Got the caching layer for the security scanner written last night.&lt;br /&gt;&lt;br /&gt;As the scanner runs, it produces ASCII files which are sent to a field solver (CVC3 in this case). Obviously, there&apos;s a bit of a performance hit in producing these ASCII files, as opposed to just passing a data structure, but it makes caching and load balancing just so much easier that I decided to go with the ASCII approach.&lt;br /&gt;&lt;br /&gt;Some of the queries are identical, especially when repeatedly running in &apos;verification mode&apos;. Since I want to set up a continuous build system, and since it&apos;d benefit performance anyway, it makes sense to cache the ASCII solver input and the ASCII solver output and respond to repeated queries.&lt;br /&gt;&lt;br /&gt;This was fairly straightforward to implement. Since there&apos;s already a &apos;co-ordinator&apos; which runs centrally, and which talks to all the instances of the actual debugger, it makes sense to throw the caching code in there. I decided to use a full-blown database to store my data, since I think that&apos;s faster (in terms of dev time) than re-inventing the binary search, and about the same speed (run time) in actually running. If anyone can prove me wrong, go ahead :D&lt;br /&gt;&lt;br /&gt;Anyway. After a few runs of the same code - pretty much ideal conditions for the cache - I&apos;ve ended up with ~4000 rows in the DB, and 2112 hits to 856 misses (71~ hits). Each hit takes, on average, 87ms, and each miss 226ms. I&apos;ve made a net time saving of 137ms per hit, or 293569 - almost four minutes - over the whole run. Yay!</description>
  <comments>http://gamesfairy.livejournal.com/22955.html</comments>
  <category>stp</category>
  <category>security scanner</category>
  <category>cvc3</category>
  <category>databases</category>
  <lj:mood>accomplished</lj:mood>
  <lj:security>public</lj:security>
  <lj:reply-count>0</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://gamesfairy.livejournal.com/22593.html</guid>
  <pubDate>Fri, 23 Oct 2009 01:12:07 GMT</pubDate>
  <title>Security scanner progress</title>
  <link>http://gamesfairy.livejournal.com/22593.html</link>
  <description>So, work churns on in the topic of the scanner.&lt;br /&gt;&lt;br /&gt;I&apos;ve just been doing a &apos;verification run&apos;, in which the program is run and the scanner observes each instruction, simulating it in terms of dataflow, and then compares results.&lt;br /&gt;&lt;br /&gt;It&apos;s falling over at the moment, due to an inability to handle a particular instruction in 16bit mode (I&apos;ll fix that in a mo). But before it does so, it simulates 250 (non-unique) instructions mainly in the C runtime library, using a variety of addressing forms, and testing my modr/m and SIB decoding, and instruction coverage. (in addition to that 250, there are 35 occurances of around 6 unsupported-at-the-moment opcodes, mainly because certain CPU flags aren&apos;t implemented yet (ie, it&apos;s not worth writing the &apos;ADd with Carry&apos; opcode until the carry bit works) or because they reference memory by segment (which isn&apos;t supported just yet).&lt;br /&gt;&lt;br /&gt;I have, of the 256-ish[1] single-byte opcodes, 67 (26%) implemented.&lt;br /&gt;&lt;br /&gt;The &apos;API call mocking&apos; system is running. When an app calls, for example, Recv(), the call isn&apos;t executed, but trapped and symbolic data returned. Other calls which are difficult to verify are similarly modified (such as GetTickCount, which returns different data on each call).&lt;br /&gt;&lt;br /&gt;Next big functionality:&lt;br /&gt;&lt;br /&gt;* More instructions, until I can run all of my VS-compiled C++ test app (including most of the C runtime library)&lt;br /&gt;&lt;br /&gt;* More API call mocks&lt;br /&gt;&lt;br /&gt;* Database-driven caching for solver files (yay)&lt;br /&gt;&lt;br /&gt;* Minor modifications to allow parallelisation (the app is architected to parallelise really well, but this was dropped a couple months ago to speed up dev)&lt;br /&gt;&lt;br /&gt;* Add logic to actually find holes (&quot;... if EIP can be equal to 0x41414141..&quot;)&lt;br /&gt;&lt;br /&gt;* Extend variable-length buffer support with some ideas I had in the shower yesterday&lt;br /&gt;&lt;br /&gt;* (maybe) speed up constraint solving with some other ideas I&apos;ve been mulling over&lt;br /&gt;&lt;br /&gt;* Fix memory leaks.&lt;br /&gt;&lt;br /&gt;&lt;img src=&quot;http://i38.tinypic.com/2q8n7lx.jpg&quot;&gt;&lt;br /&gt;&lt;br /&gt;Still hoping to have the app finding holes (preferably generating exploits) in my example &apos;vuln&apos; simple stack-based buffer overflow code by the new year. This&apos;ll depend, though, on how much time gets dedicated to the scanner over other things I have to juggle.&lt;br /&gt;&lt;br /&gt;[1] there are 256 opcodes - 0x00 through 0xff - but not all are used, some won&apos;t be supported (MMX or SSE or whatever) and some opcodes are escapes to much more functionality.</description>
  <comments>http://gamesfairy.livejournal.com/22593.html</comments>
  <category>stp</category>
  <category>security scanner</category>
  <lj:security>public</lj:security>
  <lj:reply-count>0</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://gamesfairy.livejournal.com/22518.html</guid>
  <pubDate>Thu, 01 Oct 2009 04:22:04 GMT</pubDate>
  <title>Status of Lavalamp</title>
  <link>http://gamesfairy.livejournal.com/22518.html</link>
  <description>So! You could be forgiven for thinking that the Lavalamp project is dead!&lt;br /&gt;&lt;br /&gt;The website (along with two others I own) was unfortunately lost during the great VAServ hack, and up until recently, I have been simply too busy with University to redesign it. However, the time has come that I have some free time - so hey presto! A new site. As the more astute may be able to tell, web design is really Not My Thing, so please do feel free to point out any glaring errors or horrible face-burning design issues I&apos;ve stumbled upon!&lt;br /&gt;&lt;br /&gt;The project itself is coming on well. As outlined in my previous postings, there&apos;s a lot I want to do with Lavalamp, but precious few moments in which to do it. I am, however, planning (at the moment) to have some working code released within a couple of months (of October). However, since I&apos;ve been promising a release since, ooh, about two years ago, you probably don&apos;t want to hold your breath! &lt;br /&gt;&lt;br /&gt;I&apos;ve stuck some screenshots in the &apos;user documentation&apos; section that should show how things are running. The &apos;rule&apos; mechanism is shaping up fairly well, and looks like it&apos;ll be quite powerful if I ever manage to finish it. Lets hope, eh!</description>
  <comments>http://gamesfairy.livejournal.com/22518.html</comments>
  <category>home automation</category>
  <category>lavalamp</category>
  <lj:security>public</lj:security>
  <lj:reply-count>0</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://gamesfairy.livejournal.com/22159.html</guid>
  <pubDate>Sat, 29 Aug 2009 08:23:29 GMT</pubDate>
  <title>Security scanner progress</title>
  <link>http://gamesfairy.livejournal.com/22159.html</link>
  <description>Man. Coding this security scanner - in C++ - is really reminding me how much more enjoyable things are, the &apos;closer to the metal&apos;. It&apos;s also, thankfully, giving me a great insight in to how the &apos;upper layers&apos; work - mainly C#-type stuff. My C++ has always been terrible, although my C was usually fairly strong, so I had a lot of trouble previously with working out how c# is implemented by the compiler - but now, knowledge gained in C++ is helping to fill the gap.&lt;br /&gt;&lt;br /&gt;Anyway. Progress on the security scanner. &lt;br /&gt;&lt;br /&gt;I&apos;ve finished implementing the 8bit memory layer, and have adapted a couple of the x86 instruction handlers to use it. I&apos;ve got decent tests for the ones I&apos;ve adapted - three instructions in total - which test thigns like the values received and how dependencies are mapped between the variables. Unfortunately, each is quite substantial, in terms of code, so it looks like it&apos;ll be prohibitive to write tests for every single instruction (especially since there&apos;s a gazillion of them in x86). &lt;br /&gt;&lt;br /&gt;There&apos;s another &apos;verification mode&apos;, in which the scanner traces instructions with IDA and verifies that it gets the same answers, but that&apos;s pretty useless for dependency tracking. Perhaps I can use this mode, and investigate bugs that it flags using per-instruction tests.&lt;br /&gt;&lt;br /&gt;The 8bit memory layer took longer to write than I&apos;d hoped, coming in at arrounnnddd 4 or 5 days. While doing that, though, I&apos;ve cleaned up a load of old code, and re-organised to make things more OO. I was also called to rewrite much of a solver function, so while I was at it, I implemented functionality that was on my waiting list, estimated to take a day or two, so that can&apos;t be bad.&lt;br /&gt;&lt;br /&gt;The functionality I talk about is variable re-labelling - when I write a file to send to the solver, I label each variable in order of appearance in this file, instead of with its per-run &apos;name&apos;. This&apos;ll mean that I can cache things a lot more easily and effectively (and yes, caching is &lt;i&gt;still&lt;/i&gt; on my to-do list). &lt;br /&gt;&lt;br /&gt;The next steps are to implement emulation of lots more instructions, make a few tweaks here and there, finish a bit of functionality, and it should get to a usable state. That shouldn&apos;t, hopefully, take more than a month (barring huge gaps in functionality which I&apos;ve forgotten about).&lt;br /&gt;&lt;br /&gt;Here&apos;s hoping, eh? :D</description>
  <comments>http://gamesfairy.livejournal.com/22159.html</comments>
  <category>securityscanner</category>
  <lj:music>Nick Cave and the Bad Seeds - Stagger Lee | Powered by Last.fm</lj:music>
  <media:title type="plain">Nick Cave and the Bad Seeds - Stagger Lee | Powered by Last.fm</media:title>
  <lj:mood>accomplished</lj:mood>
  <lj:security>public</lj:security>
  <lj:reply-count>0</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://gamesfairy.livejournal.com/21773.html</guid>
  <pubDate>Thu, 27 Aug 2009 11:37:44 GMT</pubDate>
  <title>Gutting the 32bit security scanner memory model and replacing with 8bit</title>
  <link>http://gamesfairy.livejournal.com/21773.html</link>
  <description>I&apos;ve mainly been working on the security scanner over the past couple of weeks, when I&apos;ve been able to find time. I&apos;ve been very busy moving house, and doing other IRL stuff.&lt;br /&gt;&lt;br /&gt;Anyway. &lt;br /&gt;&lt;br /&gt;I think I mentioned earlier, that the security scanner models memory as a set of discrete 32-bit locations, and how much headache it&apos;s caused me. I&apos;ve mostly been &apos;converting&apos; to an entirely 8-bit memory model, and using 32-bit operations purely as constructs to model the interaction of various memory locations. For example:&lt;br /&gt;&lt;br /&gt;4 bytes of memory at 0x00 thorough 0x04 are added to memory at 0x10-0x14, using a 32bit operation.&lt;br /&gt;&lt;br /&gt;The scanner would create 8 entries in the &apos;memory to variable&apos; map:&lt;br /&gt;&lt;br /&gt;memory at 0x00 is represented by variable A&lt;br /&gt;memory at 0x01 is represented by variable B&lt;br /&gt;memory at 0x02 is represented by variable C&lt;br /&gt;memory at 0x03 is represented by variable D&lt;br /&gt;memory at 0x10 is represented by variable E&lt;br /&gt;memory at 0x11 is represented by variable F&lt;br /&gt;memory at 0x12 is represented by variable G&lt;br /&gt;memory at 0x13 is represented by variable H&lt;br /&gt;&lt;br /&gt;and would then create a 32-bit &apos;helper&apos; value X. Next, the scanner marks that A through D are dependent on X, so you have:&lt;br /&gt;&lt;br /&gt;AB  CD&lt;br /&gt;|  |    | |&lt;br /&gt;VV_VV___&lt;br /&gt;| X (32bit )|&lt;br /&gt;&lt;br /&gt;&lt;i&gt;sorry about the ASCII art!&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;Similar is done for a new var, Y, and E through H:&lt;br /&gt;&lt;br /&gt;E  F    G  H&lt;br /&gt;|    |    |    |&lt;br /&gt;V_V_V_V__&lt;br /&gt;| Y (32bit )|&lt;br /&gt;&lt;br /&gt;The scanner then defines that Z is equal to the result of a 32bit add, X+Y. &lt;br /&gt;&lt;br /&gt;Z = X + Y&lt;br /&gt;&lt;br /&gt;To store computer data in memory, we can&apos;t simply set EFGH - what if something else depends on them (ie, before this add, what if a different operation used EFGH)? We make new 8bit variables, IJKL, and assign them to Z. We then tell the system that memory at 0x10 through 0x14 correlates to IJKL.&lt;br /&gt;&lt;br /&gt;The final outcome of the system:&lt;br /&gt;&lt;br /&gt;AB  CD&lt;br /&gt;|  |    | |&lt;br /&gt;VV_VV___&lt;br /&gt;| X (32bit )|&lt;br /&gt;&lt;br /&gt;EF  GH&lt;br /&gt;|  |    | |&lt;br /&gt;VV_VV___&lt;br /&gt;| Y (32bit )|&lt;br /&gt;&lt;br /&gt; Z = X + Y&lt;br /&gt;&lt;br /&gt;I  J   K  L&lt;br /&gt;|  |    | |&lt;br /&gt;VV_VV___&lt;br /&gt;| Z (32bit )|&lt;br /&gt;&lt;br /&gt;memory at 0x00 is represented by variable A&lt;br /&gt;memory at 0x01 is represented by variable B&lt;br /&gt;memory at 0x02 is represented by variable C&lt;br /&gt;memory at 0x03 is represented by variable D&lt;br /&gt;memory at 0x10 is represented by variable I&lt;br /&gt;memory at 0x11 is represented by variable J&lt;br /&gt;memory at 0x12 is represented by variable K&lt;br /&gt;memory at 0x13 is represented by variable L&lt;br /&gt;&lt;br /&gt;This is then serialised in to an input file for the STP solver I use - cvc3 - which comes out like this (as an example, we say that ABCD is hardcoded to 11223344 and CDEF is hardcoded to 55667788):&lt;br /&gt;&lt;br /&gt;(snip uninteresting bits)&lt;br /&gt;ASSERT( X = A:B:C:D  );&lt;br /&gt;ASSERT( Y = E:F:G:H  );&lt;br /&gt;ASSERT( Z = X + Y  );&lt;br /&gt;ASSERT( A = 0x11 );&lt;br /&gt;ASSERT( B = 0x22 );&lt;br /&gt;ASSERT( C = 0x33 );&lt;br /&gt;ASSERT( D = 0x44 );&lt;br /&gt;ASSERT( E = 0x55 );&lt;br /&gt;ASSERT( F = 0x66 );&lt;br /&gt;ASSERT( G = 0x77 );&lt;br /&gt;ASSERT( H = 0x88 );&lt;br /&gt;TRANSFORM(Z) ;&lt;br /&gt;&lt;br /&gt;Obviously, I&apos;ve edited that code to make it clearer. It denotes a series of &apos;simultaneous&apos; assertions - the solver will find an answer which satisfies all the assertations. The final line - TRANSFORM- asks the solver to tell the user a value of Z which does this. The only value it can come out with, for this particular STP file, is 0x6688AACC - which is 0x11223344 + 0x55667788.&lt;br /&gt;&lt;br /&gt;Notice that &apos;memory&apos; has been totally abstracted away, here, in favor of &apos;variables&apos;. Modelling memory is bad, mmmkay. We&apos;re running at so low a level - the machine code level - that heap corruption will be modeled just as if it were a legal situation.&lt;br /&gt;&lt;br /&gt;This example shows how easy it is to then add other nnon-32-bit constraints. You could then add&lt;br /&gt;&lt;br /&gt;ASSERT( F = N OR P );&lt;br /&gt;ASSERT( N = 0x60 );&lt;br /&gt;ASSERT( P = 0x06 );&lt;br /&gt;&lt;br /&gt;and get the same result.&lt;br /&gt;&lt;br /&gt;The current codebase differentiates between a register - reg_32_t - and four bytes of memory. This is bad, because we can&apos;t treat the two identically. Especially in x86.&lt;br /&gt;x86 has a concept called the &apos;modr/m byte&apos;, which is a byte tacked on to most instructions specifying what to operate on. It can specify a register (well, strictly speaking, two, actually, target and source) or a memory location (or a deref&apos;fed pointer, but that&apos;s almost the same thing, as far as we&apos;re concerned). Having a function to decode this byte was dead easy when memory was modelled as a series of registers - it just returned a &apos;register&apos; stru- er, object - and the code did with it whatever it liked.&lt;br /&gt;&lt;br /&gt;It looks like, to return to this nice neat state of affairs, I&apos;m going to model registers as groups of 8bit discrete registers. I&apos;m a bit worried this is going to be dog-slow, but it&apos;s the neatest (only?) way I can think of doing things.&lt;br /&gt;&lt;br /&gt;I really miss c#.. this project is reminding me how inexperienced I am at C++, and OO in general. If I was to restart this project from scratch, one thing I&apos;d do would be to OO-erise it a lot more.&lt;br /&gt;&lt;br /&gt;Apologies for the hard-to-read nature of this post. It was a tossup between ascii art and just scanning my &apos;working out&apos; notepad.. And its midday and I&apos;m tired, having been coding all night. Comment, or ask me via IM, if there&apos;s anything I should say more about.&lt;br /&gt;&lt;br type=&quot;_moz&quot; /&gt;</description>
  <comments>http://gamesfairy.livejournal.com/21773.html</comments>
  <category>stp</category>
  <category>constraint solving</category>
  <category>securityscanner</category>
  <lj:music>Marilyn Manson - 1996 | Powered by Last.fm</lj:music>
  <media:title type="plain">Marilyn Manson - 1996 | Powered by Last.fm</media:title>
  <lj:mood>cheerful</lj:mood>
  <lj:security>public</lj:security>
  <lj:reply-count>0</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://gamesfairy.livejournal.com/21739.html</guid>
  <pubDate>Wed, 26 Aug 2009 06:45:22 GMT</pubDate>
  <title>Wiring SMART drive health status to SNMPD</title>
  <link>http://gamesfairy.livejournal.com/21739.html</link>
  <description>* Been playing some more with Opsview. First step was getting its &apos;agent&apos; program running on Jaunty. I did a few things to get it going:&lt;br /&gt;&lt;br /&gt;1) I just downloaded the latest version (&lt;a href=&quot;https://downloads.opsera.com/opsview/yum/3.1/centos/5/i386/opsview-agent-3.1.0.2553-1.ct5.i386.rpm&quot;&gt;https://downloads.opsera.com/opsview/yum/3.1/centos/5/i386/opsview-agent-3.1.0.2553-1.ct5.i386.rpm&lt;/a&gt;)&lt;br /&gt;&lt;br /&gt;2) Turned it in to a dpkg it with alien, and installed it&lt;br /&gt;&lt;i&gt;alien -d opsview-agent-3.1.0.2553-1.ct5.i386.rpm&lt;/i&gt;&lt;br /&gt;&lt;i&gt;dpkg -i opsview-agent-3.1.0.2553-1.ct5.i386.rpm&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;3) Added the &apos;nagios&apos; user, chgrp&apos;ed the nagios dirctory, and symlinked from the openssl libs to libssl.so.6, which is (another) dirty hack, but peh. :D&lt;br /&gt;&lt;i&gt;useradd nagios&lt;/i&gt;&lt;br /&gt;&lt;i&gt;chgrp -R nagios /usr/local/nagios/&lt;/i&gt;&lt;br /&gt;&lt;i&gt;ln -s /usr/lib/libssl.so.0.9.8 /usr/lib/libssl.so.6&lt;/i&gt;&lt;br /&gt;&lt;i&gt;ln -s /usr/lib/libcrypto.so.0.9.8 /usr/lib/libcrypto.so.6&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;Kapow! It worked (for me).&lt;br /&gt;&lt;br /&gt;* Need to install NTP to sych times.&lt;br /&gt;&lt;br /&gt;* After this I installed snmpd on the machines I&apos;m monitoring, and scribbled up some simple scripts to monitor SMART information. First off, I installed snmpd and got that working, then installed smartmonctl, and checked that I could get data from all my drives. Success! I went ahead and wrote a dead simple one-line script to get drive info, and parse it (improvements are welcome, bash scripting is not my forté!):&lt;br /&gt;&lt;i&gt;&lt;br /&gt;root@anna:/home/smb-aliz# cat /usr/bin/smart-drivetemp&lt;br /&gt;#!/bin/bash&lt;br /&gt;exit `smartctl $1  -a | grep Temperature_Celsius | cut -b 85-90`&lt;br /&gt;root@anna:/home/smb-aliz#  smart-drivetemp /dev/sda&lt;br /&gt;root@anna:/home/smb-aliz# echo $?&lt;br /&gt;42&lt;br /&gt;&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;Ace. So now we&apos;ve got a script that accepts a drive name, and returns the drives temperature. Now to wire it up to snmpd. The only problem I ran in to here is that the SMART tool needs to be run as root, for obvious reasons. snmpd runs as the snmp user, so I decided to make smartctl suid root (&lt;i&gt;chmod u+s  /usr/sbin/smartctl&lt;/i&gt;). I could&apos;ve made the script suid, but I&apos;m not quite that silly. Obviously, it&apos;s a bad idea to make anything suid root, and an even worse idea to make a tool which can take your drives offline suid root. Don&apos;t do this on important machines which evil hax0rs could get an account on, kids. If there&apos;s a better way than setting smartctl to be SUID root, please let me know..&lt;br /&gt;&lt;br /&gt;So. After doing this, we tell snmpd to run it:&lt;br /&gt;&lt;i&gt;&lt;br /&gt;echo exec smart-sda &quot;/bin/sh /usr/bin/smart-drivetemp /dev/sda&quot; &amp;gt;&amp;gt; /etc/snmpd.conf&lt;br /&gt;&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;And we check it&apos;s working.&lt;br /&gt;&lt;i&gt;&lt;br /&gt;root@anna:/home/smb-aliz# snmpwalk -v 1 -c public localhost .1.3.6.1.4.1.2021.8&lt;br /&gt;UCD-SNMP-MIB::extIndex.1 = INTEGER: 1&lt;br /&gt;UCD-SNMP-MIB::extNames.1 = STRING: smart-sda&lt;br /&gt;UCD-SNMP-MIB::extCommand.1 = STRING: /bin/sh /usr/bin/smart-drivetemp /dev/sda&lt;br /&gt;&lt;b&gt;UCD-SNMP-MIB::extResult.1 = INTEGER: 42&lt;/b&gt;&lt;br /&gt;UCD-SNMP-MIB::extOutput.1 = STRING:&lt;br /&gt;UCD-SNMP-MIB::extErrFix.1 = INTEGER: noError(0)&lt;br /&gt;UCD-SNMP-MIB::extErrFixCmd.1 = STRING:&lt;br /&gt;root@anna:/home/smb-aliz#&lt;br /&gt;&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;Awesome. Now opsview can give me nice graphs of my drive temperatures! And can SMS me if they get too hot! Of course, the possibilites are endless. It&apos;s a good idea to also wire up alerts on other SMART properties - Seek_Error_Rate and Raw_Read_Error_Rate spring to mind - and it&apos;s an even better idea to wire an alert up to the general SMART health status (&lt;i&gt;smartctl -H/dev/sda&lt;/i&gt;). Happy monitoring!</description>
  <comments>http://gamesfairy.livejournal.com/21739.html</comments>
  <category>ubuntu</category>
  <category>snmp</category>
  <category>monitoring</category>
  <lj:music>Dope - So Low | Powered by Last.fm</lj:music>
  <media:title type="plain">Dope - So Low | Powered by Last.fm</media:title>
  <lj:mood>accomplished</lj:mood>
  <lj:security>public</lj:security>
  <lj:reply-count>0</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://gamesfairy.livejournal.com/21437.html</guid>
  <pubDate>Sun, 23 Aug 2009 19:43:30 GMT</pubDate>
  <title>Opsview on ubuntu jaunty jackalope, and libltdl3</title>
  <link>http://gamesfairy.livejournal.com/21437.html</link>
  <description>&lt;span class=&apos;ljuser ljuser-name_matthewrwright&apos; lj:user=&apos;matthewrwright&apos; style=&apos;white-space: nowrap;&apos;&gt;&lt;a href=&apos;http://matthewrwright.livejournal.com/profile&apos;&gt;&lt;img src=&apos;http://l-stat.livejournal.com/img/userinfo.gif&apos; alt=&apos;[info]&apos; width=&apos;17&apos; height=&apos;17&apos; style=&apos;vertical-align: bottom; border: 0; padding-right: 1px;&apos; /&gt;&lt;/a&gt;&lt;a href=&apos;http://matthewrwright.livejournal.com/&apos;&gt;&lt;b&gt;matthewrwright&lt;/b&gt;&lt;/a&gt;&lt;/span&gt; recently recommended &lt;a href=&quot;http://www.opsview.org/&quot;&gt;Opsview&lt;/a&gt; to me as a network monitoring tool. It&apos;s built on Nagios but is apparently a lot easier to configure. &lt;br /&gt;&lt;br /&gt;Unfortunately, though, packages are only provided for debian Etch, Lenny, and Hardy. &lt;a href=&quot;http://www.mail-archive.com/opsview-users@lists.opsview.org/msg00546.html&quot;&gt;this&lt;/a&gt; post seems to indicate that there are no plans to make a Ubuntu Jaunty package available (although the packages seem to work with previous versions of Ubuntu). Nevertheless, I&apos;ve gotten opsview working on my Jaunty box, so here&apos;s the way I did it:&lt;br /&gt;&lt;br /&gt;0.5) Understand that this is completely without warranty, and may break your apt configuration, your machine, your network, etc. I did this on a virgin jaunty box - I make no statements that it&apos;ll work for you. Don&apos;t forget to backup first!&lt;br /&gt;&lt;br /&gt;1) Install the &apos;equivs&apos; package.&lt;br /&gt;&lt;i&gt;apt-get install equivs&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;2) Create a dummy package, purporting to provide libltdl3.&lt;br /&gt;&lt;i&gt;equivs-control libltdl3&lt;/i&gt;&lt;br /&gt;Edit the created libltdl3 file, changing &apos;package&apos; and &apos;proves&apos; lines to contain &apos;libltdl3&apos;, like this:&lt;br /&gt;&lt;i&gt;Package: libltdl3&lt;/i&gt;&lt;br /&gt;&lt;i&gt;Provides: libltdl3&lt;/i&gt;&lt;br /&gt;Now, create the package:&lt;br /&gt;&lt;i&gt;equivs-build libltd3&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;3) Install the dummy package:&lt;br /&gt;&lt;i&gt;dpkg --install libltdl3_1.0_all.deb&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;4) This step is a bit of a hack, but works so far (again, don&apos;t blame me if it breaks stuff..)&lt;br /&gt;&lt;i&gt;ln -s /usr/lib/libltdl.so.7 /usr/lib/libltdl.so.3&lt;/i&gt; &lt;br /&gt;&lt;br /&gt;4) Add opsview repo to sources.list, and install it.&lt;br /&gt;&lt;i&gt;apt-get install opsview&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;If you don&apos;t feel like doing steps 1 through 3, you can simply download &lt;a href=&quot;http://gamesfairy.co.uk/libltdl3_1.0_all.deb&quot;&gt;the deb package I made&lt;/a&gt; and install it. You&apos;ll still need to symlink libltdl, though.</description>
  <comments>http://gamesfairy.livejournal.com/21437.html</comments>
  <lj:mood>accomplished</lj:mood>
  <lj:security>public</lj:security>
  <lj:reply-count>0</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://gamesfairy.livejournal.com/21031.html</guid>
  <pubDate>Mon, 17 Aug 2009 23:56:49 GMT</pubDate>
  <title>Telecom musings</title>
  <link>http://gamesfairy.livejournal.com/21031.html</link>
  <description>Since last time, on channel gamesfairy:&lt;br /&gt;&lt;br /&gt;* Talked to a couple of friends - one of whom works for BT - about telecoms. Really reminiscent about all the stufff I used to do with telecom (well sort of). &lt;br /&gt;&lt;br /&gt;* Saw the slashdot article about the dude that ran his own telco carrier. Interested.&lt;br /&gt;&lt;br /&gt;* Remembered the recent iphone stuff, apparently obtianed by fuzzing the iphone through some &apos;custom&apos; stuff. IDK how he did it - I&apos;d probably have emulated it, if it wasn&apos;t too much trouble? IDK.&lt;br /&gt;&lt;br /&gt;* I&apos;d really like to play with this. Run a femtocell, hooked up to one of my phones (and with too little power to get out of my house) and send the phone bizarre shit until it explodes. I should add that to the to-do list.&lt;br /&gt;&lt;br /&gt;* I wonder how hackable the commercially available femtocells are. Obviously, the best idea would be to use something like the USRP2 and GNU radio (software radio that does &apos;DC to 5ghz&apos;), which would all fit together nciely and be awesome, but the USRP2 is far too much for me ($1400US + transciever boards). I really don&apos;t want to start fuzzing the telco system live, in case I break it.. maybe I&apos;ll have An Idea about this stuff later on. Perhaps I could remove the phone&apos;s PHY and hook it to an FPGA and then to the PC. &lt;br /&gt;&lt;br /&gt;* Might be easier to just emulate the phone - particularly with stuff like the iPhone where a lot of the hardware is well-observed. If I can emulate it (or probe it live, ICE style) I should be able to hook it to the l33t security scanner I&apos;m (still) writing.&lt;br /&gt;&lt;br /&gt;* Need to rewrite a chunk of the scanner. I (rather short-sightedly) modelled memory as a set of 32bit integers, under belief that I could just mask in 16- and 8-bit memory accesses. I kinda could, but I get in to big trouble when I look at 32bit operations which span two 32bit values in memory - (eg: I&apos;ll have two memory locations, 0x00-0x03 and 0x04-0x07, and the target will request 0x01-0x04). Going to rewrite the memory access layer as dealin gin 8bit values, and tweak it a bit so it becomes easier to write tests for the instructions, too.&lt;br /&gt;&lt;br /&gt;* Really on a telecom bender at the mo. I bet there&apos;s cash in hax0ring telco kit, too.. IDK how I&apos;d go about selling stuff I found (to the telco, obv, my hat isn&apos;t black enough to sell natino-cripping bugs to The Terrorists). I guess if nothing else it&apos;d earn me skills and rep in the Industry, both of which I seem to be lacking.&lt;br /&gt;&lt;br /&gt;* Still pondering post-grad career options, if my current job plan doesn&apos;t work out. I think postgrad education might be a good bet. I&apos;d like to go &apos;freelance pentesting&apos; but realistically, I&apos;ve got no chance in the market (not enough people skills, tech skills, etc). Maybe in a few years.&lt;br /&gt;&lt;br /&gt;* Been working on lavalamp. Looks like my plan to scale it back and get a functinal release out should go ahead.</description>
  <comments>http://gamesfairy.livejournal.com/21031.html</comments>
  <category>career</category>
  <category>telco</category>
  <category>home automation</category>
  <category>securityscanner</category>
  <category>lavalamp</category>
  <lj:music>Eagles - Hotel California | Powered by Last.fm</lj:music>
  <media:title type="plain">Eagles - Hotel California | Powered by Last.fm</media:title>
  <lj:mood>geeky</lj:mood>
  <lj:security>public</lj:security>
  <lj:reply-count>0</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://gamesfairy.livejournal.com/20756.html</guid>
  <pubDate>Mon, 10 Aug 2009 08:39:16 GMT</pubDate>
  <title>Lavalamp source found! Woo!</title>
  <link>http://gamesfairy.livejournal.com/20756.html</link>
  <description>So, I found a copy of the lavalamp code yesterday. Previously I thought I&apos;d lost almost all of the code in the Great VAServ Meltdown, but evidently not. I&apos;ve lost all the repo info, but I&apos;ve got the most current working copy, so that&apos;s enough for me.&lt;br /&gt;&lt;br /&gt;All I have to do now is find enough time to work on it! It&apos;s really competing for time with other projects - ie, the securityscanner - and various real-world stuff I&apos;ve got on at the moment (ie, moving house). Having said that, I&apos;d really like to get something running with it, even if I only make it work enough for my own use and rely on the open-source patching process.&lt;br /&gt;&lt;br /&gt;The real bottleneck in the development, at last count, was the &apos;native&apos; home-grown RF link. It soaks up a lot of dev time and frequently leaves me confused. Most of my problems could probably be circumvented if I were to switch to an RF chip that does much more work for me - but I&apos;m really keen on the &apos;all parts available from (highstreet shop) Maplin&apos; idea, and all they have available is the dumb RF modules. &lt;br /&gt;One way forward is to move to Zigbee - since transcievers are now cheap enough - although using that requires a fairly beefy PIC chip. The dev time required to move to Zigbee is also not inconsiderable. &lt;br /&gt;&lt;br /&gt;I think the best way forward is to do is the following (when I get time):&lt;br /&gt;&lt;br /&gt;1) Implement modularised &apos;network&apos; layers, allowing nodes to run over different, uh, network transports.&lt;br /&gt;&lt;br /&gt;2) Implement a straightforward and dead-simple daisy-chained RS232-over-cat5 network, allowing nodes to be hooked up via cabling. This&apos;ll let me get &quot;something working&quot;, and get some real-world use out of the thing. Being cabled, this network wouldn&apos;t even need any encryption. &lt;br /&gt;&lt;br /&gt;3) Finish enough of the lavalamp PC-side software for it to be useful (ie, enough that it is solid, can be scripted, and can be used interactively in a GUI).&lt;br /&gt;&lt;br /&gt;4) Do a release under an open-source license, inviting people to use the code, give feedback, and contribute.&lt;br /&gt;&lt;br /&gt;5) Start work on all the &apos;extra&apos; features:&lt;br /&gt;&lt;br /&gt; * Zigbee interfacing, as a different network layer (allowing people to use Zigbee if they want the extra power requirements/space requirements/complexity)&lt;br /&gt;&lt;br /&gt; * Linux support (probably via Mono). This would be really nice as I could run the server on a tiny ARM-based machine instead of a full PC,&lt;br /&gt;&lt;br /&gt; * More exotic peripheral drivers (LCDs, VGA, GPS, you name it),&lt;br /&gt;&lt;br /&gt; * More exotic transport layers (homebrew RF, perhaps, and maybe even X10)&lt;br /&gt;&lt;br /&gt; * Buzzwordy ajaxy control app, WAP access, all that jazz)&lt;br /&gt;&lt;br /&gt;I also need to rewrite the lavalamp.gamesfairy.co.uk website, too, at some point. If only I had more hours in the day!</description>
  <comments>http://gamesfairy.livejournal.com/20756.html</comments>
  <category>home automation</category>
  <category>lavalamp</category>
  <lj:security>public</lj:security>
  <lj:reply-count>0</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://gamesfairy.livejournal.com/20592.html</guid>
  <pubDate>Thu, 06 Aug 2009 23:22:13 GMT</pubDate>
  <title>Ack, HD failures!</title>
  <link>http://gamesfairy.livejournal.com/20592.html</link>
  <description>Well, I guess this confirms another hardware failure!&lt;br /&gt;&lt;br /&gt;root@anna:/mnt/space# dd if=/dev/urandom of=randomdata bs=10M count=100&lt;br /&gt;100+0 records in&lt;br /&gt;100+0 records out&lt;br /&gt;1048576000 bytes (1.0 GB) copied, 661.065 s, 1.6 MB/s&lt;br /&gt;root@anna:/mnt/space# md5sum randomdata&lt;br /&gt;62a72439f880ba0a032086e1b12155e0  randomdata&lt;br /&gt;root@anna:/mnt/space# cp randomdata morerandomdata&lt;br /&gt;root@anna:/mnt/space# cp randomdata  /mnt/backup/randomdata&lt;br /&gt;root@anna:/mnt/space# cp randomdata  /mnt/backup/morerandomdata&lt;br /&gt;root@anna:/mnt/space# md5sum randomdata morerandomdata /mnt/backup/randomdata /mnt/backup/morerandomdata&lt;br /&gt;0f611ad252be943e75e2fcd9e9483103  randomdata&lt;br /&gt;87fc39b9e745f46d54b5a037088dce8e  morerandomdata&lt;br /&gt;ad572e39cb577c5d79116ed909f11f89  /mnt/backup/randomdata&lt;br /&gt;ad5093cffcd43caf00ccb55be3e2dfe5  /mnt/backup/morerandomdata&lt;br /&gt;&lt;br /&gt;Ouch! Bizarrely, nothing bad appears in dmesg, and if I repeat the above using /dev/zero, I get no errors. Since all this happened when I transplated the drives in to the Intergraph ZX10, which also bitched at me about PCI resource conflicts, I suspect some weird oddness between the PCI SATA controller and the CPU. &lt;br /&gt;&lt;br /&gt;This machine has two volumes, /mnt/space and /mnt/backup, which are both on the PCI SATA card. Normally I back up from one to the other every night, which protects against those &apos;oh shit I just rm&apos;ed the wrong disk&apos; situations that RAID 1 wouldn&apos;t. Unfortunately, putting them in one machine was fairly short-sighted, as they have both been rendered useless. Fortunately, I have an additional off-site backup at my mum&apos;s place, which should be intact (if a week or two old).&lt;br /&gt;&lt;br /&gt;The machine I keep the backup on at mum&apos;s house, however, also suffered at least one harddisk failure, a couple of days ago. I appear to have lucked out, I hope. The machine contains some five hard drives, four of which are in a linear RAID array (the idea going that availability isn&apos;t crucial on a backup machine) and one is the OS drive. None are redundant, and the OS drive has failed - so I&apos;m really, really hoping that the remaining four drives are functional enough to have the data read from them. &lt;br /&gt;&lt;br /&gt;Frustratingly, I was in the process of moving the two volumes at my place in to two separate machines, but decided to do the initial backing-up locally on the Intergraph ZX10, for speed. Damn. &lt;br /&gt;&lt;br /&gt;Moral of the story: &lt;br /&gt;&lt;br /&gt;* Backups should be on different machines. I already knew this to some extent, fearing that an Evil Haxx0r or a PSU blowout could take out two copies of the data, but neglected the possibility of a controller failure (or a controller driver failure, or whatever happened). I&apos;ve always been reluctant to use hardware RAID in applications like this, for fear of a controller &apos;dying&apos;, and the RAID array it had being inaccessible without an identical controller.&lt;br /&gt;&lt;br /&gt;* Some script to detect large amounts of file changes and alert me would be good. I only noticed the corruption after I attempted to play an mp3 and didn&apos;t get very far.&lt;br /&gt;&lt;br /&gt;* Had this occurred in a server I wasn&apos;t in the middle of setting up, I would&apos;ve been emailed the ext3 errors. Damn. As it was, the Intergraph didn&apos;t have logwatch set up correctly at this point.&lt;br /&gt;&lt;br /&gt;EDIT : A reboot and a BIOS upgrade later and it&apos;s stable. I don&apos;t know how long for, though, so I&apos;m going to stress-test it with some heavy parallel file IO and see what happens.</description>
  <comments>http://gamesfairy.livejournal.com/20592.html</comments>
  <lj:music>VNV Nation - Honour | Powered by Last.fm</lj:music>
  <media:title type="plain">VNV Nation - Honour | Powered by Last.fm</media:title>
  <lj:mood>anxious</lj:mood>
  <lj:security>public</lj:security>
  <lj:reply-count>0</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://gamesfairy.livejournal.com/20458.html</guid>
  <pubDate>Thu, 30 Jul 2009 11:40:26 GMT</pubDate>
  <title>Crowd-sourced SAT solving</title>
  <link>http://gamesfairy.livejournal.com/20458.html</link>
  <description>Yes, really, those crazy web2.0 kids are attempting to crowdsource SAT solving. Check it out. &lt;a href=&quot;http://funsat.eecs.umich.edu/&quot;&gt;http://funsat.eecs.umich.edu/&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Proper post later.</description>
  <comments>http://gamesfairy.livejournal.com/20458.html</comments>
  <lj:mood>amused</lj:mood>
  <lj:security>public</lj:security>
  <lj:reply-count>0</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://gamesfairy.livejournal.com/20105.html</guid>
  <pubDate>Sun, 19 Jul 2009 17:41:03 GMT</pubDate>
  <title>Cruisecontrol.net and other networky stuff</title>
  <link>http://gamesfairy.livejournal.com/20105.html</link>
  <description>Things done since last sleep:&lt;br /&gt;&lt;br /&gt;* Set up Linux VM as a router, meaning I don&apos;t have to have the main windows box directly on the public internet (!!). Have set up DHCP3/BIND9/squid/ipchains/logwatch/arpwatch/fwlogwatch, so I get transparent web proxying (yay for saving bandwidth) in a nicely secure environment. Hopefully. Here&apos;s hoping no-one pwns it.&lt;br /&gt;&lt;br /&gt;* Finally gotten CruiseControl.net, a CI system, running! Now, when I checkin some of the security scanner to subversion, it&apos;ll pull it back out, do a build and run my &apos;tests&apos; for me, letting me know if I&apos;ve inadvertently broken stuff. TBH the security scanner is pretty non-agile, so it&apos;s a bit kludgey in places.. &quot;#define VERIFYMODE&quot; style.&lt;br /&gt;&lt;br /&gt;* Spec&apos;ced a &apos;cheap VM server&apos; using consumer-end components. E7600 CPU (with VT externsions), 8GB RAM (board takes up to 16), motherboard with enough PCI-E to take a nice raidcard if I afford one later, and enough SATA to get hefty bandwidth. Came to a shade over £300. Haven&apos;t quite convinced myself I can afford it yet, but aim to soon.</description>
  <comments>http://gamesfairy.livejournal.com/20105.html</comments>
  <category>networking</category>
  <category>admin</category>
  <category>cruisecontrol</category>
  <category>securityscanner</category>
  <lj:music>Moby - My Weakness | Powered by Last.fm</lj:music>
  <media:title type="plain">Moby - My Weakness | Powered by Last.fm</media:title>
  <lj:security>public</lj:security>
  <lj:reply-count>0</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://gamesfairy.livejournal.com/19965.html</guid>
  <pubDate>Wed, 15 Jul 2009 04:57:07 GMT</pubDate>
  <title>Copy-on-write in virtual machines</title>
  <link>http://gamesfairy.livejournal.com/19965.html</link>
  <description>So. Todays post centers around the use of copy-on-write. If you don&apos;t know what CoW is, check out &lt;a href=&quot;http://www.etherboot.org/wiki/appnotes/cow&quot;&gt;this gPXE page&lt;/a&gt; before proceeding; things will make more sense then.&lt;br /&gt;&lt;br /&gt;&lt;img src=&quot;http://milkcashcow.files.wordpress.com/2008/04/cow_rev.jpg&quot; /&gt;&lt;br /&gt;&lt;br /&gt;^^ Copy-on-Write. CoW. Geddit?&lt;br /&gt;&lt;br /&gt;So. Since my security scanner revolves around examining each code path in a given program individually, as I&apos;ve discussed previously, I&apos;m in need of some method of &apos;cloning&apos; the process and everything it has, similar to the unix &lt;i&gt;fork()&lt;/i&gt; command. I&apos;m still not 100% sure on exactly what is cloned in a unix &lt;i&gt;fork()&lt;/i&gt;, but I _am_ 100% sure that it won&apos;t be much use in a Windows-based environment, or when I&apos;m cloning instances of an OS.&lt;br /&gt;&lt;br /&gt;The Plan involved using VMWare to do this, taking snapshots at each code branch and duplicating them. This would create a CoW disk image for each branch snapshot - ie, the cost of splitting would be approximately nil for the actual disk image - and would dump current &apos;physical&apos; RAM of the VM in a flat file. The obvious drawback is that it&apos;d require a decent amount of disk traffic as memory is dumped/restored/etc.&lt;br /&gt;&lt;br /&gt;Unfortunately, though, VMware doesn&apos;t support cloning snapshots of a &apos;live&apos; machine. Bummer. GSX server will support something called &apos;templating&apos;, which should, but it isn&apos;t supported by the .net wrapper I&apos;m using for VMWare comms, and it&apos;s unclear if templating will use CoW for the disk images (or indeed, for system RAM). &lt;br /&gt;&lt;br /&gt;The obvious solution is to run VMs from a syste that supports a CoW disk filesystem - like the following:&lt;br /&gt;&lt;br /&gt;Windows VM box -&amp;gt; SAMBA -&amp;gt; Linux file server -&amp;gt; ext3CoW&lt;br /&gt;&lt;br /&gt;Then, I could suspend a VM, causing RAM to be dumped to disk, copy the files, causing the linux box to mark them as empty CoW &apos;shadows&apos;, and then tell the VM box to load the new files as a new VM. It&apos;d be dead simple, but instinctively, I really don&apos;t like this - there&apos;s a million things to go wrong (what if VMWare doesn&apos;t flush stuff to the SAMBA share before I copy? What if SAMBA doesnt flush it to the FS?) and that&apos;s before you get to the possibility of requiring the VM-controlling app executing scripts on the fileserver to manipulate CoW. &lt;br /&gt;&lt;br /&gt;Bit of a bummer, really.&lt;br /&gt;&lt;br /&gt;It&apos;s a shame I&apos;m not some mad l33t code ninja, otherwise I&apos;d grab the source to QEmu, or the like, and hack some &apos;CoW memory&apos; code in. That way, when I wanted my code flow to branch, I could just tell QEmu to freeze the current VM and make two CoW shadow copies of RAM and disk. runtime cost - almost nil.</description>
  <comments>http://gamesfairy.livejournal.com/19965.html</comments>
  <category>security scanner</category>
  <category>cow</category>
  <lj:mood>cheerful</lj:mood>
  <lj:security>public</lj:security>
  <lj:reply-count>0</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://gamesfairy.livejournal.com/19363.html</guid>
  <pubDate>Sun, 12 Jul 2009 20:57:35 GMT</pubDate>
  <title>constraint solver magic</title>
  <link>http://gamesfairy.livejournal.com/19363.html</link>
  <description>Just reading a paper I stumbled across:&lt;br&gt;&lt;br&gt;&lt;i&gt;Abstract&lt;br&gt;The automatic patch-based exploit generation problem is: given a program P and a patched version of the program P&apos;, automatically generate an exploit for the potentially unknown vulnerability present in P but fixed in P&apos;.&lt;/i&gt;&lt;br&gt;&lt;br&gt;Interesting stuff - they&apos;re talking about using STP (or any other constraint solver) to generate &apos;exploits&apos; given a patch for 0day (&lt;a class=&quot;snap_shots&quot; href=&quot;http://www.cs.cmu.edu/%7Edbrumley/pubs/apeg.html&quot;&gt;link&lt;/a&gt;). It&apos;s interesting stuff, and really close to the STP stuff I was postulating around about this time last year.&lt;br&gt;&lt;br&gt;STP is used as the driving force behind my l33t security scanner, hopefully. Interestingly, the STP homepage notes that STP is used by &apos;various government agencies&apos;.. Intreguing.&lt;br&gt;&lt;br&gt;Definite food for thought.</description>
  <comments>http://gamesfairy.livejournal.com/19363.html</comments>
  <category>stp</category>
  <category>security scanner</category>
  <category>exploit generation</category>
  <category>constraint solving</category>
  <category>cvc3</category>
  <lj:security>public</lj:security>
  <lj:reply-count>0</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://gamesfairy.livejournal.com/18987.html</guid>
  <pubDate>Sun, 12 Jul 2009 20:55:06 GMT</pubDate>
  <title>Experiments with the IOS</title>
  <link>http://gamesfairy.livejournal.com/18987.html</link>
  <description>Been reading a lot of stuff online about hax0ring. Came across (the) Silvio&apos;s wordpress blog, which I found a pretty good read - lots of low-level bugfindy stuff. I read an &lt;a class=&quot;snap_shots&quot; href=&quot;http://silviocesare.wordpress.com/2008/07/27/finding-malloc-in-ios/&quot;&gt; entry about searching for double-free bugs in the Cisco IOS via an emulator&lt;/a&gt; and it really got me thinking about stuff - since malloc() is on the CPU (as opposed to any custom hardware) it&apos;d be pretty simple to plop an ICE - hardware debugger/emuator - on a real-life Cisco box and track calls to it (and free()) to look about for heap corruption. Silvio didn&apos;t have much success finding double-free&apos;s, and TBH exploiting something like souble-free on IOS is way above my skill level - but I&apos;m reminded of an old vuln in which you could flood a box with CDP updates and it&apos;d just consume all available RAM and die, and wonder if I should hook up some &apos;network-based fuzzing of an IRL router with an ICE hooked up to log malloc/free calls&apos;. &lt;br&gt;&lt;br&gt;* Had a really fucking awesome idea while I was in the shower last night, around the topic of the security scanner. It sounds batshit insane, so I&apos;m not totally sure it&apos;ll work yet, and thus reluctant to post about it (and I don&apos;t want naughty hax0rs stealing my ideas). &lt;br&gt;&lt;br&gt;* Work on the security scanner is fairly solid. A few people I could find online have implemented scanners around the same kind of idea, but they&apos;re mostly &apos;mad ninjas&apos;. I&apos;m hoping that, once I&apos;ve got the scanner up, I can tweak and hax0r it to reveal classes of vuln that other people haven&apos;t (and use my batshit ninja idea from the above point)</description>
  <comments>http://gamesfairy.livejournal.com/18987.html</comments>
  <category>cisco</category>
  <category>ios</category>
  <category>security scanner</category>
  <lj:security>public</lj:security>
  <lj:reply-count>0</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://gamesfairy.livejournal.com/18722.html</guid>
  <pubDate>Sun, 12 Jul 2009 20:54:10 GMT</pubDate>
  <title>Cisco box probing</title>
  <link>http://gamesfairy.livejournal.com/18722.html</link>
  <description>Popped open a Cisco 2500-series router yesterday and attached loads of probes to the memory DIMM, in the hope that I could turn CPU caching off and use it to observe malloc() and free() calls natively. Ignoring the &apos;oh crap&apos; moment where I miswired one of the GND pins to VCC (and melted one of my test clips), I suddenly realised that it&apos;s pretty much impossible to pick out genuine DRAM access from the DRAM refresh cycles (Which I&apos;d somehow forgotten about). It&apos;d be a better idea, I think, to probe directly at the host CPU, but it&apos;s a QFP (CQFP to be exact) and the pins are too closely spaced for my test probes. I don&apos;t have a test clip for QFP-132, and they are fairly expensive, so perhaps I should trace out the board it&apos;s on and attach probes to test points or even the DRAM controller, if it&apos;s not also QFP. Does anyone know much about the M68K (68030 to be exact?) AFAICT there&apos;s no hardware debug support (am I right?) unless you get an ICE, and msot people debug via a GDB target (trivia for today: &lt;a href=&quot;http://www.xfocus.net/articles/200307/583.html&quot;&gt;the production IOS has a minimal GDB stub!&lt;/a&gt;)&lt;br /&gt;&lt;br /&gt;Work on the security scanner is slow but steady. A lot of time is taken up by me implementing what basically amounts to an x86 emulator on x86. Still can&apos;t work out why my &apos;ninja idea&apos; won&apos;t work. I might try it later, but it&apos;s the kind of thing that&apos;ll only really be relevant once the project is at a much later point than it is now.</description>
  <comments>http://gamesfairy.livejournal.com/18722.html</comments>
  <category>cisco</category>
  <category>ios</category>
  <category>security scanner</category>
  <lj:security>public</lj:security>
  <lj:reply-count>0</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://gamesfairy.livejournal.com/18570.html</guid>
  <pubDate>Sun, 12 Jul 2009 20:51:15 GMT</pubDate>
  <title>Security scanner minddump</title>
  <link>http://gamesfairy.livejournal.com/18570.html</link>
  <description>Am sleepy but incredibly good. This is quite possibly the best way to be.&lt;br&gt;&lt;br&gt;So, I promised some coherent explanation of the key parts of the security scanner last night! I&apos;ve got this, which I&apos;ve just scribbled now. It&apos;s not too clear, so don&apos;t be afraid to comment asking me for vital details I&apos;ve forgotten about.&lt;br&gt;&lt;br&gt;The heart of the scanner lies in constraint solving. Essentially, you take a given set of instructions and track how they affect memory/registers. For example, check out the following sequence:&lt;br&gt;&lt;br&gt;1 : CALL someApiFunctionThatGetsDataToEAX&lt;br&gt;2 : PUSH EAX&lt;br&gt;3 : RET&lt;br&gt;&lt;br&gt;From this we infer the following:&lt;br&gt;&lt;br&gt;1 : At this point, EAX is &apos;anything&apos;.&lt;br&gt;2 : At this point, memory location pointed to by ESP is &apos;anything&apos;.&lt;br&gt;3 : At this point, EIP is &apos;anything&apos;.&lt;br&gt;&lt;br&gt;From 10,000 feet, that&apos;s all there is to it. You track what&apos;s going on, and examine for certain desirable conditions (eg, EIP is user-controlled).&lt;br&gt;&lt;br&gt;Of course, there&apos;s a lot more to it than this. You&apos;ll notice my caveat &apos;at this point&apos; in the above sequence. I&apos;m not going to dwell of the simple stuff like that; I&apos;m just going to dive straight in to the non-obvious bits.&lt;br&gt;&lt;br&gt;I use an external constraint solver, &lt;a href=&quot;http://www.cs.nyu.edu/acsys/cvc3/&quot;&gt;CVC3&lt;/a&gt;, to do the &apos;maths magic&apos; for me. It can tell me if things are &apos;satisfiable&apos;, for example:&lt;br&gt;&lt;br&gt;a = 13 ; b = 12 is satisfiable, but&lt;br&gt;a = 13 ; a = 12 is not, as &apos;a&apos; cannot be both 12 and 13.&lt;br&gt;&lt;br&gt;It can also simplify equations down - eg, &quot;A XOR B XOR B XOR 10&quot; becomes &quot;A XOR 10&quot;. &lt;br&gt;&lt;br&gt;Constraint solving is magic, and I borrow from work done at Standord by a load of dudes (Cristian Cadar , Vijay Ganesh , Peter M. Pawlowski , David L. Dill , Dawson R. Engler), published in the paper &apos;EXE: Automatically generating inputs of death&apos; and a couple of other papers I&apos;ve linked on this here blog. The &lt;a href=&quot;http://www.stanford.edu/%7Eengler/exe-ccs-06.pdf&quot;&gt;EXE paper&lt;/a&gt; is recommended if you&apos;re interested in this stuff.&lt;br&gt;&lt;br&gt;&lt;b&gt;Assumptions&lt;/b&gt;&lt;br&gt;&lt;br&gt;Since it is dog-slow to examine each instruction, we make some assumptions.&lt;br&gt;&lt;br&gt;1) The program, OS, and everything, is totally deterministic (see later on about malloc).&lt;br&gt;&lt;br&gt;2) We can disregard all instructions which are not affected by user input (for example, that obtained via Recv()). Because of this, we can simply breakpoint functions that pull in user input, and set our program executing. We don&apos;t care what it does, as long as it isn&apos;t in response to input from an untrusted user. When there is no untrusted data in memory or registers, then there is no point examining instructions - so we can just execute our process, and wait for it to call Recv(), or whatever. At that point we resume examination. This is sort-of-similar to EXE, I think? EXE approaches the problem differently, by instrumenting the target binary.&lt;br&gt;&lt;br&gt;&lt;b&gt;Conditional jumps&lt;/b&gt;&lt;br&gt;&lt;br&gt;Conditional jumps which depend on user-input data cannot be resolved without applying artificial constraints to the user-supplied data. Consider:&lt;br&gt;&lt;br&gt;1 : CALL someApiFunctionThatGetsDataToEAX&lt;br&gt;2 : JZ foo&lt;br&gt;3 : xor EAX, 0x20&lt;br&gt;4 : jmp end&lt;br&gt;foo: &lt;br&gt;5 : xor EAX, 0x10&lt;br&gt;end:&lt;br&gt;&lt;br&gt;How do we tackle this? Is EAX equal to &apos;the input byte XOR 0x10&apos; or &apos;the input byte XOR 0x20&apos; (or something else)?&lt;br&gt;The original EXE paper runs under unix, and creates two copies of itself, and defines one copy to have Z=1 and one copy to have Z=0. Two paths are examined:&lt;br&gt;&lt;br&gt;1 : CALL someApiFunctionThatGetsDataToEAX&lt;br&gt;2 : JZ foo (starts processes)&lt;br&gt;&lt;br&gt;(process 1)&lt;br&gt; (implicit inference: EAX != 0)&lt;br&gt;3 : xor EAX, 0x20&lt;br&gt;4 : jmp end&lt;br&gt;&lt;br&gt;(process 2)&lt;br&gt; (implicit inference: EAX == 0)&lt;br&gt;5 : xor EAX, 0x10&lt;br&gt;end:&lt;br&gt;&lt;br&gt;EXE observes that EAX can either be &apos;unconstrainted XOR 0x20&apos; or &apos;0 xor 10&apos;. Awesome. &lt;br&gt;&lt;br&gt;This isn&apos;t really practical on a win32 system, though. You end up giving the target process room for change in between runs, breaking the determinsm. Obvious stuff like the PID changes, but more subtly all malloc()&apos;ed address will be different and could even conceivably be in a totally different order - so the constraints we applied to constrained memory will point to completely different locations!) This is No Good.&lt;br&gt;We could do some Valgrind-esque tracking of memory blocks, but we end up slowing everything else down and generally making everything suck.&lt;br&gt;&lt;br&gt;The way I&apos;m going to attack this is to have a full VM for each run. Every time a conditional jump is reached, two VMs will be used to examine each trace. This will greatly help (although not totally solve) issues of determinism and repeatability. Obviously, it&apos;ll be slow to start up each VM shapshot (and we obviously want to snapshot, and not boot fresh every time), but it conveniently helps with another problem - scalability. I can simply dedicate a VMWare cloud to the thing, write some network-aware code, and it&apos;ll cluster really well. Adding and removing VMs could conceivably be done even mid-run, or via a WAN link, or even in rented CPU time on some supercomputer somewhere. VMWare, I think, solves enough issues that the startup performance hit is worth it.&lt;br&gt;&lt;br&gt;&lt;b&gt;Jump tables&lt;/b&gt;&lt;br&gt;&lt;br&gt;Consider the following C:&lt;br&gt;&lt;br&gt;switch(someApiFunctionThatReturnsData)&lt;br&gt;{&lt;br&gt; case 1:&lt;br&gt;  ..&lt;br&gt; case 2:&lt;br&gt;  ..&lt;br&gt;}&lt;br&gt;&lt;br&gt;and the generated asm (not actual legal x86 asm, but you get the idea)&lt;br&gt;&lt;br&gt;1 : CALL someApiFunctionThatGetsDataToEAX&lt;br&gt;2 : AND EAX, 0x000000FF&lt;br&gt;3 : MUL EAX, 0x10&lt;br&gt;4 : ADD EAX, EIP&lt;br&gt;5 : JMP EAX&lt;br&gt;...&lt;br&gt;16 : {case 1 asm}&lt;br&gt;...&lt;br&gt;27 : {case 2 asm}&lt;br&gt;...&lt;br&gt;&lt;br&gt;(this asm is horribly contrived and buggy, but it gets my point across!)&lt;br&gt;&lt;br&gt;Now. How on earth can we simulate this? The scanner simply knows:&lt;br&gt;&lt;br&gt;* EIP = (((input data&amp;amp;0xff)*10)+previous_eip&lt;br&gt;* previous_eip = 5&lt;br&gt;&lt;br&gt;How on earth do we find out where the code will branch to in a non-highlevel-dependent, arch-independent way?&lt;br&gt;&lt;br&gt;.. I think I&apos;ve solved this, but I&apos;m not going to tell. I&apos;m holding on to this one! If you want to work it out and comment, or ask me, I&apos;ll tell you if it&apos;s how I plan to do it!&lt;br&gt;&lt;br&gt;&lt;b&gt;Other stuff&lt;/b&gt;&lt;br&gt;&lt;br&gt;I&apos;ve got a whiteboard full of stuff to implement and problems to solve. I&apos;m really looking forward to it.</description>
  <comments>http://gamesfairy.livejournal.com/18570.html</comments>
  <category>stp</category>
  <category>exe</category>
  <category>security scanner</category>
  <category>constraint solving</category>
  <category>cvc3</category>
  <category>ida</category>
  <lj:security>public</lj:security>
  <lj:reply-count>0</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://gamesfairy.livejournal.com/18273.html</guid>
  <pubDate>Sun, 12 Jul 2009 20:50:05 GMT</pubDate>
  <link>http://gamesfairy.livejournal.com/18273.html</link>
  <description>So yeah. Am forging onward with the security scanner. I worked out a way of adding a &apos;self-test&apos; mode to it the other day, which tests (to some extent) the simulation of each instruction. I got that working today, and found some really, really obvious bugs (ie &quot;how on earth can PUSH work if you have no support for subtraction of pointers?!&quot;) which I was able to zone in on fairly quickly.&lt;br /&gt;&lt;br /&gt;The only problem is that it&apos;s damn slow. I could optimise it by only verifying effects to a subset of registers (ie, I could chop off the FPU regs right away, since I don&apos;t support the FPU at all) but I still end up running the solver many times per instruction. At the moment I shell out for each solver run, incurring the huge createProcess delay, which was a design decision mainly so I can bolt on some load-balancing stuff really easily. It looks like it wasn&apos;t the best decision, though, and I might move to in-process solving instead. Not totally sure on this one, and I won&apos;t change anything yet - first, I want to have planned a fairly coherent caching/load balancing system that I can just slot it in to.&lt;br /&gt;&lt;br /&gt;Speaking of which, yeah. Thinking of doing some mysql+php stuff to make a diddly little caching server.. not sure, though, since I absolutely suck at SQL and don&apos;t know much php beyond the phpinfo(). .Net and c# is my usual for webdevvy stuff, but I think that&apos;d be pretty overkill for what I need it for.&lt;br /&gt;&lt;br /&gt;Oh, I also realised that over the past few days, I&apos;ve accidentally implimented &apos;lazy flags&apos; (ie, you don&apos;t work out the flags, such as ZERO, until you find an instruction that needs them, like JNZ). This is nice. I like it when stuff just slots together like that.&lt;br /&gt;&lt;br /&gt;Code is awesome.</description>
  <comments>http://gamesfairy.livejournal.com/18273.html</comments>
  <category>security scanner</category>
  <lj:security>public</lj:security>
  <lj:reply-count>0</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://gamesfairy.livejournal.com/18024.html</guid>
  <pubDate>Sun, 12 Jul 2009 20:49:24 GMT</pubDate>
  <title>CBC weaknesses</title>
  <link>http://gamesfairy.livejournal.com/18024.html</link>
  <description>I can&apos;t remember if I posted about this before, but I found &lt;a href=&quot;http://chargen.matasano.com/chargen/2009/7/22/if-youre-typing-the-letters-a-e-s-into-your-code-youre-doing.html&quot;&gt;this article&lt;/a&gt; at matasano on crypto really interesting (if a bitch to read). It&apos;s all about carefully breaking CBC-mode crypto by fucking about with selectively corrupting blocks.&lt;br /&gt;&lt;br /&gt;Best quote: Turns out, I can make the cookie say whatever I want. It’s a property of CBC.&lt;br /&gt;&lt;br /&gt;It&apos;s a really good read, but if you&apos;re anything like me, you&apos;ll need to read it three times then have a good think about it before you get it. Crypto really fucks with my head.</description>
  <comments>http://gamesfairy.livejournal.com/18024.html</comments>
  <category>aes</category>
  <category>crypto</category>
  <category>cbc</category>
  <lj:security>public</lj:security>
  <lj:reply-count>0</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://gamesfairy.livejournal.com/17713.html</guid>
  <pubDate>Sun, 12 Jul 2009 20:43:09 GMT</pubDate>
  <title>C-style varargs - WTF LOL</title>
  <link>http://gamesfairy.livejournal.com/17713.html</link>
  <description>So. C-style varargs.&lt;br /&gt;&lt;br /&gt;All C coders know them. They&apos;re the magic that lets you &quot;printf(&quot; %s is cool&quot;, name);&quot;. Variable-length argument strings. Anyone know how they&apos;re implemented? I didn&apos;t until I read up on it. I guessed - and happened to be right - but the full horror of the details didn&apos;t hit me until later.&lt;br /&gt;&lt;br /&gt;So. You have your function.&lt;br /&gt;&lt;br /&gt;tellTheUser(char* fmt, ...) {}&lt;br /&gt;&lt;br /&gt;You use some magic compiler macros to pull stuff off your vararg list, and you call it such.&lt;br /&gt;&lt;br /&gt;tellTheUser(&quot;%d is my fave number&quot;, 3);&lt;br /&gt;&lt;br /&gt;The compiler will set up a two-argument call. Awesome. But think about this - to do this, it needs to know, at compile-time, how many arguments are in the list. So you can&apos;t call your function with a variable number of arguments, strictly speaking - the number of arguments must be determined at compile-time. This doesn&apos;t sound like a major problem, right?&lt;br /&gt;&lt;br /&gt;Wrong.&lt;br /&gt;&lt;br /&gt;This evening, I decided to write a wrapper around a vararg function that IDA exports, &apos;err(..)&apos;.&lt;br /&gt;This function takes some printf-style args, displays a messagebox with them, then exits IDA. However, I want unattended testbenches to run - so I don&apos;t want the messagebox. &quot;No problem,&quot; I thought, &quot;I&apos;ll just wrap err(..)&quot;.&lt;br /&gt;&lt;br /&gt;No. You can&apos;t do that (without inline asm/etc).&lt;br /&gt;&lt;br /&gt;You really do have no way (in hell) of calling the vararg function with compile-time variable arguments. So you, quite simply, can&apos;t. Life&apos;s a bitch. The best I can come up with is to count the arguments, then switch() on the arg count, and execute a line based on that. Like this:&lt;br /&gt;&lt;br /&gt;ulong main::throwError(char* fmt, ... )&lt;br /&gt;{&lt;br /&gt;ulong args[20];&lt;br /&gt;ulong argCnt = 0;&lt;br /&gt;ulong i;&lt;br /&gt;&lt;br /&gt;va_list myVA;&lt;br /&gt;va_start(myVA, fmt);&lt;br /&gt;i = (ulong)fmt;&lt;br /&gt;while( i != -1 &amp;&amp; argCnt&amp;lt;20 )&lt;br /&gt;{&lt;br /&gt;i = va_arg( myVA, ulong);&lt;br /&gt;args[argCnt] = (ulong)i;&lt;br /&gt;argCnt++;&lt;br /&gt;}&lt;br /&gt;va_end(myVA);&lt;br /&gt;argCnt-=2;&lt;br /&gt;&lt;br /&gt;char error[1024];&lt;br /&gt;switch(argCnt)&lt;br /&gt;{&lt;br /&gt;case(0):&lt;br /&gt;qsnprintf(error, 1024, fmt);&lt;br /&gt;case(1):&lt;br /&gt;qsnprintf(error, 1024, fmt, args[0]);&lt;br /&gt;case(2):&lt;br /&gt;qsnprintf(error, 1024, fmt, args[0], args[1]);&lt;br /&gt;case(3):&lt;br /&gt;qsnprintf(error, 1024, fmt, args[0], args[1], args[2]);&lt;br /&gt;case(4):&lt;br /&gt;qsnprintf(error, 1024, fmt, args[0], args[1], args[2], args[3]);&lt;br /&gt;default:&lt;br /&gt;// handle error somehow&lt;br /&gt;}&lt;br /&gt;dosomeloggingstuff(error);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;A zillion drawbacks, like the hardcoded limit on args, but this is a lot cleaner than my original implementation. I&apos;m going to quote the following, leave the rest to your imagination and horror, and leave it at that.&lt;br /&gt;&lt;br /&gt;static ulong main::throwError(char* fmt, ulong arg1=NULL, ulong arg2=NULL, ulong arg3=NULL, ulong arg4=NULL, ulong arg5=NULL, ulong arg6=NULL, ulong arg7=NULL, ulong arg8=NULL, ulong arg9=NULL, ulong arg10=NULL );&lt;br /&gt;...&lt;br /&gt;else if (arg7==NULL)&lt;br /&gt;qsnprintf(error, 1024, fmt, arg1, arg2, arg3, arg4, arg5, arg6);&lt;br /&gt;...&lt;br /&gt;It was NOT PRETTY.&lt;br /&gt;&lt;br /&gt;I didn&apos;t even dare _look_ at the forum entry I found while googling about P/Invoking a varargs-style function.&lt;br /&gt;&lt;br /&gt;If you have a better solution, which doesn&apos;t involve inline asm (I&apos;m really not up to making my code that platform specific (and unstable, knowing my asm)), I&apos;d be simply delighted to know it..&lt;br /&gt;&lt;br /&gt;(as a postscript - the &apos;while( i != -1)&apos; makes me wonder wtf happens if I call a vararg function with a parameter of -1.. )</description>
  <comments>http://gamesfairy.livejournal.com/17713.html</comments>
  <category>ouch</category>
  <category>horror</category>
  <category>what the shit</category>
  <category>pain</category>
  <category>c</category>
  <category>code</category>
  <lj:security>public</lj:security>
  <lj:reply-count>0</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://gamesfairy.livejournal.com/17572.html</guid>
  <pubDate>Thu, 28 May 2009 02:11:42 GMT</pubDate>
  <link>http://gamesfairy.livejournal.com/17572.html</link>
  <description>Right, University term has ended, and I want to get some serious progress with lavalamp. Here&apos;s hoping. A summary of the night&apos;s work:&lt;br /&gt;&lt;br /&gt;* Am intended to add support for Zigbee, via the Microchip MRF24J40 2.4Ghz transceiver. This may well require that I rewrite a lot of PIC-side code, but I think it&apos;ll be worth it, since the wireless layer I wrote isn&apos;t particularly great, and using Zigbee opens the door for some cool interoperability. It does, however, require quite a beefy PIC chip to run the software stack.&lt;br /&gt;&lt;br /&gt;* I&apos;m using a PIC18F46&lt;b&gt;K&lt;/b&gt;20, instead of an PIC18F4620, mainly because it&apos;s cheaper (and more powerful). Hopefully I can make it work. I had to make the following changes to the example code (the co-ordinator project) to change microcontroller:&lt;br /&gt;&lt;br /&gt;- in zLink.lkr, the linker script, change&lt;br /&gt;&lt;br /&gt;&lt;i&gt;DATABANK   NAME=gpr0       START=0x0060         END=0x00FF&lt;/i&gt;&lt;br /&gt;to&lt;br /&gt;&lt;i&gt;DATABANK   NAME=gpr0       START=0x00&lt;b&gt;8&lt;/b&gt;0         END=0x00FF&lt;/i&gt;&lt;br /&gt;(since bank 1 GPRs start at 0x80 and not 0x60)&lt;br /&gt;&lt;br /&gt;and&lt;br /&gt;&lt;br /&gt;&lt;i&gt;DATABANK   NAME=gpr15      START=0x0F00         END=0x0F7F&lt;br /&gt;ACCESSBANK NAME=accesssfr  START=0x0F80         END=0x0FFF         PROTECTED&lt;/i&gt;&lt;br /&gt;to&lt;br /&gt;&lt;i&gt;DATABANK   NAME=gpr15      START=0x0F00         END=0x0F&lt;b&gt;5&lt;/b&gt;F&lt;br /&gt;ACCESSBANK NAME=accesssfr  START=0x0F&lt;b&gt;6&lt;/b&gt;0         END=0x0FFF         PROTECTED&lt;/i&gt;&lt;br /&gt;(since bank 15 GPRs start at 0x0F5F and not 0x0F7F, and SFRs start at 0x0F60.)&lt;br /&gt;&lt;br /&gt;also change&lt;br /&gt;&lt;i&gt;FILES p18f4620.lib&lt;/i&gt;&lt;br /&gt;to&lt;br /&gt;&lt;i&gt;FILES p18f46&lt;b&gt;K&lt;/b&gt;20.lib&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;- In zNVM.c, change&lt;br /&gt;&lt;br /&gt;&lt;i&gt;#if defined(__18F4620) &amp;amp;&amp;amp; !defined(USE_EXTERNAL_NVM)&lt;/i&gt;&lt;br /&gt;to&lt;br /&gt;&lt;i&gt;#if (defined(__18F4620) || defined(__18F46K20)) &amp;amp;&amp;amp; !defined(USE_EXTERNAL_NVM)&lt;/i&gt;&lt;br /&gt;&lt;br /&gt; - and similarly, in zigbee.def&lt;br /&gt;&lt;br /&gt;&lt;i&gt;#if !defined(__18F4620)&lt;/i&gt;&lt;br /&gt;to&lt;br /&gt;&lt;i&gt;#if (!defined(__18F4620) &amp;amp;&amp;amp; !defined(__18F46K20))&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;I just &lt;b&gt;know&lt;/b&gt; this info will be useful to someone!&lt;br /&gt;&lt;br /&gt;* My ICD2 warned me that Vpp was going to go too high for the device. I put a ~8V zener across it, under recommendation from The Internet, and it seems to work.&lt;br /&gt;&lt;br /&gt;* I realised that the PIC18F46K20 is a 3.3V device, sometime after applying 5V to it. Ooops.&lt;br /&gt;&lt;br /&gt;* I realised that the three-pin 3V3 regulators I have aren&apos;t 7805-pinout&apos;ed, after neglecting to read their part numbers and hooking them up as if they were. Burnt my finger.&lt;br /&gt;&lt;br /&gt;* Realised that having a pluggable &apos;transport&apos; layer in lavalamp would be a really damn good idea, as then I can make a &apos;simple cabled&apos; transport (probs SPI/ttl-level rs232 or the like) for simple stuff, a &apos;lavalamp native&apos; transport (the one I have been working on to run over any RF Tx/Rx, which currently needs a lot of work) and &apos;Zigbee&apos; for running Zigbee via the Microchip transcievers. This&apos;d be a lot better than my current design, which has little abstraction between the transport layer and those above.</description>
  <comments>http://gamesfairy.livejournal.com/17572.html</comments>
  <lj:security>public</lj:security>
  <lj:reply-count>0</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://gamesfairy.livejournal.com/17355.html</guid>
  <pubDate>Thu, 15 Jan 2009 09:01:10 GMT</pubDate>
  <title>Videos of recent Uni work</title>
  <link>http://gamesfairy.livejournal.com/17355.html</link>
  <description>Since it&apos;s the end of Semester 1 at Uni, a couple of projects have been coming to a close. I thought I&apos;d post some videos of them running.&lt;br /&gt;&lt;br /&gt;&lt;lj-embed id=&quot;1&quot; /&gt;&lt;br /&gt;&lt;br /&gt;First up is the above, an interface from the Universities&apos; leaning environment - a load of HTML in an education-targetted CMS named BlackBoard - in to Second Life. Unfortunately, the version of BlackBoard used by the Uni doesn&apos;t make any nice data feeds available, so most of the hard work is &apos;screen scaping&apos; the relevant data out of pages. Because most of the work went in to this, I didn&apos;t get to experiment much with new-paradigm UIs - the above is the result of 12 weeks of code (!!).&lt;br /&gt;Each module the student is taking is represented by an orb, which (when clicked) tells the student any new announcements that have been posted to that module.&lt;br /&gt;&lt;br /&gt;&lt;lj-embed id=&quot;2&quot; /&gt;&lt;br /&gt;&lt;i&gt;(click &lt;a href=&quot;http://gamesfairy.co.uk/xteademo-edited-compressed.swf&quot; target=&quot;lol&quot;&gt;here&lt;/a&gt; to open the video in a new window&lt;/i&gt;&lt;br /&gt;Above is the fun one - a demo of my crypto accelerator. It&apos;s a fairly undramatic demo, but it represents, again, around 12 weeks of work. The accelerator is configured to crypt using XTEA at 32 rounds, and fed with some test data which it encrypts and then decrypts. Pay no attention to the timestamps - this is a fairly early and unoptimised version of the design. Things should be faster later on.</description>
  <comments>http://gamesfairy.livejournal.com/17355.html</comments>
  <lj:security>public</lj:security>
  <lj:reply-count>0</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://gamesfairy.livejournal.com/17016.html</guid>
  <pubDate>Sun, 28 Dec 2008 04:49:40 GMT</pubDate>
  <link>http://gamesfairy.livejournal.com/17016.html</link>
  <description>I recently threw together a small compute cluster from some spare parts I had. It comprises five Pentium 3 chips, clocked at 1Ghz, and one mobile P4 clocked at 1.4Ghz. Each has a relatively small amount of RAM - around the 64MB mark - mainly because I don&apos;t have more lying around.&lt;br /&gt;&lt;br /&gt;The cluster boots via a modified version of (the rather excellent) LTSP environment. Each node is diskless, and boots via PXE, downloads a kernel/initrd, and mounts root via NFS. Obviously, disk access is slow in this configuration (compounded by the fact that the &apos;server&apos; machine runs IDE disks, at UDMA 66) but it kicks out relatively little heat and chomps relatively little power. Each node can be powered on via WoL - important since the cluster is stored away from my house, making physical maintainence hard. There&apos;s a MOSIX kernel compiled, but not set up properly, as I don&apos;t need MOSIX yet. It&apos;s a shame that openMosix died (although great that I can get a student license of MOSIX!)&lt;br /&gt;&lt;br /&gt;Anyway, one thing that the cluster is configured for is to use distcc, a distributed C compiler. There is some discussion over the optimum number of C programs to compile in parallel (the &apos;-j&apos; flag as passed to &apos;make&apos;) and so I thought I&apos;d run some investigation.&lt;br /&gt;I took a vanilla 2.6.27-10 kernel, ran &lt;i&gt;make defconfig&lt;/i&gt;, and then ran &lt;i&gt;make CC=distcc HOSTCC=distcc -j $j&lt;/i&gt;, where $j ranged from 1 to 10. The results were interesting, shown below:&lt;br /&gt;&lt;br /&gt;&lt;img src=&quot;http://i41.tinypic.com/15mll42.jpg&quot;&gt;&lt;br /&gt;&lt;br /&gt;These results were taken when the cluster comprised of four PIII 1GHz chips, with around 64 or 128MB memory per node. distcc was configured not to use the server machine as a compilation host (any more than was neccesary).&lt;br /&gt;&lt;br /&gt;We can clearly see that 6-8 parallel processes is optimum - taking 15 minutes to compile the kernel. The elevated time at 5 is possibly a freak value, and values above 8 are probably the result of network congestion.&lt;br /&gt;&lt;br /&gt;So there you have it - for a five node NFS-root no-swap low-memory p3-1Ghz cluster, use -j 7 :D&lt;br /&gt;&lt;br /&gt;Hope this post is useful for someone. Please leave a comment if it is, or comment just if you think I&apos;m wrong!</description>
  <comments>http://gamesfairy.livejournal.com/17016.html</comments>
  <lj:security>public</lj:security>
  <lj:reply-count>0</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://gamesfairy.livejournal.com/16736.html</guid>
  <pubDate>Sat, 20 Dec 2008 16:13:39 GMT</pubDate>
  <link>http://gamesfairy.livejournal.com/16736.html</link>
  <description>Really silly problem I just spent a good three hours figuring out, just posted here in case anyone else has a similar problem:&lt;br /&gt;&lt;br /&gt;Situation was that I was booting diskless clients via TFTP/NFS root (ie, using LTSP). They&apos;re debian workstations. In order to get WoL working, I built a new kernel, pruned it (over-enthusiastically) and broke something.&lt;br /&gt;&lt;br /&gt;Symtoms were that:&lt;br /&gt;&lt;br /&gt;* No TTY open on the machine console&lt;br /&gt;* SSH reports &quot;sshdPRNG is not seeded&quot;&lt;br /&gt;* X didn&apos;t start&lt;br /&gt;&lt;br /&gt;I scratched my head for ages, verifying that /dev/random and /dev/urandom were present, twiddling .config options, verifying that random.c was being compiled, etc. All the TTY options were present/enabled. Further up the kernel logs was the warning that /dev/mem was not found, which was bizarre, since all that was enabled, too.&lt;br /&gt;&lt;br /&gt;Now, I have no idea how - but I had disabled UNIX domain sockets. &lt;b&gt;D&apos;OH&lt;/b&gt;!</description>
  <comments>http://gamesfairy.livejournal.com/16736.html</comments>
  <lj:mood>D&apos;OH</lj:mood>
  <lj:security>public</lj:security>
  <lj:reply-count>3</lj:reply-count>
</item>
</channel>
</rss>
