<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<rss version="2.0" 
  xmlns:content="http://purl.org/rss/1.0/modules/content/" 
  xmlns:dc="http://purl.org/dc/elements/1.1/" 
  xmlns:atom="http://www.w3.org/2005/Atom" 
  xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" 
  xmlns:media="http://search.yahoo.com/mrss/">
  <channel>
    <title>wireshark on Ben&#39;s ideas and projects</title>
    <link>https://ben.the-collective.net/tags/wireshark/</link>
    <description>Recent content in wireshark on Ben&#39;s ideas and projects</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en</language>
    <managingEditor>locutus@the-collective.net (Ben Mason)</managingEditor>
    <webMaster>locutus@the-collective.net (Ben Mason)</webMaster>
    <copyright>©2023, All Rights Reserved</copyright>
    <lastBuildDate>Tue, 02 Mar 2021 09:00:00 -0500</lastBuildDate>
    <sy:updatePeriod>daily</sy:updatePeriod>
    
        <atom:link href="https://ben.the-collective.net/tags/wireshark/index.xml" rel="self" type="application/rss+xml" />
    

      
      <item>
        <title>Flare-on 2 - Challenge 5</title>
        <link>https://ben.the-collective.net/posts/2021-03-02-flare-on-2-challenge-5/</link>
        <pubDate>Tue, 02 Mar 2021 09:00:00 -0500</pubDate>
        <author>locutus@the-collective.net (Ben Mason)</author>
        <atom:modified>Tue, 02 Mar 2021 09:00:00 -0500</atom:modified>
        <guid>https://ben.the-collective.net/posts/2021-03-02-flare-on-2-challenge-5/</guid>
        <description>This is a post in a series where I complete every Flare-on challenge. The landing page for all of these posts can be found here
This challenge includes two files, a packet capture formatted in PCAP format and a Windows binary.
Opening up the PCAP in Wireshark, I found multiple HTTP streams submitting POST requests. I looked at each of these POST requests and saw they all have a few bytes of content.</description>
        <content:encoded>&lt;p&gt;This is a post in a series where I complete every Flare-on challenge. The landing page for all of these posts can be found &lt;a href=&#34;https://ben.the-collective.net/project-flareon/&#34;&gt;here&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;This challenge includes two files, a packet capture formatted in PCAP format and a Windows binary.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;../2021-03-02-flare-on-2-challenge-5-images/Screen-Shot-2021-01-29-at-00.04.08.png&#34; alt=&#34;&#34; /&gt;&lt;br /&gt;
Opening up the PCAP in Wireshark, I found multiple HTTP streams submitting POST requests. I looked at each of these POST requests and saw they all have a few bytes of content.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;../2021-03-02-flare-on-2-challenge-5-images/Screen-Shot-2021-01-28-at-23.13.54-1.png&#34; alt=&#34;&#34; /&gt;&lt;br /&gt;
I copied the data from each of these HTTP POST requests and found what looked like a Base64 encoded string.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;UDYs1D7bNmdE1o3g5ms1V6RrYCVvODJF1DqxKTxAJ9xuZW=
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;img src=&#34;../2021-03-02-flare-on-2-challenge-5-images/Screen-Shot-2021-01-28-at-23.30.29.png&#34; alt=&#34;&#34; /&gt;&lt;br /&gt;
When I attempted to decode it using standard Base64 character sets I did not find any recognizable data. I knew that it wouldn’t be that easy.&lt;/p&gt;
&lt;p&gt;Looking at the strings in the binary, I found two interesting strings, “flarebearstare” which could be a password, and another string that looks like a Base64 alphabet with the uppercase and lower case sections swapped in order.&lt;/p&gt;
&lt;p&gt;I following the cross-reference for the “flarebearstare” string, finding a function with a data decoder loop. This function is passed data and loops through each byte, subtracting each character in order of “flarebearstare” from the current byte.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;../2021-03-02-flare-on-2-challenge-5-images/Screen-Shot-2021-01-28-at-23.30.53-1.png&#34; alt=&#34;Decoder function&#34; /&gt;&lt;br /&gt;
Looking over this functionality, I started to write up some code to decode the flag. I grabbed a Base64 library that needed a small modification to use a custom character set. My fork of the code can be found at this repo.&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;https://github.com/suidroot/Python-Base64&#34;&gt;https://github.com/suidroot/Python-Base64&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;In the screenshot below, you can see my final script in a Jupyter notebook. As an aside, I have been using it for many challenges and other projects to test out decoder and other functionality. They have been instrumental in quick prototyping and experimentation.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;../2021-03-02-flare-on-2-challenge-5-images/Screen-Shot-2021-02-02-at-18.58.41.png&#34; alt=&#34;&#34; /&gt;&lt;br /&gt;
Success there mostly is the flag. You can see there is some weirdness in the decoding of the flag, but this script decodes the main part of it needed in my mind to call it a solution.&lt;/p&gt;
&lt;h2 id=&#34;full-code&#34;&gt;Full Code&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;b64encoded = &amp;#34;UDYs1D7bNmdE1o3g5ms1V6RrYCVvODJF1DqxKTxAJ9xuZW==&amp;#34;
b64_alphabet = &amp;#39;abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/&amp;#39;

