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

<channel>
	<title>AXOT&#039;s BLOG</title>
	<atom:link href="http://www.axot.org/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.axot.org</link>
	<description></description>
	<lastBuildDate>Sun, 20 May 2012 02:38:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>How to resolve _rb_Digest_MD5_Finish error in Ruby 1.9.x</title>
		<link>http://www.axot.org/2012/05/01/how-to-resolve-_rb_digest_md5_finish-error-in-ruby-1-9-3/</link>
		<comments>http://www.axot.org/2012/05/01/how-to-resolve-_rb_digest_md5_finish-error-in-ruby-1-9-3/#comments</comments>
		<pubDate>Mon, 30 Apr 2012 18:50:50 +0000</pubDate>
		<dc:creator>axot</dc:creator>
				<category><![CDATA[Misc]]></category>
		<category><![CDATA[Mac OSX]]></category>
		<category><![CDATA[Metasploit]]></category>
		<category><![CDATA[Ruby 1.9.3]]></category>
		<category><![CDATA[RVM]]></category>

		<guid isPermaLink="false">http://www.axot.org/?p=36</guid>
		<description><![CDATA[When I am setting up Metasploit for Mac OSX, ruby 1.9.3 throw out a _rb_Digest_MD5_Finish error.
It seems only happend when you use RVM to manage rubies.

The Makefile in each subdirectory of $HOME/.rvm/src/ruby-1.9.*/ext/digest need be patched.
I don&#8217;t know how to use RVM to install a custom Ruby  [...]]]></description>
			<content:encoded><![CDATA[<p>When I am setting up Metasploit for Mac OSX, ruby 1.9.3 throw out a _rb_Digest_MD5_Finish error.<br />
It seems only happend when you use RVM to manage rubies.<br />
<span id="more-36"></span><br />
The Makefile in each subdirectory of $HOME/.rvm/src/ruby-1.9.*/ext/digest need be patched.<br />
I don&#8217;t know how to use RVM to install a custom Ruby version, so I made a simple shell script to do that.</p>
<p>ruby1.9.x_patch.sh(test passed on OSX 10.7.3 x86_64 version):</p>
<pre class="brush: bash; title: ; notranslate">
#!/bin/sh

cat &gt; '/tmp/sha1_patch' &lt;&lt; EOF
--- Makefile.default	2012-05-01 02:59:29.000000000 +0900
+++ Makefile	2012-05-01 02:59:46.000000000 +0900
@@ -117,8 +117,8 @@
 target_prefix = /digest
 LOCAL_LIBS =
 LIBS = \$(LIBRUBYARG_SHARED) -lcrypto  -lpthread -ldl -lobjc
-SRCS = sha1init.c sha1ossl.c
-OBJS = sha1init.o sha1ossl.o
+SRCS = sha1init.c sha1ossl.c sha1.c
+OBJS = sha1init.o sha1ossl.o sha1.o
 TARGET = sha1
 DLLIB = \$(TARGET).bundle
 EXTSTATIC =
EOF

cat &gt; '/tmp/sha2_patch' &lt;&lt; EOF
--- Makefile	2012-05-01 02:58:16.000000000 +0900
+++ Makefile.default	2012-05-01 03:06:01.000000000 +0900
@@ -117,8 +117,8 @@
 target_prefix = /digest
 LOCAL_LIBS =
 LIBS = \$(LIBRUBYARG_SHARED) -lcrypto  -lpthread -ldl -lobjc
-SRCS = sha2init.c sha2ossl.c
-OBJS = sha2init.o sha2ossl.o
+SRCS = sha2init.c sha2ossl.c sha2.c
+OBJS = sha2init.o sha2ossl.o sha2.o
 TARGET = sha2
 DLLIB = \$(TARGET).bundle
 EXTSTATIC =
EOF

cat &gt; '/tmp/md5_patch' &lt;&lt; EOF
--- Makefile	2012-05-01 02:58:15.000000000 +0900
+++ Makefile.default	2012-05-01 03:07:17.000000000 +0900
@@ -117,8 +117,8 @@
 target_prefix = /digest
 LOCAL_LIBS =
 LIBS = \$(LIBRUBYARG_SHARED) -lcrypto  -lpthread -ldl -lobjc
-SRCS = md5init.c md5ossl.c
-OBJS = md5init.o md5ossl.o
+SRCS = md5init.c md5ossl.c md5.c
+OBJS = md5init.o md5ossl.o md5.o
 TARGET = md5
 DLLIB = \$(TARGET).bundle
 EXTSTATIC =
EOF

cat &gt; '/tmp/rmd160_patch' &lt;&lt; EOF
--- Makefile	2012-05-01 02:58:15.000000000 +0900
+++ Makefile.default	2012-05-01 03:08:23.000000000 +0900
@@ -117,8 +117,8 @@
 target_prefix = /digest
 LOCAL_LIBS =
 LIBS = \$(LIBRUBYARG_SHARED) -lcrypto  -lpthread -ldl -lobjc
-SRCS = rmd160init.c rmd160ossl.c
-OBJS = rmd160init.o rmd160ossl.o
+SRCS = rmd160init.c rmd160ossl.c rmd160.c
+OBJS = rmd160init.o rmd160ossl.o rmd160.o
 TARGET = rmd160
 DLLIB = \$(TARGET).bundle
 EXTSTATIC =
EOF

cd $HOME/.rvm/src/ruby-1.9.*/ext/digest/sha1
patch -p0 &lt; '/tmp/sha1_patch'
make clean
make

cd ../sha2
patch -p0 &lt; '/tmp/sha2_patch'
make clean
make

cd ../md5
patch -p0 &lt; '/tmp/md5_patch'
make clean
make

cd ../rmd160
patch -p0 &lt; '/tmp/rmd160_patch'
make clean
make

cp ../../../.ext/x86_64-darwin11.3.0/digest/*.bundle ../../../../../rubies/ruby-1.9.*/lib/ruby/1.9.1/x86_64-darwin11.3.0/digest/
</pre>
<p>Usage example:</p>
<pre class="brush: bash; title: ; notranslate">
rvm cleanup all
rvm uninstall 1.9.3
rvm install 1.9.3
rvm reload
sh ./ruby1.9.x_patch.sh
rvm use 1.9.3
# test something whatever u want to
# for metasploit:
# msfrpcd -P password -U username
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.axot.org/2012/05/01/how-to-resolve-_rb_digest_md5_finish-error-in-ruby-1-9-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>My cydia repo</title>
		<link>http://www.axot.org/2012/02/10/cydia-repo/</link>
		<comments>http://www.axot.org/2012/02/10/cydia-repo/#comments</comments>
		<pubDate>Fri, 10 Feb 2012 09:08:31 +0000</pubDate>
		<dc:creator>axot</dc:creator>
				<category><![CDATA[iOS]]></category>
		<category><![CDATA[Cydia]]></category>
		<category><![CDATA[KIT]]></category>
		<category><![CDATA[Repo]]></category>
		<category><![CDATA[SBSetting]]></category>
		<category><![CDATA[SSH]]></category>

		<guid isPermaLink="false">http://www.axot.org/?p=31</guid>
		<description><![CDATA[いつも私用のappをCydia repoに公開しました。
まだ二つしか無いですが、自分はほぼ毎日使うので、皆に使われたら便利かもだと思ってました。

簡単に紹介します。
SSHSwitcher
SBSetting defaultのSSH toggleは起動する際にsshdを開くので、その代わりのAppです。
KITWIFI
九工大飯塚キャンパス専用のWifi登録App、Safariのautofill機能より便利だよ。
Repo Source:
http://www.axot.org/cydia

]]></description>
			<content:encoded><![CDATA[<p>いつも私用のappをCydia repoに公開しました。<br />
まだ二つしか無いですが、自分はほぼ毎日使うので、皆に使われたら便利かもだと思ってました。</p>
<p><span id="more-31"></span></p>
<p>簡単に紹介します。</p>
<p><strong>SSHSwitcher</strong><br />
SBSetting defaultのSSH toggleは起動する際にsshdを開くので、その代わりのAppです。</p>
<p><strong>KITWIFI</strong><br />
九工大飯塚キャンパス専用のWifi登録App、Safariのautofill機能より便利だよ。</p>
<p><strong>Repo Source:</strong><br />
<a href="http://www.axot.org/cydia" title="http://www.axot.org/cydia" target="_blank">http://www.axot.org/cydia</a></p>
<p><a href="http://www.axot.org/wp-content/uploads/2012/02/IMG_1088.png"><img src="http://www.axot.org/wp-content/uploads/2012/02/IMG_1088-200x300.png" alt="" title="repo" width="200" height="300" class="aligncenter size-medium wp-image-33" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.axot.org/2012/02/10/cydia-repo/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Can you crack it solution</title>
		<link>http://www.axot.org/2011/12/05/can-you-crack-it-solution/</link>
		<comments>http://www.axot.org/2011/12/05/can-you-crack-it-solution/#comments</comments>
		<pubDate>Mon, 05 Dec 2011 09:22:36 +0000</pubDate>
		<dc:creator>axot</dc:creator>
				<category><![CDATA[Reverse Engineering]]></category>
		<category><![CDATA[Crack]]></category>
		<category><![CDATA[CYGWIN]]></category>
		<category><![CDATA[GCC]]></category>
		<category><![CDATA[GDB]]></category>
		<category><![CDATA[RCE]]></category>

		<guid isPermaLink="false">http://www.axot.org/?p=17</guid>
		<description><![CDATA[Britain&#8217;s GCHQ has launched an online code test that aims to identify potential spies and codebreakers.
The solution was written in English/简体中文/日本語

]]></description>
			<content:encoded><![CDATA[<p>Britain&#8217;s GCHQ has launched an online code test that aims to identify potential spies and codebreakers.<br />
The solution was written in English/简体中文/日本語<br />
<span id="more-17"></span></p>
<div class="su-tabs su-tabs-style-1">
<div class="su-tabs-nav"><span>English</span><span>简体中文</span><span>日本語</span></div>
<div class="su-tabs-panes">
<div class="su-tabs-pane">
It&#8217;s been a long time since I&#8217;ve update my blog last time.</p>
<p>Here is the problem: http://canyoucrackit.co.uk/<br />
<strong>Part 1:</strong><br />
<a href="http://www.axot.org/wp-content/uploads/2011/12/cyber.png"></p>
<div class="su-frame su-frame-align-center">
<div class="su-frame-shell"><img src="http://www.axot.org/wp-content/uploads/2011/12/cyber.png" alt="" title="cyberPart1" width="370" height="130" class="alignnone size-full wp-image-21" /> </div>
</div>
<p></a><br />
It contains about 10&#215;16=160 bytes of information, first I find out all the strings involved.</p>
<pre class="brush: bash; title: ; notranslate">
$ strings raw
\X=AAAAuCX=BBBBu;Z
</pre>
<p>It only includes AAAA and BBBB. I have no idea what it means.<br />
But I noticed that the first byte is 0xEB, 0xEB(JMP) is often used in cracking! So, does it meaning that this is a executable binary file?</p>
<pre class="brush: asm; title: ; notranslate">
$ gobjdump -D -b binary -mi386 raw

raw:     file format binary

Disassembly of section .data:

00000000 &lt;.data&gt;:
   0:	eb 04                	jmp    0x6
   2:	af                   	scas   %es:(%edi),%eax
   3:	c2 bf a3             	ret    $0xa3bf
   6:	81 ec 00 01 00 00    	sub    $0x100,%esp
   c:	31 c9                	xor    %ecx,%ecx
   e:	88 0c 0c             	mov    %cl,(%esp,%ecx,1)
  11:	fe c1                	inc    %cl
  13:	75 f9                	jne    0xe
  15:	31 c0                	xor    %eax,%eax
  17:	ba ef be ad de       	mov    $0xdeadbeef,%edx
  1c:	02 04 0c             	add    (%esp,%ecx,1),%al
  1f:	00 d0                	add    %dl,%al
  21:	c1 ca 08             	ror    $0x8,%edx
  24:	8a 1c 0c             	mov    (%esp,%ecx,1),%bl
  27:	8a 3c 04             	mov    (%esp,%eax,1),%bh
  2a:	88 1c 04             	mov    %bl,(%esp,%eax,1)
  2d:	88 3c 0c             	mov    %bh,(%esp,%ecx,1)
  30:	fe c1                	inc    %cl
  32:	75 e8                	jne    0x1c
  34:	e9 5c 00 00 00       	jmp    0x95
  39:	89 e3                	mov    %esp,%ebx
  3b:	81 c3 04 00 00 00    	add    $0x4,%ebx
  41:	5c                   	pop    %esp
  42:	58                   	pop    %eax
  43:	3d 41 41 41 41       	cmp    $0x41414141,%eax
  48:	75 43                	jne    0x8d
  4a:	58                   	pop    %eax
  4b:	3d 42 42 42 42       	cmp    $0x42424242,%eax
  50:	75 3b                	jne    0x8d
  52:	5a                   	pop    %edx
  53:	89 d1                	mov    %edx,%ecx
  55:	89 e6                	mov    %esp,%esi
  57:	89 df                	mov    %ebx,%edi
  59:	29 cf                	sub    %ecx,%edi
  5b:	f3 a4                	rep movsb %ds:(%esi),%es:(%edi)
  5d:	89 de                	mov    %ebx,%esi
  5f:	89 d1                	mov    %edx,%ecx
  61:	89 df                	mov    %ebx,%edi
  63:	29 cf                	sub    %ecx,%edi
  65:	31 c0                	xor    %eax,%eax
  67:	31 db                	xor    %ebx,%ebx
  69:	31 d2                	xor    %edx,%edx
  6b:	fe c0                	inc    %al
  6d:	02 1c 06             	add    (%esi,%eax,1),%bl
  70:	8a 14 06             	mov    (%esi,%eax,1),%dl
  73:	8a 34 1e             	mov    (%esi,%ebx,1),%dh
  76:	88 34 06             	mov    %dh,(%esi,%eax,1)
  79:	88 14 1e             	mov    %dl,(%esi,%ebx,1)
  7c:	00 f2                	add    %dh,%dl
  7e:	30 f6                	xor    %dh,%dh
  80:	8a 1c 16             	mov    (%esi,%edx,1),%bl
  83:	8a 17                	mov    (%edi),%dl
  85:	30 da                	xor    %bl,%dl
  87:	88 17                	mov    %dl,(%edi)
  89:	47                   	inc    %edi
  8a:	49                   	dec    %ecx
  8b:	75 de                	jne    0x6b
  8d:	31 db                	xor    %ebx,%ebx
  8f:	89 d8                	mov    %ebx,%eax
  91:	fe c0                	inc    %al
  93:	cd 80                	int    $0x80
  95:	90                   	nop
  96:	90                   	nop
  97:	e8 9d ff ff ff       	call   0x39
  9c:	41                   	inc    %ecx
  9d:	41                   	inc    %ecx
  9e:	41                   	inc    %ecx
  9f:	41                   	inc    %ecx
</pre>
<p>It is strange that JMP appeared first.<br />
At line 0&#215;97, when it calls 0&#215;39, 0x9C will be pushed into stack, but at line 0&#215;42 and 0x4A which pop eax twice are meaningless。<br />
At 0&#215;43、it is comparing EAX with &#8220;AAAA&#8221;, and EAX stored with &#8220;AAAA&#8221;, so the result must be true.<br />
At the next line, it is comparing EAX with &#8220;BBBB&#8221;, but EAX is uncertainty. So some things that were missed after line 0x9f.<br />
Download the picture, dump the hex code, we will see:</p>
<pre class="brush: plain; title: ; notranslate">
$ hexdump -C cyber.png
00000000  89 50 4e 47 0d 0a 1a 0a  00 00 00 0d 49 48 44 52  |.PNG........IHDR|
00000010  00 00 02 e4 00 00 01 04  08 02 00 00 00 ef 6a b6  |..............j.|
00000020  2d 00 00 00 01 73 52 47  42 00 ae ce 1c e9 00 00  |-....sRGB.......|
00000030  00 09 70 48 59 73 00 00  0b 13 00 00 0b 13 01 00  |..pHYs..........|
00000040  9a 9c 18 00 00 00 07 74  49 4d 45 07 db 08 05 0e  |.......tIME.....|
00000050  12 33 7e 39 c1 70 00 00  00 5d 69 54 58 74 43 6f  |.3~9.p...]iTXtCo|
00000060  6d 6d 65 6e 74 00 00 00  00 00 51 6b 4a 43 51 6a  |mment.....QkJCQj|
00000070  49 41 41 41 43 52 32 50  46 74 63 43 41 36 71 32  |IAAACR2PFtcCA6q2|
00000080  65 61 43 38 53 52 2b 38  64 6d 44 2f 7a 4e 7a 4c  |eaC8SR+8dmD/zNzL|
00000090  51 43 2b 74 64 33 74 46  51 34 71 78 38 4f 34 34  |QC+td3tFQ4qx8O44|
000000a0  37 54 44 65 75 5a 77 35  50 2b 30 53 73 62 45 63  |7TDeuZw5P+0SsbEc|
000000b0  59 52 0a 37 38 6a 4b 4c  77 3d 3d 32 ca be f1 00  |YR.78jKLw==2....|
...
</pre>
<p>In the header block, </p>
<pre class="brush: plain; title: ; notranslate">
QkJCQjIAAACR2PFtcCA6q2eaC8SR+8dmD/zNzLQC+td3tFQ4qx8O447TDeuZw5P+0SsbEcYR.78jKLw==
</pre>
<p>are stored, you can see &#8220;==&#8221; at the end of line. It may mean that this code is encoded with base64.</p>
<p>Decode:</p>
<pre class="brush: plain; title: ; notranslate">
$ echo 'QkJCQjIAAACR2PFtcCA6q2eaC8SR+8dmD/zNzLQC+td3tFQ4qx8O447TDeuZw5P+0SsbEcYR78jKLw==' | base64 -D -o decoded.bin
$ hexdump -C decoded.bin
00000000  42 42 42 42 32 00 00 00  91 d8 f1 6d 70 20 3a ab  |BBBB2......mp :.|
00000010  67 9a 0b c4 91 fb c7 66  0f fc cd cc b4 02 fa d7  |g......f........|
00000020  77 b4 54 38 ab 1f 0e e3  8e d3 0d eb 99 c3 93 fe  |w.T8............|
00000030  d1 2b 1b 11 c6 11 ef c8  ca 2f                    |.+......./|
0000003a
</pre>
<p>Woo! BBBB are appeared, combine 2 parts of binary codes, and view the execution results.</p>
<pre class="brush: cpp; title: ; notranslate">
#include &lt;stdio.h&gt;
#include &lt;sys/types.h&gt;
#include &lt;sys/mman.h&gt;

main(){

  int i;

  static unsigned char shellcode[] = {
    0xEB,0x04,0xAF,0xC2,0xBF,0xA3,0x81,0xEC,
    0x00,0x01,0x00,0x00,0x31,0xC9,0x88,0x0C,
    0x0C,0xFE,0xC1,0x75,0xF9,0x31,0xC0,0xBA,
    0xEF,0xBE,0xAD,0xDE,0x02,0x04,0x0C,0x00,
    0xD0,0xC1,0xCA,0x08,0x8A,0x1C,0x0C,0x8A,
    0x3C,0x04,0x88,0x1C,0x04,0x88,0x3C,0x0C,
    0xFE,0xC1,0x75,0xE8,0xE9,0x5C,0x00,0x00,
    0x00,0x89,0xE3,0x81,0xC3,0x04,0x00,0x00,
    0x00,0x5C,0x58,0x3D,0x41,0x41,0x41,0x41,
    0x75,0x43,0x58,0x3D,0x42,0x42,0x42,0x42,
    0x75,0x3B,0x5A,0x89,0xD1,0x89,0xE6,0x89,
    0xDF,0x29,0xCF,0xF3,0xA4,0x89,0xDE,0x89,
    0xD1,0x89,0xDF,0x29,0xCF,0x31,0xC0,0x31,
    0xDB,0x31,0xD2,0xFE,0xC0,0x02,0x1C,0x06,
    0x8A,0x14,0x06,0x8A,0x34,0x1E,0x88,0x34,
    0x06,0x88,0x14,0x1E,0x00,0xF2,0x30,0xF6,
    0x8A,0x1C,0x16,0x8A,0x17,0x30,0xDA,0x88,
    0x17,0x47,0x49,0x75,0xDE,0x31,0xDB,0x89,
    0xD8,0xFE,0xC0,0xCD,0x80,0x90,0x90,0xE8,
    0x9D,0xFF,0xFF,0xFF,0x41,0x41,0x41,0x41,
    0x42,0x42,0x42,0x42,0x32,0x00,0x00,0x00,
    0x91,0xD8,0xF1,0x6D,0x70,0x20,0x3A,0xAB,
    0x67,0x9A,0x0B,0xC4,0x91,0xFB,0xC7,0x66,
    0x0F,0xFC,0xCD,0xCC,0xB4,0x02,0xFA,0xD7,
    0x77,0xB4,0x54,0x38,0xAB,0x1F,0x0E,0xE3,
    0x8E,0xD3,0x0D,0xEB,0x99,0xC3,0x93,0xFE,
    0xD1,0x2B,0x1B,0x11,0xC6,0x11,0xEF,0xC8,
    0xCA,0x2F
  };

  /*
   * patch INT 0x80 to INT 3 to throw an exception signal to debugger
   * 0xCD -&gt; 0xCC
   */
  printf(&quot;patching shellcode...\n&quot;);

  for(i = 0; i &lt; sizeof(shellcode); i++){
    if(*(unsigned short*)&amp;shellcode[i] == 0x80CD){
      shellcode[i] = 0xCC;
      printf(&quot;patch done\n&quot;);
      break;
    }
  }

  unsigned int page = ((unsigned int)shellcode)&amp;0xfffff000;

  if(-1 == mprotect((void*)page, 4096, PROT_READ | PROT_WRITE | PROT_EXEC))
    perror(&quot;mprotect error&quot;);

  ((int(*)())shellcode)();

}
</pre>
<p>The results are stored in EDI ~ EDI-0&#215;32, at line 0&#215;87.</p>
<pre class="brush: bash; title: ; notranslate">
$ gcc -arch i386 -g stage1.c -o stage1
$ gdb stage1
(gdb) r
(gdb) x/s $edi-0x32
0xbffff79a:	 &quot;GET /15b436de1f9107f3778aad525e5d0b20.js HTTP/1.1&quot;
</pre>
<p><strong>Part 2:</strong><br />
the result of part1 are: <a href="http://canyoucrackit.co.uk/15b436de1f9107f3778aad525e5d0b20.js" target="_blank">URL</a></p>
<pre class="brush: jscript; title: ; notranslate">
//--------------------------------------------------------------------------------------------------
//
// stage 2 of 3
//
// challenge:
//   reveal the solution within VM.mem
//
// disclaimer:
//   tested in ie 9, firefox 6, chrome 14 and v8 shell (http://code.google.com/apis/v8/build.html),
//   other javascript implementations may or may not work.
//
//--------------------------------------------------------------------------------------------------

var VM = {

  cpu: {
    ip: 0x00,

    r0: 0x00,
    r1: 0x00,
    r2: 0x00,
    r3: 0x00,

    cs: 0x00,
    ds: 0x10,

    fl: 0x00,

    firmware: [0xd2ab1f05, 0xda13f110]
  },

  mem: [
    0x31, 0x04, 0x33, 0xaa, 0x40, 0x02, 0x80, 0x03, 0x52, 0x00, 0x72, 0x01, 0x73, 0x01, 0xb2, 0x50,
    0x30, 0x14, 0xc0, 0x01, 0x80, 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

    0x98, 0xab, 0xd9, 0xa1, 0x9f, 0xa7, 0x83, 0x83, 0xf2, 0xb1, 0x34, 0xb6, 0xe4, 0xb7, 0xca, 0xb8,
    0xc9, 0xb8, 0x0e, 0xbd, 0x7d, 0x0f, 0xc0, 0xf1, 0xd9, 0x03, 0xc5, 0x3a, 0xc6, 0xc7, 0xc8, 0xc9,
    0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9,
    0xda, 0xdb, 0xa9, 0xcd, 0xdf, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9,
    0x26, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9,
    0x7d, 0x1f, 0x15, 0x60, 0x4d, 0x4d, 0x52, 0x7d, 0x0e, 0x27, 0x6d, 0x10, 0x6d, 0x5a, 0x06, 0x56,
    0x47, 0x14, 0x42, 0x0e, 0xb6, 0xb2, 0xb2, 0xe6, 0xeb, 0xb4, 0x83, 0x8e, 0xd7, 0xe5, 0xd4, 0xd9,
    0xc3, 0xf0, 0x80, 0x95, 0xf1, 0x82, 0x82, 0x9a, 0xbd, 0x95, 0xa4, 0x8d, 0x9a, 0x2b, 0x30, 0x69,
    0x4a, 0x69, 0x65, 0x55, 0x1c, 0x7b, 0x69, 0x1c, 0x6e, 0x04, 0x74, 0x35, 0x21, 0x26, 0x2f, 0x60,
    0x03, 0x4e, 0x37, 0x1e, 0x33, 0x54, 0x39, 0xe6, 0xba, 0xb4, 0xa2, 0xad, 0xa4, 0xc5, 0x95, 0xc8,
    0xc1, 0xe4, 0x8a, 0xec, 0xe7, 0x92, 0x8b, 0xe8, 0x81, 0xf0, 0xad, 0x98, 0xa4, 0xd0, 0xc0, 0x8d,
    0xac, 0x22, 0x52, 0x65, 0x7e, 0x27, 0x2b, 0x5a, 0x12, 0x61, 0x0a, 0x01, 0x7a, 0x6b, 0x1d, 0x67,
    0x75, 0x70, 0x6c, 0x1b, 0x11, 0x25, 0x25, 0x70, 0x7f, 0x7e, 0x67, 0x63, 0x30, 0x3c, 0x6d, 0x6a,
    0x01, 0x51, 0x59, 0x5f, 0x56, 0x13, 0x10, 0x43, 0x19, 0x18, 0xe5, 0xe0, 0xbe, 0xbf, 0xbd, 0xe9,
    0xf0, 0xf1, 0xf9, 0xfa, 0xab, 0x8f, 0xc1, 0xdf, 0xcf, 0x8d, 0xf8, 0xe7, 0xe2, 0xe9, 0x93, 0x8e,
    0xec, 0xf5, 0xc8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

    0x37, 0x7a, 0x07, 0x11, 0x1f, 0x1d, 0x68, 0x25, 0x32, 0x77, 0x1e, 0x62, 0x23, 0x5b, 0x47, 0x55,
    0x53, 0x30, 0x11, 0x42, 0xf6, 0xf1, 0xb1, 0xe6, 0xc3, 0xcc, 0xf8, 0xc5, 0xe4, 0xcc, 0xc0, 0xd3,
    0x85, 0xfd, 0x9a, 0xe3, 0xe6, 0x81, 0xb5, 0xbb, 0xd7, 0xcd, 0x87, 0xa3, 0xd3, 0x6b, 0x36, 0x6f,
    0x6f, 0x66, 0x55, 0x30, 0x16, 0x45, 0x5e, 0x09, 0x74, 0x5c, 0x3f, 0x29, 0x2b, 0x66, 0x3d, 0x0d,
    0x02, 0x30, 0x28, 0x35, 0x15, 0x09, 0x15, 0xdd, 0xec, 0xb8, 0xe2, 0xfb, 0xd8, 0xcb, 0xd8, 0xd1,
    0x8b, 0xd5, 0x82, 0xd9, 0x9a, 0xf1, 0x92, 0xab, 0xe8, 0xa6, 0xd6, 0xd0, 0x8c, 0xaa, 0xd2, 0x94,
    0xcf, 0x45, 0x46, 0x67, 0x20, 0x7d, 0x44, 0x14, 0x6b, 0x45, 0x6d, 0x54, 0x03, 0x17, 0x60, 0x62,
    0x55, 0x5a, 0x4a, 0x66, 0x61, 0x11, 0x57, 0x68, 0x75, 0x05, 0x62, 0x36, 0x7d, 0x02, 0x10, 0x4b,
    0x08, 0x22, 0x42, 0x32, 0xba, 0xe2, 0xb9, 0xe2, 0xd6, 0xb9, 0xff, 0xc3, 0xe9, 0x8a, 0x8f, 0xc1,
    0x8f, 0xe1, 0xb8, 0xa4, 0x96, 0xf1, 0x8f, 0x81, 0xb1, 0x8d, 0x89, 0xcc, 0xd4, 0x78, 0x76, 0x61,
    0x72, 0x3e, 0x37, 0x23, 0x56, 0x73, 0x71, 0x79, 0x63, 0x7c, 0x08, 0x11, 0x20, 0x69, 0x7a, 0x14,
    0x68, 0x05, 0x21, 0x1e, 0x32, 0x27, 0x59, 0xb7, 0xcf, 0xab, 0xdd, 0xd5, 0xcc, 0x97, 0x93, 0xf2,
    0xe7, 0xc0, 0xeb, 0xff, 0xe9, 0xa3, 0xbf, 0xa1, 0xab, 0x8b, 0xbb, 0x9e, 0x9e, 0x8c, 0xa0, 0xc1,
    0x9b, 0x5a, 0x2f, 0x2f, 0x4e, 0x4e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  ],

  exec: function()
  {
    // virtual machine architecture
    // ++++++++++++++++++++++++++++
    //
    // segmented memory model with 16-byte segment size (notation seg:offset)
    //
    // 4 general-purpose registers (r0-r3)
    // 2 segment registers (cs, ds equiv. to r4, r5)
    // 1 flags register (fl)
    //
    // instruction encoding
    // ++++++++++++++++++++
    //
    //           byte 1               byte 2 (optional)
    // bits      [ 7 6 5 4 3 2 1 0 ]  [ 7 6 5 4 3 2 1 0 ]
    // opcode      - - -
    // mod               -
    // operand1            - - - -
    // operand2                         - - - - - - - -
    //
    // operand1 is always a register index
    // operand2 is optional, depending upon the instruction set specified below
    // the value of mod alters the meaning of any operand2
    //   0: operand2 = reg ix
    //   1: operand2 = fixed immediate value or target segment (depending on instruction)
    //
    // instruction set
    // +++++++++++++++
    //
    // Notes:
    //   * r1, r2 =&gt; operand 1 is register 1, operand 2 is register 2
    //   * movr r1, r2 =&gt; move contents of register r2 into register r1
    //
    // opcode | instruction | operands (mod 0) | operands (mod 1)
    // -------+-------------+------------------+-----------------
    // 0x00   | jmp         | r1               | r2:r1
    // 0x01   | movr        | r1, r2           | rx,   imm
    // 0x02   | movm        | r1, [ds:r2]      | [ds:r1], r2
    // 0x03   | add         | r1, r2           | r1,   imm
    // 0x04   | xor         | r1, r2           | r1,   imm
    // 0x05   | cmp         | r1, r2           | r1,   imm
    // 0x06   | jmpe        | r1               | r2:r1
    // 0x07   | hlt         | N/A              | N/A
    //
    // flags
    // +++++
    //
    // cmp r1, r2 instruction results in:
    //   r1 == r2 =&gt; fl = 0
    //   r1 &lt; r2  =&gt; fl = 0xff
    //   r1 &gt; r2  =&gt; fl = 1
    //
    // jmpe r1
    //   =&gt; if (fl == 0) jmp r1
    //      else nop

    throw &quot;VM.exec not yet implemented&quot;;
  }

};

//--------------------------------------------------------------------------------------------------

try
{
  VM.exec();
}
catch(e)
{
  alert('\nError: ' + e + '\n');
}

//--------------------------------------------------------------------------------------------------
</pre>
<p>We need make a virtual CPU for executing these codes.</p>
<pre class="brush: cpp; title: ; notranslate">
#include &lt;stdio.h&gt;

static unsigned char mem[] = {
  0x31, 0x04, 0x33, 0xaa, 0x40, 0x02, 0x80, 0x03, 0x52, 0x00, 0x72, 0x01, 0x73, 0x01, 0xb2, 0x50,
  0x30, 0x14, 0xc0, 0x01, 0x80, 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

  0x98, 0xab, 0xd9, 0xa1, 0x9f, 0xa7, 0x83, 0x83, 0xf2, 0xb1, 0x34, 0xb6, 0xe4, 0xb7, 0xca, 0xb8,
  0xc9, 0xb8, 0x0e, 0xbd, 0x7d, 0x0f, 0xc0, 0xf1, 0xd9, 0x03, 0xc5, 0x3a, 0xc6, 0xc7, 0xc8, 0xc9,
  0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9,
  0xda, 0xdb, 0xa9, 0xcd, 0xdf, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9,
  0x26, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9,
  0x7d, 0x1f, 0x15, 0x60, 0x4d, 0x4d, 0x52, 0x7d, 0x0e, 0x27, 0x6d, 0x10, 0x6d, 0x5a, 0x06, 0x56,
  0x47, 0x14, 0x42, 0x0e, 0xb6, 0xb2, 0xb2, 0xe6, 0xeb, 0xb4, 0x83, 0x8e, 0xd7, 0xe5, 0xd4, 0xd9,
  0xc3, 0xf0, 0x80, 0x95, 0xf1, 0x82, 0x82, 0x9a, 0xbd, 0x95, 0xa4, 0x8d, 0x9a, 0x2b, 0x30, 0x69,
  0x4a, 0x69, 0x65, 0x55, 0x1c, 0x7b, 0x69, 0x1c, 0x6e, 0x04, 0x74, 0x35, 0x21, 0x26, 0x2f, 0x60,
  0x03, 0x4e, 0x37, 0x1e, 0x33, 0x54, 0x39, 0xe6, 0xba, 0xb4, 0xa2, 0xad, 0xa4, 0xc5, 0x95, 0xc8,
  0xc1, 0xe4, 0x8a, 0xec, 0xe7, 0x92, 0x8b, 0xe8, 0x81, 0xf0, 0xad, 0x98, 0xa4, 0xd0, 0xc0, 0x8d,
  0xac, 0x22, 0x52, 0x65, 0x7e, 0x27, 0x2b, 0x5a, 0x12, 0x61, 0x0a, 0x01, 0x7a, 0x6b, 0x1d, 0x67,
  0x75, 0x70, 0x6c, 0x1b, 0x11, 0x25, 0x25, 0x70, 0x7f, 0x7e, 0x67, 0x63, 0x30, 0x3c, 0x6d, 0x6a,
  0x01, 0x51, 0x59, 0x5f, 0x56, 0x13, 0x10, 0x43, 0x19, 0x18, 0xe5, 0xe0, 0xbe, 0xbf, 0xbd, 0xe9,
  0xf0, 0xf1, 0xf9, 0xfa, 0xab, 0x8f, 0xc1, 0xdf, 0xcf, 0x8d, 0xf8, 0xe7, 0xe2, 0xe9, 0x93, 0x8e,
  0xec, 0xf5, 0xc8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

  0x37, 0x7a, 0x07, 0x11, 0x1f, 0x1d, 0x68, 0x25, 0x32, 0x77, 0x1e, 0x62, 0x23, 0x5b, 0x47, 0x55,
  0x53, 0x30, 0x11, 0x42, 0xf6, 0xf1, 0xb1, 0xe6, 0xc3, 0xcc, 0xf8, 0xc5, 0xe4, 0xcc, 0xc0, 0xd3,
  0x85, 0xfd, 0x9a, 0xe3, 0xe6, 0x81, 0xb5, 0xbb, 0xd7, 0xcd, 0x87, 0xa3, 0xd3, 0x6b, 0x36, 0x6f,
  0x6f, 0x66, 0x55, 0x30, 0x16, 0x45, 0x5e, 0x09, 0x74, 0x5c, 0x3f, 0x29, 0x2b, 0x66, 0x3d, 0x0d,
  0x02, 0x30, 0x28, 0x35, 0x15, 0x09, 0x15, 0xdd, 0xec, 0xb8, 0xe2, 0xfb, 0xd8, 0xcb, 0xd8, 0xd1,
  0x8b, 0xd5, 0x82, 0xd9, 0x9a, 0xf1, 0x92, 0xab, 0xe8, 0xa6, 0xd6, 0xd0, 0x8c, 0xaa, 0xd2, 0x94,
  0xcf, 0x45, 0x46, 0x67, 0x20, 0x7d, 0x44, 0x14, 0x6b, 0x45, 0x6d, 0x54, 0x03, 0x17, 0x60, 0x62,
  0x55, 0x5a, 0x4a, 0x66, 0x61, 0x11, 0x57, 0x68, 0x75, 0x05, 0x62, 0x36, 0x7d, 0x02, 0x10, 0x4b,
  0x08, 0x22, 0x42, 0x32, 0xba, 0xe2, 0xb9, 0xe2, 0xd6, 0xb9, 0xff, 0xc3, 0xe9, 0x8a, 0x8f, 0xc1,
  0x8f, 0xe1, 0xb8, 0xa4, 0x96, 0xf1, 0x8f, 0x81, 0xb1, 0x8d, 0x89, 0xcc, 0xd4, 0x78, 0x76, 0x61,
  0x72, 0x3e, 0x37, 0x23, 0x56, 0x73, 0x71, 0x79, 0x63, 0x7c, 0x08, 0x11, 0x20, 0x69, 0x7a, 0x14,
  0x68, 0x05, 0x21, 0x1e, 0x32, 0x27, 0x59, 0xb7, 0xcf, 0xab, 0xdd, 0xd5, 0xcc, 0x97, 0x93, 0xf2,
  0xe7, 0xc0, 0xeb, 0xff, 0xe9, 0xa3, 0xbf, 0xa1, 0xab, 0x8b, 0xbb, 0x9e, 0x9e, 0x8c, 0xa0, 0xc1,
  0x9b, 0x5a, 0x2f, 0x2f, 0x4e, 0x4e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

#define adr(seg, off) ((seg &lt;&lt; 4) + off)

typedef unsigned char   byte;
typedef unsigned short  word;
typedef unsigned int    dword;

typedef struct _CPU {
  byte ip;
  byte regs[6];
  byte fl;
} _CPU;

_CPU cpu;

enum _REGISTER {
  r0,
  r1,
  r2,
  r3,
  cs,
  ds
};

typedef struct _INSTRUCTION {
  byte opcode;
  byte mod;
  byte operand1;
  byte operand2;
  byte unknown[2];
} _INSTRUCTION, *pInstruction;

_INSTRUCTION ins;

enum _OPCODE {
  JMP,
  MOVR,
  MOVM,
  ADD,
  XOR,
  CMP,
  JMPE,
  HLT
};

void fetchDecode(pInstruction pIns){
  word currentIP    = adr(cpu.regs[cs], cpu.ip);
  pIns-&gt;opcode      = (mem[currentIP] &gt;&gt; 5) &amp; 0x07;
  pIns-&gt;mod         = (mem[currentIP] &gt;&gt; 4) &amp; 0x01;
  pIns-&gt;operand1    = mem[currentIP] &amp; 0x0F;
  pIns-&gt;operand2    = mem[currentIP+1];

  pIns-&gt;unknown[0]  = mem[currentIP];
  pIns-&gt;unknown[1]  = mem[currentIP+1];

  cpu.ip += 2;
}

void exec(pInstruction pIns){

  printf(&quot;IP:%d\t&quot;, cpu.ip);

  switch(pIns-&gt;opcode) {

    case JMP:
      if(!pIns-&gt;mod){
        cpu.ip = cpu.regs[pIns-&gt;operand1];
        printf(&quot;JMP  %d\n&quot;, pIns-&gt;operand1);
      }
      else{
        cpu.regs[cs] = pIns-&gt;operand2;
        cpu.ip = (cpu.regs[cs] &lt;&lt; 4) + cpu.regs[pIns-&gt;operand1];
        printf(&quot;JMP  %d: %d\n&quot;, pIns-&gt;operand2, pIns-&gt;operand1);
      }
      break;

    case MOVR:
      if(!pIns-&gt;mod){
        cpu.regs[pIns-&gt;operand1] = cpu.regs[pIns-&gt;operand2];
        printf(&quot;MOVR %d, %d\n&quot;, pIns-&gt;operand1, pIns-&gt;operand2);
      }
      else{
        cpu.regs[pIns-&gt;operand1] = pIns-&gt;operand2;
        printf(&quot;MOVR %d, %02X\n&quot;, pIns-&gt;operand1, pIns-&gt;operand2);
      }
      break;

    case MOVM:
      if(!pIns-&gt;mod){
        cpu.regs[pIns-&gt;operand1] = mem[adr(cpu.regs[ds], cpu.regs[pIns-&gt;operand2])];
        printf(&quot;MOVM %d, [DS: %d]\n&quot;, pIns-&gt;operand1, pIns-&gt;operand2);
      }
      else{
        mem[adr(cpu.regs[ds], cpu.regs[pIns-&gt;operand1])] = cpu.regs[pIns-&gt;operand2];
        printf(&quot;MOVM [DS: %d], %d\n&quot;, pIns-&gt;operand1, pIns-&gt;operand2);
      }
      break;

    case ADD:
      if(!pIns-&gt;mod){
        cpu.regs[pIns-&gt;operand1] += cpu.regs[pIns-&gt;operand2];
        printf(&quot;ADD %d, %d\n&quot;, pIns-&gt;operand1, pIns-&gt;operand2);
      }
      else{
        cpu.regs[pIns-&gt;operand1] += pIns-&gt;operand2;
        printf(&quot;ADD %d, %02X\n&quot;, pIns-&gt;operand1, pIns-&gt;operand2);
      }
      break;

    case XOR:
      if(!pIns-&gt;mod){
        cpu.regs[pIns-&gt;operand1] ^= cpu.regs[pIns-&gt;operand2];
        printf(&quot;XOR %d, R%d\n&quot;, pIns-&gt;operand1, pIns-&gt;operand2);
      }
      else{
        cpu.regs[pIns-&gt;operand1] ^= pIns-&gt;operand2;
        printf(&quot;XOR %d, %02X\n&quot;, pIns-&gt;operand1, pIns-&gt;operand2);
      }
      break;

    case CMP:
      if(!pIns-&gt;mod){
        cpu.fl = cpu.regs[pIns-&gt;operand1] == cpu.regs[pIns-&gt;operand2]? 0x00: (cpu.regs[pIns-&gt;operand1] &lt; cpu.regs[pIns-&gt;operand2]? 0xff: 0x01);
        printf(&quot;CMP  %d, %d\n&quot;, pIns-&gt;operand1, pIns-&gt;operand2);
      }
      else{
        cpu.fl = cpu.regs[pIns-&gt;operand1] == pIns-&gt;operand2? 0x00: (cpu.regs[pIns-&gt;operand1] &lt; pIns-&gt;operand2? 0xff: 0x01);
        printf(&quot;CMP %d, %02X\n&quot;, pIns-&gt;operand1, pIns-&gt;operand2);
      }
      break;

    case JMPE:
      if(!cpu.fl){
        if(!pIns-&gt;mod){
          cpu.ip = adr(cpu.regs[cs], cpu.regs[pIns-&gt;operand1]);
          printf(&quot;JMPE %d\n&quot;, pIns-&gt;operand1);
        }
        else{
          cpu.ip = adr(cpu.regs[cs], adr(cpu.regs[pIns-&gt;operand2], cpu.regs[pIns-&gt;operand1]));
          printf(&quot;JMPE %d: %d\n&quot;, pIns-&gt;operand2, pIns-&gt;operand1);
        }
        break;
      }
      --cpu.ip;
      printf(&quot;JMPE NOP\n&quot;);
      break;

    case HLT:
      pIns-&gt;opcode = HLT;
      printf(&quot;HLT\n&quot;);
      break;

    default:
      pIns-&gt;opcode = HLT;
      printf(&quot;UNKNOW %02Xh, %02Xh\n&quot;, pIns-&gt;unknown[0], pIns-&gt;unknown[1]);
      break;
  };
}

main(){

  cpu.ip = 0x00;

  cpu.regs[r0] = 0x00;
  cpu.regs[r1] = 0x00;
  cpu.regs[r2] = 0x00;
  cpu.regs[r3] = 0x00;
  cpu.regs[cs] = 0x00;
  cpu.regs[ds] = 0x10;

  cpu.fl = 0x00;

  int i = 0;
  while ( ++i &lt; (2&lt;&lt;16) &amp;&amp; ins.opcode != HLT) {
    fetchDecode(&amp;ins);
    exec(&amp;ins);
  }

  FILE *fp = fopen(&quot;mem.dump&quot;, &quot;w&quot;);
  dword dataStart = adr(cpu.regs[ds], 0);
  fwrite((void*)(mem+dataStart), sizeof(mem)-dataStart, 1, fp);
  fclose(fp);

}
</pre>
<p>Execute it:</p>
<pre class="brush: plain; title: ; notranslate">
$ gcc -arch i386 -g stage2_vm.c -o stage2_vm
$ ./stage2_vm
...
IP:22	JMPE NOP
IP:23	CMP 0, 00
IP:25	MOVR 0, 1B
IP:27	JMPE 0
IP:29	HLT

$ strings mem.dump
GET /da75370fe15c4148bd4ceec861fbdaa5.exe HTTP/1.0
h%2w
b#[GUS0
k6oofU0
t\?)+f=
EFg }D
kEmT
`bUZJfa
xvar&gt;7#Vsqyc|
Z//NN
</pre>
<p>/da75370fe15c4148bd4ceec861fbdaa5.exe is the answer of part 2.</p>
<p><strong>Part 3:</strong><br />
The result of part2 are <a href="http://canyoucrackit.co.uk/da75370fe15c4148bd4ceec861fbdaa5.exe" target="_blank">URL</a>, it need cygwin environment for executing, so you need get Windows or wine.<br />
Have a look at which strings it contains.</p>
<pre class="brush: plain; title: ; notranslate">
$ strings da75370fe15c4148bd4ceec861fbdaa5.exe
...
hqDTK7b8K2rvw
keygen.exe
usage: keygen.exe hostname
license.txt
error: license.txt not found
loading stage1 license key(s)...
loading stage2 license key(s)...
error: license.txt invalid
error: gethostbyname() failed
error: connect(&quot;%s&quot;) failed
GET /%s/%x/%x/%x/key.txt HTTP/1.0
...
</pre>
<p>Many useful staffs are shown;<br />
First, rename da75370fe15c4148bd4ceec861fbdaa5.exe to keygen.exe.</p>
<p>usage:</p>
<pre class="brush: bash; title: ; notranslate">
keygen.exe canyoucrackit.co.uk
</pre>
<p>And, license.txt is necessary.</p>
<p>This is a part of disassembling codes, pick up from IDA Pro 6.1.110530 Evaluation version</p>
<pre class="brush: nasm8086; title: ; notranslate">
.text:00401120 loc_401120:                             ; CODE XREF: sub_401090+76j
.text:00401120                 mov     [esp+78h+var_70], 18h
.text:00401128                 mov     [esp+78h+hqDTK7b8K2rvw_copy], 0
.text:00401130                 lea     eax, [ebp+license1]
.text:00401133                 mov     [esp+78h+license2], eax
.text:00401136                 call    memset
.text:0040113B                 lea     eax, [ebp+license1]
.text:0040113E                 mov     [esp+78h+var_70], eax
.text:00401142                 mov     [esp+78h+hqDTK7b8K2rvw_copy], offset aS ; &quot;%s&quot;
.text:0040114A                 mov     eax, [ebp+var_4C]
.text:0040114D                 mov     [esp+78h+license2], eax
.text:00401150                 call    fscanf
.text:00401155                 mov     eax, [ebp+var_4C]
.text:00401158                 mov     [esp+78h+license2], eax
.text:0040115B                 call    fclose
.text:00401160                 mov     [ebp+var_4C], 0
.text:00401167                 cmp     [ebp+license1], 'qhcg'               // head 4 chars of license are qhcg
.text:0040116E                 jnz     short loc_4011CF
.text:00401170                 mov     eax, hqDTK7b8K2rvw
.text:00401175                 mov     [esp+78h+hqDTK7b8K2rvw_copy], eax
.text:00401179                 lea     eax, [ebp+license1]
.text:0040117C                 add     eax, 4
.text:0040117F                 mov     [esp+78h+license2], eax
                                                                            // char *crypt(const char *key, const char *salt);
                                                                            // key are 8 chars、salt are 2 chars
.text:00401182                 call    crypt                                // crypt(&quot;license&quot;, &quot;hq&quot;);
.text:00401187                 mov     edx, eax
.text:00401189                 mov     eax, hqDTK7b8K2rvw
.text:0040118E                 mov     [esp+78h+hqDTK7b8K2rvw_copy], eax
.text:00401192                 mov     [esp+78h+license2], edx
.text:00401195                 call    strcmp
.text:0040119A                 test    eax, eax
.text:0040119C                 jnz     short loc_4011A5
.text:0040119E                 mov     [ebp+var_C], 1
.text:004011A5
.text:004011A5 loc_4011A5:                             ; CODE XREF: sub_401090+10Cj
.text:004011A5                 mov     [esp+78h+license2], offset aLoadingStage1L ; &quot;loading stage1 license key(s)...\n&quot;
.text:004011AC                 call    printf
.text:004011B1                 mov     eax, [ebp+license3]
.text:004011B4                 mov     [ebp+license3_copy], eax
.text:004011B7                 mov     [esp+78h+license2], offset aLoadingStage2L ; &quot;loading stage2 license key(s)...\n\n&quot;
.text:004011BE                 call    printf
.text:004011C3                 mov     eax, [ebp+license4]
.text:004011C6                 mov     [ebp+license4_copy], eax
.text:004011C9                 mov     eax, [ebp+license5]
.text:004011CC                 mov     [ebp+license5_copy], eax
.text:004011CF
.text:004011CF loc_4011CF:                             ; CODE XREF: sub_401090+DEj
.text:004011CF                 cmp     [ebp+var_C], 0
.text:004011D3                 jnz     short loc_4011EA
.text:004011D5                 mov     [esp+78h+license2], offset aErrorLicense_0 ; &quot;error: license.txt invalid\n&quot;
.text:004011DC                 call    printf
.text:004011E1                 mov     [ebp+var_50], 0FFFFFFFFh
.text:004011E8                 jmp     short loc_401204
.text:004011EA ; ---------------------------------------------------------------------------
.text:004011EA
.text:004011EA loc_4011EA:                             ; CODE XREF: sub_401090+143j
.text:004011EA                 lea     eax, [ebp+license3_copy]
.text:004011ED                 mov     [esp+78h+hqDTK7b8K2rvw_copy], eax
.text:004011F1                 mov     eax, [ebp+hostname]
.text:004011F4                 add     eax, 4
.text:004011F7                 mov     eax, [eax]
.text:004011F9                 mov     [esp+78h+license2], eax
.text:004011FC                 call    genURL                                  //for generating URL only need license3,4,5
.text:00401201                 mov     [ebp+var_50], eax
.text:00401204
.text:00401204 loc_401204:                             ; CODE XREF: sub_401090+56j
.text:00401204                                         ; sub_401090+8Bj ...
.text:00401204                 mov     eax, [ebp+var_50]
.text:00401207                 leave
.text:00401208                 retn
.text:00401208 sub_401090      endp
</pre>
<p>This is the structure of license.txt</p>
<pre class="brush: plain; title: ; notranslate">
qhcg + 8 chars of crypt + license3(4bytes) + license4(4bytes) + license5(4bytes)
</pre>
<p>Where can we found license3 ~ license5?<br />
This is the hint:</p>
<pre class="brush: plain; title: ; notranslate">
&quot;loading stage1 license key(s)...\n&quot;
&quot;loading stage2 license key(s)...\n\n&quot;
</pre>
<p>It tell us, in part1 has 1 key, and in part2 have two keys.</p>
<pre class="brush: plain; title: ; notranslate">
license3:
In part1, the first op is JMP:
   0:	eb 04                	jmp    0x6
   2:	af                   	scas   %es:(%edi),%eax
   3:	c2 bf a3             	ret    $0xa3bf
So 0x2 0x3 should never be used, it is the answer.
notice: x86 is using Little endian, afc2bfa3 need be written in a3bfc2af.

license4,5:
The firmware in cpu structure of part 2 are never used.
firmware: [0xd2ab1f05, 0xda13f110]
It is the answer.
</pre>
<p>But I dont know where is the hidden license2 in.</p>
<pre class="brush: plain; title: ; notranslate">
Change jnz in .text:0040119C to
jmp can easily solve this problem.
0x75 -&gt; 0xEB
</pre>
<p>I googled license2, cyberwin is the answer.</p>
<p>Finally, the license.txt is</p>
<pre class="brush: plain; title: ; notranslate">
67636871637962657277696EAFC2BFA3051FABD210F113DA
</pre>
<p>save it with HEX.</p>
<pre class="brush: bash; title: ; notranslate">
$ ./keygen.exe canyoucrackit.co.uk

keygen.exe

loading stage1 license key(s)...
loading stage2 license key(s)...

request:

GET /hqDTK7b8K2rvw/a3bfc2af/d2ab1f05/da13f110/key.txt HTTP/1.0
</pre>
<p><a href="http://canyoucrackit.co.uk/hqDTK7b8K2rvw/a3bfc2af/d2ab1f05/da13f110/key.txt" target="_blank">http://canyoucrackit.co.uk/hqDTK7b8K2rvw/a3bfc2af/d2ab1f05/da13f110/key.txt</a>を開くと、</p>
<pre class="brush: plain; title: ; notranslate">
Pr0t3ct!on#cyber_security@12*12.2011+
</pre>
<p>This is the final answer.<br />
<a href="http://www.axot.org/wp-content/uploads/2011/12/Screen-Shot-2011-12-05-at-23.19.26-.png"></p>
<div class="su-frame su-frame-align-center">
<div class="su-frame-shell"><img src="http://www.axot.org/wp-content/uploads/2011/12/Screen-Shot-2011-12-05-at-23.19.26-.png" alt="" title="cracked" width="525" height="345" class="alignnone size-full wp-image-24" /></div>
</div>
<p></a><br />
Crackded it!</p>
<p><strong>Reference:</strong><br />
The Mac Hacker&#8217;s Handbook</p>
<p>http://pastebin.com/GAZ2aCLm</p>
</div>
<div class="su-tabs-pane">
这是我写的关于Can you crack it的解法.<br />
问题出处: http://canyoucrackit.co.uk/<br />
<strong>第1部分:</strong><br />
<a href="http://www.axot.org/wp-content/uploads/2011/12/cyber.png"></p>
<div class="su-frame su-frame-align-center">
<div class="su-frame-shell"><img src="http://www.axot.org/wp-content/uploads/2011/12/cyber.png" alt="" title="cyberPart1" width="370" height="130" class="alignnone size-full wp-image-21" /> </div>
</div>
<p></a><br />
从图片中可以看到共有10&#215;16=160字节的信息、因为是16进制编码的, 乍看之下也没有什么头绪, 首先先来查看下里面含有哪些ASCII文字.</p>
<pre class="brush: bash; title: ; notranslate">
$ strings raw
\X=AAAAuCX=BBBBu;Z
</pre>
<p>只有AAAA, BBBB. 看不出什么特别的意思.<br />
回到16进制, 可以看到第一个字节是0xEB、0xEB(JMP)这个无条件跳转经常在破解中用到. 难道说这个是2进制可执行文件?</p>
<pre class="brush: asm; title: ; notranslate">
$ gobjdump -D -b binary -mi386 raw

raw:     file format binary

Disassembly of section .data:

00000000 &lt;.data&gt;:
   0:	eb 04                	jmp    0x6
   2:	af                   	scas   %es:(%edi),%eax
   3:	c2 bf a3             	ret    $0xa3bf
   6:	81 ec 00 01 00 00    	sub    $0x100,%esp
   c:	31 c9                	xor    %ecx,%ecx
   e:	88 0c 0c             	mov    %cl,(%esp,%ecx,1)
  11:	fe c1                	inc    %cl
  13:	75 f9                	jne    0xe
  15:	31 c0                	xor    %eax,%eax
  17:	ba ef be ad de       	mov    $0xdeadbeef,%edx
  1c:	02 04 0c             	add    (%esp,%ecx,1),%al
  1f:	00 d0                	add    %dl,%al
  21:	c1 ca 08             	ror    $0x8,%edx
  24:	8a 1c 0c             	mov    (%esp,%ecx,1),%bl
  27:	8a 3c 04             	mov    (%esp,%eax,1),%bh
  2a:	88 1c 04             	mov    %bl,(%esp,%eax,1)
  2d:	88 3c 0c             	mov    %bh,(%esp,%ecx,1)
  30:	fe c1                	inc    %cl
  32:	75 e8                	jne    0x1c
  34:	e9 5c 00 00 00       	jmp    0x95
  39:	89 e3                	mov    %esp,%ebx
  3b:	81 c3 04 00 00 00    	add    $0x4,%ebx
  41:	5c                   	pop    %esp
  42:	58                   	pop    %eax
  43:	3d 41 41 41 41       	cmp    $0x41414141,%eax
  48:	75 43                	jne    0x8d
  4a:	58                   	pop    %eax
  4b:	3d 42 42 42 42       	cmp    $0x42424242,%eax
  50:	75 3b                	jne    0x8d
  52:	5a                   	pop    %edx
  53:	89 d1                	mov    %edx,%ecx
  55:	89 e6                	mov    %esp,%esi
  57:	89 df                	mov    %ebx,%edi
  59:	29 cf                	sub    %ecx,%edi
  5b:	f3 a4                	rep movsb %ds:(%esi),%es:(%edi)
  5d:	89 de                	mov    %ebx,%esi
  5f:	89 d1                	mov    %edx,%ecx
  61:	89 df                	mov    %ebx,%edi
  63:	29 cf                	sub    %ecx,%edi
  65:	31 c0                	xor    %eax,%eax
  67:	31 db                	xor    %ebx,%ebx
  69:	31 d2                	xor    %edx,%edx
  6b:	fe c0                	inc    %al
  6d:	02 1c 06             	add    (%esi,%eax,1),%bl
  70:	8a 14 06             	mov    (%esi,%eax,1),%dl
  73:	8a 34 1e             	mov    (%esi,%ebx,1),%dh
  76:	88 34 06             	mov    %dh,(%esi,%eax,1)
  79:	88 14 1e             	mov    %dl,(%esi,%ebx,1)
  7c:	00 f2                	add    %dh,%dl
  7e:	30 f6                	xor    %dh,%dh
  80:	8a 1c 16             	mov    (%esi,%edx,1),%bl
  83:	8a 17                	mov    (%edi),%dl
  85:	30 da                	xor    %bl,%dl
  87:	88 17                	mov    %dl,(%edi)
  89:	47                   	inc    %edi
  8a:	49                   	dec    %ecx
  8b:	75 de                	jne    0x6b
  8d:	31 db                	xor    %ebx,%ebx
  8f:	89 d8                	mov    %ebx,%eax
  91:	fe c0                	inc    %al
  93:	cd 80                	int    $0x80
  95:	90                   	nop
  96:	90                   	nop
  97:	e8 9d ff ff ff       	call   0x39
  9c:	41                   	inc    %ecx
  9d:	41                   	inc    %ecx
  9e:	41                   	inc    %ecx
  9f:	41                   	inc    %ecx
</pre>
<p>第一行出现JMP让人感到莫名其妙. 但是从整个代码来看, 基本上能确定是正常的可执行文件片段.<br />
有几个地方在执行的时候会出现问题:<br />
0&#215;97行在调用了0&#215;39的同时把0x9C压入栈中、但是在0&#215;42、0x4A两行都是pop指令的话, 第2次的pop会是没有意义的.<br />
0x9c~0x9f行的内容是0&#215;41414141、也就是ASCIIのAAAA. 在先前的文字搜索的时候还出现了BBBB.<br />
0&#215;43行、比较了EAX和AAAA的值、因为EAX储存的是0x9c~0x9f行のAAAA、其結果必然是真。<br />
但是在下一行, 于BBBB进行比较的时候、EAX的值是不确定的。从这边可以看出0x9f行的后面可能遗漏了部分代码.<br />
把问题的照片下载下来, 看下照片的16进制代码:</p>
<pre class="brush: plain; title: ; notranslate">
$ hexdump -C cyber.png
00000000  89 50 4e 47 0d 0a 1a 0a  00 00 00 0d 49 48 44 52  |.PNG........IHDR|
00000010  00 00 02 e4 00 00 01 04  08 02 00 00 00 ef 6a b6  |..............j.|
00000020  2d 00 00 00 01 73 52 47  42 00 ae ce 1c e9 00 00  |-....sRGB.......|
00000030  00 09 70 48 59 73 00 00  0b 13 00 00 0b 13 01 00  |..pHYs..........|
00000040  9a 9c 18 00 00 00 07 74  49 4d 45 07 db 08 05 0e  |.......tIME.....|
00000050  12 33 7e 39 c1 70 00 00  00 5d 69 54 58 74 43 6f  |.3~9.p...]iTXtCo|
00000060  6d 6d 65 6e 74 00 00 00  00 00 51 6b 4a 43 51 6a  |mment.....QkJCQj|
00000070  49 41 41 41 43 52 32 50  46 74 63 43 41 36 71 32  |IAAACR2PFtcCA6q2|
00000080  65 61 43 38 53 52 2b 38  64 6d 44 2f 7a 4e 7a 4c  |eaC8SR+8dmD/zNzL|
00000090  51 43 2b 74 64 33 74 46  51 34 71 78 38 4f 34 34  |QC+td3tFQ4qx8O44|
000000a0  37 54 44 65 75 5a 77 35  50 2b 30 53 73 62 45 63  |7TDeuZw5P+0SsbEc|
000000b0  59 52 0a 37 38 6a 4b 4c  77 3d 3d 32 ca be f1 00  |YR.78jKLw==2....|
...
</pre>
<p>在文件的头部</p>
<pre class="brush: plain; title: ; notranslate">
QkJCQjIAAACR2PFtcCA6q2eaC8SR+8dmD/zNzLQC+td3tFQ4qx8O447TDeuZw5P+0SsbEcYR.78jKLw==
</pre>
<p>是这样写的. 文字的最后是&#8221;==&#8221;, 这就提醒了我, 这段代码应该是通过Base64进行编码的.<br />
BASE64中对&#8221;.&#8221;是没有定义的、这边&#8221;.&#8221;实际上是换行符0x0A、应该被省略。</p>
<p>解码:</p>
<pre class="brush: plain; title: ; notranslate">
$ echo 'QkJCQjIAAACR2PFtcCA6q2eaC8SR+8dmD/zNzLQC+td3tFQ4qx8O447TDeuZw5P+0SsbEcYR78jKLw==' | base64 -D -o decoded.bin
$ hexdump -C decoded.bin
00000000  42 42 42 42 32 00 00 00  91 d8 f1 6d 70 20 3a ab  |BBBB2......mp :.|
00000010  67 9a 0b c4 91 fb c7 66  0f fc cd cc b4 02 fa d7  |g......f........|
00000020  77 b4 54 38 ab 1f 0e e3  8e d3 0d eb 99 c3 93 fe  |w.T8............|
00000030  d1 2b 1b 11 c6 11 ef c8  ca 2f                    |.+......./|
0000003a
</pre>
<p>BBBB出现了, 把这段代码和先前代码合并后, 执行看下.</p>
<pre class="brush: cpp; title: ; notranslate">
#include &lt;stdio.h&gt;
#include &lt;sys/types.h&gt;
#include &lt;sys/mman.h&gt;

main(){

  int i;

  static unsigned char shellcode[] = {
    0xEB,0x04,0xAF,0xC2,0xBF,0xA3,0x81,0xEC,
    0x00,0x01,0x00,0x00,0x31,0xC9,0x88,0x0C,
    0x0C,0xFE,0xC1,0x75,0xF9,0x31,0xC0,0xBA,
    0xEF,0xBE,0xAD,0xDE,0x02,0x04,0x0C,0x00,
    0xD0,0xC1,0xCA,0x08,0x8A,0x1C,0x0C,0x8A,
    0x3C,0x04,0x88,0x1C,0x04,0x88,0x3C,0x0C,
    0xFE,0xC1,0x75,0xE8,0xE9,0x5C,0x00,0x00,
    0x00,0x89,0xE3,0x81,0xC3,0x04,0x00,0x00,
    0x00,0x5C,0x58,0x3D,0x41,0x41,0x41,0x41,
    0x75,0x43,0x58,0x3D,0x42,0x42,0x42,0x42,
    0x75,0x3B,0x5A,0x89,0xD1,0x89,0xE6,0x89,
    0xDF,0x29,0xCF,0xF3,0xA4,0x89,0xDE,0x89,
    0xD1,0x89,0xDF,0x29,0xCF,0x31,0xC0,0x31,
    0xDB,0x31,0xD2,0xFE,0xC0,0x02,0x1C,0x06,
    0x8A,0x14,0x06,0x8A,0x34,0x1E,0x88,0x34,
    0x06,0x88,0x14,0x1E,0x00,0xF2,0x30,0xF6,
    0x8A,0x1C,0x16,0x8A,0x17,0x30,0xDA,0x88,
    0x17,0x47,0x49,0x75,0xDE,0x31,0xDB,0x89,
    0xD8,0xFE,0xC0,0xCD,0x80,0x90,0x90,0xE8,
    0x9D,0xFF,0xFF,0xFF,0x41,0x41,0x41,0x41,
    0x42,0x42,0x42,0x42,0x32,0x00,0x00,0x00,
    0x91,0xD8,0xF1,0x6D,0x70,0x20,0x3A,0xAB,
    0x67,0x9A,0x0B,0xC4,0x91,0xFB,0xC7,0x66,
    0x0F,0xFC,0xCD,0xCC,0xB4,0x02,0xFA,0xD7,
    0x77,0xB4,0x54,0x38,0xAB,0x1F,0x0E,0xE3,
    0x8E,0xD3,0x0D,0xEB,0x99,0xC3,0x93,0xFE,
    0xD1,0x2B,0x1B,0x11,0xC6,0x11,0xEF,0xC8,
    0xCA,0x2F
  };

  /*
   * patch INT 0x80 to INT 3 to throw an exception signal to debugger
   * 0xCD -&gt; 0xCC
   */
  printf(&quot;patching shellcode...\n&quot;);

  for(i = 0; i &lt; sizeof(shellcode); i++){
    if(*(unsigned short*)&amp;shellcode[i] == 0x80CD){
      shellcode[i] = 0xCC;
      printf(&quot;patch done\n&quot;);
      break;
    }
  }

  unsigned int page = ((unsigned int)shellcode)&amp;0xfffff000;

  if(-1 == mprotect((void*)page, 4096, PROT_READ | PROT_WRITE | PROT_EXEC))
    perror(&quot;mprotect error&quot;);

  ((int(*)())shellcode)();

}
</pre>
<p>代码的执行结果在0&#215;87行中的, EDI到EDI-0&#215;32(解码后得到的BBBB后面的那个字节).</p>
<pre class="brush: bash; title: ; notranslate">
$ gcc -arch i386 -g stage1.c -o stage1
$ gdb stage1
(gdb) r
(gdb) x/s $edi-0x32
0xbffff79a:	 &quot;GET /15b436de1f9107f3778aad525e5d0b20.js HTTP/1.1&quot;
</pre>
<p><strong>第2部分:</strong><br />
第1部分中得到的结果<a href="http://canyoucrackit.co.uk/15b436de1f9107f3778aad525e5d0b20.js" target="_blank">URL</a></p>
<pre class="brush: jscript; title: ; notranslate">
//--------------------------------------------------------------------------------------------------
//
// stage 2 of 3
//
// challenge:
//   reveal the solution within VM.mem
//
// disclaimer:
//   tested in ie 9, firefox 6, chrome 14 and v8 shell (http://code.google.com/apis/v8/build.html),
//   other javascript implementations may or may not work.
//
//--------------------------------------------------------------------------------------------------

var VM = {

  cpu: {
    ip: 0x00,

    r0: 0x00,
    r1: 0x00,
    r2: 0x00,
    r3: 0x00,

    cs: 0x00,
    ds: 0x10,

    fl: 0x00,

    firmware: [0xd2ab1f05, 0xda13f110]
  },

  mem: [
    0x31, 0x04, 0x33, 0xaa, 0x40, 0x02, 0x80, 0x03, 0x52, 0x00, 0x72, 0x01, 0x73, 0x01, 0xb2, 0x50,
    0x30, 0x14, 0xc0, 0x01, 0x80, 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

    0x98, 0xab, 0xd9, 0xa1, 0x9f, 0xa7, 0x83, 0x83, 0xf2, 0xb1, 0x34, 0xb6, 0xe4, 0xb7, 0xca, 0xb8,
    0xc9, 0xb8, 0x0e, 0xbd, 0x7d, 0x0f, 0xc0, 0xf1, 0xd9, 0x03, 0xc5, 0x3a, 0xc6, 0xc7, 0xc8, 0xc9,
    0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9,
    0xda, 0xdb, 0xa9, 0xcd, 0xdf, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9,
    0x26, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9,
    0x7d, 0x1f, 0x15, 0x60, 0x4d, 0x4d, 0x52, 0x7d, 0x0e, 0x27, 0x6d, 0x10, 0x6d, 0x5a, 0x06, 0x56,
    0x47, 0x14, 0x42, 0x0e, 0xb6, 0xb2, 0xb2, 0xe6, 0xeb, 0xb4, 0x83, 0x8e, 0xd7, 0xe5, 0xd4, 0xd9,
    0xc3, 0xf0, 0x80, 0x95, 0xf1, 0x82, 0x82, 0x9a, 0xbd, 0x95, 0xa4, 0x8d, 0x9a, 0x2b, 0x30, 0x69,
    0x4a, 0x69, 0x65, 0x55, 0x1c, 0x7b, 0x69, 0x1c, 0x6e, 0x04, 0x74, 0x35, 0x21, 0x26, 0x2f, 0x60,
    0x03, 0x4e, 0x37, 0x1e, 0x33, 0x54, 0x39, 0xe6, 0xba, 0xb4, 0xa2, 0xad, 0xa4, 0xc5, 0x95, 0xc8,
    0xc1, 0xe4, 0x8a, 0xec, 0xe7, 0x92, 0x8b, 0xe8, 0x81, 0xf0, 0xad, 0x98, 0xa4, 0xd0, 0xc0, 0x8d,
    0xac, 0x22, 0x52, 0x65, 0x7e, 0x27, 0x2b, 0x5a, 0x12, 0x61, 0x0a, 0x01, 0x7a, 0x6b, 0x1d, 0x67,
    0x75, 0x70, 0x6c, 0x1b, 0x11, 0x25, 0x25, 0x70, 0x7f, 0x7e, 0x67, 0x63, 0x30, 0x3c, 0x6d, 0x6a,
    0x01, 0x51, 0x59, 0x5f, 0x56, 0x13, 0x10, 0x43, 0x19, 0x18, 0xe5, 0xe0, 0xbe, 0xbf, 0xbd, 0xe9,
    0xf0, 0xf1, 0xf9, 0xfa, 0xab, 0x8f, 0xc1, 0xdf, 0xcf, 0x8d, 0xf8, 0xe7, 0xe2, 0xe9, 0x93, 0x8e,
    0xec, 0xf5, 0xc8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

    0x37, 0x7a, 0x07, 0x11, 0x1f, 0x1d, 0x68, 0x25, 0x32, 0x77, 0x1e, 0x62, 0x23, 0x5b, 0x47, 0x55,
    0x53, 0x30, 0x11, 0x42, 0xf6, 0xf1, 0xb1, 0xe6, 0xc3, 0xcc, 0xf8, 0xc5, 0xe4, 0xcc, 0xc0, 0xd3,
    0x85, 0xfd, 0x9a, 0xe3, 0xe6, 0x81, 0xb5, 0xbb, 0xd7, 0xcd, 0x87, 0xa3, 0xd3, 0x6b, 0x36, 0x6f,
    0x6f, 0x66, 0x55, 0x30, 0x16, 0x45, 0x5e, 0x09, 0x74, 0x5c, 0x3f, 0x29, 0x2b, 0x66, 0x3d, 0x0d,
    0x02, 0x30, 0x28, 0x35, 0x15, 0x09, 0x15, 0xdd, 0xec, 0xb8, 0xe2, 0xfb, 0xd8, 0xcb, 0xd8, 0xd1,
    0x8b, 0xd5, 0x82, 0xd9, 0x9a, 0xf1, 0x92, 0xab, 0xe8, 0xa6, 0xd6, 0xd0, 0x8c, 0xaa, 0xd2, 0x94,
    0xcf, 0x45, 0x46, 0x67, 0x20, 0x7d, 0x44, 0x14, 0x6b, 0x45, 0x6d, 0x54, 0x03, 0x17, 0x60, 0x62,
    0x55, 0x5a, 0x4a, 0x66, 0x61, 0x11, 0x57, 0x68, 0x75, 0x05, 0x62, 0x36, 0x7d, 0x02, 0x10, 0x4b,
    0x08, 0x22, 0x42, 0x32, 0xba, 0xe2, 0xb9, 0xe2, 0xd6, 0xb9, 0xff, 0xc3, 0xe9, 0x8a, 0x8f, 0xc1,
    0x8f, 0xe1, 0xb8, 0xa4, 0x96, 0xf1, 0x8f, 0x81, 0xb1, 0x8d, 0x89, 0xcc, 0xd4, 0x78, 0x76, 0x61,
    0x72, 0x3e, 0x37, 0x23, 0x56, 0x73, 0x71, 0x79, 0x63, 0x7c, 0x08, 0x11, 0x20, 0x69, 0x7a, 0x14,
    0x68, 0x05, 0x21, 0x1e, 0x32, 0x27, 0x59, 0xb7, 0xcf, 0xab, 0xdd, 0xd5, 0xcc, 0x97, 0x93, 0xf2,
    0xe7, 0xc0, 0xeb, 0xff, 0xe9, 0xa3, 0xbf, 0xa1, 0xab, 0x8b, 0xbb, 0x9e, 0x9e, 0x8c, 0xa0, 0xc1,
    0x9b, 0x5a, 0x2f, 0x2f, 0x4e, 0x4e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  ],

  exec: function()
  {
    // virtual machine architecture
    // ++++++++++++++++++++++++++++
    //
    // segmented memory model with 16-byte segment size (notation seg:offset)
    //
    // 4 general-purpose registers (r0-r3)
    // 2 segment registers (cs, ds equiv. to r4, r5)
    // 1 flags register (fl)
    //
    // instruction encoding
    // ++++++++++++++++++++
    //
    //           byte 1               byte 2 (optional)
    // bits      [ 7 6 5 4 3 2 1 0 ]  [ 7 6 5 4 3 2 1 0 ]
    // opcode      - - -
    // mod               -
    // operand1            - - - -
    // operand2                         - - - - - - - -
    //
    // operand1 is always a register index
    // operand2 is optional, depending upon the instruction set specified below
    // the value of mod alters the meaning of any operand2
    //   0: operand2 = reg ix
    //   1: operand2 = fixed immediate value or target segment (depending on instruction)
    //
    // instruction set
    // +++++++++++++++
    //
    // Notes:
    //   * r1, r2 =&gt; operand 1 is register 1, operand 2 is register 2
    //   * movr r1, r2 =&gt; move contents of register r2 into register r1
    //
    // opcode | instruction | operands (mod 0) | operands (mod 1)
    // -------+-------------+------------------+-----------------
    // 0x00   | jmp         | r1               | r2:r1
    // 0x01   | movr        | r1, r2           | rx,   imm
    // 0x02   | movm        | r1, [ds:r2]      | [ds:r1], r2
    // 0x03   | add         | r1, r2           | r1,   imm
    // 0x04   | xor         | r1, r2           | r1,   imm
    // 0x05   | cmp         | r1, r2           | r1,   imm
    // 0x06   | jmpe        | r1               | r2:r1
    // 0x07   | hlt         | N/A              | N/A
    //
    // flags
    // +++++
    //
    // cmp r1, r2 instruction results in:
    //   r1 == r2 =&gt; fl = 0
    //   r1 &lt; r2  =&gt; fl = 0xff
    //   r1 &gt; r2  =&gt; fl = 1
    //
    // jmpe r1
    //   =&gt; if (fl == 0) jmp r1
    //      else nop

    throw &quot;VM.exec not yet implemented&quot;;
  }

};

//--------------------------------------------------------------------------------------------------

try
{
  VM.exec();
}
catch(e)
{
  alert('\nError: ' + e + '\n');
}

//--------------------------------------------------------------------------------------------------
</pre>
<p>问题已经写的很清楚了, 设计一个虚拟CPU, 执行2进制代码后的的结果便是答案。</p>
<pre class="brush: cpp; title: ; notranslate">
#include &lt;stdio.h&gt;

static unsigned char mem[] = {
  0x31, 0x04, 0x33, 0xaa, 0x40, 0x02, 0x80, 0x03, 0x52, 0x00, 0x72, 0x01, 0x73, 0x01, 0xb2, 0x50,
  0x30, 0x14, 0xc0, 0x01, 0x80, 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

  0x98, 0xab, 0xd9, 0xa1, 0x9f, 0xa7, 0x83, 0x83, 0xf2, 0xb1, 0x34, 0xb6, 0xe4, 0xb7, 0xca, 0xb8,
  0xc9, 0xb8, 0x0e, 0xbd, 0x7d, 0x0f, 0xc0, 0xf1, 0xd9, 0x03, 0xc5, 0x3a, 0xc6, 0xc7, 0xc8, 0xc9,
  0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9,
  0xda, 0xdb, 0xa9, 0xcd, 0xdf, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9,
  0x26, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9,
  0x7d, 0x1f, 0x15, 0x60, 0x4d, 0x4d, 0x52, 0x7d, 0x0e, 0x27, 0x6d, 0x10, 0x6d, 0x5a, 0x06, 0x56,
  0x47, 0x14, 0x42, 0x0e, 0xb6, 0xb2, 0xb2, 0xe6, 0xeb, 0xb4, 0x83, 0x8e, 0xd7, 0xe5, 0xd4, 0xd9,
  0xc3, 0xf0, 0x80, 0x95, 0xf1, 0x82, 0x82, 0x9a, 0xbd, 0x95, 0xa4, 0x8d, 0x9a, 0x2b, 0x30, 0x69,
  0x4a, 0x69, 0x65, 0x55, 0x1c, 0x7b, 0x69, 0x1c, 0x6e, 0x04, 0x74, 0x35, 0x21, 0x26, 0x2f, 0x60,
  0x03, 0x4e, 0x37, 0x1e, 0x33, 0x54, 0x39, 0xe6, 0xba, 0xb4, 0xa2, 0xad, 0xa4, 0xc5, 0x95, 0xc8,
  0xc1, 0xe4, 0x8a, 0xec, 0xe7, 0x92, 0x8b, 0xe8, 0x81, 0xf0, 0xad, 0x98, 0xa4, 0xd0, 0xc0, 0x8d,
  0xac, 0x22, 0x52, 0x65, 0x7e, 0x27, 0x2b, 0x5a, 0x12, 0x61, 0x0a, 0x01, 0x7a, 0x6b, 0x1d, 0x67,
  0x75, 0x70, 0x6c, 0x1b, 0x11, 0x25, 0x25, 0x70, 0x7f, 0x7e, 0x67, 0x63, 0x30, 0x3c, 0x6d, 0x6a,
  0x01, 0x51, 0x59, 0x5f, 0x56, 0x13, 0x10, 0x43, 0x19, 0x18, 0xe5, 0xe0, 0xbe, 0xbf, 0xbd, 0xe9,
  0xf0, 0xf1, 0xf9, 0xfa, 0xab, 0x8f, 0xc1, 0xdf, 0xcf, 0x8d, 0xf8, 0xe7, 0xe2, 0xe9, 0x93, 0x8e,
  0xec, 0xf5, 0xc8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

  0x37, 0x7a, 0x07, 0x11, 0x1f, 0x1d, 0x68, 0x25, 0x32, 0x77, 0x1e, 0x62, 0x23, 0x5b, 0x47, 0x55,
  0x53, 0x30, 0x11, 0x42, 0xf6, 0xf1, 0xb1, 0xe6, 0xc3, 0xcc, 0xf8, 0xc5, 0xe4, 0xcc, 0xc0, 0xd3,
  0x85, 0xfd, 0x9a, 0xe3, 0xe6, 0x81, 0xb5, 0xbb, 0xd7, 0xcd, 0x87, 0xa3, 0xd3, 0x6b, 0x36, 0x6f,
  0x6f, 0x66, 0x55, 0x30, 0x16, 0x45, 0x5e, 0x09, 0x74, 0x5c, 0x3f, 0x29, 0x2b, 0x66, 0x3d, 0x0d,
  0x02, 0x30, 0x28, 0x35, 0x15, 0x09, 0x15, 0xdd, 0xec, 0xb8, 0xe2, 0xfb, 0xd8, 0xcb, 0xd8, 0xd1,
  0x8b, 0xd5, 0x82, 0xd9, 0x9a, 0xf1, 0x92, 0xab, 0xe8, 0xa6, 0xd6, 0xd0, 0x8c, 0xaa, 0xd2, 0x94,
  0xcf, 0x45, 0x46, 0x67, 0x20, 0x7d, 0x44, 0x14, 0x6b, 0x45, 0x6d, 0x54, 0x03, 0x17, 0x60, 0x62,
  0x55, 0x5a, 0x4a, 0x66, 0x61, 0x11, 0x57, 0x68, 0x75, 0x05, 0x62, 0x36, 0x7d, 0x02, 0x10, 0x4b,
  0x08, 0x22, 0x42, 0x32, 0xba, 0xe2, 0xb9, 0xe2, 0xd6, 0xb9, 0xff, 0xc3, 0xe9, 0x8a, 0x8f, 0xc1,
  0x8f, 0xe1, 0xb8, 0xa4, 0x96, 0xf1, 0x8f, 0x81, 0xb1, 0x8d, 0x89, 0xcc, 0xd4, 0x78, 0x76, 0x61,
  0x72, 0x3e, 0x37, 0x23, 0x56, 0x73, 0x71, 0x79, 0x63, 0x7c, 0x08, 0x11, 0x20, 0x69, 0x7a, 0x14,
  0x68, 0x05, 0x21, 0x1e, 0x32, 0x27, 0x59, 0xb7, 0xcf, 0xab, 0xdd, 0xd5, 0xcc, 0x97, 0x93, 0xf2,
  0xe7, 0xc0, 0xeb, 0xff, 0xe9, 0xa3, 0xbf, 0xa1, 0xab, 0x8b, 0xbb, 0x9e, 0x9e, 0x8c, 0xa0, 0xc1,
  0x9b, 0x5a, 0x2f, 0x2f, 0x4e, 0x4e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

#define adr(seg, off) ((seg &lt;&lt; 4) + off)

typedef unsigned char   byte;
typedef unsigned short  word;
typedef unsigned int    dword;

typedef struct _CPU {
  byte ip;
  byte regs[6];
  byte fl;
} _CPU;

_CPU cpu;

enum _REGISTER {
  r0,
  r1,
  r2,
  r3,
  cs,
  ds
};

typedef struct _INSTRUCTION {
  byte opcode;
  byte mod;
  byte operand1;
  byte operand2;
  byte unknown[2];
} _INSTRUCTION, *pInstruction;

_INSTRUCTION ins;

enum _OPCODE {
  JMP,
  MOVR,
  MOVM,
  ADD,
  XOR,
  CMP,
  JMPE,
  HLT
};

void fetchDecode(pInstruction pIns){
  word currentIP    = adr(cpu.regs[cs], cpu.ip);
  pIns-&gt;opcode      = (mem[currentIP] &gt;&gt; 5) &amp; 0x07;
  pIns-&gt;mod         = (mem[currentIP] &gt;&gt; 4) &amp; 0x01;
  pIns-&gt;operand1    = mem[currentIP] &amp; 0x0F;
  pIns-&gt;operand2    = mem[currentIP+1];

  pIns-&gt;unknown[0]  = mem[currentIP];
  pIns-&gt;unknown[1]  = mem[currentIP+1];

  cpu.ip += 2;
}

void exec(pInstruction pIns){

  printf(&quot;IP:%d\t&quot;, cpu.ip);

  switch(pIns-&gt;opcode) {

    case JMP:
      if(!pIns-&gt;mod){
        cpu.ip = cpu.regs[pIns-&gt;operand1];
        printf(&quot;JMP  %d\n&quot;, pIns-&gt;operand1);
      }
      else{
        cpu.regs[cs] = pIns-&gt;operand2;
        cpu.ip = (cpu.regs[cs] &lt;&lt; 4) + cpu.regs[pIns-&gt;operand1];
        printf(&quot;JMP  %d: %d\n&quot;, pIns-&gt;operand2, pIns-&gt;operand1);
      }
      break;

    case MOVR:
      if(!pIns-&gt;mod){
        cpu.regs[pIns-&gt;operand1] = cpu.regs[pIns-&gt;operand2];
        printf(&quot;MOVR %d, %d\n&quot;, pIns-&gt;operand1, pIns-&gt;operand2);
      }
      else{
        cpu.regs[pIns-&gt;operand1] = pIns-&gt;operand2;
        printf(&quot;MOVR %d, %02X\n&quot;, pIns-&gt;operand1, pIns-&gt;operand2);
      }
      break;

    case MOVM:
      if(!pIns-&gt;mod){
        cpu.regs[pIns-&gt;operand1] = mem[adr(cpu.regs[ds], cpu.regs[pIns-&gt;operand2])];
        printf(&quot;MOVM %d, [DS: %d]\n&quot;, pIns-&gt;operand1, pIns-&gt;operand2);
      }
      else{
        mem[adr(cpu.regs[ds], cpu.regs[pIns-&gt;operand1])] = cpu.regs[pIns-&gt;operand2];
        printf(&quot;MOVM [DS: %d], %d\n&quot;, pIns-&gt;operand1, pIns-&gt;operand2);
      }
      break;

    case ADD:
      if(!pIns-&gt;mod){
        cpu.regs[pIns-&gt;operand1] += cpu.regs[pIns-&gt;operand2];
        printf(&quot;ADD %d, %d\n&quot;, pIns-&gt;operand1, pIns-&gt;operand2);
      }
      else{
        cpu.regs[pIns-&gt;operand1] += pIns-&gt;operand2;
        printf(&quot;ADD %d, %02X\n&quot;, pIns-&gt;operand1, pIns-&gt;operand2);
      }
      break;

    case XOR:
      if(!pIns-&gt;mod){
        cpu.regs[pIns-&gt;operand1] ^= cpu.regs[pIns-&gt;operand2];
        printf(&quot;XOR %d, R%d\n&quot;, pIns-&gt;operand1, pIns-&gt;operand2);
      }
      else{
        cpu.regs[pIns-&gt;operand1] ^= pIns-&gt;operand2;
        printf(&quot;XOR %d, %02X\n&quot;, pIns-&gt;operand1, pIns-&gt;operand2);
      }
      break;

    case CMP:
      if(!pIns-&gt;mod){
        cpu.fl = cpu.regs[pIns-&gt;operand1] == cpu.regs[pIns-&gt;operand2]? 0x00: (cpu.regs[pIns-&gt;operand1] &lt; cpu.regs[pIns-&gt;operand2]? 0xff: 0x01);
        printf(&quot;CMP  %d, %d\n&quot;, pIns-&gt;operand1, pIns-&gt;operand2);
      }
      else{
        cpu.fl = cpu.regs[pIns-&gt;operand1] == pIns-&gt;operand2? 0x00: (cpu.regs[pIns-&gt;operand1] &lt; pIns-&gt;operand2? 0xff: 0x01);
        printf(&quot;CMP %d, %02X\n&quot;, pIns-&gt;operand1, pIns-&gt;operand2);
      }
      break;

    case JMPE:
      if(!cpu.fl){
        if(!pIns-&gt;mod){
          cpu.ip = adr(cpu.regs[cs], cpu.regs[pIns-&gt;operand1]);
          printf(&quot;JMPE %d\n&quot;, pIns-&gt;operand1);
        }
        else{
          cpu.ip = adr(cpu.regs[cs], adr(cpu.regs[pIns-&gt;operand2], cpu.regs[pIns-&gt;operand1]));
          printf(&quot;JMPE %d: %d\n&quot;, pIns-&gt;operand2, pIns-&gt;operand1);
        }
        break;
      }
      --cpu.ip;
      printf(&quot;JMPE NOP\n&quot;);
      break;

    case HLT:
      pIns-&gt;opcode = HLT;
      printf(&quot;HLT\n&quot;);
      break;

    default:
      pIns-&gt;opcode = HLT;
      printf(&quot;UNKNOW %02Xh, %02Xh\n&quot;, pIns-&gt;unknown[0], pIns-&gt;unknown[1]);
      break;
  };
}

main(){

  cpu.ip = 0x00;

  cpu.regs[r0] = 0x00;
  cpu.regs[r1] = 0x00;
  cpu.regs[r2] = 0x00;
  cpu.regs[r3] = 0x00;
  cpu.regs[cs] = 0x00;
  cpu.regs[ds] = 0x10;

  cpu.fl = 0x00;

  int i = 0;
  while ( ++i &lt; (2&lt;&lt;16) &amp;&amp; ins.opcode != HLT) {
    fetchDecode(&amp;ins);
    exec(&amp;ins);
  }

  FILE *fp = fopen(&quot;mem.dump&quot;, &quot;w&quot;);
  dword dataStart = adr(cpu.regs[ds], 0);
  fwrite((void*)(mem+dataStart), sizeof(mem)-dataStart, 1, fp);
  fclose(fp);

}
</pre>
<p>执行:</p>
<pre class="brush: plain; title: ; notranslate">
$ gcc -arch i386 -g stage2_vm.c -o stage2_vm
$ ./stage2_vm
...
IP:22	JMPE NOP
IP:23	CMP 0, 00
IP:25	MOVR 0, 1B
IP:27	JMPE 0
IP:29	HLT

$ strings mem.dump
GET /da75370fe15c4148bd4ceec861fbdaa5.exe HTTP/1.0
h%2w
b#[GUS0
k6oofU0
t\?)+f=
EFg }D
kEmT
`bUZJfa
xvar&gt;7#Vsqyc|
Z//NN
</pre>
<p>/da75370fe15c4148bd4ceec861fbdaa5.exe 是第2部分的答案</p>
<p><strong>第3部分</strong><br />
第2部分取得的<a href="http://canyoucrackit.co.uk/da75370fe15c4148bd4ceec861fbdaa5.exe" target="_blank">URL</a>需要cygwin环境的支持、因此要在Windows或者wine中执行。<br />
在执行之前先搜索下代码中包含了哪些文字</p>
<pre class="brush: plain; title: ; notranslate">
$ strings da75370fe15c4148bd4ceec861fbdaa5.exe
...
hqDTK7b8K2rvw
keygen.exe
usage: keygen.exe hostname
license.txt
error: license.txt not found
loading stage1 license key(s)...
loading stage2 license key(s)...
error: license.txt invalid
error: gethostbyname() failed
error: connect(&quot;%s&quot;) failed
GET /%s/%x/%x/%x/key.txt HTTP/1.0
...
</pre>
<p>这次有很多有意义的结果.<br />
首先把da75370fe15c4148bd4ceec861fbdaa5.exe重命名为keygen.exe。</p>
<p>使用方法:</p>
<pre class="brush: bash; title: ; notranslate">
keygen.exe canyoucrackit.co.uk
</pre>
<p>另外需要license.txt这个文件才能执行.</p>
<p>下面这段是反汇编的结果, 取自IDA Pro 6.1.110530 Evaluation version </p>
<pre class="brush: nasm8086; title: ; notranslate">
.text:00401120 loc_401120:                             ; CODE XREF: sub_401090+76j
.text:00401120                 mov     [esp+78h+var_70], 18h
.text:00401128                 mov     [esp+78h+hqDTK7b8K2rvw_copy], 0
.text:00401130                 lea     eax, [ebp+license1]
.text:00401133                 mov     [esp+78h+license2], eax
.text:00401136                 call    memset
.text:0040113B                 lea     eax, [ebp+license1]
.text:0040113E                 mov     [esp+78h+var_70], eax
.text:00401142                 mov     [esp+78h+hqDTK7b8K2rvw_copy], offset aS ; &quot;%s&quot;
.text:0040114A                 mov     eax, [ebp+var_4C]
.text:0040114D                 mov     [esp+78h+license2], eax
.text:00401150                 call    fscanf
.text:00401155                 mov     eax, [ebp+var_4C]
.text:00401158                 mov     [esp+78h+license2], eax
.text:0040115B                 call    fclose
.text:00401160                 mov     [ebp+var_4C], 0
.text:00401167                 cmp     [ebp+license1], 'qhcg'               // license开始4个字是qhcg
.text:0040116E                 jnz     short loc_4011CF
.text:00401170                 mov     eax, hqDTK7b8K2rvw
.text:00401175                 mov     [esp+78h+hqDTK7b8K2rvw_copy], eax
.text:00401179                 lea     eax, [ebp+license1]
.text:0040117C                 add     eax, 4
.text:0040117F                 mov     [esp+78h+license2], eax
                                                                            // char *crypt(const char *key, const char *salt);
                                                                            // key:8字、salt:2字
.text:00401182                 call    crypt                                // crypt(&quot;license第5个字以后&quot;, &quot;hq&quot;);
.text:00401187                 mov     edx, eax
.text:00401189                 mov     eax, hqDTK7b8K2rvw
.text:0040118E                 mov     [esp+78h+hqDTK7b8K2rvw_copy], eax
.text:00401192                 mov     [esp+78h+license2], edx
.text:00401195                 call    strcmp
.text:0040119A                 test    eax, eax
.text:0040119C                 jnz     short loc_4011A5
.text:0040119E                 mov     [ebp+var_C], 1
.text:004011A5
.text:004011A5 loc_4011A5:                             ; CODE XREF: sub_401090+10Cj
.text:004011A5                 mov     [esp+78h+license2], offset aLoadingStage1L ; &quot;loading stage1 license key(s)...\n&quot;
.text:004011AC                 call    printf
.text:004011B1                 mov     eax, [ebp+license3]
.text:004011B4                 mov     [ebp+license3_copy], eax
.text:004011B7                 mov     [esp+78h+license2], offset aLoadingStage2L ; &quot;loading stage2 license key(s)...\n\n&quot;
.text:004011BE                 call    printf
.text:004011C3                 mov     eax, [ebp+license4]
.text:004011C6                 mov     [ebp+license4_copy], eax
.text:004011C9                 mov     eax, [ebp+license5]
.text:004011CC                 mov     [ebp+license5_copy], eax
.text:004011CF
.text:004011CF loc_4011CF:                             ; CODE XREF: sub_401090+DEj
.text:004011CF                 cmp     [ebp+var_C], 0
.text:004011D3                 jnz     short loc_4011EA
.text:004011D5                 mov     [esp+78h+license2], offset aErrorLicense_0 ; &quot;error: license.txt invalid\n&quot;
.text:004011DC                 call    printf
.text:004011E1                 mov     [ebp+var_50], 0FFFFFFFFh
.text:004011E8                 jmp     short loc_401204
.text:004011EA ; ---------------------------------------------------------------------------
.text:004011EA
.text:004011EA loc_4011EA:                             ; CODE XREF: sub_401090+143j
.text:004011EA                 lea     eax, [ebp+license3_copy]
.text:004011ED                 mov     [esp+78h+hqDTK7b8K2rvw_copy], eax
.text:004011F1                 mov     eax, [ebp+hostname]
.text:004011F4                 add     eax, 4
.text:004011F7                 mov     eax, [eax]
.text:004011F9                 mov     [esp+78h+license2], eax
.text:004011FC                 call    genURL                                  //生成URL需要license的3,4,5部分
.text:00401201                 mov     [ebp+var_50], eax
.text:00401204
.text:00401204 loc_401204:                             ; CODE XREF: sub_401090+56j
.text:00401204                                         ; sub_401090+8Bj ...
.text:00401204                 mov     eax, [ebp+var_50]
.text:00401207                 leave
.text:00401208                 retn
.text:00401208 sub_401090      endp
</pre>
<p>总结这段代码, license的构成应该是:</p>
<pre class="brush: plain; title: ; notranslate">
qhcg + crypt用的8字符的密匙(可省略) + license3(4字节) + license4(4字节) + license5(4字节)
</pre>
<p>license3 ~ license5在哪边能找到呢?<br />
这里有一段提示:</p>
<pre class="brush: plain; title: ; notranslate">
&quot;loading stage1 license key(s)...\n&quot;
&quot;loading stage2 license key(s)...\n\n&quot;
</pre>
<p>也就是说、第1部分中有1个密匙、第2部分中有2个密匙</p>
<pre class="brush: plain; title: ; notranslate">
license3:
第1部分中代码开始部分就JMP了, 这边值得怀疑
   0:	eb 04                	jmp    0x6
   2:	af                   	scas   %es:(%edi),%eax
   3:	c2 bf a3             	ret    $0xa3bf
JMP后面的4字节afc2bfa3就是答案.
注意: x86是小尾序、afc2bfa3 应该写成 a3bfc2af。

license4,5:
CPU的结构体中定义的firmware实际上并没有使用
firmware: [0xd2ab1f05, 0xda13f110]
这就是答案了
</pre>
<p>license2如果不知道的话</p>
<pre class="brush: plain; title: ; notranslate">
.text:0040119C的jnz
改成jmp就行了
0x75 -&gt; 0xEB
</pre>
<p>google后发现, license2的答案是cyberwin。</p>
<p>license.txt的内容:</p>
<pre class="brush: plain; title: ; notranslate">
67636871637962657277696EAFC2BFA3051FABD210F113DA
</pre>
<p>用16进制保存.</p>
<pre class="brush: bash; title: ; notranslate">
$ ./keygen.exe canyoucrackit.co.uk

keygen.exe

loading stage1 license key(s)...
loading stage2 license key(s)...

request:

GET /hqDTK7b8K2rvw/a3bfc2af/d2ab1f05/da13f110/key.txt HTTP/1.0
</pre>
<p>打开<a href="http://canyoucrackit.co.uk/hqDTK7b8K2rvw/a3bfc2af/d2ab1f05/da13f110/key.txt" target="_blank">http://canyoucrackit.co.uk/hqDTK7b8K2rvw/a3bfc2af/d2ab1f05/da13f110/key.txt</a></p>
<pre class="brush: plain; title: ; notranslate">
Pr0t3ct!on#cyber_security@12*12.2011+
</pre>
<p>这就是最终的答案<br />
<a href="http://www.axot.org/wp-content/uploads/2011/12/Screen-Shot-2011-12-05-at-23.19.26-.png"></p>
<div class="su-frame su-frame-align-center">
<div class="su-frame-shell"><img src="http://www.axot.org/wp-content/uploads/2011/12/Screen-Shot-2011-12-05-at-23.19.26-.png" alt="" title="cracked" width="525" height="345" class="alignnone size-full wp-image-24" /></div>
</div>
<p></a><br />
成功!!!</p>
<p><strong>参考引用:</strong><br />
The Mac Hacker&#8217;s Handbook</p>
<p>http://pastebin.com/GAZ2aCLm</p>
</div>
<div class="su-tabs-pane">
Blogの更新も久しぶりだね、今回のテーマは、イギリスの政府通信本部GCHQからの求職問題です。<br />
問題はここ: http://canyoucrackit.co.uk/<br />
<strong>Part 1:</strong><br />
<a href="http://www.axot.org/wp-content/uploads/2011/12/cyber.png"></p>
<div class="su-frame su-frame-align-center">
<div class="su-frame-shell"><img src="http://www.axot.org/wp-content/uploads/2011/12/cyber.png" alt="" title="cyberPart1" width="370" height="130" class="alignnone size-full wp-image-21" /> </div>
</div>
<p></a><br />
目に見える生データは10&#215;16=160バイトの情報です、そのままじゃ考えにくいので、その中に何かの文字を入っているかを確認する。</p>
<pre class="brush: bash; title: ; notranslate">
$ strings raw
\X=AAAAuCX=BBBBu;Z
</pre>
<p>AAAA, BBBBしか無い、それはヒントにならない!<br />
ちょっと、最初のバイトは0xEBだ、0xEB(JMP)はクラッキングによく使うよね! もしかして、実行できるBinaryファイルなの? 確認しよう!</p>
<pre class="brush: asm; title: ; notranslate">
$ gobjdump -D -b binary -mi386 raw

raw:     file format binary

Disassembly of section .data:

00000000 &lt;.data&gt;:
   0:	eb 04                	jmp    0x6
   2:	af                   	scas   %es:(%edi),%eax
   3:	c2 bf a3             	ret    $0xa3bf
   6:	81 ec 00 01 00 00    	sub    $0x100,%esp
   c:	31 c9                	xor    %ecx,%ecx
   e:	88 0c 0c             	mov    %cl,(%esp,%ecx,1)
  11:	fe c1                	inc    %cl
  13:	75 f9                	jne    0xe
  15:	31 c0                	xor    %eax,%eax
  17:	ba ef be ad de       	mov    $0xdeadbeef,%edx
  1c:	02 04 0c             	add    (%esp,%ecx,1),%al
  1f:	00 d0                	add    %dl,%al
  21:	c1 ca 08             	ror    $0x8,%edx
  24:	8a 1c 0c             	mov    (%esp,%ecx,1),%bl
  27:	8a 3c 04             	mov    (%esp,%eax,1),%bh
  2a:	88 1c 04             	mov    %bl,(%esp,%eax,1)
  2d:	88 3c 0c             	mov    %bh,(%esp,%ecx,1)
  30:	fe c1                	inc    %cl
  32:	75 e8                	jne    0x1c
  34:	e9 5c 00 00 00       	jmp    0x95
  39:	89 e3                	mov    %esp,%ebx
  3b:	81 c3 04 00 00 00    	add    $0x4,%ebx
  41:	5c                   	pop    %esp
  42:	58                   	pop    %eax
  43:	3d 41 41 41 41       	cmp    $0x41414141,%eax
  48:	75 43                	jne    0x8d
  4a:	58                   	pop    %eax
  4b:	3d 42 42 42 42       	cmp    $0x42424242,%eax
  50:	75 3b                	jne    0x8d
  52:	5a                   	pop    %edx
  53:	89 d1                	mov    %edx,%ecx
  55:	89 e6                	mov    %esp,%esi
  57:	89 df                	mov    %ebx,%edi
  59:	29 cf                	sub    %ecx,%edi
  5b:	f3 a4                	rep movsb %ds:(%esi),%es:(%edi)
  5d:	89 de                	mov    %ebx,%esi
  5f:	89 d1                	mov    %edx,%ecx
  61:	89 df                	mov    %ebx,%edi
  63:	29 cf                	sub    %ecx,%edi
  65:	31 c0                	xor    %eax,%eax
  67:	31 db                	xor    %ebx,%ebx
  69:	31 d2                	xor    %edx,%edx
  6b:	fe c0                	inc    %al
  6d:	02 1c 06             	add    (%esi,%eax,1),%bl
  70:	8a 14 06             	mov    (%esi,%eax,1),%dl
  73:	8a 34 1e             	mov    (%esi,%ebx,1),%dh
  76:	88 34 06             	mov    %dh,(%esi,%eax,1)
  79:	88 14 1e             	mov    %dl,(%esi,%ebx,1)
  7c:	00 f2                	add    %dh,%dl
  7e:	30 f6                	xor    %dh,%dh
  80:	8a 1c 16             	mov    (%esi,%edx,1),%bl
  83:	8a 17                	mov    (%edi),%dl
  85:	30 da                	xor    %bl,%dl
  87:	88 17                	mov    %dl,(%edi)
  89:	47                   	inc    %edi
  8a:	49                   	dec    %ecx
  8b:	75 de                	jne    0x6b
  8d:	31 db                	xor    %ebx,%ebx
  8f:	89 d8                	mov    %ebx,%eax
  91:	fe c0                	inc    %al
  93:	cd 80                	int    $0x80
  95:	90                   	nop
  96:	90                   	nop
  97:	e8 9d ff ff ff       	call   0x39
  9c:	41                   	inc    %ecx
  9d:	41                   	inc    %ecx
  9e:	41                   	inc    %ecx
  9f:	41                   	inc    %ecx
</pre>
<p>なんで最初からJMPしているかがよく分からないが、コード全体は基本OPしかないので、実行できそうな感じ。<br />
ただ、0&#215;97行のところから、0&#215;39行にCALLしている間に、0x9C行をstackにpushしているのに、0&#215;42行、0x4A行二回連続POPするとはあり得ない。<br />
0x9c~0x9f行は0&#215;41414141になっているけど、それはASCIIのAAAAだね、先文字列を検索するときに、BBBBも出ていたよ。<br />
0&#215;43行に見たら、EAXとAAAAをCMPしている、EAXは0x9c~0x9f行のAAAAを格納しているので、結果がtrueのことが分かったね。<br />
問題は、その次の行がBBBBとCMPしているのに、EAXは何かが格納しているのは分からない。即ち、0x9f行の後ろが何かのデータが抜いている。<br />
問題の写真をダウンロードして、HEXコードを見ていたら、</p>
<pre class="brush: plain; title: ; notranslate">
$ hexdump -C cyber.png
00000000  89 50 4e 47 0d 0a 1a 0a  00 00 00 0d 49 48 44 52  |.PNG........IHDR|
00000010  00 00 02 e4 00 00 01 04  08 02 00 00 00 ef 6a b6  |..............j.|
00000020  2d 00 00 00 01 73 52 47  42 00 ae ce 1c e9 00 00  |-....sRGB.......|
00000030  00 09 70 48 59 73 00 00  0b 13 00 00 0b 13 01 00  |..pHYs..........|
00000040  9a 9c 18 00 00 00 07 74  49 4d 45 07 db 08 05 0e  |.......tIME.....|
00000050  12 33 7e 39 c1 70 00 00  00 5d 69 54 58 74 43 6f  |.3~9.p...]iTXtCo|
00000060  6d 6d 65 6e 74 00 00 00  00 00 51 6b 4a 43 51 6a  |mment.....QkJCQj|
00000070  49 41 41 41 43 52 32 50  46 74 63 43 41 36 71 32  |IAAACR2PFtcCA6q2|
00000080  65 61 43 38 53 52 2b 38  64 6d 44 2f 7a 4e 7a 4c  |eaC8SR+8dmD/zNzL|
00000090  51 43 2b 74 64 33 74 46  51 34 71 78 38 4f 34 34  |QC+td3tFQ4qx8O44|
000000a0  37 54 44 65 75 5a 77 35  50 2b 30 53 73 62 45 63  |7TDeuZw5P+0SsbEc|
000000b0  59 52 0a 37 38 6a 4b 4c  77 3d 3d 32 ca be f1 00  |YR.78jKLw==2....|
...
</pre>
<p>最初の当たりに</p>
<pre class="brush: plain; title: ; notranslate">
QkJCQjIAAACR2PFtcCA6q2eaC8SR+8dmD/zNzLQC+td3tFQ4qx8O447TDeuZw5P+0SsbEcYR.78jKLw==
</pre>
<p>が書いている。後ろが&#8221;==&#8221;になっていることは、もしかして、Base64でエンコードしているのかを疑ったいる。<br />
BASE64では&#8221;.&#8221;が定義していないが、ここの&#8221;.&#8221;は実際に改行記号の0x0Aなので、要らない。</p>
<p>Decode:</p>
<pre class="brush: plain; title: ; notranslate">
$ echo 'QkJCQjIAAACR2PFtcCA6q2eaC8SR+8dmD/zNzLQC+td3tFQ4qx8O447TDeuZw5P+0SsbEcYR78jKLw==' | base64 -D -o decoded.bin
$ hexdump -C decoded.bin
00000000  42 42 42 42 32 00 00 00  91 d8 f1 6d 70 20 3a ab  |BBBB2......mp :.|
00000010  67 9a 0b c4 91 fb c7 66  0f fc cd cc b4 02 fa d7  |g......f........|
00000020  77 b4 54 38 ab 1f 0e e3  8e d3 0d eb 99 c3 93 fe  |w.T8............|
00000030  d1 2b 1b 11 c6 11 ef c8  ca 2f                    |.+......./|
0000003a
</pre>
<p>Woo! BBBBが出てきたぞ! それを前のコードを合併して、実行してみよう!</p>
<pre class="brush: cpp; title: ; notranslate">
#include &lt;stdio.h&gt;
#include &lt;sys/types.h&gt;
#include &lt;sys/mman.h&gt;

main(){

  int i;

  static unsigned char shellcode[] = {
    0xEB,0x04,0xAF,0xC2,0xBF,0xA3,0x81,0xEC,
    0x00,0x01,0x00,0x00,0x31,0xC9,0x88,0x0C,
    0x0C,0xFE,0xC1,0x75,0xF9,0x31,0xC0,0xBA,
    0xEF,0xBE,0xAD,0xDE,0x02,0x04,0x0C,0x00,
    0xD0,0xC1,0xCA,0x08,0x8A,0x1C,0x0C,0x8A,
    0x3C,0x04,0x88,0x1C,0x04,0x88,0x3C,0x0C,
    0xFE,0xC1,0x75,0xE8,0xE9,0x5C,0x00,0x00,
    0x00,0x89,0xE3,0x81,0xC3,0x04,0x00,0x00,
    0x00,0x5C,0x58,0x3D,0x41,0x41,0x41,0x41,
    0x75,0x43,0x58,0x3D,0x42,0x42,0x42,0x42,
    0x75,0x3B,0x5A,0x89,0xD1,0x89,0xE6,0x89,
    0xDF,0x29,0xCF,0xF3,0xA4,0x89,0xDE,0x89,
    0xD1,0x89,0xDF,0x29,0xCF,0x31,0xC0,0x31,
    0xDB,0x31,0xD2,0xFE,0xC0,0x02,0x1C,0x06,
    0x8A,0x14,0x06,0x8A,0x34,0x1E,0x88,0x34,
    0x06,0x88,0x14,0x1E,0x00,0xF2,0x30,0xF6,
    0x8A,0x1C,0x16,0x8A,0x17,0x30,0xDA,0x88,
    0x17,0x47,0x49,0x75,0xDE,0x31,0xDB,0x89,
    0xD8,0xFE,0xC0,0xCD,0x80,0x90,0x90,0xE8,
    0x9D,0xFF,0xFF,0xFF,0x41,0x41,0x41,0x41,
    0x42,0x42,0x42,0x42,0x32,0x00,0x00,0x00,
    0x91,0xD8,0xF1,0x6D,0x70,0x20,0x3A,0xAB,
    0x67,0x9A,0x0B,0xC4,0x91,0xFB,0xC7,0x66,
    0x0F,0xFC,0xCD,0xCC,0xB4,0x02,0xFA,0xD7,
    0x77,0xB4,0x54,0x38,0xAB,0x1F,0x0E,0xE3,
    0x8E,0xD3,0x0D,0xEB,0x99,0xC3,0x93,0xFE,
    0xD1,0x2B,0x1B,0x11,0xC6,0x11,0xEF,0xC8,
    0xCA,0x2F
  };

  /*
   * patch INT 0x80 to INT 3 to throw an exception signal to debugger
   * 0xCD -&gt; 0xCC
   */
  printf(&quot;patching shellcode...\n&quot;);

  for(i = 0; i &lt; sizeof(shellcode); i++){
    if(*(unsigned short*)&amp;shellcode[i] == 0x80CD){
      shellcode[i] = 0xCC;
      printf(&quot;patch done\n&quot;);
      break;
    }
  }

  unsigned int page = ((unsigned int)shellcode)&amp;0xfffff000;

  if(-1 == mprotect((void*)page, 4096, PROT_READ | PROT_WRITE | PROT_EXEC))
    perror(&quot;mprotect error&quot;);

  ((int(*)())shellcode)();

}
</pre>
<p>結果は0&#215;87行あたりに、EDIに格納しているアドレスから、EDI-(新しい取ったデータのBBBBの後ろの1バイト0&#215;32)に保存している。</p>
<pre class="brush: bash; title: ; notranslate">
$ gcc -arch i386 -g stage1.c -o stage1
$ gdb stage1
(gdb) r
(gdb) x/s $edi-0x32
0xbffff79a:	 &quot;GET /15b436de1f9107f3778aad525e5d0b20.js HTTP/1.1&quot;
</pre>
<p><strong>Part 2:</strong><br />
part1で取った<a href="http://canyoucrackit.co.uk/15b436de1f9107f3778aad525e5d0b20.js" target="_blank">URL</a></p>
<pre class="brush: jscript; title: ; notranslate">
//--------------------------------------------------------------------------------------------------
//
// stage 2 of 3
//
// challenge:
//   reveal the solution within VM.mem
//
// disclaimer:
//   tested in ie 9, firefox 6, chrome 14 and v8 shell (http://code.google.com/apis/v8/build.html),
//   other javascript implementations may or may not work.
//
//--------------------------------------------------------------------------------------------------

var VM = {

  cpu: {
    ip: 0x00,

    r0: 0x00,
    r1: 0x00,
    r2: 0x00,
    r3: 0x00,

    cs: 0x00,
    ds: 0x10,

    fl: 0x00,

    firmware: [0xd2ab1f05, 0xda13f110]
  },

  mem: [
    0x31, 0x04, 0x33, 0xaa, 0x40, 0x02, 0x80, 0x03, 0x52, 0x00, 0x72, 0x01, 0x73, 0x01, 0xb2, 0x50,
    0x30, 0x14, 0xc0, 0x01, 0x80, 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

    0x98, 0xab, 0xd9, 0xa1, 0x9f, 0xa7, 0x83, 0x83, 0xf2, 0xb1, 0x34, 0xb6, 0xe4, 0xb7, 0xca, 0xb8,
    0xc9, 0xb8, 0x0e, 0xbd, 0x7d, 0x0f, 0xc0, 0xf1, 0xd9, 0x03, 0xc5, 0x3a, 0xc6, 0xc7, 0xc8, 0xc9,
    0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9,
    0xda, 0xdb, 0xa9, 0xcd, 0xdf, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9,
    0x26, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9,
    0x7d, 0x1f, 0x15, 0x60, 0x4d, 0x4d, 0x52, 0x7d, 0x0e, 0x27, 0x6d, 0x10, 0x6d, 0x5a, 0x06, 0x56,
    0x47, 0x14, 0x42, 0x0e, 0xb6, 0xb2, 0xb2, 0xe6, 0xeb, 0xb4, 0x83, 0x8e, 0xd7, 0xe5, 0xd4, 0xd9,
    0xc3, 0xf0, 0x80, 0x95, 0xf1, 0x82, 0x82, 0x9a, 0xbd, 0x95, 0xa4, 0x8d, 0x9a, 0x2b, 0x30, 0x69,
    0x4a, 0x69, 0x65, 0x55, 0x1c, 0x7b, 0x69, 0x1c, 0x6e, 0x04, 0x74, 0x35, 0x21, 0x26, 0x2f, 0x60,
    0x03, 0x4e, 0x37, 0x1e, 0x33, 0x54, 0x39, 0xe6, 0xba, 0xb4, 0xa2, 0xad, 0xa4, 0xc5, 0x95, 0xc8,
    0xc1, 0xe4, 0x8a, 0xec, 0xe7, 0x92, 0x8b, 0xe8, 0x81, 0xf0, 0xad, 0x98, 0xa4, 0xd0, 0xc0, 0x8d,
    0xac, 0x22, 0x52, 0x65, 0x7e, 0x27, 0x2b, 0x5a, 0x12, 0x61, 0x0a, 0x01, 0x7a, 0x6b, 0x1d, 0x67,
    0x75, 0x70, 0x6c, 0x1b, 0x11, 0x25, 0x25, 0x70, 0x7f, 0x7e, 0x67, 0x63, 0x30, 0x3c, 0x6d, 0x6a,
    0x01, 0x51, 0x59, 0x5f, 0x56, 0x13, 0x10, 0x43, 0x19, 0x18, 0xe5, 0xe0, 0xbe, 0xbf, 0xbd, 0xe9,
    0xf0, 0xf1, 0xf9, 0xfa, 0xab, 0x8f, 0xc1, 0xdf, 0xcf, 0x8d, 0xf8, 0xe7, 0xe2, 0xe9, 0x93, 0x8e,
    0xec, 0xf5, 0xc8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

    0x37, 0x7a, 0x07, 0x11, 0x1f, 0x1d, 0x68, 0x25, 0x32, 0x77, 0x1e, 0x62, 0x23, 0x5b, 0x47, 0x55,
    0x53, 0x30, 0x11, 0x42, 0xf6, 0xf1, 0xb1, 0xe6, 0xc3, 0xcc, 0xf8, 0xc5, 0xe4, 0xcc, 0xc0, 0xd3,
    0x85, 0xfd, 0x9a, 0xe3, 0xe6, 0x81, 0xb5, 0xbb, 0xd7, 0xcd, 0x87, 0xa3, 0xd3, 0x6b, 0x36, 0x6f,
    0x6f, 0x66, 0x55, 0x30, 0x16, 0x45, 0x5e, 0x09, 0x74, 0x5c, 0x3f, 0x29, 0x2b, 0x66, 0x3d, 0x0d,
    0x02, 0x30, 0x28, 0x35, 0x15, 0x09, 0x15, 0xdd, 0xec, 0xb8, 0xe2, 0xfb, 0xd8, 0xcb, 0xd8, 0xd1,
    0x8b, 0xd5, 0x82, 0xd9, 0x9a, 0xf1, 0x92, 0xab, 0xe8, 0xa6, 0xd6, 0xd0, 0x8c, 0xaa, 0xd2, 0x94,
    0xcf, 0x45, 0x46, 0x67, 0x20, 0x7d, 0x44, 0x14, 0x6b, 0x45, 0x6d, 0x54, 0x03, 0x17, 0x60, 0x62,
    0x55, 0x5a, 0x4a, 0x66, 0x61, 0x11, 0x57, 0x68, 0x75, 0x05, 0x62, 0x36, 0x7d, 0x02, 0x10, 0x4b,
    0x08, 0x22, 0x42, 0x32, 0xba, 0xe2, 0xb9, 0xe2, 0xd6, 0xb9, 0xff, 0xc3, 0xe9, 0x8a, 0x8f, 0xc1,
    0x8f, 0xe1, 0xb8, 0xa4, 0x96, 0xf1, 0x8f, 0x81, 0xb1, 0x8d, 0x89, 0xcc, 0xd4, 0x78, 0x76, 0x61,
    0x72, 0x3e, 0x37, 0x23, 0x56, 0x73, 0x71, 0x79, 0x63, 0x7c, 0x08, 0x11, 0x20, 0x69, 0x7a, 0x14,
    0x68, 0x05, 0x21, 0x1e, 0x32, 0x27, 0x59, 0xb7, 0xcf, 0xab, 0xdd, 0xd5, 0xcc, 0x97, 0x93, 0xf2,
    0xe7, 0xc0, 0xeb, 0xff, 0xe9, 0xa3, 0xbf, 0xa1, 0xab, 0x8b, 0xbb, 0x9e, 0x9e, 0x8c, 0xa0, 0xc1,
    0x9b, 0x5a, 0x2f, 0x2f, 0x4e, 0x4e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  ],

  exec: function()
  {
    // virtual machine architecture
    // ++++++++++++++++++++++++++++
    //
    // segmented memory model with 16-byte segment size (notation seg:offset)
    //
    // 4 general-purpose registers (r0-r3)
    // 2 segment registers (cs, ds equiv. to r4, r5)
    // 1 flags register (fl)
    //
    // instruction encoding
    // ++++++++++++++++++++
    //
    //           byte 1               byte 2 (optional)
    // bits      [ 7 6 5 4 3 2 1 0 ]  [ 7 6 5 4 3 2 1 0 ]
    // opcode      - - -
    // mod               -
    // operand1            - - - -
    // operand2                         - - - - - - - -
    //
    // operand1 is always a register index
    // operand2 is optional, depending upon the instruction set specified below
    // the value of mod alters the meaning of any operand2
    //   0: operand2 = reg ix
    //   1: operand2 = fixed immediate value or target segment (depending on instruction)
    //
    // instruction set
    // +++++++++++++++
    //
    // Notes:
    //   * r1, r2 =&gt; operand 1 is register 1, operand 2 is register 2
    //   * movr r1, r2 =&gt; move contents of register r2 into register r1
    //
    // opcode | instruction | operands (mod 0) | operands (mod 1)
    // -------+-------------+------------------+-----------------
    // 0x00   | jmp         | r1               | r2:r1
    // 0x01   | movr        | r1, r2           | rx,   imm
    // 0x02   | movm        | r1, [ds:r2]      | [ds:r1], r2
    // 0x03   | add         | r1, r2           | r1,   imm
    // 0x04   | xor         | r1, r2           | r1,   imm
    // 0x05   | cmp         | r1, r2           | r1,   imm
    // 0x06   | jmpe        | r1               | r2:r1
    // 0x07   | hlt         | N/A              | N/A
    //
    // flags
    // +++++
    //
    // cmp r1, r2 instruction results in:
    //   r1 == r2 =&gt; fl = 0
    //   r1 &lt; r2  =&gt; fl = 0xff
    //   r1 &gt; r2  =&gt; fl = 1
    //
    // jmpe r1
    //   =&gt; if (fl == 0) jmp r1
    //      else nop

    throw &quot;VM.exec not yet implemented&quot;;
  }

};

//--------------------------------------------------------------------------------------------------

try
{
  VM.exec();
}
catch(e)
{
  alert('\nError: ' + e + '\n');
}

//--------------------------------------------------------------------------------------------------
</pre>
<p>問題の主旨ははっきり分かる、仮想CPUを作って、バイナリコードを実行し結果を得られる。<br />
低いレベルのプログラミングになるね、CS,DSなどを復習したら、出来ると思う。</p>
<pre class="brush: cpp; title: ; notranslate">
#include &lt;stdio.h&gt;

static unsigned char mem[] = {
  0x31, 0x04, 0x33, 0xaa, 0x40, 0x02, 0x80, 0x03, 0x52, 0x00, 0x72, 0x01, 0x73, 0x01, 0xb2, 0x50,
  0x30, 0x14, 0xc0, 0x01, 0x80, 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

  0x98, 0xab, 0xd9, 0xa1, 0x9f, 0xa7, 0x83, 0x83, 0xf2, 0xb1, 0x34, 0xb6, 0xe4, 0xb7, 0xca, 0xb8,
  0xc9, 0xb8, 0x0e, 0xbd, 0x7d, 0x0f, 0xc0, 0xf1, 0xd9, 0x03, 0xc5, 0x3a, 0xc6, 0xc7, 0xc8, 0xc9,
  0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9,
  0xda, 0xdb, 0xa9, 0xcd, 0xdf, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9,
  0x26, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9,
  0x7d, 0x1f, 0x15, 0x60, 0x4d, 0x4d, 0x52, 0x7d, 0x0e, 0x27, 0x6d, 0x10, 0x6d, 0x5a, 0x06, 0x56,
  0x47, 0x14, 0x42, 0x0e, 0xb6, 0xb2, 0xb2, 0xe6, 0xeb, 0xb4, 0x83, 0x8e, 0xd7, 0xe5, 0xd4, 0xd9,
  0xc3, 0xf0, 0x80, 0x95, 0xf1, 0x82, 0x82, 0x9a, 0xbd, 0x95, 0xa4, 0x8d, 0x9a, 0x2b, 0x30, 0x69,
  0x4a, 0x69, 0x65, 0x55, 0x1c, 0x7b, 0x69, 0x1c, 0x6e, 0x04, 0x74, 0x35, 0x21, 0x26, 0x2f, 0x60,
  0x03, 0x4e, 0x37, 0x1e, 0x33, 0x54, 0x39, 0xe6, 0xba, 0xb4, 0xa2, 0xad, 0xa4, 0xc5, 0x95, 0xc8,
  0xc1, 0xe4, 0x8a, 0xec, 0xe7, 0x92, 0x8b, 0xe8, 0x81, 0xf0, 0xad, 0x98, 0xa4, 0xd0, 0xc0, 0x8d,
  0xac, 0x22, 0x52, 0x65, 0x7e, 0x27, 0x2b, 0x5a, 0x12, 0x61, 0x0a, 0x01, 0x7a, 0x6b, 0x1d, 0x67,
  0x75, 0x70, 0x6c, 0x1b, 0x11, 0x25, 0x25, 0x70, 0x7f, 0x7e, 0x67, 0x63, 0x30, 0x3c, 0x6d, 0x6a,
  0x01, 0x51, 0x59, 0x5f, 0x56, 0x13, 0x10, 0x43, 0x19, 0x18, 0xe5, 0xe0, 0xbe, 0xbf, 0xbd, 0xe9,
  0xf0, 0xf1, 0xf9, 0xfa, 0xab, 0x8f, 0xc1, 0xdf, 0xcf, 0x8d, 0xf8, 0xe7, 0xe2, 0xe9, 0x93, 0x8e,
  0xec, 0xf5, 0xc8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

  0x37, 0x7a, 0x07, 0x11, 0x1f, 0x1d, 0x68, 0x25, 0x32, 0x77, 0x1e, 0x62, 0x23, 0x5b, 0x47, 0x55,
  0x53, 0x30, 0x11, 0x42, 0xf6, 0xf1, 0xb1, 0xe6, 0xc3, 0xcc, 0xf8, 0xc5, 0xe4, 0xcc, 0xc0, 0xd3,
  0x85, 0xfd, 0x9a, 0xe3, 0xe6, 0x81, 0xb5, 0xbb, 0xd7, 0xcd, 0x87, 0xa3, 0xd3, 0x6b, 0x36, 0x6f,
  0x6f, 0x66, 0x55, 0x30, 0x16, 0x45, 0x5e, 0x09, 0x74, 0x5c, 0x3f, 0x29, 0x2b, 0x66, 0x3d, 0x0d,
  0x02, 0x30, 0x28, 0x35, 0x15, 0x09, 0x15, 0xdd, 0xec, 0xb8, 0xe2, 0xfb, 0xd8, 0xcb, 0xd8, 0xd1,
  0x8b, 0xd5, 0x82, 0xd9, 0x9a, 0xf1, 0x92, 0xab, 0xe8, 0xa6, 0xd6, 0xd0, 0x8c, 0xaa, 0xd2, 0x94,
  0xcf, 0x45, 0x46, 0x67, 0x20, 0x7d, 0x44, 0x14, 0x6b, 0x45, 0x6d, 0x54, 0x03, 0x17, 0x60, 0x62,
  0x55, 0x5a, 0x4a, 0x66, 0x61, 0x11, 0x57, 0x68, 0x75, 0x05, 0x62, 0x36, 0x7d, 0x02, 0x10, 0x4b,
  0x08, 0x22, 0x42, 0x32, 0xba, 0xe2, 0xb9, 0xe2, 0xd6, 0xb9, 0xff, 0xc3, 0xe9, 0x8a, 0x8f, 0xc1,
  0x8f, 0xe1, 0xb8, 0xa4, 0x96, 0xf1, 0x8f, 0x81, 0xb1, 0x8d, 0x89, 0xcc, 0xd4, 0x78, 0x76, 0x61,
  0x72, 0x3e, 0x37, 0x23, 0x56, 0x73, 0x71, 0x79, 0x63, 0x7c, 0x08, 0x11, 0x20, 0x69, 0x7a, 0x14,
  0x68, 0x05, 0x21, 0x1e, 0x32, 0x27, 0x59, 0xb7, 0xcf, 0xab, 0xdd, 0xd5, 0xcc, 0x97, 0x93, 0xf2,
  0xe7, 0xc0, 0xeb, 0xff, 0xe9, 0xa3, 0xbf, 0xa1, 0xab, 0x8b, 0xbb, 0x9e, 0x9e, 0x8c, 0xa0, 0xc1,
  0x9b, 0x5a, 0x2f, 0x2f, 0x4e, 0x4e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

#define adr(seg, off) ((seg &lt;&lt; 4) + off)

typedef unsigned char   byte;
typedef unsigned short  word;
typedef unsigned int    dword;

typedef struct _CPU {
  byte ip;
  byte regs[6];
  byte fl;
} _CPU;

_CPU cpu;

enum _REGISTER {
  r0,
  r1,
  r2,
  r3,
  cs,
  ds
};

typedef struct _INSTRUCTION {
  byte opcode;
  byte mod;
  byte operand1;
  byte operand2;
  byte unknown[2];
} _INSTRUCTION, *pInstruction;

_INSTRUCTION ins;

enum _OPCODE {
  JMP,
  MOVR,
  MOVM,
  ADD,
  XOR,
  CMP,
  JMPE,
  HLT
};

void fetchDecode(pInstruction pIns){
  word currentIP    = adr(cpu.regs[cs], cpu.ip);
  pIns-&gt;opcode      = (mem[currentIP] &gt;&gt; 5) &amp; 0x07;
  pIns-&gt;mod         = (mem[currentIP] &gt;&gt; 4) &amp; 0x01;
  pIns-&gt;operand1    = mem[currentIP] &amp; 0x0F;
  pIns-&gt;operand2    = mem[currentIP+1];

  pIns-&gt;unknown[0]  = mem[currentIP];
  pIns-&gt;unknown[1]  = mem[currentIP+1];

  cpu.ip += 2;
}

void exec(pInstruction pIns){

  printf(&quot;IP:%d\t&quot;, cpu.ip);

  switch(pIns-&gt;opcode) {

    case JMP:
      if(!pIns-&gt;mod){
        cpu.ip = cpu.regs[pIns-&gt;operand1];
        printf(&quot;JMP  %d\n&quot;, pIns-&gt;operand1);
      }
      else{
        cpu.regs[cs] = pIns-&gt;operand2;
        cpu.ip = (cpu.regs[cs] &lt;&lt; 4) + cpu.regs[pIns-&gt;operand1];
        printf(&quot;JMP  %d: %d\n&quot;, pIns-&gt;operand2, pIns-&gt;operand1);
      }
      break;

    case MOVR:
      if(!pIns-&gt;mod){
        cpu.regs[pIns-&gt;operand1] = cpu.regs[pIns-&gt;operand2];
        printf(&quot;MOVR %d, %d\n&quot;, pIns-&gt;operand1, pIns-&gt;operand2);
      }
      else{
        cpu.regs[pIns-&gt;operand1] = pIns-&gt;operand2;
        printf(&quot;MOVR %d, %02X\n&quot;, pIns-&gt;operand1, pIns-&gt;operand2);
      }
      break;

    case MOVM:
      if(!pIns-&gt;mod){
        cpu.regs[pIns-&gt;operand1] = mem[adr(cpu.regs[ds], cpu.regs[pIns-&gt;operand2])];
        printf(&quot;MOVM %d, [DS: %d]\n&quot;, pIns-&gt;operand1, pIns-&gt;operand2);
      }
      else{
        mem[adr(cpu.regs[ds], cpu.regs[pIns-&gt;operand1])] = cpu.regs[pIns-&gt;operand2];
        printf(&quot;MOVM [DS: %d], %d\n&quot;, pIns-&gt;operand1, pIns-&gt;operand2);
      }
      break;

    case ADD:
      if(!pIns-&gt;mod){
        cpu.regs[pIns-&gt;operand1] += cpu.regs[pIns-&gt;operand2];
        printf(&quot;ADD %d, %d\n&quot;, pIns-&gt;operand1, pIns-&gt;operand2);
      }
      else{
        cpu.regs[pIns-&gt;operand1] += pIns-&gt;operand2;
        printf(&quot;ADD %d, %02X\n&quot;, pIns-&gt;operand1, pIns-&gt;operand2);
      }
      break;

    case XOR:
      if(!pIns-&gt;mod){
        cpu.regs[pIns-&gt;operand1] ^= cpu.regs[pIns-&gt;operand2];
        printf(&quot;XOR %d, R%d\n&quot;, pIns-&gt;operand1, pIns-&gt;operand2);
      }
      else{
        cpu.regs[pIns-&gt;operand1] ^= pIns-&gt;operand2;
        printf(&quot;XOR %d, %02X\n&quot;, pIns-&gt;operand1, pIns-&gt;operand2);
      }
      break;

    case CMP:
      if(!pIns-&gt;mod){
        cpu.fl = cpu.regs[pIns-&gt;operand1] == cpu.regs[pIns-&gt;operand2]? 0x00: (cpu.regs[pIns-&gt;operand1] &lt; cpu.regs[pIns-&gt;operand2]? 0xff: 0x01);
        printf(&quot;CMP  %d, %d\n&quot;, pIns-&gt;operand1, pIns-&gt;operand2);
      }
      else{
        cpu.fl = cpu.regs[pIns-&gt;operand1] == pIns-&gt;operand2? 0x00: (cpu.regs[pIns-&gt;operand1] &lt; pIns-&gt;operand2? 0xff: 0x01);
        printf(&quot;CMP %d, %02X\n&quot;, pIns-&gt;operand1, pIns-&gt;operand2);
      }
      break;

    case JMPE:
      if(!cpu.fl){
        if(!pIns-&gt;mod){
          cpu.ip = adr(cpu.regs[cs], cpu.regs[pIns-&gt;operand1]);
          printf(&quot;JMPE %d\n&quot;, pIns-&gt;operand1);
        }
        else{
          cpu.ip = adr(cpu.regs[cs], adr(cpu.regs[pIns-&gt;operand2], cpu.regs[pIns-&gt;operand1]));
          printf(&quot;JMPE %d: %d\n&quot;, pIns-&gt;operand2, pIns-&gt;operand1);
        }
        break;
      }
      --cpu.ip;
      printf(&quot;JMPE NOP\n&quot;);
      break;

    case HLT:
      pIns-&gt;opcode = HLT;
      printf(&quot;HLT\n&quot;);
      break;

    default:
      pIns-&gt;opcode = HLT;
      printf(&quot;UNKNOW %02Xh, %02Xh\n&quot;, pIns-&gt;unknown[0], pIns-&gt;unknown[1]);
      break;
  };
}

main(){

  cpu.ip = 0x00;

  cpu.regs[r0] = 0x00;
  cpu.regs[r1] = 0x00;
  cpu.regs[r2] = 0x00;
  cpu.regs[r3] = 0x00;
  cpu.regs[cs] = 0x00;
  cpu.regs[ds] = 0x10;

  cpu.fl = 0x00;

  int i = 0;
  while ( ++i &lt; (2&lt;&lt;16) &amp;&amp; ins.opcode != HLT) {
    fetchDecode(&amp;ins);
    exec(&amp;ins);
  }

  FILE *fp = fopen(&quot;mem.dump&quot;, &quot;w&quot;);
  dword dataStart = adr(cpu.regs[ds], 0);
  fwrite((void*)(mem+dataStart), sizeof(mem)-dataStart, 1, fp);
  fclose(fp);

}
</pre>
<p>実行してみる:</p>
<pre class="brush: plain; title: ; notranslate">
$ gcc -arch i386 -g stage2_vm.c -o stage2_vm
$ ./stage2_vm
...
IP:22	JMPE NOP
IP:23	CMP 0, 00
IP:25	MOVR 0, 1B
IP:27	JMPE 0
IP:29	HLT

$ strings mem.dump
GET /da75370fe15c4148bd4ceec861fbdaa5.exe HTTP/1.0
h%2w
b#[GUS0
k6oofU0
t\?)+f=
EFg }D
kEmT
`bUZJfa
xvar&gt;7#Vsqyc|
Z//NN
</pre>
<p>/da75370fe15c4148bd4ceec861fbdaa5.exe はPart 2で得られた結果!!</p>
<p><strong>Part 3:</strong><br />
part2で取った<a href="http://canyoucrackit.co.uk/da75370fe15c4148bd4ceec861fbdaa5.exe" target="_blank">URL</a>はcygwin環境が必要なので、Windowsもしくはwineで実行しよう。<br />
実行する前に文字検索するね</p>
<pre class="brush: plain; title: ; notranslate">
$ strings da75370fe15c4148bd4ceec861fbdaa5.exe
...
hqDTK7b8K2rvw
keygen.exe
usage: keygen.exe hostname
license.txt
error: license.txt not found
loading stage1 license key(s)...
loading stage2 license key(s)...
error: license.txt invalid
error: gethostbyname() failed
error: connect(&quot;%s&quot;) failed
GET /%s/%x/%x/%x/key.txt HTTP/1.0
...
</pre>
<p>お!、結構情報入ってるじゃん。<br />
まずda75370fe15c4148bd4ceec861fbdaa5.exeをkeygen.exeにrenameする。</p>
<p>使い方は:</p>
<pre class="brush: bash; title: ; notranslate">
keygen.exe canyoucrackit.co.uk
</pre>
<p>後、license.txtというファイルが用意せんとだめよね。</p>
<p>Disassemblyしたコードの抜粹です, IDA Pro 6.1.110530 Evaluation versionより </p>
<pre class="brush: nasm8086; title: ; notranslate">
.text:00401120 loc_401120:                             ; CODE XREF: sub_401090+76j
.text:00401120                 mov     [esp+78h+var_70], 18h
.text:00401128                 mov     [esp+78h+hqDTK7b8K2rvw_copy], 0
.text:00401130                 lea     eax, [ebp+license1]
.text:00401133                 mov     [esp+78h+license2], eax
.text:00401136                 call    memset
.text:0040113B                 lea     eax, [ebp+license1]
.text:0040113E                 mov     [esp+78h+var_70], eax
.text:00401142                 mov     [esp+78h+hqDTK7b8K2rvw_copy], offset aS ; &quot;%s&quot;
.text:0040114A                 mov     eax, [ebp+var_4C]
.text:0040114D                 mov     [esp+78h+license2], eax
.text:00401150                 call    fscanf
.text:00401155                 mov     eax, [ebp+var_4C]
.text:00401158                 mov     [esp+78h+license2], eax
.text:0040115B                 call    fclose
.text:00401160                 mov     [ebp+var_4C], 0
.text:00401167                 cmp     [ebp+license1], 'qhcg'               // license先頭の4文字がqhcg
.text:0040116E                 jnz     short loc_4011CF
.text:00401170                 mov     eax, hqDTK7b8K2rvw
.text:00401175                 mov     [esp+78h+hqDTK7b8K2rvw_copy], eax
.text:00401179                 lea     eax, [ebp+license1]
.text:0040117C                 add     eax, 4
.text:0040117F                 mov     [esp+78h+license2], eax
                                                                            // char *crypt(const char *key, const char *salt);
                                                                            // keyは8文字、saltは2文字
.text:00401182                 call    crypt                                // crypt(&quot;license5文字以後&quot;, &quot;hq&quot;);
.text:00401187                 mov     edx, eax
.text:00401189                 mov     eax, hqDTK7b8K2rvw
.text:0040118E                 mov     [esp+78h+hqDTK7b8K2rvw_copy], eax
.text:00401192                 mov     [esp+78h+license2], edx
.text:00401195                 call    strcmp
.text:0040119A                 test    eax, eax
.text:0040119C                 jnz     short loc_4011A5
.text:0040119E                 mov     [ebp+var_C], 1
.text:004011A5
.text:004011A5 loc_4011A5:                             ; CODE XREF: sub_401090+10Cj
.text:004011A5                 mov     [esp+78h+license2], offset aLoadingStage1L ; &quot;loading stage1 license key(s)...\n&quot;
.text:004011AC                 call    printf
.text:004011B1                 mov     eax, [ebp+license3]
.text:004011B4                 mov     [ebp+license3_copy], eax
.text:004011B7                 mov     [esp+78h+license2], offset aLoadingStage2L ; &quot;loading stage2 license key(s)...\n\n&quot;
.text:004011BE                 call    printf
.text:004011C3                 mov     eax, [ebp+license4]
.text:004011C6                 mov     [ebp+license4_copy], eax
.text:004011C9                 mov     eax, [ebp+license5]
.text:004011CC                 mov     [ebp+license5_copy], eax
.text:004011CF
.text:004011CF loc_4011CF:                             ; CODE XREF: sub_401090+DEj
.text:004011CF                 cmp     [ebp+var_C], 0
.text:004011D3                 jnz     short loc_4011EA
.text:004011D5                 mov     [esp+78h+license2], offset aErrorLicense_0 ; &quot;error: license.txt invalid\n&quot;
.text:004011DC                 call    printf
.text:004011E1                 mov     [ebp+var_50], 0FFFFFFFFh
.text:004011E8                 jmp     short loc_401204
.text:004011EA ; ---------------------------------------------------------------------------
.text:004011EA
.text:004011EA loc_4011EA:                             ; CODE XREF: sub_401090+143j
.text:004011EA                 lea     eax, [ebp+license3_copy]
.text:004011ED                 mov     [esp+78h+hqDTK7b8K2rvw_copy], eax
.text:004011F1                 mov     eax, [ebp+hostname]
.text:004011F4                 add     eax, 4
.text:004011F7                 mov     eax, [eax]
.text:004011F9                 mov     [esp+78h+license2], eax
.text:004011FC                 call    genURL                                  //URL生成するにはlicenseの3,4,5だけで出来る
.text:00401201                 mov     [ebp+var_50], eax
.text:00401204
.text:00401204 loc_401204:                             ; CODE XREF: sub_401090+56j
.text:00401204                                         ; sub_401090+8Bj ...
.text:00401204                 mov     eax, [ebp+var_50]
.text:00401207                 leave
.text:00401208                 retn
.text:00401208 sub_401090      endp
</pre>
<p>まとめてすると、licenseと構成は</p>
<pre class="brush: plain; title: ; notranslate">
qhcg + crypt用8文字のキー(無くてもおk) + license3(4バイト) + license4(4バイト) + license5(4バイト)
</pre>
<p>license3 ~ license5はどこで探せんるんだ?<br />
ヒントは</p>
<pre class="brush: plain; title: ; notranslate">
&quot;loading stage1 license key(s)...\n&quot;
&quot;loading stage2 license key(s)...\n\n&quot;
</pre>
<p>即ち、part1のところから1つと、part2からキー2つがどこかに隠していると考えられる。<br />
これは運で言うものか、よく分からんだけど、答えとしては</p>
<pre class="brush: plain; title: ; notranslate">
license3:
part1の最初がJMPしたよね? そこがヒントにならん?
   0:	eb 04                	jmp    0x6
   2:	af                   	scas   %es:(%edi),%eax
   3:	c2 bf a3             	ret    $0xa3bf
ここの afc2bfa3 が答え!
注意: x86はLittle endianのため、afc2bfa3 は a3 bf c2 afで書くね。

license4,5:
cpu構造体の中に定義したfirmwareは実際使ってないじゃない?
firmware: [0xd2ab1f05, 0xda13f110]
それが答え!
</pre>
<p>license2はどこかに隠しているのは分からないが、分からなかったら、</p>
<pre class="brush: plain; title: ; notranslate">
.text:0040119Cのjnz
をjmpにするだけてできる。
0x75 -&gt; 0xEB
</pre>
<p>ネットで検索すると、license2はcyberwinが答えになってる。分かる方は是非教えてください。<br />
最終的にlicense.txtの内容を</p>
<pre class="brush: plain; title: ; notranslate">
67636871637962657277696EAFC2BFA3051FABD210F113DA
</pre>
<p>HEXで保存するね。</p>
<pre class="brush: bash; title: ; notranslate">
$ ./keygen.exe canyoucrackit.co.uk

keygen.exe

loading stage1 license key(s)...
loading stage2 license key(s)...

request:

GET /hqDTK7b8K2rvw/a3bfc2af/d2ab1f05/da13f110/key.txt HTTP/1.0
</pre>
<p><a href="http://canyoucrackit.co.uk/hqDTK7b8K2rvw/a3bfc2af/d2ab1f05/da13f110/key.txt" target="_blank">http://canyoucrackit.co.uk/hqDTK7b8K2rvw/a3bfc2af/d2ab1f05/da13f110/key.txt</a>を開くと、</p>
<pre class="brush: plain; title: ; notranslate">
Pr0t3ct!on#cyber_security@12*12.2011+
</pre>
<p>これが最終の答えだ! 入力してみると<br />
<a href="http://www.axot.org/wp-content/uploads/2011/12/Screen-Shot-2011-12-05-at-23.19.26-.png"></p>
<div class="su-frame su-frame-align-center">
<div class="su-frame-shell"><img src="http://www.axot.org/wp-content/uploads/2011/12/Screen-Shot-2011-12-05-at-23.19.26-.png" alt="" title="cracked" width="525" height="345" class="alignnone size-full wp-image-24" /></div>
</div>
<p></a><br />
成功!!!</p>
<p><strong>参考引用:</strong><br />
The Mac Hacker&#8217;s Handbook</p>
<p>http://pastebin.com/GAZ2aCLm</p>
</div>
</div>
<div class="su-spacer"></div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.axot.org/2011/12/05/can-you-crack-it-solution/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>How to pass through new state packets[NetGear WNR854T]</title>
		<link>http://www.axot.org/2011/06/27/how-to-pass-through-new-state-packets-on-wan-interface-netgear-wnr854t/</link>
		<comments>http://www.axot.org/2011/06/27/how-to-pass-through-new-state-packets-on-wan-interface-netgear-wnr854t/#comments</comments>
		<pubDate>Mon, 27 Jun 2011 17:27:35 +0000</pubDate>
		<dc:creator>axot</dc:creator>
				<category><![CDATA[Network]]></category>
		<category><![CDATA[iptables]]></category>
		<category><![CDATA[Router]]></category>
		<category><![CDATA[static table]]></category>
		<category><![CDATA[WNR854T]]></category>

		<guid isPermaLink="false">http://www.axot.org/?p=6</guid>
		<description><![CDATA[Sometimes you may want add a static routing for accessing another network.
When you done the static routing table, you found the ip routing was working fine, but the connection can&#8217;t be established. The problem caused by firewall rule.


#update1: I made a new firmware based on 1.4.38, the iptables  [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes you may want add a static routing for accessing another network.<br />
When you done the static routing table, you found the ip routing was working fine, but the connection can&#8217;t be established. The problem caused by firewall rule.</p>
<p><span id="more-6"></span></p>
<hr/>
#update1: I made a new firmware based on 1.4.38, the iptables rule will load automatically. @2012.01.12<br />
<a href='http://www.axot.org/wp-content/uploads/2011/06/WNR854T_axot.img_.zip'>WNR854T custom firmware</a></p>
<hr/>
<p>Here I want show you how to fix the problem in the case of NetGear WNR854T.</p>
<p>go to: http://www.routerlogin.net/cmd.htm<br />
then run: &#8216;iptables -L -n &#8211;line-numbers&#8217; for the print whole iptables rules.</p>
<p>the result(possible):</p>
<pre class="brush: bash; title: ; notranslate">
Chain INPUT (policy ACCEPT)
num  target     prot opt source               destination
1    ACCEPT     udp  --  0.0.0.0/0            0.0.0.0/0          udp spt:520 dpt:520
2    ACCEPT     tcp  --  192.168.0.96/27      0.0.0.0/0          tcp dpt:81
3    ACCEPT     icmp --  0.0.0.0/0            192.168.0.93       icmp type 8
4    ACCEPT     all  --  192.168.0.96/27      0.0.0.0/0
5    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0          state RELATED,ESTABLISHED
6    ACCEPT     udp  --  0.0.0.0/0            0.0.0.0/0          udp dpt:520
7    ACCEPT     udp  --  0.0.0.0/0            0.0.0.0/0          udp dpt:68
8    DROP       all  --  0.0.0.0/0            0.0.0.0/0          state NEW,INVALID

Chain FORWARD (policy ACCEPT)
num  target     prot opt source               destination
1    PORT_FW    all  --  0.0.0.0/0            0.0.0.0/0
2    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0          state RELATED,ESTABLISHED
3    DROP       all  --  0.0.0.0/0            0.0.0.0/0          state NEW,INVALID

Chain OUTPUT (policy ACCEPT)
num  target     prot opt source               destination

Chain PORT_FW (1 references)
num  target     prot opt source               destination
...
</pre>
<p>In index 8 of Chain INPUT and index 3 of Chain FORWARD, New state will be dropped by.<br />
So, we need modify these rules</p>
<p>like:</p>
<pre class="brush: bash; title: ; notranslate">
iptables -R INPUT 8 -i eth0 -m state --state INVALID -j DROP
iptables -R FORWARD 3 -i eth0 -m state --state INVALID -j DROP
iptables -A INPUT -i eth0 -m state --state NEW -j ACCEPT
iptables -A FORWARD -i eth0 -m state --state NEW -j ACCEPT
</pre>
<p>Change the number(8, 3) in your case.</p>
<p>the new rule table like this:</p>
<pre class="brush: bash; title: ; notranslate">
Chain INPUT (policy ACCEPT)
num  target     prot opt source               destination
1    ACCEPT     udp  --  0.0.0.0/0            0.0.0.0/0          udp spt:520 dpt:520
2    ACCEPT     tcp  --  192.168.0.96/27      0.0.0.0/0          tcp dpt:81
3    ACCEPT     icmp --  0.0.0.0/0            192.168.0.93       icmp type 8
4    ACCEPT     all  --  192.168.0.96/27      0.0.0.0/0
5    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0          state RELATED,ESTABLISHED
6    ACCEPT     udp  --  0.0.0.0/0            0.0.0.0/0          udp dpt:520
7    ACCEPT     udp  --  0.0.0.0/0            0.0.0.0/0          udp dpt:68
8    DROP       all  --  0.0.0.0/0            0.0.0.0/0          state INVALID
9    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0          state NEW

Chain FORWARD (policy ACCEPT)
num  target     prot opt source               destination
1    PORT_FW    all  --  0.0.0.0/0            0.0.0.0/0
2    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0          state RELATED,ESTABLISHED
3    DROP       all  --  0.0.0.0/0            0.0.0.0/0          state INVALID
4    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0          state NEW

Chain OUTPUT (policy ACCEPT)
num  target     prot opt source               destination

Chain PORT_FW (1 references)
num  target     prot opt source               destination
...
</pre>
<p>now, test the connection via ping or anything you like. <img src='http://www.axot.org/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>Special thanks to Masaki わふー.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.axot.org/2011/06/27/how-to-pass-through-new-state-packets-on-wan-interface-netgear-wnr854t/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Served from: www.axot.org @ 2012-05-21 10:27:45 -->
