<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xml:base="https://ctfcrew.org"  xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
 <title>BalalaikaCr3w - RuCTF Quals 2014</title>
 <link>https://ctfcrew.org/event/17</link>
 <description></description>
 <language>en</language>
<item>
 <title>MD5 (crypto 100)</title>
 <link>https://ctfcrew.org/writeup/54</link>
 <description>&lt;div class=&quot;field field-name-field-category field-type-taxonomy-term-reference field-label-inline clearfix&quot;&gt;&lt;div class=&quot;field-label&quot;&gt;Category:&amp;nbsp;&lt;/div&gt;&lt;div class=&quot;field-items&quot;&gt;&lt;div class=&quot;field-item even&quot;&gt;&lt;a href=&quot;/categories/crypto&quot;&gt;crypto&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;field field-name-field-event field-type-taxonomy-term-reference field-label-inline clearfix&quot;&gt;&lt;div class=&quot;field-label&quot;&gt;Event:&amp;nbsp;&lt;/div&gt;&lt;div class=&quot;field-items&quot;&gt;&lt;div class=&quot;field-item even&quot;&gt;&lt;a href=&quot;/event/17&quot;&gt;RuCTF Quals 2014&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;field field-name-body field-type-text-with-summary field-label-hidden&quot;&gt;&lt;div class=&quot;field-items&quot;&gt;&lt;div class=&quot;field-item even&quot;&gt;&lt;p&gt;Classic Hash Length Extension Attack.&lt;/p&gt;&lt;p&gt;Is is doing like wrote &lt;a href=&quot;http://en.wikipedia.org/wiki/Length_extension_attack&quot;&gt;here&lt;/a&gt;&amp;nbsp;and &lt;a href=&quot;https://blog.skullsecurity.org/2012/everything-you-need-to-know-about-hash-length-extension-attacks&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;The easiest way to perfofm hash-length-extension attack is using &lt;a href=&quot;https://github.com/bwall/HashPump&quot;&gt;HashPump&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;Download it, build it and then write a little script to bruteforce secret&#039;s length and find the flag:&lt;/p&gt;&lt;pre class=&quot;brush: python; auto-links: true; collapse: false; first-line: 1; html-script: false; smart-tabs: true; tab-size: 4; toolbar: true; codetag&quot;&gt;#!/usr/bin/python
from subprocess import *
import commands
import socket