b = b64()
b64decoded = b.decode(b64encoded, alttable=b64_alphabet)

for i in b64decoded:
    print (hex(ord(i)) + &amp;#34; &amp;#34;, end=&amp;#34;&amp;#34;)

print ()
count = 1

key = &amp;#34;flarebearstare&amp;#34;
key_len = len(key)

output = &amp;#34;&amp;#34;
counter = 0

for i in b64decoded:
    temp = ord(i) - ord(key[counter])
    
    print (chr(temp),end=&amp;#34;&amp;#34;)

    #print (i, hex(temp), key[counter], chr(temp))
    output += chr(temp)
    
    if counter+1 &amp;lt; key_len:
        counter+=1
    else:
        counter = 0
&lt;/code&gt;&lt;/pre&gt;</content:encoded>
        <dc:creator>suidroot</dc:creator>
        <media:content url="https://ben.the-collective.net/images/post-images/Flare-on-Template-2-5.png" medium="image"><media:title type="html">featured image</media:title></media:content>
        
        
        
          
            
              <category>ctf</category>
            
          
            
              <category>flare-on</category>
            
          
            
              <category>python</category>
            
          
            
              <category>reverse engineering</category>
            
          
            
              <category>wireshark</category>
            
          
        
        
          
            
              <category>Reverse Engineering</category>
            
          
        
        
      </item>
      
      <item>
        <title>Flare-on 2 - Challenge 3</title>
        <link>https://ben.the-collective.net/posts/2021-02-23-flare-on-2-challenge-3/</link>
        <pubDate>Tue, 23 Feb 2021 09:05:00 -0500</pubDate>
        <author>locutus@the-collective.net (Ben Mason)</author>
        <atom:modified>Tue, 23 Feb 2021 09:05:00 -0500</atom:modified>
        <guid>https://ben.the-collective.net/posts/2021-02-23-flare-on-2-challenge-3/</guid>
        <description>This is a post in a series where I complete every Flare-on challenge. The landing page for all of these posts can be found here
In the third challenge, you are greeted with a nice goat named Elfie that when you are typing characters show up on the screen. As always I start off by checking out what kind of binary I am looking at
λ file elfie elfie: PE32 executable (console) Intel 80386, for MS Windows As I said we are greeted by thie goat that eats magic keys</description>
        <content:encoded>&lt;p&gt;This is a post in a series where I complete every Flare-on challenge. The landing page for all of these posts can be found &lt;a href=&#34;https://ben.the-collective.net/project-flareon/&#34;&gt;here&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;In the third challenge, you are greeted with a nice goat named Elfie that when you are typing characters show up on the screen. As always I start off by checking out what kind of binary I am looking at&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;λ file elfie
elfie: PE32 executable (console) Intel 80386, for MS Windows
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;As I said we are greeted by thie goat that eats magic keys&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;../2021-02-23-flare-on-2-challenge-3-images/Screen-Shot-2021-01-23-at-18.09.43.png&#34; alt=&#34;&#34; /&gt;&lt;br /&gt;
After doing some initial analysis in Ghidra found some strings that indicate that this file might be a python executable.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;../2021-02-23-flare-on-2-challenge-3-images/Screen-Shot-2021-01-23-at-18.18.54.png&#34; alt=&#34;&#34; /&gt;&lt;br /&gt;
&lt;img src=&#34;../2021-02-23-flare-on-2-challenge-3-images/Screen-Shot-2021-01-23-at-18.18.33.png&#34; alt=&#34;&#34; /&gt;&lt;br /&gt;
Additionally, the icon embedded in the binary should have been a giveaway. I guessed it was probably a pyInstaller executable. I ran it through &lt;em&gt;&lt;a href=&#34;https://github.com/extremecoders-re/pyinstxtractor&#34;&gt;pyinstextractor.py&lt;/a&gt;&lt;/em&gt; to expand it out and get a copy of the python source to analyze.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;C:\Users\IEUser\Desktop
λ pyinstxtractor.py elfie.exe
C:\Tools\pyinstxtractor\pyinstxtractor.py:86: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module&amp;#39;s documentation for alternative uses
  import imp
[*] Processing elfie.exe
[*] Pyinstaller version: 2.1+
[*] Python version: 27
[*] Length of package: 12034944 bytes
[*] Found 26 files in CArchive
[*] Beginning extraction...please standby
[!] Warning: The script is running in a different python version than the one used to build the executable
    Run this script in Python27 to prevent extraction errors(if any) during unmarshalling
[*] Found 244 files in PYZ archive
[+] Possible entry point: _pyi_bootstrap
[+] Possible entry point: pyi_carchive
[+] Possible entry point: elfie
[*] Successfully extracted pyinstaller archive: elfie.exe

You can now use a python decompiler on the pyc files within the extracted directory

C:\Users\IEUser\Desktop
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;I found the file &lt;em&gt;elfie&lt;/em&gt; and opened it in VSCode to look at the contents.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;../2021-02-23-flare-on-2-challenge-3-images/Screen-Shot-2021-01-23-at-18.11.44.png&#34; alt=&#34;&#34; /&gt;&lt;br /&gt;
it looks to be full of Base64 strings that are concatenated together, decoded, and executed.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;../2021-02-23-flare-on-2-challenge-3-images/Screen-Shot-2021-01-23-at-18.12.14.png&#34; alt=&#34;Strings&#34; /&gt;&lt;br /&gt;
I changed the final operation to print the encoded python code for further analysis.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;../2021-02-23-flare-on-2-challenge-3-images/Screen-Shot-2021-01-23-at-18.13.31.png&#34; alt=&#34;&#34; /&gt;&lt;br /&gt;
The next layer down looked more like normal python code with obfuscated variable names.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;../2021-02-23-flare-on-2-challenge-3-images/Screen-Shot-2021-01-23-at-18.14.30.png&#34; alt=&#34;&#34; /&gt;&lt;br /&gt;
Even looking at the obfuscated code the is pretty obvious but I wanted to clean up some of the variable names to make sure I was not missing anything else.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;../2021-02-23-flare-on-2-challenge-3-images/Screen-Shot-2021-01-23-at-18.14.41.png&#34; alt=&#34;&#34; /&gt;&lt;br /&gt;
After reversing the string the flag is revealed&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;../2021-02-23-flare-on-2-challenge-3-images/Screen-Shot-2021-01-23-at-18.07.41.png&#34; alt=&#34;&#34; /&gt;&lt;br /&gt;
and Elfie is happy!&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;../2021-02-23-flare-on-2-challenge-3-images/Screen-Shot-2021-01-23-at-18.09.33.png&#34; alt=&#34;&#34; /&gt;&lt;/p&gt;
</content:encoded>
        <dc:creator>suidroot</dc:creator>
        <media:content url="https://ben.the-collective.net/images/post-images/Flare-on-Template-2-3.png" medium="image"><media:title type="html">featured image</media:title></media:content>
        
        
        
          
            
              <category>ctf</category>
            
          
            
              <category>flare-on</category>
            
          
            
              <category>python</category>
            
          
            
              <category>reverse engineering</category>
            
          
            
              <category>wireshark</category>
            
          
        
        
          
            
              <category>Reverse Engineering</category>
            
          
        
        
      </item>
      
      <item>
        <title>Flare-on 2 - Challenge 2</title>
        <link>https://ben.the-collective.net/posts/2021-02-16-flare-on-2-challenge-2/</link>
        <pubDate>Tue, 16 Feb 2021 09:00:00 -0500</pubDate>
        <author>locutus@the-collective.net (Ben Mason)</author>
        <atom:modified>Tue, 16 Feb 2021 09:00:00 -0500</atom:modified>
        <guid>https://ben.the-collective.net/posts/2021-02-16-flare-on-2-challenge-2/</guid>
        <description>This is a post in a series where I complete every Flare-on challenge. The landing page for all of these posts can be found here
The second challenge from this season built on the first challenge. It was another password entry challenge but with a more complicated password encoding scheme.
First things first I validated what kind of file I was looking at.
λ file very_succes very_succes: PE32 executable (console) Intel 80386, for MS Windows When running the file I entered some test data to see how it looked to a user.</description>
        <content:encoded>&lt;p&gt;This is a post in a series where I complete every Flare-on challenge. The landing page for all of these posts can be found &lt;a href=&#34;https://ben.the-collective.net/project-flareon/&#34;&gt;here&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The second challenge from this season built on the first challenge. It was another password entry challenge but with a more complicated password encoding scheme.&lt;/p&gt;
&lt;p&gt;First things first I validated what kind of file I was looking at.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;λ file very_succes
very_succes: PE32 executable (console) Intel 80386, for MS Windows
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;When running the file I entered some test data to see how it looked to a user.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;../2021-02-16-flare-on-2-challenge-2-images/Screen-Shot-2021-01-23-at-13.23.59.png&#34; alt=&#34;&#34; /&gt;&lt;br /&gt;
I switched back to Ghidra to do some static analysis on this binary and found the area of code that looked to handle the password comparison. The first check that jumped out to me was the length check that checked to see if the password was 37 characters long.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;../2021-02-16-flare-on-2-challenge-2-images/Screen-Shot-2021-02-02-at-19.33.18.png&#34; alt=&#34;&#34; /&gt;&lt;br /&gt;
Then I found the encoding and matching bulk of the code which I have commented below. This block of code uses a combination of XOR and Bit-wise shifting of the characters to encode each character of the input to match it against the encoded password.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;../2021-02-16-flare-on-2-challenge-2-images/Screen-Shot-2021-01-23-at-13.35.08.png&#34; alt=&#34;&#34; /&gt;&lt;br /&gt;
It took me a little bit to see that the SCASB instruction at 0x4010c8 is used to set the zero flag to 1 if the encoded value does not match and jump to a failure condition. Otherwise is set to 0 for success and continues the loop.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;../2021-02-16-flare-on-2-challenge-2-images/Screen-Shot-2021-01-21-at-20.11.47.png&#34; alt=&#34;&#34; /&gt;&lt;br /&gt;
I ran the binary using x64dbg to walk through and monitor execution manually setting the Zero Flag to check how the algorithm operated. I also identified the location of the encoded key stored in EDI and copied out that data in hex.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;AFAAADEB AEAAECA4 BAAFAEAA 8AC0A7B0 BC9ABAA5 A5BAAFB8 9DB8F9AE 9DABB4BC B6B3909A A8
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;As with the first challenge in this season I crudely implemented the encoder in python and using brute force was able to successfully generate the key.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;../2021-02-16-flare-on-2-challenge-2-images/Screen-Shot-2021-01-23-at-13.23.26.png&#34; alt=&#34;&#34; /&gt;&lt;/p&gt;
&lt;h2 id=&#34;decoder-code&#34;&gt;Decoder code&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;encoded = [0xAF, 0xAA, 0xAD, 0xEB, 0xAE, 0xAA, 0xEC, 0xA4, 0xBA, 0xAF, 0xAE, 0xAA, 0x8A, 0xC0, 0xA7, 0xB0, 0xBC, 0x9A, 0xBA, 0xA5, 0xA5, 0xBA, 0xAF, 0xB8, 0x9D, 0xB8, 0xF9, 0xAE, 0x9D, 0xAB, 0xB4, 0xBC, 0xB6, 0xB3, 0x90, 0x9A, 0xA8]

result_key = &amp;#34;&amp;#34;
    
def xchg(s1, s2):
    temp = s1
    s1 = s2
    s2 = temp
    
    return s1, s2

def decoder(text_data):
    global result_key
   
    success_count = 0
    
    bx = 0
    dx = 0
    key_store = 0 # stack
    cl = 37
    eax = 0x1901c7

    for i in text_data:
        dx = bx
        dx = dx &amp;amp; 0x3
        ah = (eax &amp;amp; 0x0000FF00 &amp;gt; 1)
        al = (eax &amp;amp; 0x000000FF)

        dl = (dx &amp;amp; 0x00FF)
        al = (i ^ al)
        dl, cl = xchg(dl, cl)
        ah, cf = ah &amp;lt;&amp;lt; cl, ah &amp;amp; 1
        al = al + ah + cf
        ax = al + (ah*0x100)
        dl, cl = xchg(dl, cl)

        dx = 0
        dl = 0
        ax = ax &amp;amp; 0xff
        output = ax
        bx = bx + (ax &amp;amp; 0xff)

        cl = cl - 0x1
        if encoded[cl] != output:
            pass
        else:
            result_key += chr(i)
            success_count += 1
            
    return success_count

test = [65] * 37

for element in range(len(test)):            
    for i in range(0x21,0x7e):
        test[element] = i

        succ_coun = decoder(test)
        if succ_coun &amp;lt; element+1:
            pass
            result_key = &amp;#34;&amp;#34;

        else:
            print (succ_coun, element, chr(i))
            print(&amp;#34;Key:&amp;#34;, result_key)
            break
            
print (test)
print (&amp;#34;resultkey: \&amp;#34;&amp;#34; + result_key + &amp;#34;\&amp;#34;&amp;#34;)
    
&lt;/code&gt;&lt;/pre&gt;</content:encoded>
        <dc:creator>suidroot</dc:creator>
        <media:content url="https://ben.the-collective.net/images/post-images/Flare-on-Template-2-2.png" medium="image"><media:title type="html">featured image</media:title></media:content>
        
        
        
          
            
              <category>ctf</category>
            
          
            
              <category>flare-on</category>
            
          
            
              <category>python</category>
            
          
            
              <category>reverse engineering</category>
            
          
            
              <category>wireshark</category>
            
          
        
        
          
            
              <category>Reverse Engineering</category>
            
          
        
        
      </item>
      
      <item>
        <title>Flare-on 2 - Challenge 1</title>
        <link>https://ben.the-collective.net/posts/2021-02-09-flare-on-2-challenge-1/</link>
        <pubDate>Tue, 09 Feb 2021 09:00:00 -0500</pubDate>
        <author>locutus@the-collective.net (Ben Mason)</author>
        <atom:modified>Tue, 09 Feb 2021 09:00:00 -0500</atom:modified>
        <guid>https://ben.the-collective.net/posts/2021-02-09-flare-on-2-challenge-1/</guid>
        <description>This is a post in a series where I complete every Flare-on challenge. The landing page for all of these posts can be found here
The first challenge in the 2015 season on Flare On was a pretty easy enter the password type of challenge. I started off by opening the extracted file in IDA and running it in the debugger. I stepped to the section of code that evaluates the input versus the input</description>
        <content:encoded>&lt;p&gt;This is a post in a series where I complete every Flare-on challenge. The landing page for all of these posts can be found &lt;a href=&#34;https://ben.the-collective.net/project-flareon/&#34;&gt;here&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The first challenge in the 2015 season on Flare On was a pretty easy enter the password type of challenge. I started off by opening the extracted file in IDA and running it in the debugger. I stepped to the section of code that evaluates the input versus the input&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;../2021-02-09-flare-on-2-challenge-1-images/Screen-Shot-2021-01-19-at-19.47.26-2.png&#34; alt=&#34;Key encoding and comparison routine&#34; /&gt;&lt;br /&gt;
I extracted the encoded key from memory&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;../2021-02-09-flare-on-2-challenge-1-images/Screen-Shot-2021-01-19-at-19.47.16.png&#34; alt=&#34;Encoded Key data&#34; /&gt;&lt;br /&gt;
Then I re-implemented the XOR encryption in python and generated the key from the data.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;../2021-02-09-flare-on-2-challenge-1-images/Screen-Shot-2021-01-19-at-19.48.19.png&#34; alt=&#34;Jupyter notebook key decoder&#34; /&gt;&lt;br /&gt;
Which successfully worked!&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;../2021-02-09-flare-on-2-challenge-1-images/Screen-Shot-2021-01-19-at-19.48.04.png&#34; alt=&#34;Successful Key Entry&#34; /&gt;&lt;/p&gt;
</content:encoded>
        <dc:creator>suidroot</dc:creator>
        <media:content url="https://ben.the-collective.net/images/post-images/Flare-on-Template-2-1.png" medium="image"><media:title type="html">featured image</media:title></media:content>
        
        
        
          
            
              <category>ctf</category>
            
          
            
              <category>flare-on</category>
            
          
            
              <category>python</category>
            
          
            
              <category>reverse engineering</category>
            
          
            
              <category>wireshark</category>
            
          
        
        
          
            
              <category>Reverse Engineering</category>
            
          
        
        
      </item>
      
      <item>
        <title>Flare-on 1 - Challenge 4 - Sploitastic</title>
        <link>https://ben.the-collective.net/posts/2021-01-28-flare-on-1-challenge-4-sploitastic/</link>
        <pubDate>Thu, 28 Jan 2021 09:00:00 -0500</pubDate>
        <author>locutus@the-collective.net (Ben Mason)</author>
        <atom:modified>Thu, 28 Jan 2021 09:00:00 -0500</atom:modified>
        <guid>https://ben.the-collective.net/posts/2021-01-28-flare-on-1-challenge-4-sploitastic/</guid>
        <description>This is a post in a series where I complete every Flare-on challenge. The landing page for all of these posts can be found here
We start off with a PDF file in Challenge 4, I start off by dumping the contents of the streams using pdf-parser from Didier Stevens PDF-tools
pdf-parser.py -f APT9001.orig.pdf &amp;gt; apt5.txt
Looking through the content I find a block of Javascript code that looks interesting</description>
        <content:encoded>&lt;p&gt;This is a post in a series where I complete every Flare-on challenge. The landing page for all of these posts can be found &lt;a href=&#34;https://ben.the-collective.net/project-flareon/&#34;&gt;here&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;We start off with a PDF file in Challenge 4, I start off by dumping the contents of the streams using pdf-parser from &lt;a href=&#34;https://blog.didierstevens.com/programs/pdf-tools/&#34;&gt;Didier Stevens PDF-tools&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;pdf-parser.py -f APT9001.orig.pdf &amp;gt; apt5.txt&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Looking through the content I find a block of Javascript code that looks interesting&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;../2021-01-28-flare-on-1-challenge-4-sploitastic-images/Screen-Shot-2021-01-12-at-22.44.13.png&#34; alt=&#34;&#34; /&gt;&lt;br /&gt;
After copying it out and some manual de-obfuscation I find a block of what looks to be hex-encoded shellcode. I grabbed a script to decode it into a binary file to run and debug.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;../2021-01-28-flare-on-1-challenge-4-sploitastic-images/Screen-Shot-2021-01-12-at-22.44.25.png&#34; alt=&#34;&#34; /&gt;&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;from binascii import unhexlify as unhx

#encoded = open(&amp;#39;encoded.txt&amp;#39;).read() # The shellcode dump
out = open(&amp;#39;shellcode.bin&amp;#39;, &amp;#39;wb&amp;#39;)

encoded =&amp;#34;%u72f9%u4649%u1525%u7f0d%u3d3c%ue084%ud62a%ue139%ua84a%u76b9%u9824%u7378%u7d71%u757f%u2076%u96d4%uba91%u1970%ub8f9%ue232%u467b%u-SNIP-%u2454%u5740%ud0ff&amp;#34;

for s in encoded.split(&amp;#39;%&amp;#39;):
    if len(s) == 5:
        HI_BYTE = s[3:]
        LO_BYTE = s[1:3]
        out.write(unhx(HI_BYTE))
        out.write(unhx(LO_BYTE))
out.close()
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;I took the binary code and loaded it in &lt;a href=&#34;https://github.com/OALabs/BlobRunner&#34;&gt;BlobRunner&lt;/a&gt; and attached x64dbg to it.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;../2021-01-28-flare-on-1-challenge-4-sploitastic-images/711a85a33e33427082e24b7a13b3dd50.png&#34; alt=&#34;&#34; /&gt;&lt;br /&gt;
The first instruction sets the carry flag to 1, the following instruction JMPs to end the code if the CF flag is set, the JB instruction needs to be patched to a NOP or the CF set to 0 to keep running the code.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;../2021-01-28-flare-on-1-challenge-4-sploitastic-images/Screen-Shot-2021-01-12-at-22.32.04.png&#34; alt=&#34;&#34; /&gt;&lt;br /&gt;
The code can be walked through until it loads the flag into the stack around offsec of +0x3c1 and it shows up in the register of ECX.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;../2021-01-28-flare-on-1-challenge-4-sploitastic-images/Screen-Shot-2021-01-12-at-22.36.20.png&#34; alt=&#34;&#34; /&gt;&lt;br /&gt;
&lt;img src=&#34;../2021-01-28-flare-on-1-challenge-4-sploitastic-images/Screen-Shot-2021-01-12-at-22.28.37.png&#34; alt=&#34;&#34; /&gt;&lt;br /&gt;
However, if you run the code until completion it shows up as junk in the message box that is displayed.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;../2021-01-28-flare-on-1-challenge-4-sploitastic-images/Screen-Shot-2021-01-12-at-22.29.34.png&#34; alt=&#34;&#34; /&gt;&lt;br /&gt;
To get the flag to show up in the message box you need to NOP the look starting at +0x3ce before the CALL to EAX.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;../2021-01-28-flare-on-1-challenge-4-sploitastic-images/Screen-Shot-2021-01-12-at-22.35.04.png&#34; alt=&#34;&#34; /&gt;&lt;br /&gt;
Now the flag shows up in the message box!&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;../2021-01-28-flare-on-1-challenge-4-sploitastic-images/Screen-Shot-2021-01-12-at-22.35.29.png&#34; alt=&#34;&#34; /&gt;&lt;/p&gt;
</content:encoded>
        <dc:creator>suidroot</dc:creator>
        <media:content url="https://ben.the-collective.net/images/post-images/Flare-on-Template-1-4.png" medium="image"><media:title type="html">featured image</media:title></media:content>
        
        
        
          
            
              <category>ctf</category>
            
          
            
              <category>flare-on</category>
            
          
            
              <category>python</category>
            
          
            
              <category>reverse engineering</category>
            
          
            
              <category>wireshark</category>
            
          
        
        
          
            
              <category>Reverse Engineering</category>
            
          
        
        
      </item>
      

    
  </channel>
</rss>
