{"id":19156,"date":"2016-09-15T16:53:15","date_gmt":"2016-09-15T23:53:15","guid":{"rendered":"https:\/\/www.paloaltonetworks.com\/blog\/?p=19156"},"modified":"2016-09-29T09:43:56","modified_gmt":"2016-09-29T16:43:56","slug":"labyrenth-capture-the-flag-ctf-windows-track-1-6-solutions","status":"publish","type":"post","link":"https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/2016\/09\/labyrenth-capture-the-flag-ctf-windows-track-1-6-solutions\/","title":{"rendered":"LabyREnth Capture the Flag (CTF): Windows Track 1-6 Solutions"},"content":{"rendered":"<p>Welcome back to our blog series where we reveal the\u00a0solutions\u00a0to\u00a0<a href=\"https:\/\/www.paloaltonetworks.com\/blog\/2016\/07\/unit42-announcing-the-labyrenth-capture-the-flag-ctf-challenge\/\" target=\"_blank\">LabyREnth, the Unit 42 Capture the Flag (CTF)<\/a>\u00a0challenge. We\u2019ll be revealing the\u00a0<a href=\"https:\/\/www.paloaltonetworks.com\/blog\/tag\/ctf\/\" target=\"_blank\">solutions<\/a>\u00a0to one challenge track per week. Next up, the Windows track challenges 1 through 6, followed by 7 through 9 next week.\u00a0<!--more--><\/p>\n<h3><strong>Windows 1 Challenge: Deez bugs are bad bugs.<\/strong><\/h3>\n<p><em>Challenge Created By: Richard Wartell <a href=\"https:\/\/twitter.com\/wartortell\" rel=\"nofollow,noopener\"  target=\"_blank\">@wartortell<\/a><\/em><\/p>\n<p>We are given a PE file that we open in DetectItEasy and see that it is packed with UPX.<\/p>\n<p><a href=\"https:\/\/www.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_1.png\"><div style=\"max-width:100%\" data-width=\"500\"><span class=\"ar-custom\" style=\"padding-bottom:59.4%;\"><img loading=\"lazy\" decoding=\"async\"  class=\"size-large wp-image-19270 aligncenter lozad\"  data-src=\"https:\/\/www.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_1-500x297.png\" alt=\"ctf_windows_1\" width=\"500\" height=\"297\" srcset=\"https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_1-500x297.png 500w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_1-230x137.png 230w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_1-768x456.png 768w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_1-505x300.png 505w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_1-67x40.png 67w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_1.png 975w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/span><\/div><\/a><\/p>\n<p>We can try and unpack it with upx \u2013d, but it couldn\u2019t be that easy.<\/p>\n<pre class=\"lang:default decode:true \">upx -d AntiD.exe\r\n                       Ultimate Packer for eXecutables\r\n                          Copyright (C) 1996 - 2013\r\nUPX 3.91        Markus Oberhumer, Laszlo Molnar &amp; John Reiser   Sep 30th 2013\r\n\r\n        File size         Ratio      Format      Name\r\n   --------------------   ------   -----------   -----------\r\nupx: AntiD.exe: CantUnpackException: file is modified\/hacked\/protected; take care!!!\r\n\r\nUnpacked 0 files.\r\n<\/pre>\n<p>It looks like we will have to unpack this ourselves before we can solve it.\u00a0 UPX uses the pushad instruction at the beginning to push the registers on to the stack so that it can retrieve them after unpacking and jumping to the original entry point.\u00a0 We can script IDA\u2019s debugger to set a hardware read breakpoint at the location of the pushed registers on the stack to get us close to the OEP.<\/p>\n<pre class=\"lang:default decode:true \">import idc\r\nimport idaapi\r\nimport idautils\r\n\r\nidc.AddBpt(ScreenEA())\r\n\r\nidc.LoadDebugger(\"win32\", 0)\r\nidc.StartDebugger(\"\", \"\", \"\")\r\n\r\nidc.ResumeProcess()\r\nidc.GetDebuggerEvent(WFNE_SUSP, -1);\r\n\r\naddress = idc.GetRegValue('ESP') - 1\r\nidc.AddBptEx(address, 1, BPT_RDWR)\r\n\r\nidc.ResumeProcess()\r\n<\/pre>\n<p>After we hit our breakpoint, we can remove the breakpoint and run until the tail jump that gets us to the original entry point.<\/p>\n<p><a href=\"https:\/\/www.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_2.png\"><div style=\"max-width:100%\" data-width=\"500\"><span class=\"ar-custom\" style=\"padding-bottom:179.2%;\"><img loading=\"lazy\" decoding=\"async\"  class=\"size-large wp-image-19267 aligncenter lozad\"  data-src=\"https:\/\/www.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_2-500x896.png\" alt=\"ctf_windows_2\" width=\"500\" height=\"896\" srcset=\"https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_2-500x896.png 500w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_2-230x412.png 230w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_2-167x300.png 167w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_2-22x40.png 22w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_2.png 681w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/span><\/div><\/a><\/p>\n<p style=\"text-align: center;\"><em>popa Instruction Followed by the Tail Jump<\/em><\/p>\n<p>We can take the jump to the unpacked code and then use Scylla with our new found OEP to dump the process.<\/p>\n<p><a href=\"https:\/\/www.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_3.png\"><div style=\"max-width:100%\" data-width=\"500\"><span class=\"ar-custom\" style=\"padding-bottom:106.8%;\"><img loading=\"lazy\" decoding=\"async\"  class=\"size-large wp-image-19264 aligncenter lozad\"  data-src=\"https:\/\/www.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_3-500x534.png\" alt=\"ctf_windows_3\" width=\"500\" height=\"534\" srcset=\"https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_3-500x534.png 500w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_3-230x246.png 230w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_3-768x820.png 768w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_3-281x300.png 281w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_3-37x40.png 37w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_3.png 975w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/span><\/div><\/a><\/p>\n<p>We can open our unpacked executable in <a href=\"http:\/\/binary.ninja\/\" rel=\"nofollow,noopener\"  target=\"_blank\">Binary Ninja<\/a> and can see there is a path that prints the good boy message and one that prints the bad boy message.\u00a0 There is a function called right before the branch that checks the key and determines what path we will take.<\/p>\n<p><a href=\"https:\/\/www.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_4.png\"><div style=\"max-width:100%\" data-width=\"500\"><span class=\"ar-custom\" style=\"padding-bottom:149.8%;\"><img loading=\"lazy\" decoding=\"async\"  class=\"size-large wp-image-19261 aligncenter lozad\"  data-src=\"https:\/\/www.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_4-500x749.png\" alt=\"ctf_windows_4\" width=\"500\" height=\"749\" srcset=\"https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_4-500x749.png 500w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_4-230x345.png 230w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_4-768x1151.png 768w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_4-200x300.png 200w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_4-27x40.png 27w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_4.png 901w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/span><\/div><\/a><\/p>\n<p style=\"text-align: center;\"><em>Main Showing the Good Boy and Bad Boy paths<\/em><\/p>\n<p>If we look at the function we renamed to check_key, we can see that it moves bytes on to the stack and then checks to see if the input is 16 bytes long.<\/p>\n<p><a href=\"https:\/\/www.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_5.png\"><div style=\"max-width:100%\" data-width=\"453\"><span class=\"ar-custom\" style=\"padding-bottom:241.94%;\"><img loading=\"lazy\" decoding=\"async\"  class=\"size-full wp-image-19258 aligncenter lozad\"  data-src=\"https:\/\/www.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_5.png\" alt=\"ctf_windows_5\" width=\"453\" height=\"1096\" srcset=\"https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_5.png 453w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_5-230x556.png 230w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_5-124x300.png 124w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_5-17x40.png 17w\" sizes=\"auto, (max-width: 453px) 100vw, 453px\" \/><\/span><\/div><\/a><\/p>\n<p>The program then enters a series of anti-debugging checks that will cause the function to return 0 (FALSE) if they are triggered.\u00a0 Before each check, there is also a string encoding operation performed against our string.<\/p>\n<p><a href=\"https:\/\/www.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_6.png\"><div style=\"max-width:100%\" data-width=\"500\"><span class=\"ar-custom\" style=\"padding-bottom:78.8%;\"><img loading=\"lazy\" decoding=\"async\"  class=\"size-large wp-image-19255 aligncenter lozad\"  data-src=\"https:\/\/www.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_6-500x394.png\" alt=\"ctf_windows_6\" width=\"500\" height=\"394\" srcset=\"https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_6-500x394.png 500w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_6-230x181.png 230w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_6-768x606.png 768w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_6-380x300.png 380w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_6-51x40.png 51w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_6.png 975w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/span><\/div><\/a><\/p>\n<p>The first anti-debugging check is a call to CheckRemoteDebuggerPresent, which checks to see if the process is being debugged.<\/p>\n<p><a href=\"https:\/\/www.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_7.png\"><div style=\"max-width:100%\" data-width=\"500\"><span class=\"ar-custom\" style=\"padding-bottom:88.6%;\"><img loading=\"lazy\" decoding=\"async\"  class=\"size-large wp-image-19252 aligncenter lozad\"  data-src=\"https:\/\/www.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_7-500x443.png\" alt=\"ctf_windows_7\" width=\"500\" height=\"443\" srcset=\"https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_7-500x443.png 500w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_7-230x204.png 230w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_7-768x680.png 768w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_7-339x300.png 339w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_7-45x40.png 45w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_7.png 975w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/span><\/div><\/a><\/p>\n<p>The second anti-debugging check is a call to FindWindowW checking for a Window named OLLYDBG, which is a popular debugger used by analysts.<\/p>\n<p><a href=\"https:\/\/www.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_8.png\"><div style=\"max-width:100%\" data-width=\"500\"><span class=\"ar-custom\" style=\"padding-bottom:87%;\"><img loading=\"lazy\" decoding=\"async\"  class=\"size-large wp-image-19249 aligncenter lozad\"  data-src=\"https:\/\/www.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_8-500x435.png\" alt=\"ctf_windows_8\" width=\"500\" height=\"435\" srcset=\"https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_8-500x435.png 500w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_8-230x200.png 230w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_8-768x668.png 768w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_8-345x300.png 345w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_8-46x40.png 46w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_8.png 975w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/span><\/div><\/a><\/p>\n<p>The third anti-debugging check is a call to IsDebuggerPresent, which checks to see if the process is being debugged.<\/p>\n<p><a href=\"https:\/\/www.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_9.png\"><div style=\"max-width:100%\" data-width=\"500\"><span class=\"ar-custom\" style=\"padding-bottom:70%;\"><img loading=\"lazy\" decoding=\"async\"  class=\"size-large wp-image-19246 aligncenter lozad\"  data-src=\"https:\/\/www.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_9-500x350.png\" alt=\"ctf_windows_9\" width=\"500\" height=\"350\" srcset=\"https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_9-500x350.png 500w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_9-230x161.png 230w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_9-768x538.png 768w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_9-428x300.png 428w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_9-57x40.png 57w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_9.png 975w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/span><\/div><\/a><\/p>\n<p>The fourth and final anti-debugging check uses the assembly instruction rdtsc twice as a timing check to see if the process is executing slowly and probably being debugged.<\/p>\n<p><a href=\"https:\/\/www.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_10.png\"><div style=\"max-width:100%\" data-width=\"500\"><span class=\"ar-custom\" style=\"padding-bottom:94%;\"><img loading=\"lazy\" decoding=\"async\"  class=\"size-large wp-image-19243 aligncenter lozad\"  data-src=\"https:\/\/www.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_10-500x470.png\" alt=\"ctf_windows_10\" width=\"500\" height=\"470\" srcset=\"https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_10-500x470.png 500w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_10-230x216.png 230w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_10-768x722.png 768w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_10-319x300.png 319w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_10-43x40.png 43w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_10.png 975w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/span><\/div><\/a><\/p>\n<p>If we pass all the anti-debugging checks, we end up getting the final string operation, which checks the result of all the operations against an offset in the initial buffer of bytes. If they are not equal, the function returns 0 (FALSE). But if they are equal, the result is added, which is used as the XOR key in the final operation.<\/p>\n<p><a href=\"https:\/\/www.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_11.png\"><div style=\"max-width:100%\" data-width=\"500\"><span class=\"ar-custom\" style=\"padding-bottom:50.4%;\"><img loading=\"lazy\" decoding=\"async\"  class=\"size-large wp-image-19240 aligncenter lozad\"  data-src=\"https:\/\/www.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_11-500x252.png\" alt=\"ctf_windows_11\" width=\"500\" height=\"252\" srcset=\"https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_11-500x252.png 500w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_11-230x116.png 230w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_11-768x388.png 768w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_11-510x257.png 510w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_11-79x40.png 79w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_11.png 975w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/span><\/div><\/a><\/p>\n<p>We can copy off the initial buffer and rewrite the operations in python, so that we can obtain the key.<\/p>\n<pre class=\"lang:default decode:true \">buffer = [0x8C, 0xF1, 0x53, 0xA3, 0x08, 0xD7, 0xDC, 0x48, 0xDB, 0x0C, 0x3A, 0xEE, 0x15, 0x22, \r\n0xC4, 0xE5, 0xC9, 0xA0, 0xA5, 0x0C, 0xD3, 0xDC, 0x51, 0xC7, 0x39, 0xFD, 0xD0, 0xF8, 0x3B, \r\n0xE8, 0xCC, 0x03, 0x06, 0x43, 0xF7, 0xDA, 0x7E, 0x65, 0xAE, 0x80 ]\r\n\r\nanswer = []\r\nc = 0\r\n\r\nfor i in buffer:\r\n    for x in range(31, 127):\r\n        a = (x ^ 0x33) &amp; 0xFF\r\n        a = (a + 68) &amp; 0xFF\r\n        a = (a ^ 0x55) &amp; 0xFF\r\n        a = (a - 102) &amp; 0xFF\r\n        a = (a ^ (c &amp; 0xFF) &amp; 0xFF)\r\n        if a == i:\r\n            answer.append(chr(abs(x)))\r\n            break\r\n    c += a\r\n\r\nprint(\"\".join(answer))\r\n<\/pre>\n<p>When we run the script we get the key.<\/p>\n<p>python solve.py<\/p>\n<p>PAN{C0nf1agul4ti0ns_0n_4_J08_W3LL_D0N3!}<\/p>\n<h3><strong>Windows 2 Challenge: What does the goat say?<\/strong><\/h3>\n<p><em>Challenge Created By: Richard Wartell <a href=\"https:\/\/twitter.com\/wartortell\" rel=\"nofollow,noopener\"  target=\"_blank\">@wartortell<\/a><\/em><\/p>\n<p><a href=\"https:\/\/www.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_12.png\"><div style=\"max-width:100%\" data-width=\"500\"><span class=\"ar-custom\" style=\"padding-bottom:20.6%;\"><img loading=\"lazy\" decoding=\"async\"  class=\"size-large wp-image-19237 aligncenter lozad\"  data-src=\"https:\/\/www.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_12-500x103.png\" alt=\"ctf_windows_12\" width=\"500\" height=\"103\" srcset=\"https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_12-500x103.png 500w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_12-230x47.png 230w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_12-768x158.png 768w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_12-510x105.png 510w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_12-195x40.png 195w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_12.png 975w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/span><\/div><\/a><\/p>\n<p>We can open it in dnSpy to decompile and debug.\u00a0 We can see the key_click function looks interesting because it is tracking a state if keys are pressed in a certain order.<\/p>\n<p><a href=\"https:\/\/www.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_13.png\"><div style=\"max-width:100%\" data-width=\"500\"><span class=\"ar-custom\" style=\"padding-bottom:64.4%;\"><img loading=\"lazy\" decoding=\"async\"  class=\"size-large wp-image-19234 aligncenter lozad\"  data-src=\"https:\/\/www.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_13-500x322.png\" alt=\"ctf_windows_13\" width=\"500\" height=\"322\" srcset=\"https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_13-500x322.png 500w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_13-230x148.png 230w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_13-768x494.png 768w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_13-467x300.png 467w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_13-62x40.png 62w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_13.png 975w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/span><\/div><\/a><\/p>\n<p>The keys are numbered from left to right starting at 0 for the white keys and the same for the black keys.\u00a0 If we press the keys in the correct order do_a_thing() is called.<\/p>\n<p><a href=\"https:\/\/www.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_14.png\"><div style=\"max-width:100%\" data-width=\"500\"><span class=\"ar-custom\" style=\"padding-bottom:39.4%;\"><img loading=\"lazy\" decoding=\"async\"  class=\"size-large wp-image-19231 aligncenter lozad\"  data-src=\"https:\/\/www.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_14-500x197.png\" alt=\"ctf_windows_14\" width=\"500\" height=\"197\" srcset=\"https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_14-500x197.png 500w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_14-230x91.png 230w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_14-768x302.png 768w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_14-510x201.png 510w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_14-102x40.png 102w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_14.png 975w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/span><\/div><\/a><\/p>\n<p>This function plays a funny David Bowie video while the key scrolls in ascii art behind.<\/p>\n<p><a href=\"https:\/\/www.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_15.png\"><div style=\"max-width:100%\" data-width=\"500\"><span class=\"ar-custom\" style=\"padding-bottom:20.6%;\"><img loading=\"lazy\" decoding=\"async\"  class=\"size-large wp-image-19228 aligncenter lozad\"  data-src=\"https:\/\/www.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_15-500x103.png\" alt=\"ctf_windows_15\" width=\"500\" height=\"103\" srcset=\"https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_15-500x103.png 500w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_15-230x47.png 230w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_15-768x158.png 768w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_15-510x105.png 510w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_15-194x40.png 194w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_15.png 975w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/span><\/div><\/a><\/p>\n<p><a href=\"https:\/\/www.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_16.png\"><div style=\"max-width:100%\" data-width=\"500\"><span class=\"ar-custom\" style=\"padding-bottom:19%;\"><img loading=\"lazy\" decoding=\"async\"  class=\"size-large wp-image-19225 aligncenter lozad\"  data-src=\"https:\/\/www.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_16-500x95.png\" alt=\"ctf_windows_16\" width=\"500\" height=\"95\" srcset=\"https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_16-500x95.png 500w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_16-230x44.png 230w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_16-768x146.png 768w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_16-510x97.png 510w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_16-211x40.png 211w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_16.png 975w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/span><\/div><\/a><\/p>\n<p>PAN{B4BY_Y3LL5_5O_LOUD!}<\/p>\n<h3><strong>Windows 3 Challenge: Gotta keep your Squirtle happy <\/strong><\/h3>\n<p><em>Challenge Created By: Tyler Halfpop <a href=\"https:\/\/twitter.com\/0xtyh\" rel=\"nofollow,noopener\"  target=\"_blank\">@0xtyh<\/a><\/em><\/p>\n<p>We are given an executable for the Squirtle challenge.\u00a0 When we run the binary we see some ascii art of Squirtle and a check for a password.\u00a0 If we get the password wrong, we sadly find out that we just killed a Squirtle and the program exits.<\/p>\n<p><a href=\"https:\/\/www.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_17.png\"><div style=\"max-width:100%\" data-width=\"500\"><span class=\"ar-custom\" style=\"padding-bottom:91%;\"><img loading=\"lazy\" decoding=\"async\"  class=\"size-large wp-image-19222 aligncenter lozad\"  data-src=\"https:\/\/www.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_17-500x455.png\" alt=\"ctf_windows_17\" width=\"500\" height=\"455\" srcset=\"https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_17-500x455.png 500w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_17-230x209.png 230w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_17-768x698.png 768w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_17-330x300.png 330w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_17-44x40.png 44w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_17.png 905w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/span><\/div><\/a><\/p>\n<p style=\"text-align: center;\"><em>Dead Squirtle from an Incorrect Password<\/em><\/p>\n<p>We can open the binary in <a href=\"http:\/\/binary.ninja\/\" rel=\"nofollow,noopener\"  target=\"_blank\">Binary Ninja<\/a> and take a look at the main function. If we look at the first branch instruction, there is a function call right before at 401070 that checks the password. We can see that it is just a string compare with the string \u201cincorrect\u201d.<\/p>\n<p><a href=\"https:\/\/www.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_18.png\"><div style=\"max-width:100%\" data-width=\"500\"><span class=\"ar-custom\" style=\"padding-bottom:144.4%;\"><img loading=\"lazy\" decoding=\"async\"  class=\"size-large wp-image-19219 aligncenter lozad\"  data-src=\"https:\/\/www.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_18-500x722.png\" alt=\"ctf_windows_18\" width=\"500\" height=\"722\" srcset=\"https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_18-500x722.png 500w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_18-230x332.png 230w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_18-768x1109.png 768w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_18-208x300.png 208w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_18-28x40.png 28w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_18.png 935w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/span><\/div><\/a><\/p>\n<p style=\"text-align: center;\"><em>Password Check Function<\/em><\/p>\n<p>If we type the password correctly we happily find out that we didn\u2019t kill a Squirtle and we get some more output. We have to pass some anti-debugging and anti-vm checks and then we are told that the answer is written in an answer.jpg file.<\/p>\n<p><a href=\"https:\/\/www.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_19.png\"><div style=\"max-width:100%\" data-width=\"500\"><span class=\"ar-custom\" style=\"padding-bottom:64%;\"><img loading=\"lazy\" decoding=\"async\"  class=\"size-large wp-image-19216 aligncenter lozad\"  data-src=\"https:\/\/www.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_19-500x320.png\" alt=\"ctf_windows_19\" width=\"500\" height=\"320\" srcset=\"https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_19-500x320.png 500w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_19-230x147.png 230w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_19-768x492.png 768w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_19-468x300.png 468w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_19-62x40.png 62w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_19.png 976w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/span><\/div><\/a><\/p>\n<p style=\"text-align: center;\"><em>Correct Password Output<\/em><\/p>\n<p>There is an answer.jpg file written after we ran the program, but it is corrupted so we need to figure out how to make the program write it correctly to disk. We can see at the end of the main function there is a loop with a multi-byte XOR key.<\/p>\n<p><a href=\"https:\/\/www.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_20.png\"><div style=\"max-width:100%\" data-width=\"500\"><span class=\"ar-custom\" style=\"padding-bottom:121.4%;\"><img loading=\"lazy\" decoding=\"async\"  class=\"size-large wp-image-19213 aligncenter lozad\"  data-src=\"https:\/\/www.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_20-500x607.png\" alt=\"ctf_windows_20\" width=\"500\" height=\"607\" srcset=\"https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_20-500x607.png 500w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_20-230x279.png 230w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_20-768x932.png 768w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_20-247x300.png 247w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_20-33x40.png 33w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_20.png 976w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/span><\/div><\/a><\/p>\n<p style=\"text-align: center;\"><em>XOR Loop Writing the answer.jpg file<\/em><\/p>\n<p>We can assume that if we pass each step we will get the correct key that will output the correct image. At each stage there is a check and then some fake rand() == rand() checks with some funny messages to obfuscate the code.\u00a0 Thankfully there are also helpful hints at each stage if we get stuck or are unsure of the correct path.<\/p>\n<p><a href=\"https:\/\/www.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_21.png\"><div style=\"max-width:100%\" data-width=\"500\"><span class=\"ar-custom\" style=\"padding-bottom:105.4%;\"><img loading=\"lazy\" decoding=\"async\"  class=\"size-large wp-image-19210 aligncenter lozad\"  data-src=\"https:\/\/www.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_21-500x527.png\" alt=\"ctf_windows_21\" width=\"500\" height=\"527\" srcset=\"https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_21-500x527.png 500w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_21-230x242.png 230w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_21-768x810.png 768w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_21-285x300.png 285w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_21-38x40.png 38w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_21.png 976w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/span><\/div><\/a><\/p>\n<p style=\"text-align: center;\"><em>Sleep\/GetTickCount Check along with fake rand checks<\/em><\/p>\n<p>The first check is to see if there is a common debugger window class found.<\/p>\n<pre class=\"lang:default decode:true \">BOOL wdw_class()\r\n{\r\n\tHWND hOlly = FindWindow(_T(\"OLLYDBG\"), NULL);\r\n\tHWND hIDA = FindWindow(_T(\"QWidget\"), NULL);\r\n\tHWND hWdbg = FindWindow(_T(\"WinDbgFrameClass\"), NULL);\r\n\tHWND hImm = FindWindow(_T(\"ID\"), NULL);\r\n\r\n\tif ((hOlly) || (hIDA) || (hWdbg) || (hImm))\r\n\t{\r\n\t\treturn TRUE;\r\n\t}\r\n\r\n\treturn FALSE;\r\n}\r\n<\/pre>\n<p>The second check is to look at the Process Environment Block at offset fs: [30h+2] to see if the process is being debugged.<\/p>\n<pre class=\"lang:default decode:true \">BOOL fs_chk(VOID)\r\n{\r\n\tchar IsDbgPresent = 0;\r\n\r\n\t__asm {\r\n\t\tmov eax, fs:[30h]\r\n\t\t\tmov al, [eax + 2h]\r\n\t\t\tmov IsDbgPresent, al\r\n\t}\r\n\tif (IsDbgPresent)\r\n\t{\r\n\t\treturn TRUE;\r\n\t}\r\n\treturn FALSE;\r\n}\r\n<\/pre>\n<p>The third check uses the Windows API GetTickCount() to make sure the system hasn\u2019t been freshly booted.<\/p>\n<pre class=\"lang:default decode:true \">DWORD Counter = GetTickCount();\r\nif (Counter &lt; 0xFFFFF) {\r\n<\/pre>\n<p>The fourth check used Sleep along with GetTickCount() and wanted you to bypass the sleep call.<\/p>\n<pre class=\"&quot;lang:default\" decode:true=\"\">Sleep(1000);\r\nDWORD Counter2 = GetTickCount();\r\nCounter2 -= Counter;\r\nif (Counter2 &gt; 0xFF)\r\n<\/pre>\n<p>The fifth check just used the Windows API IsDebuggerPresent to find out if the process is being debugged. The sixth check similarly called the Windows API CheckRemoteDebuggerPresent to find out if the process was being debugged.<\/p>\n<p>The seventh stage checked to see if there are greater than 2 CPUs.<\/p>\n<pre class=\"lang:default decode:true \">BOOL cpu_num()\r\n{\r\n\tSYSTEM_INFO siSysInfo;\r\n\tGetSystemInfo(&amp;siSysInfo);\r\n\tif (siSysInfo.dwNumberOfProcessors &lt; 2)\r\n\t{\r\n\t\treturn TRUE;\r\n\t}\r\n\treturn FALSE;\r\n}\r\n<\/pre>\n<p>The eighth stage checked to see if there were more than 1024 GB of RAM.<\/p>\n<pre class=\"lang:default decode:true \">MEMORYSTATUSEX statex;\r\n\tstatex.dwLength = sizeof(statex);\r\n\r\n\tGlobalMemoryStatusEx(&amp;statex);\r\n\tif ((statex.ullTotalPhys \/ 1024) &lt; 1048576)\r\n<\/pre>\n<p>The final check looked to see if the CPU hypervisor bit was set.<\/p>\n<pre class=\"lang:default decode:true \">BOOL hv_bit(VOID)\r\n{\r\n\tint CPUInfo[4] = { -1 };\r\n\r\n\t__cpuid(CPUInfo, 1);\r\n\tif ((CPUInfo[2] &gt;&gt; 31) &amp; 1)\r\n\t{\r\n\t\treturn TRUE;\r\n\t}\r\n\r\n\treturn FALSE;\r\n}\r\n<\/pre>\n<p>We can step through the program in a binary and make sure the correct path is taken. Then we will get the correct image.<\/p>\n<p><a href=\"https:\/\/www.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_22.png\"><div style=\"max-width:100%\" data-width=\"500\"><span class=\"ar-custom\" style=\"padding-bottom:68.6%;\"><img loading=\"lazy\" decoding=\"async\"  class=\"size-large wp-image-19207 aligncenter lozad\"  data-src=\"https:\/\/www.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_22-500x343.png\" alt=\"ctf_windows_22\" width=\"500\" height=\"343\" srcset=\"https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_22-500x343.png 500w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_22-230x158.png 230w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_22-768x527.png 768w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_22-437x300.png 437w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_22-58x40.png 58w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_22.png 978w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/span><\/div><\/a><\/p>\n<p style=\"text-align: center;\"><em>Graph Trace of the Correct Path<\/em><\/p>\n<p>We could also get the correct key at each stage and grab the buffer of the XOR\u2019d image and decrypt it with python.<\/p>\n<pre class=\"lang:default decode:true\">def xor(data, key):\r\n    l = len(key)\r\n    return bytearray((\r\n        (data[i] ^ key[i % l]) for i in range(0,len(data))\r\n    ))\r\n\r\ndata = bytearray(open('xor.jpg', 'rb').read())\r\n\r\nkey = \r\nbytearray([0xAA,0xBB,0xCC,0x11,0x22,0x33,0xEE,0xCC,0x33,0x80,0x2e,0xeb,0xfe,0xff,0xcc])\r\n\r\nwith open('unxor.jpg', \"w\") as f:\r\nf.write(xor(data, key))\r\n<\/pre>\n<p><a href=\"https:\/\/www.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_23.png\"><div style=\"max-width:100%\" data-width=\"500\"><span class=\"ar-custom\" style=\"padding-bottom:122%;\"><img loading=\"lazy\" decoding=\"async\"  class=\"size-large wp-image-19204 aligncenter lozad\"  data-src=\"https:\/\/www.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_23-500x610.png\" alt=\"ctf_windows_23\" width=\"500\" height=\"610\" srcset=\"https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_23-500x610.png 500w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_23-230x281.png 230w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_23-246x300.png 246w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_23-33x40.png 33w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_23.png 608w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/span><\/div><\/a><\/p>\n<p style=\"text-align: center;\"><em>Correct Image<\/em><\/p>\n<p style=\"text-align: left;\">We can finally decode the binary and obtain the key (Sorry :)).<\/p>\n<p>PAN{Th3_$quirtL3_$qu@d_w@z_bLuffiNg}<\/p>\n<h3><strong>Windows 4 Challenge: 99 bottles of beer on the wall, 99 bottles of beer. Take one down and pass it around, 98 bottles of beer on the wall.\u00a0 Nah, you need to just pass the jugs of beer around.<\/strong><\/h3>\n<p><em>Challenge Created By: Jacob Soo <a href=\"https:\/\/twitter.com\/_jsoo_\" rel=\"nofollow,noopener\"  target=\"_blank\">@_jsoo_<\/a><\/em><\/p>\n<p>For this particular <a href=\"http:\/\/labyrenth.com\/challenges\/windows\/3dd0d247d51df1e9c8ae594089c82608792f6bbc376e102aee52ad7c1baa91ab\" rel=\"nofollow,noopener\" >challenge<\/a>, participants were given an x64 binary asking for a valid serial number.<\/p>\n<p>If the serial number is wrong, they should see the image below.<\/p>\n<p><a href=\"https:\/\/www.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_24.png\"><div style=\"max-width:100%\" data-width=\"500\"><span class=\"ar-custom\" style=\"padding-bottom:44.2%;\"><img loading=\"lazy\" decoding=\"async\"  class=\"size-large wp-image-19201 aligncenter lozad\"  data-src=\"https:\/\/www.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_24-500x221.png\" alt=\"ctf_windows_24\" width=\"500\" height=\"221\" srcset=\"https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_24-500x221.png 500w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_24-230x101.png 230w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_24-768x339.png 768w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_24-510x225.png 510w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_24-91x40.png 91w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_24.png 970w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/span><\/div><\/a>This seems like those traditional crackmes. Let\u2019s try to find the function that is checking users\u2019 input. In order to find it, we should always look for suspicious strings\u00a0if applicable.<\/p>\n<p>Using Hopper, we found the following strings as indicated in the image below.<\/p>\n<p><a href=\"https:\/\/www.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_25.png\"><div style=\"max-width:100%\" data-width=\"500\"><span class=\"ar-custom\" style=\"padding-bottom:70%;\"><img loading=\"lazy\" decoding=\"async\"  class=\"size-large wp-image-19198 aligncenter lozad\"  data-src=\"https:\/\/www.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_25-500x350.png\" alt=\"ctf_windows_25\" width=\"500\" height=\"350\" srcset=\"https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_25-500x350.png 500w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_25-230x161.png 230w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_25-768x538.png 768w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_25-428x300.png 428w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_25-57x40.png 57w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_25.png 914w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/span><\/div><\/a><\/p>\n<p>So let\u2019s pick one of the \u201cstrings\u201d and see where it was referenced.<\/p>\n<p><a href=\"https:\/\/www.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_26.png\"><div style=\"max-width:100%\" data-width=\"500\"><span class=\"ar-custom\" style=\"padding-bottom:46.4%;\"><img loading=\"lazy\" decoding=\"async\"  class=\"size-large wp-image-19195 aligncenter lozad\"  data-src=\"https:\/\/www.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_26-500x232.png\" alt=\"ctf_windows_26\" width=\"500\" height=\"232\" srcset=\"https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_26-500x232.png 500w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_26-230x107.png 230w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_26-768x356.png 768w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_26-510x236.png 510w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_26-86x40.png 86w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_26.png 900w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/span><\/div><\/a><\/p>\n<p>Ok, let\u2019s try and see whether we can find any <strong>GetDlgItemText\/GetDlgItemTextW<\/strong> API calls. Ok, it seems like we got one at <strong>140001464<\/strong>.<\/p>\n<p><a href=\"https:\/\/www.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_27.png\"><div style=\"max-width:100%\" data-width=\"500\"><span class=\"ar-custom\" style=\"padding-bottom:72.2%;\"><img loading=\"lazy\" decoding=\"async\"  class=\"size-large wp-image-19192 aligncenter lozad\"  data-src=\"https:\/\/www.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_27-500x361.png\" alt=\"ctf_windows_27\" width=\"500\" height=\"361\" srcset=\"https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_27-500x361.png 500w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_27-230x166.png 230w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_27-768x554.png 768w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_27-416x300.png 416w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_27-55x40.png 55w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_27.png 914w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/span><\/div><\/a><\/p>\n<p>If we step debug it and follow the flow, we will come across a string length check at <strong>1400014b3<\/strong>. Now we know that the input string must be 32 characters in length.<\/p>\n<p>Stepping through again, at <strong>140001500<\/strong> we will encounter a check to ensure that the input characters must be 1, 2 or 3.\u00a0 This makes sure that the serial for this challenge is only comprised of 1, 2 and 3.<\/p>\n<p>If we were to analyze the application at <strong>140001750<\/strong>, we can see that there is an array with an initial capacity of [0, 13, 7].\u00a0 However the maximum capacity of the \u201cjugs\u201d is [19, 13, 7] and the expected end state is having the array be [10, 10, 0].\u00a0 You basically have three \u201cjugs\u201d with a size of 7, 13 and 19.\u00a0 The 7 and 13 size \u201cjugs\u201d are filled and the container with size 19 is empty. What you need is 10 in two of the containers (13 and 19).<\/p>\n<p>Let\u2019s re-write it in pseudo codes.\u00a0 Let\u2019s assume that 3 \u201cjugs\u201d are under the array, M and the 3 jugs are a,b and c.<\/p>\n<pre class=\"lang:default decode:true \">for (int i = 0; i &lt; szSerial.Length; i += 2){\r\n    a = convert_it_to_int(Substring_of_szSerial(i, 1));\r\n    b = convert_it_to_int (Substring_of_szSerial (i + 1, 1));\r\n    if (a != b){\r\n        switch (b){\r\n            case 1:\r\n                c = 19;\r\n                break;\r\n            case 2:\r\n                c = 13;\r\n                break;\r\n            case 3:\r\n                c = 7;\r\n                break;\r\n        }\r\n        if ((M[b] + M[a]) &gt; c){\r\n            M[a] += M[b] - c;\r\n            L[b] = c;\r\n        }else{\r\n            M[b] += L[a];\r\n            M[a] = 0;\r\n        }\r\n    }\r\n}\r\n<\/pre>\n<p>At first it may seem to be very confusing what is actually going on here. But let\u2019s take a closer look.<\/p>\n<p>This is the limit of the jugs.<\/p>\n<pre class=\"lang:default decode:true \">Limit: 19    13    7\r\n-----------------------\r\n             A     B     C\r\nJug:\t1  | 2   | 3\r\nWater:\t0  | 13 | 7\r\n\r\nIf [B] +[A] &gt; Limit-of-[A]\r\n    Fill [B] and put the remaining in [A]\r\nElse\r\n    Fill [B] and clear [A]\r\n<\/pre>\n<p>Now in the serial, if we were to start with 31, it simply means to fill up jug C to jug A.<br \/>\nSo the aim of this is to move around the \u201cbeer\u201d so jug A == 10 and jug B == 10.<\/p>\n<p>We would have realized that this is the classic \u201c<a href=\"http:\/\/www.cut-the-knot.org\/ctk\/Water.shtml\" rel=\"nofollow,noopener\"  target=\"_blank\">Liquid Pouring Puzzle<\/a>\u201d that some, if not most of us, have seen while we were in school.<\/p>\n<p>You can write your tool based on the findings. But if we were to do it with pen and paper. We should get something like the one below.<\/p>\n<p>0-13-7<br \/>\n7-13-0<br \/>\n19-1-0<br \/>\n12-1-7<br \/>\n12-8-0<br \/>\n5-8-7<br \/>\n5-13-2<br \/>\n18-0-2<br \/>\n18-2-0<br \/>\n11-2-7<br \/>\n11-9-0<br \/>\n4-9-7<br \/>\n4-13-3<br \/>\n17-0-3<br \/>\n17-3-0<br \/>\n10-3-7<br \/>\n10-10-0<\/p>\n<p>Rewriting this to serial code: 31211332133221321332133221321332<\/p>\n<p>Using that as the serial, we will solve it and get this message back.<\/p>\n<p><a href=\"https:\/\/www.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_28.png\"><div style=\"max-width:100%\" data-width=\"500\"><span class=\"ar-custom\" style=\"padding-bottom:45%;\"><img loading=\"lazy\" decoding=\"async\"  class=\"size-large wp-image-19189 aligncenter lozad\"  data-src=\"https:\/\/www.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_28-500x225.png\" alt=\"ctf_windows_28\" width=\"500\" height=\"225\" srcset=\"https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_28-500x225.png 500w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_28-230x103.png 230w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_28-768x345.png 768w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_28-510x229.png 510w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_28-89x40.png 89w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_28.png 997w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/span><\/div><\/a><\/p>\n<p class=\"p1\"><span class=\"s1\">PAN{C0ngr47ulaT1ons<i>buddy<\/i>y0Uv3<i>solved<\/i>the<i>re4l<\/i>_prObL3M}<\/span><\/p>\n<h3><strong>Windows 5 Challenge: Pick your favorite decimal code. <\/strong><\/h3>\n<p><em>Challenge Created By: Jacob Soo <a href=\"https:\/\/twitter.com\/_jsoo_\" rel=\"nofollow,noopener\"  target=\"_blank\">@_jsoo_<\/a><\/em><\/p>\n<p>Upon running RGB.exe, we\u2019re presented with three sliders, presumably corresponding to the RBG colors, and once you\u2019ve set their values you can check them. This indicates that we\u2019ll need to figure out the correct three values to access the key.<\/p>\n<p><a href=\"https:\/\/www.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_29.png\"><div style=\"max-width:100%\" data-width=\"500\"><span class=\"ar-custom\" style=\"padding-bottom:35%;\"><img loading=\"lazy\" decoding=\"async\"  class=\"size-large wp-image-19186 aligncenter lozad\"  data-src=\"https:\/\/www.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_29-500x175.png\" alt=\"ctf_windows_29\" width=\"500\" height=\"175\" srcset=\"https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_29-500x175.png 500w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_29-230x81.png 230w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_29-768x269.png 768w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_29-510x179.png 510w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_29-114x40.png 114w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_29.png 904w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/span><\/div><\/a><\/p>\n<p style=\"text-align: center;\"><em>Wrong values<\/em><\/p>\n<p>A quick look at the PE file with Exeinfo shows that it\u2019s a .NET program, which can be unpacked with de4dot.<\/p>\n<p><a href=\"https:\/\/www.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_30.png\"><div style=\"max-width:100%\" data-width=\"500\"><span class=\"ar-custom\" style=\"padding-bottom:48.2%;\"><img loading=\"lazy\" decoding=\"async\"  class=\"size-large wp-image-19183 aligncenter lozad\"  data-src=\"https:\/\/www.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_30-500x241.png\" alt=\"ctf_windows_30\" width=\"500\" height=\"241\" srcset=\"https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_30-500x241.png 500w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_30-230x111.png 230w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_30-768x370.png 768w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_30-510x245.png 510w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_30-83x40.png 83w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_30.png 904w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/span><\/div><\/a><\/p>\n<p style=\"text-align: center;\"><em>Checking binary type<\/em><\/p>\n<p>Running de4dot against the executable creates a new file, \u201cRGB-cleaned.exe\u201d that we can then decompile with dnSpy to look at the underlying source code.<\/p>\n<p><a href=\"https:\/\/www.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_31.png\"><div style=\"max-width:100%\" data-width=\"500\"><span class=\"ar-custom\" style=\"padding-bottom:31.4%;\"><img loading=\"lazy\" decoding=\"async\"  class=\"size-large wp-image-19180 aligncenter lozad\"  data-src=\"https:\/\/www.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_31-500x157.png\" alt=\"ctf_windows_31\" width=\"500\" height=\"157\" srcset=\"https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_31-500x157.png 500w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_31-230x72.png 230w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_31-768x240.png 768w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_31-510x160.png 510w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_31-128x40.png 128w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_31.png 904w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/span><\/div><\/a><\/p>\n<p style=\"text-align: center;\"><em>Deobfuscating binary<\/em><\/p>\n<p style=\"text-align: left;\">When looking at the source code, we come to the challenge that we\u2019ll need to solve.<\/p>\n<p style=\"text-align: left;\"><a href=\"https:\/\/www.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_32.png\"><div style=\"max-width:100%\" data-width=\"500\"><span class=\"ar-custom\" style=\"padding-bottom:16.4%;\"><img loading=\"lazy\" decoding=\"async\"  class=\"size-large wp-image-19177 aligncenter lozad\"  data-src=\"https:\/\/www.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_32-500x82.png\" alt=\"ctf_windows_32\" width=\"500\" height=\"82\" srcset=\"https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_32-500x82.png 500w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_32-230x38.png 230w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_32-768x126.png 768w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_32-510x83.png 510w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_32-240x40.png 240w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_32.png 904w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/span><\/div><\/a><\/p>\n<p style=\"text-align: center;\"><em>Algorithm<\/em><\/p>\n<p>Simply put, three conditions need to be met to get the MessageBox we want to display. At this point, I started poking around to see if I can just modify the code so it always prints the answer, but when you start diving into the functions being called, you can see there is a bit more going on and requires the actual numbers.<\/p>\n<p><a href=\"https:\/\/www.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_33.png\"><div style=\"max-width:100%\" data-width=\"500\"><span class=\"ar-custom\" style=\"padding-bottom:26.6%;\"><img loading=\"lazy\" decoding=\"async\"  class=\"size-large wp-image-19174 aligncenter lozad\"  data-src=\"https:\/\/www.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_33-500x133.png\" alt=\"ctf_windows_33\" width=\"500\" height=\"133\" srcset=\"https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_33-500x133.png 500w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_33-230x61.png 230w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_33-768x204.png 768w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_33-510x136.png 510w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_33-150x40.png 150w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_33.png 902w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/span><\/div><\/a><\/p>\n<p style=\"text-align: center;\"><em>XORing numbers against array of numbers<\/em><\/p>\n<p>So I decided to tackle the math aspect instead.<\/p>\n<p>The three conditions that need to be met are that one equation result must equal another equation result and one of the specific values needs to be over 60. I opt to brute force it by iterating through every possible combination of numbers, knowing that each slider will be in a range of 1-255, with one being in the range of 60-255. This gives us roughly 12.5 million possibilities, 255*255*(255-60), which shouldn\u2019t take long at all.<\/p>\n<p>After a few minutes of thinking through the logic, I use the below script to find the value.<\/p>\n<pre class=\"lang:default decode:true \">-----rgb.py\r\nimport sys\r\n\u00a0\r\ndef func1(value, value2, value3, num, num2):\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 result = value + num - value2 + value * value * value2 - value3\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 return result\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\r\ndef func2(value, value2, value3, num, num2):\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 result = value2 * (value3 * 34 + (num2 - value)) + 3744\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 return result\r\n\u00a0\r\ndef check(value, value2, value3, num, num2):\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 a = func1(value, value2, value3, num, num2)\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 b = func2(value, value2, value3, num, num2)\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 if a == b:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 print \"\\nwinner winner, chicken dinner!\\n\\n\", value, value2, value3, \" [\" + str(a), \r\nstr(b) + \"]\"\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 sys.exit(1)\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 return\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\r\nvalue = 60\r\nvalue2 = 0\r\nvalue3 = 0\r\nnum = value2 * value3\r\nnum2 = value * 3\r\n\u00a0\r\nwhile value &lt; 256:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 value2 = 0\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 value3 = 0\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 num = value2 * value3\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 num2 = value * 3\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 check(value, value2, value3, num, num2)\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 while value2 &lt; 256:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 value3 = 0\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 num = value2 * value3\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 num2 = value * 3\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 check(value, value2, value3, num, num2)\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 while value3 &lt; 256:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 num = value2 * value3\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 num2 = value * 3\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 check(value, value2, value3, num, num2)\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 value3 += 1\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 value2 += 1\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 value += 1\r\n-----\r\n<\/pre>\n<p>Within a few seconds, we have the answer and can validate it within RGB.exe to get the key.<\/p>\n<p><a href=\"https:\/\/www.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_34.png\"><div style=\"max-width:100%\" data-width=\"500\"><span class=\"ar-custom\" style=\"padding-bottom:35.2%;\"><img loading=\"lazy\" decoding=\"async\"  class=\"size-large wp-image-19171 aligncenter lozad\"  data-src=\"https:\/\/www.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_34-500x176.png\" alt=\"ctf_windows_34\" width=\"500\" height=\"176\" srcset=\"https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_34-500x176.png 500w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_34-230x81.png 230w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_34-768x271.png 768w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_34-510x180.png 510w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_34-113x40.png 113w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_34.png 904w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/span><\/div><\/a><\/p>\n<p style=\"text-align: center;\"><em>83 168 203<\/em><\/p>\n<p>PAN{l4byr1n7h_s4yz_x0r1s_4m4z1ng}<\/p>\n<h3><strong>Windows 6 Challenge: Discover the key in the shellC0DE to rescue the Princess!<\/strong><\/h3>\n<p><em>Created By: Josh Grunzweig <a href=\"https:\/\/twitter.com\/jgrunzweig\" rel=\"nofollow,noopener\"  target=\"_blank\">@jgrunzweig<\/a><\/em><\/p>\n<p>Opening up this Windows executable quickly reveals that we\u2019re working with some shellcode. If this wasn\u2019t apparent, the clue provided gave some hints as to what you\u2019d be dealing with.<\/p>\n<p>Discover the key in the sh&gt;E11C0DE to rescue the Princess!<br \/>\n@jgrunzweig<\/p>\n<p>To make things easier for challengers, I went ahead and compiled the shellcode into a working executable, versus simply giving you the raw shellcode bytes. Once opened we see that there are no imports and only seven functions.<\/p>\n<p><a href=\"https:\/\/www.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_35.png\"><div style=\"max-width:100%\" data-width=\"500\"><span class=\"ar-custom\" style=\"padding-bottom:28%;\"><img loading=\"lazy\" decoding=\"async\"  class=\"size-large wp-image-19168 aligncenter lozad\"  data-src=\"https:\/\/www.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_35-500x140.png\" alt=\"ctf_windows_35\" width=\"500\" height=\"140\" srcset=\"https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_35-500x140.png 500w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_35-230x64.png 230w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_35-768x214.png 768w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_35-510x142.png 510w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_35-143x40.png 143w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_35.png 974w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/span><\/div><\/a><\/p>\n<p style=\"text-align: center;\"><em>Figure 1 Functions in shellcode and import table<\/em><\/p>\n<p>Without even debugging this shellcode we can quickly scan the seven functions provided to see if anything jumps out. Sure enough, we quickly identify a function that is almost certainly RC4 at 0x40106C. The two loops iterating 256 times gives us a big hint. Working through this function, we can confirm it is in fact RC4.<\/p>\n<p><a href=\"https:\/\/www.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_36.png\"><div style=\"max-width:100%\" data-width=\"500\"><span class=\"ar-custom\" style=\"padding-bottom:188.6%;\"><img loading=\"lazy\" decoding=\"async\"  class=\"size-large wp-image-19165 aligncenter lozad\"  data-src=\"https:\/\/www.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_36-500x943.png\" alt=\"ctf_windows_36\" width=\"500\" height=\"943\" srcset=\"https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_36-500x943.png 500w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_36-230x434.png 230w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_36-159x300.png 159w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_36-21x40.png 21w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_36.png 715w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/span><\/div><\/a><\/p>\n<p style=\"text-align: center;\"><em>Figure 2 RC4 function<\/em><\/p>\n<p>We also identify a very small function which starts by loading fs:0x30, which should get a reverser\u2019s attention fairly quickly. For those unaware, fs:0x30 points to the <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/windows\/desktop\/aa813706%28v=vs.85%29.aspx?f=255&amp;MSPPError=-2147217396\" rel=\"nofollow,noopener\"  target=\"_blank\">Process Environment Block<\/a> (PEB), which holds a wealth of information. This function in question is specifically looking at the PEB\u2019s LoaderData offset, which holds information about the loaded modules in the process. We then get the third loaded module, which is kernel32.dll, and grab this DLL\u2019s base address (offset 0x10). This function is essentially grabbing the base address of kernel32.dll, which is most likely going to be used to load further functions.<\/p>\n<p><a href=\"https:\/\/www.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_37.png\"><div style=\"max-width:100%\" data-width=\"500\"><span class=\"ar-custom\" style=\"padding-bottom:33.6%;\"><img loading=\"lazy\" decoding=\"async\"  class=\"size-large wp-image-19162 aligncenter lozad\"  data-src=\"https:\/\/www.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_37-500x168.png\" alt=\"ctf_windows_37\" width=\"500\" height=\"168\" srcset=\"https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_37-500x168.png 500w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_37-230x77.png 230w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_37-768x258.png 768w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_37-510x171.png 510w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_37-119x40.png 119w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_37.png 974w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/span><\/div><\/a><\/p>\n<p style=\"text-align: center;\"><em>Figure 3 Function getting kernel32 base address<\/em><\/p>\n<p>We continue to identify yet another function that appears to be hashing data, as evident by the ROR13 call.<\/p>\n<p><a href=\"https:\/\/www.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_38.png\"><div style=\"max-width:100%\" data-width=\"500\"><span class=\"ar-custom\" style=\"padding-bottom:111%;\"><img loading=\"lazy\" decoding=\"async\"  class=\"size-large wp-image-19159 aligncenter lozad\"  data-src=\"https:\/\/www.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_38-500x555.png\" alt=\"ctf_windows_38\" width=\"500\" height=\"555\" srcset=\"https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_38-500x555.png 500w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_38-230x255.png 230w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_38-768x852.png 768w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_38-270x300.png 270w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_38-36x40.png 36w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/09\/CTF_Windows_38.png 975w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/span><\/div><\/a><\/p>\n<p style=\"text-align: center;\"><em>Figure 4 Possibly hashing function<\/em><\/p>\n<p>At this point, let\u2019s start stepping through our shellcode in a debugger. We quickly see multiple calls to our function that got kernel32\u2019s base address, followed by another function that takes this base address and a DWORD as arguments. Looking through this function we see it walking through all of kernel32\u2019s exported functions, hashing the name, and comparing it against the provided DWORD. This is a simple shellcode trick that will allow attackers to obfuscate what functions are being loaded by the malware when viewed statically. There are a few ways we can approach this. We can debug the code and rename as we encounter them. Alternatively, we can simply search for the hashes on Google. Since the ROR13 technique is so common, there are many places online that have documented these hashes, <a href=\"https:\/\/hiddencodes.wordpress.com\/2014\/08\/22\/windows-api-hash-list-1\/\" rel=\"nofollow,noopener\"  target=\"_blank\">like this one<\/a>.<\/p>\n<p>After getting over this minor hurdle we can start to see what the code is doing to understand what it\u2019s looking for. Looking at the code in detail, we can see that it\u2019s building a buffer of 54 bytes and attempting to decode it against a key that is generated using RC4. In the event the key starts with \u2018PAN{\u2018, it will display it in a messagebox dialog window.<\/p>\n<p>The key is generated using a number of variables that are pulled from the machine it is running on. The first four bytes of the key are a static value of \u2018b00!\u2019. Following this, the code looks for the following data:<\/p>\n<ul>\n<li>Current month plus 0x2D<\/li>\n<li>Current day plus 0x5E<\/li>\n<li>Current hour plus 0x42<\/li>\n<li>The operating system major version plus 0x3C<\/li>\n<li>The operating system minor version plus 0x3F<\/li>\n<li>The isDebugged flag, which is pulled from the PEB, plus 0x69<\/li>\n<li>The language version plus 0x5E<\/li>\n<\/ul>\n<p>These values together give us a key that is eleven bytes long. With only that information, it would be very difficult to brute force. However, since we know how each byte in the key is generated, we can limit our key space for the brute force and hopefully determine what the malware is looking for.<\/p>\n<p>Knowing that there are only 12 months in a year, we can assume the first generated byte is in the range between 1 and 12. Similarly, there are a maximum of 31 days in a month, giving our second byte a range of 1 to 31. We continue this pattern on the rest of the bytes in the RC4 key. Most people looked to have the most trouble limiting the key space on the operating system versions, and the language version. Fortunately, there are very few legimate operating system (OS) versions overall. The major OS version will have a value of either 5, 6, or 10. The minor OS version will have a value of 0, 1, 2, or 3.<\/p>\n<p>For the language version, there is a check early on in the execution flow where the result of GetUserDefaultUILanguage has its primary language identifier verified to be 0x0, or LANG_NEUTRAL. Knowing this, we can limit the possibilities of to values of 0x0, 0x04, 0x08, 0x0c, 0x10, or 0x14.<\/p>\n<p>Using all of this information, we can generate a brute-forcing script such as the following.<\/p>\n<pre class=\"lang:default decode:true \">import sys\r\nfrom datetime import datetime\r\nstartTime = datetime.now()\r\n\r\ndef rc4_crypt( data , key ):\r\n  S = range(256)\r\n  j = 0\r\n  out = []\r\n  for i in range(256):\r\n    j = (j + S[i] + ord( key[i % len(key)] )) % 256\r\n    S[i] , S[j] = S[j] , S[i]\r\n  i = j = 0\r\n  for char in data:\r\n    i = ( i + 1 ) % 256\r\n    j = ( j + S[i] ) % 256\r\n    S[i] , S[j] = S[j] , S[i]\r\n    out.append(chr(ord(char) ^ S[(S[i] + S[j]) % 256]))\r\n  return ''.join(out)\r\n\r\n\r\nc = 0\r\nfor current_month in range(1, 13):\r\n  for current_day in range(1, 32):\r\n    for current_hour in range(1, 25):\r\n      for os_major_version in [5, 6, 10]:\r\n        for os_minor_version in [0, 1, 2, 3]:\r\n          for peb_isdebugged_flag in [0, 1]:\r\n            for language_version in [0x0, 0x04, 0x08, 0x0c, \r\n0x10, 0x14]:\r\n              key = 'b00!' + chr(current_month+0x2d) + \r\nchr(current_day+0x5e) + chr(current_hour+0x42) + \r\nchr(os_major_version+0x3c) + chr(os_minor_version+0x3f) + \r\nchr(peb_isdebugged_flag+0x69) + chr(language_version+0x5e)\r\n              x = \r\nrc4_crypt('\\xba\\xafMU&lt;\\xe3\\x03\"\\xb0\\xdf\\xf3\\xd3W\\xd0\\xe1@\\xf9\\x1\r\n3\\x1f\\xba\\x8d\\x12\\xf1\\xffH\\xc2\\x8e\\x00\\xfdT\\x97\\x9duq0\\x8fC(\\xfe\r\ni6G\\x8f\\xa2\\xefIt|\\xe1LoO\\xd4\\x82', key)\r\n              if x[0:4] == 'PAN{':\r\n                print \"Winner winner, chicken dinner:\", x\r\n                print \"Month: {}\".format(current_month)\r\n                print \"Day: {}\".format(current_day)\r\n                print \"Hour: {}\".format(current_hour)\r\n                print \"OS Major Version: \r\n{}\".format(os_major_version)\r\n                print \"OS Minor Version: \r\n{}\".format(os_minor_version)\r\n                print \"Debugged: {}\".format(peb_isdebugged_flag)\r\n                print \"Language Version: \r\n{}\".format(language_version)\r\n                print \"Time taken:\", datetime.now() - startTime\r\n                sys.exit(1)\r\n              c+=1\r\n              if c % 100000 == 0: print '%d attempts made.' % c\r\n\r\nprint \"Time taken:\", datetime.now() - startTime\r\n<\/pre>\n<p>After running the script for roughly 3 minutes, we are presented with the following:<\/p>\n<pre class=\"lang:default decode:true \">100000 attempts made.\r\n200000 attempts made.\r\n300000 attempts made.\r\n400000 attempts made.\r\n500000 attempts made.\r\n600000 attempts made.\r\n700000 attempts made.\r\n800000 attempts made.\r\n900000 attempts made.\r\n1000000 attempts made.\r\n1100000 attempts made.\r\n1200000 attempts made.\r\nWinner winner, chicken dinner: PAN{th0se_puPP3ts_creeped_m3_out_and_I_h4d_NIGHTMARES}\r\nMonth: 12\r\nDay: 13\r\nHour: 10\r\nOS Major Version: 5\r\nOS Minor Version: 1\r\nDebugged: 1\r\nLanguage Version: 8\r\nTime taken: 0:03:04.102476\r\n<\/pre>\n<p class=\"p1\"><span class=\"s1\">PAN{th0se_puPP3ts_creeped_m3_out_and_I_h4d_NIGHTMARES}<\/span><\/p>\n<p>Leave a comment below to share your thoughts about these challenges. Be sure to also check out how other threat researchers solved these challenges:<\/p>\n<p class=\"p1\"><strong><span class=\"s1\">Windows 1:<\/span><\/strong><\/p>\n<ul>\n<li class=\"p2\"><span class=\"s2\"><a href=\"https:\/\/jmprsp.wordpress.com\/2016\/08\/31\/labyrenth-windows-track-challenge-1\" rel=\"nofollow,noopener\" >https:\/\/jmprsp.wordpress.com\/2016\/08\/31\/labyrenth-windows-track-challenge-1<\/a><\/span><span class=\"s3\">\/<\/span><\/li>\n<li class=\"p2\"><span class=\"s2\"><a href=\"https:\/\/github.com\/gray-panda\/grayrepo\/tree\/master\/2016_labyREnth\/win1_antid\" rel=\"nofollow,noopener\" >https:\/\/github.com\/gray-panda\/grayrepo\/tree\/master\/2016_labyREnth\/win1_antid<\/a><\/span><\/li>\n<li class=\"p2\"><span class=\"s2\"><a href=\"http:\/\/www.ghettoforensics.com\/2016\/08\/running-labyrenth-unit-42-ctf.html\" rel=\"nofollow,noopener\" >http:\/\/www.ghettoforensics.com\/2016\/08\/running-labyrenth-unit-42-ctf.html<\/a><\/span><\/li>\n<li class=\"p2\"><span class=\"s2\"><a href=\"https:\/\/github.com\/nullsector\/ctf\/tree\/master\/PANLabyREnthCTF\/Windows\/1\/AntiD\" rel=\"nofollow,noopener\" >https:\/\/github.com\/nullsector\/ctf\/tree\/master\/PANLabyREnthCTF\/Windows\/1\/AntiD<\/a><\/span><\/li>\n<li class=\"p2\"><span class=\"s2\"><a href=\"https:\/\/github.com\/uafio\/git\/blob\/master\/scripts\/labyREnth-2016\/labyrenth-2016-win-1.py\" rel=\"nofollow,noopener\" >https:\/\/github.com\/uafio\/git\/blob\/master\/scripts\/labyREnth-2016\/labyrenth-2016-win-1.py<\/a><\/span><\/li>\n<li class=\"p2\"><span class=\"s2\"><a href=\"https:\/\/github.com\/11x256\/CTFs\/tree\/master\/2016\/LabyREnth\/1-AntiD\" rel=\"nofollow,noopener\" >https:\/\/github.com\/11x256\/CTFs\/tree\/master\/2016\/LabyREnth\/1-AntiD<\/a><\/span><\/li>\n<li class=\"p2\"><span class=\"s2\"><a href=\"https:\/\/github.com\/spartansecurity\/Writeups\/blob\/master\/labyrenth2016\/windows.md#challenge-1\" rel=\"nofollow,noopener\" >https:\/\/github.com\/spartansecurity\/Writeups\/blob\/master\/labyrenth2016\/windows.md#challenge-1<\/a><\/span><\/li>\n<li class=\"p2\"><span class=\"s2\"><a href=\"http:\/\/chrisbedev.blogspot.com\/2016\/08\/labyrenth-ctf.html\" rel=\"nofollow,noopener\" >http:\/\/chrisbedev.blogspot.com\/2016\/08\/labyrenth-ctf.html<\/a><\/span><\/li>\n<\/ul>\n<p class=\"p1\"><strong><span class=\"s1\">Windows 2:<\/span><\/strong><\/p>\n<ul>\n<li class=\"p2\"><span class=\"s2\"><a href=\"https:\/\/jmprsp.wordpress.com\/2016\/08\/31\/labyrenth-ctf-windows-track-challenge-2\" rel=\"nofollow,noopener\" >https:\/\/jmprsp.wordpress.com\/2016\/08\/31\/labyrenth-ctf-windows-track-challenge-2<\/a><\/span><span class=\"s3\">\/<\/span><\/li>\n<li class=\"p2\"><span class=\"s2\"><a href=\"https:\/\/github.com\/gray-panda\/grayrepo\/tree\/master\/2016_labyREnth\/win2_babbysays\" rel=\"nofollow,noopener\" >https:\/\/github.com\/gray-panda\/grayrepo\/tree\/master\/2016_labyREnth\/win2_babbysays<\/a><\/span><\/li>\n<li class=\"p2\"><span class=\"s2\"><a href=\"https:\/\/github.com\/nullsector\/ctf\/tree\/master\/PANLabyREnthCTF\/Windows\/2\" rel=\"nofollow,noopener\" >https:\/\/github.com\/nullsector\/ctf\/tree\/master\/PANLabyREnthCTF\/Windows\/2<\/a><\/span><\/li>\n<li class=\"p2\"><span class=\"s2\"><a href=\"https:\/\/github.com\/11x256\/CTFs\/tree\/master\/2016\/LabyREnth\/2-BabbySay\" rel=\"nofollow,noopener\" >https:\/\/github.com\/11x256\/CTFs\/tree\/master\/2016\/LabyREnth\/2-BabbySay<\/a><\/span><\/li>\n<li class=\"p2\"><span class=\"s2\"><a href=\"https:\/\/github.com\/spartansecurity\/Writeups\/blob\/master\/labyrenth2016\/windows.md#challenge-2\" rel=\"nofollow,noopener\" >https:\/\/github.com\/spartansecurity\/Writeups\/blob\/master\/labyrenth2016\/windows.md#challenge-2<\/a><\/span><\/li>\n<\/ul>\n<p class=\"p1\"><strong><span class=\"s1\">Windows 3:<\/span><\/strong><\/p>\n<ul>\n<li class=\"p2\"><span class=\"s2\"><a href=\"https:\/\/jmprsp.wordpress.com\/2016\/09\/03\/labyrenth-ctf-windows-track-challenge-3\" rel=\"nofollow,noopener\" >https:\/\/jmprsp.wordpress.com\/2016\/09\/03\/labyrenth-ctf-windows-track-challenge-3<\/a><\/span><span class=\"s3\">\/<\/span><\/li>\n<li class=\"p2\"><span class=\"s2\"><a href=\"https:\/\/github.com\/gray-panda\/grayrepo\/tree\/master\/2016_labyREnth\/win3_squirtle\" rel=\"nofollow,noopener\" >https:\/\/github.com\/gray-panda\/grayrepo\/tree\/master\/2016_labyREnth\/win3_squirtle<\/a><\/span><\/li>\n<li class=\"p2\"><span class=\"s2\"><a href=\"https:\/\/github.com\/nullsector\/ctf\/tree\/master\/PANLabyREnthCTF\/Windows\/3\/Squirtle\" rel=\"nofollow,noopener\" >https:\/\/github.com\/nullsector\/ctf\/tree\/master\/PANLabyREnthCTF\/Windows\/3\/Squirtle<\/a><\/span><\/li>\n<li class=\"p2\"><span class=\"s2\"><a href=\"https:\/\/github.com\/11x256\/CTFs\/tree\/master\/2016\/LabyREnth\/3-Squirtle\" rel=\"nofollow,noopener\" >https:\/\/github.com\/11x256\/CTFs\/tree\/master\/2016\/LabyREnth\/3-Squirtle<\/a><\/span><\/li>\n<li class=\"p2\"><span class=\"s2\"><a href=\"https:\/\/github.com\/spartansecurity\/Writeups\/blob\/master\/labyrenth2016\/windows.md#challenge-3\" rel=\"nofollow,noopener\" >https:\/\/github.com\/spartansecurity\/Writeups\/blob\/master\/labyrenth2016\/windows.md#challenge-3<\/a><\/span><\/li>\n<\/ul>\n<p class=\"p1\"><strong><span class=\"s1\">Windows 4:<\/span><\/strong><\/p>\n<ul>\n<li class=\"p2\"><span class=\"s2\"><a href=\"https:\/\/jmprsp.wordpress.com\/2016\/09\/04\/labyrenth-ctf-windows-track-challenge-4\" rel=\"nofollow,noopener\" >https:\/\/jmprsp.wordpress.com\/2016\/09\/04\/labyrenth-ctf-windows-track-challenge-4<\/a><\/span><span class=\"s3\">\/<\/span><\/li>\n<li class=\"p2\"><span class=\"s2\"><a href=\"https:\/\/github.com\/gray-panda\/grayrepo\/tree\/master\/2016_labyREnth\/win4_jugsofbeer\" rel=\"nofollow,noopener\" >https:\/\/github.com\/gray-panda\/grayrepo\/tree\/master\/2016_labyREnth\/win4_jugsofbeer<\/a><\/span><\/li>\n<li class=\"p2\"><span class=\"s2\"><a href=\"http:\/\/www.ghettoforensics.com\/2016\/08\/running-labyrenth-unit-42-ctf.html\" rel=\"nofollow,noopener\" >http:\/\/www.ghettoforensics.com\/2016\/08\/running-labyrenth-unit-42-ctf.html<\/a><\/span><\/li>\n<li class=\"p2\"><span class=\"s2\"><a href=\"http:\/\/sibears.ru\/labs\/labyrenth2016-win-4\" rel=\"nofollow,noopener\" >http:\/\/sibears.ru\/labs\/labyrenth2016-win-4<\/a><\/span><span class=\"s3\">\/<\/span><\/li>\n<li class=\"p2\"><span class=\"s2\"><a href=\"https:\/\/github.com\/nullsector\/ctf\/tree\/master\/PANLabyREnthCTF\/Windows\/4\/JugsofBeer\" rel=\"nofollow,noopener\" >https:\/\/github.com\/nullsector\/ctf\/tree\/master\/PANLabyREnthCTF\/Windows\/4\/JugsofBeer<\/a><\/span><\/li>\n<li class=\"p2\"><span class=\"s2\"><a href=\"https:\/\/github.com\/uafio\/git\/blob\/master\/scripts\/labyREnth-2016\/labyrenth-2016-win-4.py\" rel=\"nofollow,noopener\" >https:\/\/github.com\/uafio\/git\/blob\/master\/scripts\/labyREnth-2016\/labyrenth-2016-win-4.py<\/a><\/span><\/li>\n<li class=\"p2\"><span class=\"s2\"><a href=\"https:\/\/github.com\/11x256\/CTFs\/tree\/master\/2016\/LabyREnth\/4-JugsofBeer\" rel=\"nofollow,noopener\" >https:\/\/github.com\/11x256\/CTFs\/tree\/master\/2016\/LabyREnth\/4-JugsofBeer<\/a><\/span><\/li>\n<li class=\"p2\"><span class=\"s2\"><a href=\"https:\/\/github.com\/spartansecurity\/Writeups\/blob\/master\/labyrenth2016\/windows.md#challenge-4\" rel=\"nofollow,noopener\" >https:\/\/github.com\/spartansecurity\/Writeups\/blob\/master\/labyrenth2016\/windows.md#challenge-4<\/a><\/span><\/li>\n<\/ul>\n<p class=\"p1\"><strong><span class=\"s1\">Windows 5:<\/span><\/strong><\/p>\n<ul>\n<li class=\"p2\"><span class=\"s2\"><a href=\"https:\/\/jmprsp.wordpress.com\/2016\/09\/04\/labyrenth-ctf-windows-track-challenge-5\" rel=\"nofollow,noopener\" >https:\/\/jmprsp.wordpress.com\/2016\/09\/04\/labyrenth-ctf-windows-track-challenge-5<\/a><\/span><span class=\"s3\">\/<\/span><\/li>\n<li class=\"p2\"><span class=\"s2\"><a href=\"https:\/\/github.com\/gray-panda\/grayrepo\/tree\/master\/2016_labyREnth\/win5_rgb\" rel=\"nofollow,noopener\" >https:\/\/github.com\/gray-panda\/grayrepo\/tree\/master\/2016_labyREnth\/win5_rgb<\/a><\/span><\/li>\n<li class=\"p2\"><span class=\"s2\"><a href=\"https:\/\/github.com\/nullsector\/ctf\/tree\/master\/PANLabyREnthCTF\/Windows\/5\/RGB\" rel=\"nofollow,noopener\" >https:\/\/github.com\/nullsector\/ctf\/tree\/master\/PANLabyREnthCTF\/Windows\/5\/RGB<\/a><\/span><\/li>\n<li class=\"p2\"><span class=\"s2\"><a href=\"https:\/\/github.com\/uafio\/git\/blob\/master\/scripts\/labyREnth-2016\/labyrenth-2016-win-5.py\" rel=\"nofollow,noopener\" >https:\/\/github.com\/uafio\/git\/blob\/master\/scripts\/labyREnth-2016\/labyrenth-2016-win-5.py<\/a><\/span><\/li>\n<li class=\"p2\"><span class=\"s2\"><a href=\"https:\/\/github.com\/11x256\/CTFs\/tree\/master\/2016\/LabyREnth\/5-RGB\" rel=\"nofollow,noopener\" >https:\/\/github.com\/11x256\/CTFs\/tree\/master\/2016\/LabyREnth\/5-RGB<\/a><\/span><\/li>\n<li class=\"p2\"><span class=\"s2\"><a href=\"https:\/\/github.com\/spartansecurity\/Writeups\/blob\/master\/labyrenth2016\/windows.md#challenge-5\" rel=\"nofollow,noopener\" >https:\/\/github.com\/spartansecurity\/Writeups\/blob\/master\/labyrenth2016\/windows.md#challenge-5<\/a><\/span><\/li>\n<\/ul>\n<p class=\"p1\"><strong><span class=\"s1\">Windows 6:<\/span><\/strong><\/p>\n<ul>\n<li class=\"p2\"><span class=\"s2\"><a href=\"https:\/\/jmprsp.wordpress.com\/2016\/09\/07\/labyrenth-ctf-windows-track-challenge-6\" rel=\"nofollow,noopener\" >https:\/\/jmprsp.wordpress.com\/2016\/09\/07\/labyrenth-ctf-windows-track-challenge-6<\/a><\/span><span class=\"s3\">\/<\/span><\/li>\n<li class=\"p2\"><span class=\"s2\"><a href=\"https:\/\/github.com\/gray-panda\/grayrepo\/tree\/master\/2016_labyREnth\/win6_shellcode\" rel=\"nofollow,noopener\" >https:\/\/github.com\/gray-panda\/grayrepo\/tree\/master\/2016_labyREnth\/win6_shellcode<\/a><\/span><\/li>\n<li class=\"p2\"><span class=\"s2\"><a href=\"https:\/\/github.com\/uafio\/git\/blob\/master\/scripts\/labyREnth-2016\/labyrenth-2016-win-6.py\" rel=\"nofollow,noopener\" >https:\/\/github.com\/uafio\/git\/blob\/master\/scripts\/labyREnth-2016\/labyrenth-2016-win-6.py<\/a><\/span><\/li>\n<li class=\"p2\"><span class=\"s2\"><a href=\"https:\/\/github.com\/11x256\/CTFs\/tree\/master\/2016\/LabyREnth\/6-Shellcode\" rel=\"nofollow,noopener\" >https:\/\/github.com\/11x256\/CTFs\/tree\/master\/2016\/LabyREnth\/6-Shellcode<\/a><\/span><\/li>\n<li class=\"p2\"><span class=\"s2\"><a href=\"https:\/\/github.com\/spartansecurity\/Writeups\/blob\/master\/labyrenth2016\/windows.md#challenge-6\" rel=\"nofollow,noopener\" >https:\/\/github.com\/spartansecurity\/Writeups\/blob\/master\/labyrenth2016\/windows.md#challenge-6<\/a><\/span><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Welcome back to our blog series where we reveal the\u00a0solutions\u00a0to\u00a0LabyREnth, the Unit 42 Capture the Flag (CTF)\u00a0challenge. We\u2019ll be revealing the\u00a0solutions\u00a0to one challenge track per week. Next up, the Windows track challenges &hellip;<\/p>\n","protected":false},"author":138,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[133],"tags":[2644,2145,2142,586,882],"coauthors":[1312,1588,1116,1673,2329],"class_list":["post-19156","post","type-post","status-publish","format-standard","hentry","category-events","tag-capture-the-flag","tag-ctf","tag-labyrenth","tag-unit-42","tag-windows"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-json\/wp\/v2\/posts\/19156","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-json\/wp\/v2\/users\/138"}],"replies":[{"embeddable":true,"href":"https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-json\/wp\/v2\/comments?post=19156"}],"version-history":[{"count":7,"href":"https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-json\/wp\/v2\/posts\/19156\/revisions"}],"predecessor-version":[{"id":19920,"href":"https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-json\/wp\/v2\/posts\/19156\/revisions\/19920"}],"wp:attachment":[{"href":"https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-json\/wp\/v2\/media?parent=19156"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-json\/wp\/v2\/categories?post=19156"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-json\/wp\/v2\/tags?post=19156"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-json\/wp\/v2\/coauthors?post=19156"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}