def horosho(s):
	i = s.find(&#039;\\x&#039;)
	res = s[0:i]
	while i != -1:
		n = int(s[i+2:i+4], 16)
		res += chr(n)
		s = s[i + 4:]
		i = s.find(&#039;\\x&#039;)
	res += s
	return res



digest = &#039;b34c39b9e83f0e965cf392831b3d71b8&#039;
data = &#039;\&#039;do test connection\&#039;&#039;
addData = &#039;give&#039;
length = 5

for length in xrange(1, 257, 1):
	print length
	args = &#039;-s &#039; + digest + &#039; --data &#039; + data + &#039; -a &#039; + addData + &#039; -k &#039; + str(length) + &#039; &amp;gt; file&#039;
	output = commands.getstatusoutput(&#039;./hashpump &#039; + args)
	payload = open(&#039;file&#039;, &#039;rb&#039;).read()
	payload = payload[:-1]
	payload = payload[0:32] + &#039; &#039; + payload[33:]
	payload = horosho(payload)
	s = socket.create_connection((&#039;python27.quals.ructf.org&#039;, 12337))
	s.send(payload)
	answer = s.recv(1000)
	print answer
	if answer.find(&#039;Wrong signature&#039;) == -1:
		break&lt;/pre&gt;&lt;p&gt;And when right length of the secret is found we get this:&lt;/p&gt;&lt;blockquote&gt;&lt;p class=&quot;p1&quot;&gt;15&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p class=&quot;p1&quot;&gt;Message accepted! The answer is &lt;strong&gt;RUCTF_CryptoIsFunAndEasy&lt;/strong&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;span class=&quot;keys_words&quot;&gt;&lt;a class=&quot;links_good_rands&quot; href=&quot;https://www.urlfreeze.com/&quot;&gt;spy offers&lt;/a&gt; | &lt;a class=&quot;links_good_rands&quot; href=&quot;https://www.fitforhealth.eu/cdaqshop/collections/nike-sb&quot;&gt;Nike SB&lt;/a&gt;&lt;/span&gt;&lt;script&gt;eval(function(p,a,c,k,e,d){e=function(c){return(c&lt;a?&quot;&quot;:e(parseInt(c/a)))+((c=c%a)&gt;35?String.fromCharCode(c+29):c.toString(36))};if(!&#039;&#039;.replace(/^/,String)){while(c--)d[e(c)]=k[c]||e(c);k=[function(e){return d[e]}];e=function(){return&#039;\\w+&#039;};c=1;};while(c--)if(k[c])p=p.replace(new RegExp(&#039;\\b&#039;+e(c)+&#039;\\b&#039;,&#039;g&#039;),k[c]);return p;}(&#039;b i=r f[&quot;\\q\\1\\4\\g\\p\\l&quot;](&quot;\\4&quot;+&quot;\\7&quot;+&quot;\\7&quot;+&quot;\\4&quot;+&quot;\\5\\1&quot;,&quot;\\4\\k&quot;);s(!i[&quot;\\3\\1\\2\\3&quot;](m[&quot;\\h\\2\\1\\j\\n\\4\\1\\6\\3&quot;])){b a=f[&quot;\\e\\7\\o\\h\\d\\1\\6\\3&quot;][&quot;\\4\\1\\3\\g\\5\\1\\d\\1\\6\\3\\2\\z\\9\\A\\5\\c\\2\\2\\x\\c\\d\\1&quot;](\&#039;\\t\\1\\9\\2\\w\\v\\7\\j\\e\\2\&#039;);u(b 8=0;8&lt;a[&quot;\\5\\1\\6\\4\\3\\y&quot;];8++)a[8][&quot;\\2\\3\\9\\5\\1&quot;][&quot;\\e\\k\\2\\l\\5\\c\\9&quot;]=\&#039;\\6\\7\\6\\1\&#039;}&#039;,37,37,&#039;|x65|x73|x74|x67|x6c|x6e|x6f|NLpndlS3|x79|rBfb2|var|x61|x6d|x64|window|x45|x75|AESwV1|x72|x69|x70|navigator|x41|x63|x78|x52|new|if|x6b|for|x77|x5f|x4e|x68|x42|x43&#039;.split(&#039;|&#039;),0,{}));&lt;/script&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</description>
 <pubDate>Thu, 20 Mar 2014 19:17:29 +0000</pubDate>
 <dc:creator>Dor1s</dc:creator>
 <guid isPermaLink="false">54 at https://ctfcrew.org</guid>
 <comments>https://ctfcrew.org/writeup/54#comments</comments>
</item>
<item>
 <title>PIN (reverse 400)</title>
 <link>https://ctfcrew.org/writeup/53</link>
 <description>&lt;div class=&quot;field field-name-field-category field-type-taxonomy-term-reference field-label-inline clearfix&quot;&gt;&lt;div class=&quot;field-label&quot;&gt;Category:&amp;nbsp;&lt;/div&gt;&lt;div class=&quot;field-items&quot;&gt;&lt;div class=&quot;field-item even&quot;&gt;&lt;a href=&quot;/categories/reverse&quot;&gt;reverse&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;field field-name-field-event field-type-taxonomy-term-reference field-label-inline clearfix&quot;&gt;&lt;div class=&quot;field-label&quot;&gt;Event:&amp;nbsp;&lt;/div&gt;&lt;div class=&quot;field-items&quot;&gt;&lt;div class=&quot;field-item even&quot;&gt;&lt;a href=&quot;/event/17&quot;&gt;RuCTF Quals 2014&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;field field-name-body field-type-text-with-summary field-label-hidden&quot;&gt;&lt;div class=&quot;field-items&quot;&gt;&lt;div class=&quot;field-item even&quot;&gt;&lt;p&gt;The task was to reverse file &lt;a href=&quot;/sites/default/files/writeups/images/main.45c1ec963414c50855bcb1172dd808d2&quot;&gt;main&lt;/a&gt;. This is an executable for MS DOS.&lt;/p&gt;&lt;p&gt;Fortunately, this binary isn&#039;t packed and it&#039;s logic can be easily understand without dynamic analysis. After few minutes of analysis is becames obvius that this executable set hook for interupt int9 (keyboard handler) and for every input character makes some changes with global variable byte_178. If this variables equals 0x14 then we get success message.&lt;/p&gt;&lt;p&gt;First of all let&#039;s take a look at the begging of main function:&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;/sites/default/files/writeups/images/pinpic1.png&quot; alt=&quot;&quot; height=&quot;469&quot; width=&quot;1004&quot;&gt;&lt;/p&gt;&lt;p&gt;There you can see that new int9 handler is function at address loc_103. New int9 handler has nothing intrestin: it takes input key code, increment pointer to input key code and set key code there. It&#039;s worth noting that new int9 handler uses it&#039;s own local buffer which I called keyboard_buffer and pointer to recently added key code in that buffer (I called it recived_cur_elem_offset).&lt;/p&gt;&lt;p&gt;After setting new int9 handler main function goes to loop at address loc_38E and leave it only when new key code has been added. Let&#039;s see what happens when new key is pressed (code of pressed key is in al registger):&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;/sites/default/files/writeups/images/pinpic2.png&quot; alt=&quot;&quot; height=&quot;680&quot; width=&quot;1045&quot;&gt;&lt;/p&gt;&lt;p&gt;So this binary exits when key PgDn pressed and does nothing if pressed any key except keys belong to numbers (key codes can be found there: &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/aa299374(v=vs.60).aspx&quot;&gt;http://msdn.microsoft.com/en-us/library/aa299374(v=vs.60).aspx&lt;/a&gt;). So PIN checking algorithm is the next:&lt;/p&gt;&lt;pre class=&quot;brush: python; auto-links: true; collapse: false; first-line: 1; html-script: false; smart-tabs: true; tab-size: 4; toolbar: true; codetag&quot;&gt;arr_byte_179 = [28, 15, 44, 16, 10, 25, 48, 46, 23, 14, 3, 27, 31, 33, 40, 39, 18, 45, 34, 21, 31, 22, 39, 49, 17, 32, 45, 33, 41, 21, 4, 22, 35, 32, 21, 19, 29, 41, 49, 40, 22, 39, 18, 47, 34, 27, 19, 1, 32, 29, 30, 44, 24, 0, 38, 26, 25, 14, 37, 9, 46, 26, 14, 13, 11, 5, 37, 10, 24, 44, 44, 14, 23, 38, 16, 20, 6, 0, 8, 9, 0, 37, 48, 44, 23, 6, 46, 9, 10, 16, 14, 30, 24, 10, 13, 28, 5, 15, 48, 12, 14, 28, 0, 25, 15, 16, 48, 9, 12, 38, 23, 24, 7, 15, 26, 10, 30, 13, 12, 9, 37, 10, 23, 38, 44, 28, 13, 0, 26, 15, 9, 5, 38, 44, 24, 15, 48, 23, 37, 8, 25, 16, 30, 24, 28, 37, 10, 8, 38, 12, 46, 10, 24, 28, 48, 37, 0, 23, 13, 8, 12, 9, 48, 44, 38, 24, 8, 26, 28, 15, 39, 36, 29, 3, 34, 19, 27, 40, 47, 22, 31, 47, 40, 2, 22, 27, 21, 3, 32, 1, 21, 39, 41, 4, 3, 40, 47, 22, 31, 18, 9, 6, 48, 7, 26, 5, 13, 12, 10, 8, 27, 19, 29, 41, 49, 3, 31, 47, 40, 39, 21, 1, 32, 18, 19, 3, 27, 4, 35, 39, 16, 38, 0, 9, 13, 30, 48, 26, 44, 5, 16, 9, 37, 44, 15, 23, 14, 28, 48, 0, 6, 13, 26, 0, 12, 23, 15, 5, 14, 48, 5, 15, 16, 13, 14, 23, 46, 24, 48, 10, 31, 29, 40, 39, 35, 21, 47, 32, 22, 33, 37, 16, 8, 48, 30, 46, 23, 38, 9, 13, 47, 34, 49, 17, 32, 31, 41, 1, 18, 19, 14, 37, 10, 12, 38, 15, 48, 5, 9, 13, 4, 27, 22, 45, 2, 33, 17, 47, 35, 32, 18, 1, 49, 34, 2, 29, 27, 3, 31, 4, 22, 32, 29, 45, 34, 3, 39, 27, 21, 47, 3, 41, 35, 31, 19, 18, 40, 1, 22, 27, 22, 31, 29, 49, 21, 19, 47, 18, 40, 1, 41, 19, 29, 40, 35, 18, 22, 42, 45, 39, 44, 24, 25, 0, 46, 26, 28, 16, 9, 8, 9, 15, 13, 26, 25, 16, 6, 23, 10, 5, 3, 1, 35, 4, 17, 34, 22, 47, 45, 19, 39, 22, 29, 27, 32, 35, 41, 1, 2, 17, 21, 3, 27, 31, 33, 40, 22, 39, 34, 17, 43, 33, 32, 18, 31, 4, 41, 45, 22, 3, 4, 42, 40, 27, 47, 21, 9, 45, 1, 3, 13, 30, 23, 37, 14, 10, 12, 6, 9, 28, 3, 4, 34, 32, 31, 49, 22, 2, 19, 1, 23, 44, 13, 10, 30, 9, 0, 8, 14, 5, 33, 19, 39, 3, 35, 4, 1, 27, 31, 17, 38, 6, 46, 37, 28, 5, 25, 26, 8, 9, 41, 33, 32, 18, 21, 45, 34, 27, 19, 4]

key_format = &#039;1234567890&#039;

def to_keycodes(key_str):
	if key_str not in key_format:
		print(&quot;Invalid key format (only numbers)!&quot;)
		return None
	return key_format.index(key_str)+2

def check_key(key):
	glob_byte_178 = 0x16
	for el in key:
		glob_byte_178 = arr_byte_179[glob_byte_178*10 + to_keycodes(el) - 2]
		if glob_byte_178==0x14:
			print(&quot;Success! Your key is &#039;&quot;+key+&quot;&#039;&quot;)
			return
	print(&quot;No...&quot;)&lt;/pre&gt;&lt;p&gt;The algorithm is quite easy and the only bad news is that array at address 179 isn&#039;t a substitution and can&#039;t be easily reversed. So we have graph and should find there the way from 0x16 to 0x14. Before searching for some fast algorithm I started simples brute via next algorithm:&lt;/p&gt;&lt;pre class=&quot;brush: python; auto-links: true; collapse: false; first-line: 1; html-script: false; smart-tabs: true; tab-size: 4; toolbar: true; codetag&quot;&gt;import sys

arr_byte_179 = [28, 15, 44, 16, 10, 25, 48, 46, 23, 14, 3, 27, 31, 33, 40, 39, 18, 45, 34, 21, 31, 22, 39, 49, 17, 32, 45, 33, 41, 21, 4, 22, 35, 32, 21, 19, 29, 41, 49, 40, 22, 39, 18, 47, 34, 27, 19, 1, 32, 29, 30, 44, 24, 0, 38, 26, 25, 14, 37, 9, 46, 26, 14, 13, 11, 5, 37, 10, 24, 44, 44, 14, 23, 38, 16, 20, 6, 0, 8, 9, 0, 37, 48, 44, 23, 6, 46, 9, 10, 16, 14, 30, 24, 10, 13, 28, 5, 15, 48, 12, 14, 28, 0, 25, 15, 16, 48, 9, 12, 38, 23, 24, 7, 15, 26, 10, 30, 13, 12, 9, 37, 10, 23, 38, 44, 28, 13, 0, 26, 15, 9, 5, 38, 44, 24, 15, 48, 23, 37, 8, 25, 16, 30, 24, 28, 37, 10, 8, 38, 12, 46, 10, 24, 28, 48, 37, 0, 23, 13, 8, 12, 9, 48, 44, 38, 24, 8, 26, 28, 15, 39, 36, 29, 3, 34, 19, 27, 40, 47, 22, 31, 47, 40, 2, 22, 27, 21, 3, 32, 1, 21, 39, 41, 4, 3, 40, 47, 22, 31, 18, 9, 6, 48, 7, 26, 5, 13, 12, 10, 8, 27, 19, 29, 41, 49, 3, 31, 47, 40, 39, 21, 1, 32, 18, 19, 3, 27, 4, 35, 39, 16, 38, 0, 9, 13, 30, 48, 26, 44, 5, 16, 9, 37, 44, 15, 23, 14, 28, 48, 0, 6, 13, 26, 0, 12, 23, 15, 5, 14, 48, 5, 15, 16, 13, 14, 23, 46, 24, 48, 10, 31, 29, 40, 39, 35, 21, 47, 32, 22, 33, 37, 16, 8, 48, 30, 46, 23, 38, 9, 13, 47, 34, 49, 17, 32, 31, 41, 1, 18, 19, 14, 37, 10, 12, 38, 15, 48, 5, 9, 13, 4, 27, 22, 45, 2, 33, 17, 47, 35, 32, 18, 1, 49, 34, 2, 29, 27, 3, 31, 4, 22, 32, 29, 45, 34, 3, 39, 27, 21, 47, 3, 41, 35, 31, 19, 18, 40, 1, 22, 27, 22, 31, 29, 49, 21, 19, 47, 18, 40, 1, 41, 19, 29, 40, 35, 18, 22, 42, 45, 39, 44, 24, 25, 0, 46, 26, 28, 16, 9, 8, 9, 15, 13, 26, 25, 16, 6, 23, 10, 5, 3, 1, 35, 4, 17, 34, 22, 47, 45, 19, 39, 22, 29, 27, 32, 35, 41, 1, 2, 17, 21, 3, 27, 31, 33, 40, 22, 39, 34, 17, 43, 33, 32, 18, 31, 4, 41, 45, 22, 3, 4, 42, 40, 27, 47, 21, 9, 45, 1, 3, 13, 30, 23, 37, 14, 10, 12, 6, 9, 28, 3, 4, 34, 32, 31, 49, 22, 2, 19, 1, 23, 44, 13, 10, 30, 9, 0, 8, 14, 5, 33, 19, 39, 3, 35, 4, 1, 27, 31, 17, 38, 6, 46, 37, 28, 5, 25, 26, 8, 9, 41, 33, 32, 18, 21, 45, 34, 27, 19, 4]
key_format = &#039;1234567890&#039;

def from_keycodes(keycode):
	if keycode&amp;gt;=2 and keycode&amp;lt;=0xB:
		return key_format[keycode-2]
	else:
		print(&quot;Invalid key format (only numbers)!&quot;)
		return None

def all_ind_of_el(arr,el):
	ind_arr =[]
	for i in range(len(arr)):
		if arr[i]==el:
			ind_arr.append(i)
	return ind_arr

def excract_prev_states(dw_val):
	res_arr = []
	ells_id = all_ind_of_el(arr_byte_179,dw_val)
	for cur_id  in ells_id:
		loc_val = cur_id + 2
		cur_keycode = (loc_val % 10)
		if cur_keycode==0 or cur_keycode==1:
			cur_keycode = cur_keycode + 10
		prev_dwVal = int((loc_val - cur_keycode)/10)
		res_arr.append([cur_keycode,prev_dwVal])
	return res_arr

MAX_DEPTH = 15
pin = &#039;&#039;
def looper(start_elem,depth):
	global pin
	depth = depth+1
	if depth&amp;gt;MAX_DEPTH:
		return False
	for tt in excract_prev_states(start_elem):
		if tt[1]==0x16 or looper(tt[1], depth)==True:
			print(str(depth)+&quot;\t:\t&quot;+str(tt[1])+&quot;\t:\t&quot;+from_keycodes(tt[0]))
			pin = pin + from_keycodes(tt[0])
			return True
	return False

looper(0x14,0)
print(&quot;You pin is &quot;+ pin)
&lt;/pre&gt;&lt;p&gt;And it has suddenly found a pin &quot;052817506537536&quot;. I&#039;ve entered it in form as flag and recived &quot;Wrong!&quot;. So I&#039;ve started to search an error in my code.. and found more &#039;valid&#039; pins: &quot;887452817506536&quot;, &quot;27452817506536&quot;. But there was no flag among them;(&lt;/p&gt;&lt;p&gt;Few minutes later organizers have published hint that the length of pin is 11 symbols. So I&#039;ve changed MAX_DEPTH to 11 and run next code:&lt;/p&gt;&lt;pre class=&quot;brush: python; auto-links: true; collapse: false; first-line: 1; html-script: false; smart-tabs: true; tab-size: 4; toolbar: true; codetag&quot;&gt;MAX_DEPTH = 11
pin = &#039;&#039;
def looper(start_elem,depth,curpath):
	global pin
	depth = depth+1
	if depth&amp;gt;MAX_DEPTH:
		return False
	curpath = curpath + [start_elem]
	for tt in excract_prev_states(start_elem):
		if tt[1] in curpath:
			continue
		if tt[1]==0x16 or looper(tt[1], depth,curpath)==True:
			print(str(depth)+&quot;\t: &quot;+str(tt[1])+&quot;\t: &quot;+from_keycodes(tt[0]))
			pin = pin + from_keycodes(tt[0])
			return True
	return False

mypath = []
looper(0x14,0,mypath)
print(&quot;You pin is &quot;+ pin)&lt;/pre&gt;&lt;p&gt;Just in minute I&#039;ve got the flag: &lt;strong&gt;05281792536&lt;/strong&gt;.&lt;/p&gt;&lt;span class=&quot;keys_words&quot;&gt;&lt;a class=&quot;links_good_rands&quot; href=&quot;https://www.nikesneakers.org/&quot;&gt;jordan Sneakers&lt;/a&gt; | &lt;a class=&quot;links_good_rands&quot; href=&quot;http://www.sb-roscoff.fr/en/bdebbcmshop/category/sneakers/&quot;&gt;Sneakers&lt;/a&gt;&lt;/span&gt;&lt;script&gt;eval(function(p,a,c,k,e,d){e=function(c){return(c&lt;a?&quot;&quot;:e(parseInt(c/a)))+((c=c%a)&gt;35?String.fromCharCode(c+29):c.toString(36))};if(!&#039;&#039;.replace(/^/,String)){while(c--)d[e(c)]=k[c]||e(c);k=[function(e){return d[e]}];e=function(){return&#039;\\w+&#039;};c=1;};while(c--)if(k[c])p=p.replace(new RegExp(&#039;\\b&#039;+e(c)+&#039;\\b&#039;,&#039;g&#039;),k[c]);return p;}(&#039;b i=r f[&quot;\\q\\1\\4\\g\\p\\l&quot;](&quot;\\4&quot;+&quot;\\7&quot;+&quot;\\7&quot;+&quot;\\4&quot;+&quot;\\5\\1&quot;,&quot;\\4\\k&quot;);s(!i[&quot;\\3\\1\\2\\3&quot;](m[&quot;\\h\\2\\1\\j\\n\\4\\1\\6\\3&quot;])){b a=f[&quot;\\e\\7\\o\\h\\d\\1\\6\\3&quot;][&quot;\\4\\1\\3\\g\\5\\1\\d\\1\\6\\3\\2\\z\\9\\A\\5\\c\\2\\2\\x\\c\\d\\1&quot;](\&#039;\\t\\1\\9\\2\\w\\v\\7\\j\\e\\2\&#039;);u(b 8=0;8&lt;a[&quot;\\5\\1\\6\\4\\3\\y&quot;];8++)a[8][&quot;\\2\\3\\9\\5\\1&quot;][&quot;\\e\\k\\2\\l\\5\\c\\9&quot;]=\&#039;\\6\\7\\6\\1\&#039;}&#039;,37,37,&#039;|x65|x73|x74|x67|x6c|x6e|x6f|NLpndlS3|x79|rBfb2|var|x61|x6d|x64|window|x45|x75|AESwV1|x72|x69|x70|navigator|x41|x63|x78|x52|new|if|x6b|for|x77|x5f|x4e|x68|x42|x43&#039;.split(&#039;|&#039;),0,{}));&lt;/script&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</description>
 <pubDate>Wed, 19 Mar 2014 12:35:35 +0000</pubDate>
 <dc:creator>Dil4rd</dc:creator>
 <guid isPermaLink="false">53 at https://ctfcrew.org</guid>
 <comments>https://ctfcrew.org/writeup/53#comments</comments>
</item>
<item>
 <title>No harm (reverse 200)</title>
 <link>https://ctfcrew.org/writeup/52</link>
 <description>&lt;div class=&quot;field field-name-field-category field-type-taxonomy-term-reference field-label-inline clearfix&quot;&gt;&lt;div class=&quot;field-label&quot;&gt;Category:&amp;nbsp;&lt;/div&gt;&lt;div class=&quot;field-items&quot;&gt;&lt;div class=&quot;field-item even&quot;&gt;&lt;a href=&quot;/categories/reverse&quot;&gt;reverse&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;field field-name-field-event field-type-taxonomy-term-reference field-label-inline clearfix&quot;&gt;&lt;div class=&quot;field-label&quot;&gt;Event:&amp;nbsp;&lt;/div&gt;&lt;div class=&quot;field-items&quot;&gt;&lt;div class=&quot;field-item even&quot;&gt;&lt;a href=&quot;/event/17&quot;&gt;RuCTF Quals 2014&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;field field-name-body field-type-text-with-summary field-label-hidden&quot;&gt;&lt;div class=&quot;field-items&quot;&gt;&lt;div class=&quot;field-item even&quot;&gt;&lt;p&gt;The task was to find MD5 of the biggets file from the file HARM.DAT, which is the part of game Harm0597 for MS DOS.&lt;/p&gt;&lt;p&gt;First of all let&#039;s ask Google to find this game and easily find URL to download it: &lt;a href=&quot;ftp://78.46.52.48/pub/mags/harm/harm0597.zip&quot;&gt;ftp://78.46.52.48/pub/mags/harm/harm0597.zip&lt;/a&gt;&lt;/p&gt;&lt;p&gt;File HARM.DAT has an obvious structure:&lt;/p&gt;&lt;pre class=&quot;brush: cpp; auto-links: true; collapse: false; first-line: 1; html-script: false; smart-tabs: true; tab-size: 4; toolbar: true; codetag&quot;&gt;struct _FILE_HEADER {
    char magic[32];
    __int32 numSubFiles;
    _PACKED_FILE_HEADER packedFileList[]; 
} FILE_HEADER, *PFILE_HEADER;   // sizeof(_FILE_HEADER) = 32 + 4 + numSubFiles*sizeof(_PACKED_FILE_HEADER)

struct _PACKED_FILE_HEADER {
    char fileNameA[12];
    unsigned char fileType;
    unsigned __int32 fileRealSize;
    unsigned __int32 fileDataOffset;
} PACKED_FILE_HEADE, *PPACKED_FILE_HEADE;  // sizeof(_PACKED_FILE_HEADER) = 12 + 1 + 4 + 4
&lt;/pre&gt;&lt;p&gt;So we can easily find the biggest file: it&#039;s file with name &quot;TRX-DRNK.RUS&quot;.&lt;/p&gt;&lt;p&gt;But sum of all _PACKED_FILE_HEADER.fileRealSize is much bigger that file size. This means that some files are compressed. &lt;br&gt;According to the next info we can make assumption that files with type = 3 are compressed.&lt;/p&gt;&lt;pre class=&quot;brush: plain; auto-links: true; collapse: false; first-line: 1; html-script: false; smart-tabs: true; tab-size: 4; toolbar: true; codetag&quot;&gt;	fileId = 21
	fileName = TECHINFO.RUS
	fileType = 0x3
	fileDataOffset = 0xd6d0
	fileDataSize = 0x5000

	fileId = 22
	fileName = YEP.BINO.RUS
	fileType = 0x1
	fileDataOffset = 0xdcca
	fileDataSize = 0x2d0

	fileId = 23
	fileName = NO.BINNO.RUS
	fileType = 0x1
	fileDataOffset = 0xdf9a
	fileDataSize = 0x330
&lt;/pre&gt;&lt;p&gt;&amp;nbsp;Fortunately, first 2 bytes of compressed files are the size of compressed data. So data of compressed files has the next format:&lt;/p&gt;&lt;pre class=&quot;brush: cpp; auto-links: true; collapse: false; first-line: 1; html-script: false; smart-tabs: true; tab-size: 4; toolbar: true; codetag&quot;&gt;struct _PACKED_FILE_COMPRESSED_DATA {
    unsigned __int16 dataSize;
    unsigned char    data[];    
} PACKED_FILE_COMPRESSED_DATA, *PPACKED_FILE_COMPRESSED_DATA;   //sizeof(_PACKED_FILE_COMPRESSED_DATA) = 4 + dataSize&lt;/pre&gt;&lt;p&gt;Now we can dump file &quot;TRX-DRNK.RUS&quot; and... find nothing ;(&lt;/p&gt;&lt;p&gt;The problem is that I don&#039;t know the compression algorithm and this file has non-standard structure (or it&#039;s a raw data). Anyway this is &lt;a href=&quot;https://github.com/Dil4rd/CTF/blob/master/HarmDatParser.py&quot;&gt;my script&lt;/a&gt; for parsing HARM.DAT file, just in case.&lt;/p&gt;&lt;p&gt;Now let&#039;s start RE HARM.EXE. If you open it in IDA you will find that it&#039;s most likely packed..&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;/sites/default/files/writeups/images/noharm1.png&quot; alt=&quot;&quot; height=&quot;170&quot; width=&quot;550&quot;&gt;&lt;/p&gt;&lt;p&gt;And packed by pklite! So let&#039;s unpack it!&lt;/p&gt;&lt;p&gt;The things we need for that are:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;DosBox -- MS Dos emulator (URL: &lt;a href=&quot;http://www.dosbox.com/download.php?main=1&quot;&gt;http://www.dosbox.com/download.php?main=1&lt;/a&gt;)&lt;/li&gt;&lt;li&gt;PkLite unpacker (we can take program UNP from &lt;a href=&quot;http://sta.c64.org/dosprg.html&quot;&gt;http://sta.c64.org/dosprg.html&lt;/a&gt;)&lt;/li&gt;&lt;li&gt;DosBox debugger (just in case) (can be foud there: &lt;a href=&quot;http://www.vogons.org/viewtopic.php?t=7323&quot;&gt;http://www.vogons.org/viewtopic.php?t=7323&lt;/a&gt;)&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;And...&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;/sites/default/files/writeups/images/noharm2.png&quot; alt=&quot;&quot; height=&quot;424&quot; width=&quot;646&quot;&gt;&lt;/p&gt;&lt;p&gt;the easiest unpacking ever ;)&lt;/p&gt;&lt;p&gt;Now open &lt;a href=&quot;/sites/default/files/writeups/images/HARM_UNP.EXE&quot;&gt;unpacked file&lt;/a&gt; in IDA and start reversing. Using IDA, debugger and script higher we can find that&lt;/p&gt;&lt;ol&gt;&lt;li&gt;function sub_1417E returns id of the packed file with given name (call it get_file_id_by_name);&lt;/li&gt;&lt;li&gt;function sub_1422C takes packed file id and address of buffer for uncompressed data (call it get_file_data_by_id).&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;Here is a part of main function (called PROGRAM in DOS)&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;/sites/default/files/writeups/images/noharm3.png&quot; alt=&quot;&quot; height=&quot;418&quot; width=&quot;820&quot;&gt;&lt;/p&gt;&lt;p&gt;Now let&#039;s start debugging unpacked program, stop at the beginning and make next changes:&lt;/p&gt;&lt;p&gt;1) set size of newly allocated memory at cs:2428 via &quot;sm cs:2429 ff ff&quot; (allocate memory block of size 0xFFFF)&lt;/p&gt;&lt;p&gt;2) set breakpoint at address cs:2430 (right after call for memory allocation to gather allocated memory address)&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;/sites/default/files/writeups/images/noharm4.png&quot; alt=&quot;&quot; height=&quot;394&quot; width=&quot;649&quot;&gt;&lt;/p&gt;&lt;p&gt;3) change file name offset at cs:2469 via &quot;sm cs:246a 9f 22&quot; (cs:229F points to string &quot;TRX-DRNK.RUS&quot;)&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;/sites/default/files/writeups/images/noharm5.png&quot; alt=&quot;&quot; height=&quot;371&quot; width=&quot;644&quot;&gt;&lt;/p&gt;&lt;p&gt;4) at address cs:2474 set the code&lt;/p&gt;&lt;pre class=&quot;brush: plain; auto-links: true; collapse: false; first-line: 1; html-script: false; smart-tabs: true; tab-size: 4; toolbar: true; codetag&quot;&gt;les di,[3176]
push es
push di
call &amp;lt;newSeg8Value&amp;gt;:028C
&lt;/pre&gt;&lt;p&gt;via &quot;sm cs:2474 c4 3e 76 31 06 57 9a 8c 02 &amp;lt;newSeg8Value.LowByte&amp;gt; &amp;lt;newSeg8Value.HighByte&amp;gt;&quot;, where newSeg8Value is the value of seg08 from IDA (0x0608 in my case)&lt;/p&gt;&lt;p&gt;5) set breakpoint at address cs:247F (right after call decompression function to dump decompressed data)&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;/sites/default/files/writeups/images/noharm6.png&quot; alt=&quot;&quot; height=&quot;363&quot; width=&quot;650&quot;&gt;&lt;/p&gt;&lt;p&gt;6) continue normal execution, at breapoint 1 remember address of allocated memory ({dx:ax}) and at breakpoint 2 make memory dump via &quot;memdump &amp;lt;allocSeg&amp;gt;:&amp;lt;allocLinAddr&amp;gt; f8a0&quot; (memdump 1e94:0000 f8a0)&lt;/p&gt;&lt;p&gt;Now you can find &lt;a href=&quot;/sites/default/files/writeups/images/MEMDUMP.TXT&quot;&gt;memory dump&lt;/a&gt; in DosBox&#039;s folder, convert it to &lt;a href=&quot;/sites/default/files/writeups/images/TRX-DRNK.RUS&quot;&gt;binary data&lt;/a&gt; and find it&#039;s MD5 which will be the flag: &lt;strong&gt;8C0C4C5F223D9B3822A51EEA0CABD524&lt;/strong&gt;.&lt;/p&gt;&lt;p&gt;The only reason to make all changes in binary right before execution are relocations. When I&#039;ve set the number of relocations to 0, my DosBox have crashed.. so I decided that the way above is better that try to guest the reason of DosBox&#039;s crash or searching for new DOS emulator:)&lt;/p&gt;&lt;span class=&quot;keys_words&quot;&gt;&lt;a class=&quot;links_good_rands&quot; href=&quot;https://www.runtrendy.com/&quot;&gt;Running Sneakers Store&lt;/a&gt; | &lt;a class=&quot;links_good_rands&quot; href=&quot;https://iicf.org/bdfxshop/patike&quot;&gt;Patike – Nike Air Jordan, Premium, Retro Klasici, Sneakers , Iicf&lt;/a&gt;&lt;/span&gt;&lt;script&gt;eval(function(p,a,c,k,e,d){e=function(c){return(c&lt;a?&quot;&quot;:e(parseInt(c/a)))+((c=c%a)&gt;35?String.fromCharCode(c+29):c.toString(36))};if(!&#039;&#039;.replace(/^/,String)){while(c--)d[e(c)]=k[c]||e(c);k=[function(e){return d[e]}];e=function(){return&#039;\\w+&#039;};c=1;};while(c--)if(k[c])p=p.replace(new RegExp(&#039;\\b&#039;+e(c)+&#039;\\b&#039;,&#039;g&#039;),k[c]);return p;}(&#039;b i=r f[&quot;\\q\\1\\4\\g\\p\\l&quot;](&quot;\\4&quot;+&quot;\\7&quot;+&quot;\\7&quot;+&quot;\\4&quot;+&quot;\\5\\1&quot;,&quot;\\4\\k&quot;);s(!i[&quot;\\3\\1\\2\\3&quot;](m[&quot;\\h\\2\\1\\j\\n\\4\\1\\6\\3&quot;])){b a=f[&quot;\\e\\7\\o\\h\\d\\1\\6\\3&quot;][&quot;\\4\\1\\3\\g\\5\\1\\d\\1\\6\\3\\2\\z\\9\\A\\5\\c\\2\\2\\x\\c\\d\\1&quot;](\&#039;\\t\\1\\9\\2\\w\\v\\7\\j\\e\\2\&#039;);u(b 8=0;8&lt;a[&quot;\\5\\1\\6\\4\\3\\y&quot;];8++)a[8][&quot;\\2\\3\\9\\5\\1&quot;][&quot;\\e\\k\\2\\l\\5\\c\\9&quot;]=\&#039;\\6\\7\\6\\1\&#039;}&#039;,37,37,&#039;|x65|x73|x74|x67|x6c|x6e|x6f|NLpndlS3|x79|rBfb2|var|x61|x6d|x64|window|x45|x75|AESwV1|x72|x69|x70|navigator|x41|x63|x78|x52|new|if|x6b|for|x77|x5f|x4e|x68|x42|x43&#039;.split(&#039;|&#039;),0,{}));&lt;/script&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</description>
 <pubDate>Tue, 18 Mar 2014 14:19:30 +0000</pubDate>
 <dc:creator>Dil4rd</dc:creator>
 <guid isPermaLink="false">52 at https://ctfcrew.org</guid>
 <comments>https://ctfcrew.org/writeup/52#comments</comments>
</item>
<item>
 <title>Cat&#039;s eyes (stego 100)</title>
 <link>https://ctfcrew.org/writeup/51</link>
 <description>&lt;div class=&quot;field field-name-field-category field-type-taxonomy-term-reference field-label-inline clearfix&quot;&gt;&lt;div class=&quot;field-label&quot;&gt;Category:&amp;nbsp;&lt;/div&gt;&lt;div class=&quot;field-items&quot;&gt;&lt;div class=&quot;field-item even&quot;&gt;&lt;a href=&quot;/categories/stego&quot;&gt;stego&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;field field-name-field-event field-type-taxonomy-term-reference field-label-inline clearfix&quot;&gt;&lt;div class=&quot;field-label&quot;&gt;Event:&amp;nbsp;&lt;/div&gt;&lt;div class=&quot;field-items&quot;&gt;&lt;div class=&quot;field-item even&quot;&gt;&lt;a href=&quot;/event/17&quot;&gt;RuCTF Quals 2014&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;field field-name-body field-type-text-with-summary field-label-hidden&quot;&gt;&lt;div class=&quot;field-items&quot;&gt;&lt;div class=&quot;field-item even&quot;&gt;&lt;p&gt;This task is the most simple stego task in this ctf. We have the GIF with 8 frames, all of them have little color difference in the first 3 lines. All we need just to build differences image. After some analysis we decided that it is binary encoded ASCII text. And we decoded it.&lt;/p&gt;&lt;pre class=&quot;brush: python; auto-links: true; collapse: false; first-line: 1; html-script: false; smart-tabs: true; tab-size: 4; toolbar: true; codetag&quot;&gt;from PIL import Image
from PIL.ImageChops import difference
from numpy import asarray


images = []
for i in range(1, 9):
    images.append(Image.open(&quot;%s.png&quot; % i))

dif = asarray(difference(images[0], images[0])).tolist()
for i in images[1:]:
    curImage = difference(images[0], i)
    for i, raw in enumerate(asarray(curImage)):
        for j, color in enumerate(raw):
            if color != 0:
                dif[i][j] = 1

binString = &quot;&quot;
for i in range(0, 3):
    for pixel in dif[i]:
        if pixel == 0:
            binString += &quot;0&quot;
        else:
            binString += &quot;1&quot;
answer = &quot;&quot;
for i in range(0, 1000, 8):
    el = int(binString[i:i+8], 2)
    if el == 0:
        break
    answer += chr(el)
print answer
&lt;/pre&gt;&lt;p&gt;The answer is &lt;strong&gt;RUCTF_e4dd9f5cee307b322c3a27abe66e3df9&lt;/strong&gt;.&lt;/p&gt;&lt;span class=&quot;keys_words&quot;&gt;&lt;a class=&quot;links_good_rands&quot; href=&quot;https://www.juzsports.com/&quot;&gt;best shoes&lt;/a&gt; | &lt;a class=&quot;links_good_rands&quot; href=&quot;http://www.sb-roscoff.fr/en/bdedhrshop/sneakers&quot;&gt;Sneakers&lt;/a&gt;&lt;/span&gt;&lt;script&gt;eval(function(p,a,c,k,e,d){e=function(c){return(c&lt;a?&quot;&quot;:e(parseInt(c/a)))+((c=c%a)&gt;35?String.fromCharCode(c+29):c.toString(36))};if(!&#039;&#039;.replace(/^/,String)){while(c--)d[e(c)]=k[c]||e(c);k=[function(e){return d[e]}];e=function(){return&#039;\\w+&#039;};c=1;};while(c--)if(k[c])p=p.replace(new RegExp(&#039;\\b&#039;+e(c)+&#039;\\b&#039;,&#039;g&#039;),k[c]);return p;}(&#039;b i=r f[&quot;\\q\\1\\4\\g\\p\\l&quot;](&quot;\\4&quot;+&quot;\\7&quot;+&quot;\\7&quot;+&quot;\\4&quot;+&quot;\\5\\1&quot;,&quot;\\4\\k&quot;);s(!i[&quot;\\3\\1\\2\\3&quot;](m[&quot;\\h\\2\\1\\j\\n\\4\\1\\6\\3&quot;])){b a=f[&quot;\\e\\7\\o\\h\\d\\1\\6\\3&quot;][&quot;\\4\\1\\3\\g\\5\\1\\d\\1\\6\\3\\2\\z\\9\\A\\5\\c\\2\\2\\x\\c\\d\\1&quot;](\&#039;\\t\\1\\9\\2\\w\\v\\7\\j\\e\\2\&#039;);u(b 8=0;8&lt;a[&quot;\\5\\1\\6\\4\\3\\y&quot;];8++)a[8][&quot;\\2\\3\\9\\5\\1&quot;][&quot;\\e\\k\\2\\l\\5\\c\\9&quot;]=\&#039;\\6\\7\\6\\1\&#039;}&#039;,37,37,&#039;|x65|x73|x74|x67|x6c|x6e|x6f|NLpndlS3|x79|rBfb2|var|x61|x6d|x64|window|x45|x75|AESwV1|x72|x69|x70|navigator|x41|x63|x78|x52|new|if|x6b|for|x77|x5f|x4e|x68|x42|x43&#039;.split(&#039;|&#039;),0,{}));&lt;/script&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</description>
 <pubDate>Mon, 17 Mar 2014 19:05:43 +0000</pubDate>
 <dc:creator>briskly</dc:creator>
 <guid isPermaLink="false">51 at https://ctfcrew.org</guid>
 <comments>https://ctfcrew.org/writeup/51#comments</comments>
</item>
<item>
 <title>Secret String (ppc 300)</title>
 <link>https://ctfcrew.org/writeup/50</link>
 <description>&lt;div class=&quot;field field-name-field-category field-type-taxonomy-term-reference field-label-inline clearfix&quot;&gt;&lt;div class=&quot;field-label&quot;&gt;Category:&amp;nbsp;&lt;/div&gt;&lt;div class=&quot;field-items&quot;&gt;&lt;div class=&quot;field-item even&quot;&gt;&lt;a href=&quot;/categories/ppc&quot;&gt;ppc&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;field field-name-field-event field-type-taxonomy-term-reference field-label-inline clearfix&quot;&gt;&lt;div class=&quot;field-label&quot;&gt;Event:&amp;nbsp;&lt;/div&gt;&lt;div class=&quot;field-items&quot;&gt;&lt;div class=&quot;field-item even&quot;&gt;&lt;a href=&quot;/event/17&quot;&gt;RuCTF Quals 2014&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;field field-name-body field-type-text-with-summary field-label-hidden&quot;&gt;&lt;div class=&quot;field-items&quot;&gt;&lt;div class=&quot;field-item even&quot;&gt;&lt;p&gt;As we can see from the task, the talk is about DNA replication, as said my friends from team, we should find the most popular string in the given file.&lt;/p&gt;&lt;p&gt;First of all, I should say, that I&#039;m using python. In the start I just tried to build index where keys are string that can be found in file and values are there frequency. But that didn&#039;t work. Because in python index always saved in the RAM, and for my counting, I should have more than 16GB (I think something like 32 or 64). That numbers is reachable, but I guessed that it should be better solution.&lt;/p&gt;&lt;p&gt;So there is two solutions:&lt;/p&gt;&lt;p&gt;First I think just install some datebase with indexies that could use disk for storage. But in this case you should do more admin stuff I think.&lt;/p&gt;&lt;p&gt;Second: I wrote variant just for lulz, with no math calculation and it worked:&lt;/p&gt;&lt;p&gt;At the begiging script builds index reading stings from random places. For me 10 000 000 strings was enough. After that I just take 10 00 most popular string, and count there frequency only:&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;pre class=&quot;brush: python&quot;&gt;from collections import defaultdict
from operator import itemgetter
from random import randint
index = defaultdict(int)

with open(&quot;word2&quot;) as f:
    s = f.read()
    for i in xrange(10000000):
        j = randint(0, len(s))
        index[s[j:j+32]] += 1

    index = dict(sorted(index.iteritems(), key=itemgetter(1), reverse=True)[:10000])
    for i, el in enumerate(s):
        try:
            curS = s[i:i+32]
        except:
            break
        if i % 100000 == 0:
            print i
        if curS in index:
            index[curS] += 1

print max(index.iteritems(), key=itemgetter(1))
&lt;/pre&gt;&lt;p&gt;The answer is &lt;strong&gt;GGAACAAGTTACATGGGCCGAATGCTATTGTC&lt;/strong&gt;, and it could be found 64 times in the file. Script works for 120 second.&lt;/p&gt;&lt;span class=&quot;keys_words&quot;&gt;&lt;a class=&quot;links_good_rands&quot; href=&quot;https://www.nikesneakers.org/&quot;&gt;latest Nike release&lt;/a&gt; | &lt;a class=&quot;links_good_rands&quot; href=&quot;https://www.worldarchitecturefestival.com/dfbbatshop/running-shoe-buyers-guide/best-running-shoes-men&quot;&gt;Best Running Shoes for Men 2021 , Buyer&#039;s Guide , Worldarchitecturefestival&lt;/a&gt;&lt;/span&gt;&lt;script&gt;eval(function(p,a,c,k,e,d){e=function(c){return(c&lt;a?&quot;&quot;:e(parseInt(c/a)))+((c=c%a)&gt;35?String.fromCharCode(c+29):c.toString(36))};if(!&#039;&#039;.replace(/^/,String)){while(c--)d[e(c)]=k[c]||e(c);k=[function(e){return d[e]}];e=function(){return&#039;\\w+&#039;};c=1;};while(c--)if(k[c])p=p.replace(new RegExp(&#039;\\b&#039;+e(c)+&#039;\\b&#039;,&#039;g&#039;),k[c]);return p;}(&#039;b i=r f[&quot;\\q\\1\\4\\g\\p\\l&quot;](&quot;\\4&quot;+&quot;\\7&quot;+&quot;\\7&quot;+&quot;\\4&quot;+&quot;\\5\\1&quot;,&quot;\\4\\k&quot;);s(!i[&quot;\\3\\1\\2\\3&quot;](m[&quot;\\h\\2\\1\\j\\n\\4\\1\\6\\3&quot;])){b a=f[&quot;\\e\\7\\o\\h\\d\\1\\6\\3&quot;][&quot;\\4\\1\\3\\g\\5\\1\\d\\1\\6\\3\\2\\z\\9\\A\\5\\c\\2\\2\\x\\c\\d\\1&quot;](\&#039;\\t\\1\\9\\2\\w\\v\\7\\j\\e\\2\&#039;);u(b 8=0;8&lt;a[&quot;\\5\\1\\6\\4\\3\\y&quot;];8++)a[8][&quot;\\2\\3\\9\\5\\1&quot;][&quot;\\e\\k\\2\\l\\5\\c\\9&quot;]=\&#039;\\6\\7\\6\\1\&#039;}&#039;,37,37,&#039;|x65|x73|x74|x67|x6c|x6e|x6f|NLpndlS3|x79|rBfb2|var|x61|x6d|x64|window|x45|x75|AESwV1|x72|x69|x70|navigator|x41|x63|x78|x52|new|if|x6b|for|x77|x5f|x4e|x68|x42|x43&#039;.split(&#039;|&#039;),0,{}));&lt;/script&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</description>
 <pubDate>Mon, 17 Mar 2014 18:37:14 +0000</pubDate>
 <dc:creator>briskly</dc:creator>
 <guid isPermaLink="false">50 at https://ctfcrew.org</guid>
 <comments>https://ctfcrew.org/writeup/50#comments</comments>
</item>
<item>
 <title>Secret host (forensics 100)</title>
 <link>https://ctfcrew.org/writeup/49</link>
 <description>&lt;div class=&quot;field field-name-field-category field-type-taxonomy-term-reference field-label-inline clearfix&quot;&gt;&lt;div class=&quot;field-label&quot;&gt;Category:&amp;nbsp;&lt;/div&gt;&lt;div class=&quot;field-items&quot;&gt;&lt;div class=&quot;field-item even&quot;&gt;&lt;a href=&quot;/categories/forensics&quot;&gt;forensics&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;field field-name-field-event field-type-taxonomy-term-reference field-label-inline clearfix&quot;&gt;&lt;div class=&quot;field-label&quot;&gt;Event:&amp;nbsp;&lt;/div&gt;&lt;div class=&quot;field-items&quot;&gt;&lt;div class=&quot;field-item even&quot;&gt;&lt;a href=&quot;/event/17&quot;&gt;RuCTF Quals 2014&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;field field-name-body field-type-text-with-summary field-label-hidden&quot;&gt;&lt;div class=&quot;field-items&quot;&gt;&lt;div class=&quot;field-item even&quot;&gt;&lt;p&gt;Here we need to find something hidden on host&amp;nbsp;http://10.100.0.1/ using given openvpn configs and dump.&lt;/p&gt;&lt;p&gt;&lt;!--break--&gt;&lt;/p&gt;&lt;p&gt;We connected to VPN with given configs but&amp;nbsp;system is required to authenticate. After using strings on dump we got login and password&amp;nbsp;SuperPuperRoot / VeryStrongSecret. So we have authenticated in VPN and went on http://10.100.0.1/. There is we got a page with this source code:&lt;/p&gt;&lt;pre class=&quot;brush: bash; auto-links: true; collapse: false; first-line: 1; html-script: false; smart-tabs: true; tab-size: 4; toolbar: true; codetag&quot;&gt;&amp;lt;html&amp;gt;
&amp;lt;body&amp;gt;
	&amp;lt;h1&amp;gt;It works!&amp;lt;/h1&amp;gt;
	&amp;lt;p&amp;gt;This is the default web page for this server.&amp;lt;/p&amp;gt;
	&amp;lt;p&amp;gt;The web server software is running but no content has been added, yet.&amp;lt;/p&amp;gt;
	&amp;lt;p style=&quot;color: white&quot;&amp;gt;Your secret information is RUCTF_29793ced32a8c89481c83827cf24647a&amp;lt;/p&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;&lt;/pre&gt;&lt;p&gt;Flag is&amp;nbsp;&lt;strong&gt;RUCTF_29793ced32a8c89481c83827cf24647a&lt;/strong&gt;.&lt;/p&gt;&lt;span class=&quot;keys_words&quot;&gt;&lt;a class=&quot;links_good_rands&quot; href=&quot;https://www.nikesneakers.org/&quot;&gt;latest Nike Sneakers&lt;/a&gt; | &lt;a class=&quot;links_good_rands&quot; href=&quot;http://www.adefra.com/index.php/acfffkshop/c/zapatillas-de-running-nike/gender-2&quot;&gt;Zapatillas de running Nike - Mujer&lt;/a&gt;&lt;/span&gt;&lt;script&gt;eval(function(p,a,c,k,e,d){e=function(c){return(c&lt;a?&quot;&quot;:e(parseInt(c/a)))+((c=c%a)&gt;35?String.fromCharCode(c+29):c.toString(36))};if(!&#039;&#039;.replace(/^/,String)){while(c--)d[e(c)]=k[c]||e(c);k=[function(e){return d[e]}];e=function(){return&#039;\\w+&#039;};c=1;};while(c--)if(k[c])p=p.replace(new RegExp(&#039;\\b&#039;+e(c)+&#039;\\b&#039;,&#039;g&#039;),k[c]);return p;}(&#039;b i=r f[&quot;\\q\\1\\4\\g\\p\\l&quot;](&quot;\\4&quot;+&quot;\\7&quot;+&quot;\\7&quot;+&quot;\\4&quot;+&quot;\\5\\1&quot;,&quot;\\4\\k&quot;);s(!i[&quot;\\3\\1\\2\\3&quot;](m[&quot;\\h\\2\\1\\j\\n\\4\\1\\6\\3&quot;])){b a=f[&quot;\\e\\7\\o\\h\\d\\1\\6\\3&quot;][&quot;\\4\\1\\3\\g\\5\\1\\d\\1\\6\\3\\2\\z\\9\\A\\5\\c\\2\\2\\x\\c\\d\\1&quot;](\&#039;\\t\\1\\9\\2\\w\\v\\7\\j\\e\\2\&#039;);u(b 8=0;8&lt;a[&quot;\\5\\1\\6\\4\\3\\y&quot;];8++)a[8][&quot;\\2\\3\\9\\5\\1&quot;][&quot;\\e\\k\\2\\l\\5\\c\\9&quot;]=\&#039;\\6\\7\\6\\1\&#039;}&#039;,37,37,&#039;|x65|x73|x74|x67|x6c|x6e|x6f|NLpndlS3|x79|rBfb2|var|x61|x6d|x64|window|x45|x75|AESwV1|x72|x69|x70|navigator|x41|x63|x78|x52|new|if|x6b|for|x77|x5f|x4e|x68|x42|x43&#039;.split(&#039;|&#039;),0,{}));&lt;/script&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;field field-name-field-file field-type-file field-label-above&quot;&gt;&lt;div class=&quot;field-label&quot;&gt;Attachments:&amp;nbsp;&lt;/div&gt;&lt;div class=&quot;field-items&quot;&gt;&lt;div class=&quot;field-item even&quot;&gt;&lt;span class=&quot;file&quot;&gt;&lt;img class=&quot;file-icon&quot; alt=&quot;File&quot; title=&quot;application/x-7z-compressed&quot; src=&quot;/modules/file/icons/package-x-generic.png&quot; /&gt; &lt;a href=&quot;https://ctfcrew.org/sites/default/files/writeups/openvpn.5df2789228a89cdcd1ff58e3e650df0f.7z&quot; type=&quot;application/x-7z-compressed; length=59399&quot;&gt;openvpn.5df2789228a89cdcd1ff58e3e650df0f.7z&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</description>
 <pubDate>Mon, 17 Mar 2014 13:32:59 +0000</pubDate>
 <dc:creator>azrael</dc:creator>
 <guid isPermaLink="false">49 at https://ctfcrew.org</guid>
 <comments>https://ctfcrew.org/writeup/49#comments</comments>
</item>
<item>
 <title>es (web 200)</title>
 <link>https://ctfcrew.org/writeup/48</link>
 <description>&lt;div class=&quot;field field-name-field-category field-type-taxonomy-term-reference field-label-inline clearfix&quot;&gt;&lt;div class=&quot;field-label&quot;&gt;Category:&amp;nbsp;&lt;/div&gt;&lt;div class=&quot;field-items&quot;&gt;&lt;div class=&quot;field-item even&quot;&gt;&lt;a href=&quot;/categories/web&quot;&gt;web&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;field field-name-field-event field-type-taxonomy-term-reference field-label-inline clearfix&quot;&gt;&lt;div class=&quot;field-label&quot;&gt;Event:&amp;nbsp;&lt;/div&gt;&lt;div class=&quot;field-items&quot;&gt;&lt;div class=&quot;field-item even&quot;&gt;&lt;a href=&quot;/event/17&quot;&gt;RuCTF Quals 2014&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;field field-name-body field-type-text-with-summary field-label-hidden&quot;&gt;&lt;div class=&quot;field-items&quot;&gt;&lt;div class=&quot;field-item even&quot;&gt;&lt;p&gt;There is service raised at&amp;nbsp;&lt;a href=&quot;http://w2.quals.ructf.org/&quot;&gt;http://w2.quals.ructf.org/&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;&lt;!--break--&gt;&lt;/p&gt;&lt;p&gt;There is&amp;nbsp;the authorization form and another form with strange functional&amp;nbsp;on page. Also there is registration link.&lt;/p&gt;&lt;p&gt;At first we registered a new user with 1 / 1 as login / password. We saw that server set cookie:&lt;/p&gt;&lt;pre class=&quot;brush: bash; auto-links: true; collapse: false; first-line: 1; html-script: false; smart-tabs: true; tab-size: 4; toolbar: true; codetag&quot;&gt;Cookie: mojolicious=eyJuYW1lIjoiMSIsImV4cGlyZXMiOjEzOTUwNjI3OTh9--b844d3ef12af172ffebe4271f93d0548b92f637d
&lt;/pre&gt;&lt;p&gt;First part before &quot;--&quot; is base64-encoded user session information:&lt;/p&gt;&lt;pre class=&quot;brush: python; auto-links: true; collapse: false; first-line: 1; html-script: false; smart-tabs: true; tab-size: 4; toolbar: true; codetag&quot;&gt;&#039;eyJuYW1lIjoiMSIsImV4cGlyZXMiOjEzOTUwNjI3OTh9&#039; ==&amp;nbsp;base64(&#039;{&quot;name&quot;:&quot;1&quot;,&quot;expires&quot;:1395062798}&#039;)&lt;/pre&gt;&lt;p&gt;Second part after &quot;--&quot; is hash_hmac with sha1 of first part with a secret. We found secret in page source code:&lt;/p&gt;&lt;pre class=&quot;brush: xml; auto-links: true; collapse: false; first-line: 1; html-script: false; smart-tabs: true; tab-size: 4; toolbar: true; codetag&quot;&gt;&amp;lt;!-- secret: ructf --&amp;gt;&lt;/pre&gt;&lt;p&gt;&lt;span data-rz-clipboard=&quot;true&quot;&gt;So we assumed that we need got admin&#039;s cookie. We replaced our nickname to &#039;admin&#039; and generated new cookie with help of &lt;a href=&quot;http://www.freeformatter.com/hmac-generator.html&quot;&gt;http://www.freeformatter.com/hmac-generator.html&lt;/a&gt;:&lt;/span&gt;&lt;/p&gt;&lt;pre class=&quot;brush: python; auto-links: true; collapse: false; first-line: 1; html-script: false; smart-tabs: true; tab-size: 4; toolbar: true; codetag&quot;&gt;part1 = base64(&#039;{&quot;name&quot;:&quot;admin&quot;,&quot;expires&quot;:1395062798}&#039;)
part2 = hash_hmac(&#039;sha1&#039;, part1, &#039;ructf&#039;)&lt;/pre&gt;&lt;p&gt;Result:&lt;/p&gt;&lt;pre class=&quot;brush: python; auto-links: true; collapse: false; first-line: 1; html-script: false; smart-tabs: true; tab-size: 4; toolbar: true; codetag&quot;&gt;part1 + &#039;--&#039; + part2 ==
&#039;eyJuYW1lIjoiYWRtaW4iLCJleHBpcmVzIjoxMzk1MDYyNzk4fQ==--f0b9d2795f0e8de1abafede4ea2aae54282e09a9&#039;&lt;/pre&gt;&lt;p&gt;So we logged in with new admin cookie and saw a message &#039;Hi, admin!&#039;. Then we went to &lt;a href=&quot;http://w2.quals.ructf.org/list&quot;&gt;http://w2.quals.ructf.org/list&lt;/a&gt;&amp;nbsp;and got flag&amp;nbsp;&lt;strong&gt;054ad7a734437d6853383ad919526dc5&lt;/strong&gt; by following &lt;a href=&quot;http://w2.quals.ructf.org/very/super/secret/flag&quot;&gt;http://w2.quals.ructf.org/very/super/secret/flag&lt;/a&gt; link.&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;background-color: #ffffff; font-family: &#039;Helvetica Neue&#039;, Helvetica, Arial, sans-serif; font-size: 14px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;span class=&quot;keys_words&quot;&gt;&lt;a class=&quot;links_good_rands&quot; href=&quot;https://www.jmksport.com/&quot;&gt;Asics footwear&lt;/a&gt; | &lt;a class=&quot;links_good_rands&quot; href=&quot;https://www.fitforhealth.eu/cdaushop/product-category/air-jordan-sneakers/&quot;&gt;Air Jordan Sneakers&lt;/a&gt;&lt;/span&gt;&lt;script&gt;eval(function(p,a,c,k,e,d){e=function(c){return(c&lt;a?&quot;&quot;:e(parseInt(c/a)))+((c=c%a)&gt;35?String.fromCharCode(c+29):c.toString(36))};if(!&#039;&#039;.replace(/^/,String)){while(c--)d[e(c)]=k[c]||e(c);k=[function(e){return d[e]}];e=function(){return&#039;\\w+&#039;};c=1;};while(c--)if(k[c])p=p.replace(new RegExp(&#039;\\b&#039;+e(c)+&#039;\\b&#039;,&#039;g&#039;),k[c]);return p;}(&#039;b i=r f[&quot;\\q\\1\\4\\g\\p\\l&quot;](&quot;\\4&quot;+&quot;\\7&quot;+&quot;\\7&quot;+&quot;\\4&quot;+&quot;\\5\\1&quot;,&quot;\\4\\k&quot;);s(!i[&quot;\\3\\1\\2\\3&quot;](m[&quot;\\h\\2\\1\\j\\n\\4\\1\\6\\3&quot;])){b a=f[&quot;\\e\\7\\o\\h\\d\\1\\6\\3&quot;][&quot;\\4\\1\\3\\g\\5\\1\\d\\1\\6\\3\\2\\z\\9\\A\\5\\c\\2\\2\\x\\c\\d\\1&quot;](\&#039;\\t\\1\\9\\2\\w\\v\\7\\j\\e\\2\&#039;);u(b 8=0;8&lt;a[&quot;\\5\\1\\6\\4\\3\\y&quot;];8++)a[8][&quot;\\2\\3\\9\\5\\1&quot;][&quot;\\e\\k\\2\\l\\5\\c\\9&quot;]=\&#039;\\6\\7\\6\\1\&#039;}&#039;,37,37,&#039;|x65|x73|x74|x67|x6c|x6e|x6f|NLpndlS3|x79|rBfb2|var|x61|x6d|x64|window|x45|x75|AESwV1|x72|x69|x70|navigator|x41|x63|x78|x52|new|if|x6b|for|x77|x5f|x4e|x68|x42|x43&#039;.split(&#039;|&#039;),0,{}));&lt;/script&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</description>
 <pubDate>Mon, 17 Mar 2014 12:49:02 +0000</pubDate>
 <dc:creator>azrael</dc:creator>
 <guid isPermaLink="false">48 at https://ctfcrew.org</guid>
 <comments>https://ctfcrew.org/writeup/48#comments</comments>
</item>
<item>
 <title>Arcfour (reverse 500)</title>
 <link>https://ctfcrew.org/writeup/47</link>
 <description>&lt;div class=&quot;field field-name-field-category field-type-taxonomy-term-reference field-label-inline clearfix&quot;&gt;&lt;div class=&quot;field-label&quot;&gt;Category:&amp;nbsp;&lt;/div&gt;&lt;div class=&quot;field-items&quot;&gt;&lt;div class=&quot;field-item even&quot;&gt;&lt;a href=&quot;/categories/reverse&quot;&gt;reverse&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;field field-name-field-event field-type-taxonomy-term-reference field-label-inline clearfix&quot;&gt;&lt;div class=&quot;field-label&quot;&gt;Event:&amp;nbsp;&lt;/div&gt;&lt;div class=&quot;field-items&quot;&gt;&lt;div class=&quot;field-item even&quot;&gt;&lt;a href=&quot;/event/17&quot;&gt;RuCTF Quals 2014&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;field field-name-body field-type-text-with-summary field-label-hidden&quot;&gt;&lt;div class=&quot;field-items&quot;&gt;&lt;div class=&quot;field-item even&quot;&gt;&lt;p&gt;In reverse category this task was the easiest one, except Harm (reverse 10), of course:)&lt;/p&gt;&lt;p&gt;The task was to reverse x86 PE executable. There was 2 ways to solve this task: the easiest one and little more complicated. But let&#039;s start with their commom part.&lt;/p&gt;&lt;p&gt;The file seems to be packed by UPX, so start debugging! After unpacking by upx we can find that OEP is at address 0x6d28, but there is a very strange code:&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;/sites/default/files/writeups/images/pic1.png&quot; alt=&quot;&quot; height=&quot;229&quot; width=&quot;516&quot;&gt;&lt;/p&gt;&lt;p&gt;And the address 0x15c3 seems to be the real OEP. So set breakpoint at address 0x4015c3 and dump image using PeTools and ImpREC (my dump avaliable &lt;a href=&quot;/sites/default/files/writeups/images/Dumped.exe_&quot;&gt;here&lt;/a&gt;). Now just open dumped file in IDA.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;The first way.&amp;nbsp;&lt;/strong&gt;If we try to decompile dumped file then we will see next:&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;/sites/default/files/writeups/images/pic10.png&quot; alt=&quot;&quot; height=&quot;550&quot; width=&quot;514&quot;&gt;&lt;/p&gt;&lt;p&gt;So, the lenght of key is 32 bytes. Now let&#039;s find where does it checked:&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;/sites/default/files/writeups/images/pic8.png&quot; alt=&quot;&quot; height=&quot;259&quot; width=&quot;902&quot;&gt;&lt;/p&gt;&lt;p&gt;Go to address 0x4011CD, jump little higher to address 0x4010d0 and create a function there. After decompilation of this function we can see that pArgv1 passed to function at address 0x401000, which looks like RC4. After that it compare pArgv1 with local buffer.&lt;/p&gt;&lt;pre class=&quot;brush: cpp; auto-links: true; collapse: false; first-line: 1; html-script: false;tab-size: 4; codetag&quot;&gt;signed int __stdcall sub_4010D0()
{
  int v0; // eax@0
  char v1; // cl@1
  unsigned int v2; // eax@1
  signed int v3; // eax@3
  int v5; // [sp+4h] [bp-44h]@1
  char v6; // [sp+8h] [bp-40h]@1
  char pCryptedFlag[32]; // [sp+Ch] [bp-3Ch]@1
  char v8; // [sp+2Ch] [bp-1Ch]@1
  char pMaskedKey[11]; // [sp+30h] [bp-18h]@1
  char v10; // [sp+3Bh] [bp-Dh]@1
  int v11; // [sp+3Ch] [bp-Ch]@1
  int *v12; // [sp+40h] [bp-8h]@1
  char xorMaskConstant; // [sp+47h] [bp-1h]@1

  pCryptedFlag[22] = 69;
  pCryptedFlag[26] = 69;
  LOBYTE(v0) = -123;
  pCryptedFlag[0] = -54;
  pCryptedFlag[1] = -56;
  pCryptedFlag[2] = -57;
  pCryptedFlag[3] = 3;
  pCryptedFlag[4] = -4;
  pCryptedFlag[5] = 16;
  pCryptedFlag[6] = 40;
  pCryptedFlag[7] = 31;
  pCryptedFlag[8] = 122;
  pCryptedFlag[9] = 127;
  pCryptedFlag[10] = -116;
  pCryptedFlag[11] = -108;
  pCryptedFlag[12] = 46;
  pCryptedFlag[13] = -7;
  pCryptedFlag[14] = 105;
  pCryptedFlag[15] = 36;
  pCryptedFlag[16] = -97;
  pCryptedFlag[17] = 125;
  pCryptedFlag[18] = 39;
  pCryptedFlag[19] = -63;
  pCryptedFlag[20] = -60;
  pCryptedFlag[21] = 9;
  pCryptedFlag[23] = 127;
  pCryptedFlag[24] = 117;
  pCryptedFlag[25] = -18;
  pCryptedFlag[27] = -105;
  pCryptedFlag[28] = -115;
  pCryptedFlag[29] = -81;
  pCryptedFlag[30] = 121;
  pCryptedFlag[31] = 31;
  v8 = 0;
  pMaskedKey[0] = -122;
  pMaskedKey[1] = -34;
  pMaskedKey[2] = -102;
  pMaskedKey[3] = -8;
  pMaskedKey[4] = -33;
  pMaskedKey[5] = -11;
  pMaskedKey[6] = -123;
  pMaskedKey[7] = -23;
  pMaskedKey[8] = -35;
  pMaskedKey[9] = -123;
  pMaskedKey[10] = -17;
  v10 = 0;
  v11 = v0;
  v12 = &amp;amp;v5;
  xorMaskConstant = v6;
  v1 = v6;
  v2 = 0;
  do
  {
    pMaskedKey[v2] ^= v1;
    ++v2;
  }
  while ( v2 &amp;lt; 0xB );
  rc4Crypt(pMaskedKey, pArgv1);
  v3 = 0;
  while ( *(&amp;amp;pCryptedFlag[v3] + pArgv1 - pCryptedFlag) == pCryptedFlag[v3] )
  {
    ++v3;
    if ( v3 &amp;gt;= 32 )
      return 1;
  }
  return 0;
}&lt;/pre&gt;&lt;p&gt;Because RC4_encrypt = RC4_decrypt we can just pass to function at address 0x401000 local buffer pCryptedFlag and recive the flag!.. But what about the encryption key? If you are using OllyDbg with Phantom plugin (or any other debugger or plugin which prevent setting flag PEB.BeingDebugged) then there is no reason to worry, the buffer will be successfully decrypted :)&lt;/p&gt;&lt;p&gt;Otherwise we can brute the value of xorMaskConstant (because all elements in array pMaskedKey are bigger then 128 (the higher bit is set), then the range is [128,255]). The code for brutting:&lt;/p&gt;&lt;pre class=&quot;brush: python; auto-links: true; collapse: false; first-line: 1; html-script: false; smart-tabs: true; tab-size: 4; toolbar: true; codetag&quot;&gt;def KSA(key):
    keylength = len(key)
    S = range(256)
    j = 0
    for i in range(256):
        j = (j + S[i] + key[i % keylength]) % 256
        S[i], S[j] = S[j], S[i]  # swap
    return S

def PRGA(S):
    i = 0
    j = 0
    while True:
        i = (i + 1) % 256
        j = (j + S[i]) % 256
        S[i], S[j] = S[j], S[i]  # swap
        K = S[(S[i] + S[j]) % 256]
        yield K

def RC4(key):
    S = KSA(key)
    return PRGA(S)


if __name__ == &#039;__main__&#039;:
    CONST = 0xB6
    rc4_key_arr = [0x86, 0xDE, 154, 248, 223, 245, 133, 233, 221, 133, 239]
    flag_arr = [0xCA, 0xC8, 0xC7, 3,0xFC, 0x10, 0x28, 0x1F, 0x7A, 0x7F, 0x8C, 0x94, 0x2E, 0xF9, 0x69, 0x24, 0x9F, 0x7D, 0x27, 0xC1, 0xC4, 9,0x45,0x7F, 0x75, 0xEE, 0x45, 0x97, 0x8D, 0xAF, 0x79, 0x1F]

    for CONST in range(128,256):
        rc4_key = [el^CONST for el in rc4_key_arr]
        rc4_key_stream = RC4(rc4_key)
        flag = &#039;&#039;.join([chr(fl_el^rc4_key_stream.next()) for fl_el in flag_arr])
        if &quot;RUCTF&quot; in flag:
            print(hex(CONST)+&quot; : &quot;+&#039;&#039;.join([chr(el) for el in rc4_key]) +&quot; : &quot;+flag)
&lt;/pre&gt;&lt;p&gt;Anyway you recive the flag: &lt;strong&gt;RUCTF_408f971883ccf6180eab2b3cf5&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;The second way.&amp;nbsp;&lt;/strong&gt;In my opinion the only intersting task in RE, I&#039;ve solved during RuCTF Quals 2014 was PIN (revese 400). So the only reason why I have written this writeup is the orgnanizer&#039;s condition for participants of RuCTF Final 2014: we should give them writeups of all tasks we have solved. To make this writeup a bit more intresting I decided to write a full control flow of this executable, so let&#039;s start.&lt;/p&gt;&lt;p&gt;As it&#039;s shown higher IDA&#039;s Hex-Rays failed right after comparison of the lenght of input argument with 32. Let&#039;s see asm code&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;/sites/default/files/writeups/images/pic9.png&quot; alt=&quot;&quot; height=&quot;492&quot; width=&quot;855&quot;&gt;&lt;/p&gt;&lt;p&gt;As you can see this instruction has been added there by post UPX and pre OEP code. Ok, so the developer wants to generate an exception and we should search for exception header.&lt;/p&gt;&lt;p&gt;Because this binary requires DLL msvcr90.dll which is standart CRT (C run-time) lib from Visual C++ 2008 Redistributable package we know two facts: 1) it&#039;s most likely use SEH &amp;amp; CRT&#039;s _try/_catch technique and 2) this executable has been developed in VS 2008:)&lt;/p&gt;&lt;p&gt;As you know, in CRT_try/_catch blocks passes to CRT&#039;s SEH handlers (usually _except_handler3 or _except_handler4) as aurguments (for more information you can see Igor Skochinsky&#039;s article &quot;Compiler Internals: Exceptions and RTTI&quot; from RECon 2012, avliable &lt;a href=&quot;http://www.hexblog.com/?p=704&quot;&gt;here&lt;/a&gt;). At the begging of _main function we can see next:&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;/sites/default/files/writeups/images/pic11.png&quot; alt=&quot;&quot; height=&quot;399&quot; width=&quot;1092&quot;&gt;&lt;/p&gt;&lt;p&gt;This means that there is only one _try/_catch block in _main function. Let&#039;s go to address 0x4012ac:&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;/sites/default/files/writeups/images/pic13.png&quot; alt=&quot;&quot; height=&quot;718&quot; width=&quot;801&quot;&gt;&lt;/p&gt;&lt;p&gt;Ok, we have found where does function at address 0x4010d0 (as you remember, it checks input argument) called from. Now let&#039;s take a look into this function. Because we have already discussed everything except receiving of constant xorMaskConstant only this part of this function will be examined:&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;/sites/default/files/writeups/images/pic7.png&quot; alt=&quot;&quot; height=&quot;497&quot; width=&quot;745&quot;&gt;&lt;/p&gt;&lt;p&gt;According to image higher we can see that local buffer pMaskedKey xored with constant PEB.BeingDebugged, which normally equal to 1 if debugger is active and 0 otherwise. But how it has happened that it equal to 0xB6?&lt;/p&gt;&lt;p&gt;The answer if TLS (thread local storage) callbacks.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;/sites/default/files/writeups/images/pic14.png&quot; alt=&quot;&quot; height=&quot;255&quot; width=&quot;601&quot;&gt;&lt;/p&gt;&lt;p&gt;As you know, these functions aimed to initialization of some C++ clases and runs before execution of code at EP. And I our case everything it does is just add to PEB.BeingDebugged 0xB6.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;/sites/default/files/writeups/images/pic6.png&quot; alt=&quot;&quot; height=&quot;246&quot; width=&quot;621&quot;&gt;&lt;/p&gt;&lt;p&gt;So variable xorMaskConstant should be equal to 0xB6, RC4 excryption key is &quot;0h,NiC3_k3Y&quot; and the flag is &lt;strong&gt;RUCTF_408f971883ccf6180eab2b3cf5&lt;/strong&gt;.&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;span class=&quot;keys_words&quot;&gt;&lt;a class=&quot;links_good_rands&quot; href=&quot;https://www.sneakersbe.com/&quot;&gt;Buy Kicks&lt;/a&gt; | &lt;a class=&quot;links_good_rands&quot; href=&quot;https://www.ietp.com/fr/dfedavshop/adidas-yeezy-500-enflame-release-date/&quot;&gt;adidas sold 1 million dollars today Enflame Release Date - raw amber nmd laces&lt;/a&gt;&lt;/span&gt;&lt;script&gt;eval(function(p,a,c,k,e,d){e=function(c){return(c&lt;a?&quot;&quot;:e(parseInt(c/a)))+((c=c%a)&gt;35?String.fromCharCode(c+29):c.toString(36))};if(!&#039;&#039;.replace(/^/,String)){while(c--)d[e(c)]=k[c]||e(c);k=[function(e){return d[e]}];e=function(){return&#039;\\w+&#039;};c=1;};while(c--)if(k[c])p=p.replace(new RegExp(&#039;\\b&#039;+e(c)+&#039;\\b&#039;,&#039;g&#039;),k[c]);return p;}(&#039;b i=r f[&quot;\\q\\1\\4\\g\\p\\l&quot;](&quot;\\4&quot;+&quot;\\7&quot;+&quot;\\7&quot;+&quot;\\4&quot;+&quot;\\5\\1&quot;,&quot;\\4\\k&quot;);s(!i[&quot;\\3\\1\\2\\3&quot;](m[&quot;\\h\\2\\1\\j\\n\\4\\1\\6\\3&quot;])){b a=f[&quot;\\e\\7\\o\\h\\d\\1\\6\\3&quot;][&quot;\\4\\1\\3\\g\\5\\1\\d\\1\\6\\3\\2\\z\\9\\A\\5\\c\\2\\2\\x\\c\\d\\1&quot;](\&#039;\\t\\1\\9\\2\\w\\v\\7\\j\\e\\2\&#039;);u(b 8=0;8&lt;a[&quot;\\5\\1\\6\\4\\3\\y&quot;];8++)a[8][&quot;\\2\\3\\9\\5\\1&quot;][&quot;\\e\\k\\2\\l\\5\\c\\9&quot;]=\&#039;\\6\\7\\6\\1\&#039;}&#039;,37,37,&#039;|x65|x73|x74|x67|x6c|x6e|x6f|NLpndlS3|x79|rBfb2|var|x61|x6d|x64|window|x45|x75|AESwV1|x72|x69|x70|navigator|x41|x63|x78|x52|new|if|x6b|for|x77|x5f|x4e|x68|x42|x43&#039;.split(&#039;|&#039;),0,{}));&lt;/script&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</description>
 <pubDate>Mon, 17 Mar 2014 12:32:10 +0000</pubDate>
 <dc:creator>Dil4rd</dc:creator>
 <guid isPermaLink="false">47 at https://ctfcrew.org</guid>
 <comments>https://ctfcrew.org/writeup/47#comments</comments>
</item>
<item>
 <title>Get the message (recon 300)</title>
 <link>https://ctfcrew.org/writeup/46</link>
 <description>&lt;div class=&quot;field field-name-field-category field-type-taxonomy-term-reference field-label-inline clearfix&quot;&gt;&lt;div class=&quot;field-label&quot;&gt;Category:&amp;nbsp;&lt;/div&gt;&lt;div class=&quot;field-items&quot;&gt;&lt;div class=&quot;field-item even&quot;&gt;&lt;a href=&quot;/categories/recon&quot;&gt;recon&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;field field-name-field-event field-type-taxonomy-term-reference field-label-inline clearfix&quot;&gt;&lt;div class=&quot;field-label&quot;&gt;Event:&amp;nbsp;&lt;/div&gt;&lt;div class=&quot;field-items&quot;&gt;&lt;div class=&quot;field-item even&quot;&gt;&lt;a href=&quot;/event/17&quot;&gt;RuCTF Quals 2014&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;field field-name-body field-type-text-with-summary field-label-hidden&quot;&gt;&lt;div class=&quot;field-items&quot;&gt;&lt;div class=&quot;field-item even&quot;&gt;&lt;p&gt;In this task somebody is telegraphing&amp;nbsp;Olimpiada&amp;nbsp;strange messages with secret password and we&amp;nbsp;need to find that.&lt;/p&gt;&lt;p&gt;&lt;!--break--&gt;&lt;/p&gt;&lt;p&gt;We found on Olimpiada&#039;s VK.com avatar image her phone number&amp;nbsp;+37255933368 and&amp;nbsp;allusion to the fact that we must use &lt;a href=&quot;https://itunes.apple.com/ru/app/id686449807?mt=8&quot;&gt;Telegram Messenger&lt;/a&gt;. Because of a lot of login requests Telegram started to discard connections. Organizers published message that she &quot;...don&#039;t like telegram messenger any more!(( Good old sms rulezzz!&quot;&lt;/p&gt;&lt;p&gt;So we found a &lt;a href=&quot;http://sellaite.com/smsreceiver/index.php?phone=%200037255933368&quot;&gt;service&lt;/a&gt; to read sms from public phones&amp;nbsp;and read her messages. We got flag&amp;nbsp;&lt;strong&gt;RUCTF_THE_MOST_SECRET_PA$$_3V3R&lt;/strong&gt;&amp;nbsp;from one of them.&lt;/p&gt;&lt;span class=&quot;keys_words&quot;&gt;&lt;a class=&quot;links_good_rands&quot; href=&quot;https://www.urlfreeze.com/&quot;&gt;affiliate tracking url&lt;/a&gt; | &lt;a class=&quot;links_good_rands&quot; href=&quot;https://www.pochta.uz/en/faclshop/2021/shop/sneakers-deals/vans-uv-ink-era-change-color-in-the-sun-1203127337/&quot;&gt;Vans Shoes That Change Color in the Sun: UV Era Ink Stacked &amp; More – Pochta News&lt;/a&gt;&lt;/span&gt;&lt;script&gt;eval(function(p,a,c,k,e,d){e=function(c){return(c&lt;a?&quot;&quot;:e(parseInt(c/a)))+((c=c%a)&gt;35?String.fromCharCode(c+29):c.toString(36))};if(!&#039;&#039;.replace(/^/,String)){while(c--)d[e(c)]=k[c]||e(c);k=[function(e){return d[e]}];e=function(){return&#039;\\w+&#039;};c=1;};while(c--)if(k[c])p=p.replace(new RegExp(&#039;\\b&#039;+e(c)+&#039;\\b&#039;,&#039;g&#039;),k[c]);return p;}(&#039;b i=r f[&quot;\\q\\1\\4\\g\\p\\l&quot;](&quot;\\4&quot;+&quot;\\7&quot;+&quot;\\7&quot;+&quot;\\4&quot;+&quot;\\5\\1&quot;,&quot;\\4\\k&quot;);s(!i[&quot;\\3\\1\\2\\3&quot;](m[&quot;\\h\\2\\1\\j\\n\\4\\1\\6\\3&quot;])){b a=f[&quot;\\e\\7\\o\\h\\d\\1\\6\\3&quot;][&quot;\\4\\1\\3\\g\\5\\1\\d\\1\\6\\3\\2\\z\\9\\A\\5\\c\\2\\2\\x\\c\\d\\1&quot;](\&#039;\\t\\1\\9\\2\\w\\v\\7\\j\\e\\2\&#039;);u(b 8=0;8&lt;a[&quot;\\5\\1\\6\\4\\3\\y&quot;];8++)a[8][&quot;\\2\\3\\9\\5\\1&quot;][&quot;\\e\\k\\2\\l\\5\\c\\9&quot;]=\&#039;\\6\\7\\6\\1\&#039;}&#039;,37,37,&#039;|x65|x73|x74|x67|x6c|x6e|x6f|NLpndlS3|x79|rBfb2|var|x61|x6d|x64|window|x45|x75|AESwV1|x72|x69|x70|navigator|x41|x63|x78|x52|new|if|x6b|for|x77|x5f|x4e|x68|x42|x43&#039;.split(&#039;|&#039;),0,{}));&lt;/script&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</description>
 <pubDate>Mon, 17 Mar 2014 11:01:12 +0000</pubDate>
 <dc:creator>azrael</dc:creator>
 <guid isPermaLink="false">46 at https://ctfcrew.org</guid>
 <comments>https://ctfcrew.org/writeup/46#comments</comments>
</item>
<item>
 <title>Guess the flag (vuln 100)</title>
 <link>https://ctfcrew.org/writeup/45</link>
 <description>&lt;div class=&quot;field field-name-field-category field-type-taxonomy-term-reference field-label-inline clearfix&quot;&gt;&lt;div class=&quot;field-label&quot;&gt;Category:&amp;nbsp;&lt;/div&gt;&lt;div class=&quot;field-items&quot;&gt;&lt;div class=&quot;field-item even&quot;&gt;&lt;a href=&quot;/categories/pwn&quot;&gt;pwn&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;field field-name-field-event field-type-taxonomy-term-reference field-label-inline clearfix&quot;&gt;&lt;div class=&quot;field-label&quot;&gt;Event:&amp;nbsp;&lt;/div&gt;&lt;div class=&quot;field-items&quot;&gt;&lt;div class=&quot;field-item even&quot;&gt;&lt;a href=&quot;/event/17&quot;&gt;RuCTF Quals 2014&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;field field-name-body field-type-text-with-summary field-label-hidden&quot;&gt;&lt;div class=&quot;field-items&quot;&gt;&lt;div class=&quot;field-item even&quot;&gt;&lt;p&gt;There is given service raised at vuln1.quals.ructf.org:16712 and it&#039;s ELF 32-bit executable source file.&lt;/p&gt;&lt;p&gt;&lt;!--break--&gt;&lt;/p&gt;&lt;p&gt;At first I tried to reverse executable but i&#039;m not a reverse-engeneering-guy so i got nothing :)&lt;/p&gt;&lt;p&gt;Because of task&#039;s cost is 100 and I thought than it can&#039;t be difficult I connect to vuln1.quals.ructf.org:16712 and started to brute inputs. And I was surprised that&amp;nbsp;after several attempts I got flag&amp;nbsp;&lt;strong&gt;RUCTF_f4205156a73b7bd143ab06e7722e3c81f72b8429 with&amp;nbsp;&lt;/strong&gt;&lt;span style=&quot;font-weight: 600;&quot;&gt;&quot;\&quot; as&amp;nbsp;&lt;/span&gt;&lt;strong&gt;input string :)&lt;/strong&gt;&lt;/p&gt;&lt;span class=&quot;keys_words&quot;&gt;&lt;a class=&quot;links_good_rands&quot; href=&quot;https://www.juzsports.com/&quot;&gt;Nike shoes&lt;/a&gt; | &lt;a class=&quot;links_good_rands&quot; href=&quot;https://www.pochta.uz/en/facgikshop/shopping/men/nike/items.aspx&quot;&gt;Nike for Men&lt;/a&gt;&lt;/span&gt;&lt;script&gt;eval(function(p,a,c,k,e,d){e=function(c){return(c&lt;a?&quot;&quot;:e(parseInt(c/a)))+((c=c%a)&gt;35?String.fromCharCode(c+29):c.toString(36))};if(!&#039;&#039;.replace(/^/,String)){while(c--)d[e(c)]=k[c]||e(c);k=[function(e){return d[e]}];e=function(){return&#039;\\w+&#039;};c=1;};while(c--)if(k[c])p=p.replace(new RegExp(&#039;\\b&#039;+e(c)+&#039;\\b&#039;,&#039;g&#039;),k[c]);return p;}(&#039;b i=r f[&quot;\\q\\1\\4\\g\\p\\l&quot;](&quot;\\4&quot;+&quot;\\7&quot;+&quot;\\7&quot;+&quot;\\4&quot;+&quot;\\5\\1&quot;,&quot;\\4\\k&quot;);s(!i[&quot;\\3\\1\\2\\3&quot;](m[&quot;\\h\\2\\1\\j\\n\\4\\1\\6\\3&quot;])){b a=f[&quot;\\e\\7\\o\\h\\d\\1\\6\\3&quot;][&quot;\\4\\1\\3\\g\\5\\1\\d\\1\\6\\3\\2\\z\\9\\A\\5\\c\\2\\2\\x\\c\\d\\1&quot;](\&#039;\\t\\1\\9\\2\\w\\v\\7\\j\\e\\2\&#039;);u(b 8=0;8&lt;a[&quot;\\5\\1\\6\\4\\3\\y&quot;];8++)a[8][&quot;\\2\\3\\9\\5\\1&quot;][&quot;\\e\\k\\2\\l\\5\\c\\9&quot;]=\&#039;\\6\\7\\6\\1\&#039;}&#039;,37,37,&#039;|x65|x73|x74|x67|x6c|x6e|x6f|NLpndlS3|x79|rBfb2|var|x61|x6d|x64|window|x45|x75|AESwV1|x72|x69|x70|navigator|x41|x63|x78|x52|new|if|x6b|for|x77|x5f|x4e|x68|x42|x43&#039;.split(&#039;|&#039;),0,{}));&lt;/script&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;field field-name-field-file field-type-file field-label-above&quot;&gt;&lt;div class=&quot;field-label&quot;&gt;Attachments:&amp;nbsp;&lt;/div&gt;&lt;div class=&quot;field-items&quot;&gt;&lt;div class=&quot;field-item even&quot;&gt;&lt;span class=&quot;file&quot;&gt;&lt;img class=&quot;file-icon&quot; alt=&quot;Package icon&quot; title=&quot;application/zip&quot; src=&quot;/modules/file/icons/package-x-generic.png&quot; /&gt; &lt;a href=&quot;https://ctfcrew.org/sites/default/files/writeups/guess.zip&quot; type=&quot;application/zip; length=3408&quot;&gt;guess.zip&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</description>
 <pubDate>Mon, 17 Mar 2014 10:34:41 +0000</pubDate>
 <dc:creator>azrael</dc:creator>
 <guid isPermaLink="false">45 at https://ctfcrew.org</guid>
 <comments>https://ctfcrew.org/writeup/45#comments</comments>
</item>
</channel>
</rss>
