mizazhaider-ceh/agentarsenal/hash-length-extension

Claude Code and agent skill by mizazhaider-ceh/agentarsenal

Trust tier 3
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

Use when testing for hash length extension attacks on an

Install

npx vskill@latest install mizazhaider-ceh/agentarsenal/hash-length-extension

SKILL.md

The same SKILL.md was published earlier as mizazhaider-ceh/agentarsenal/hash-length-extension.

Hash length extension exploits Merkle Damgard hashes (MD5, SHA-1, SHA-256): given hash(secret + message), an attacker can compute hash(secret + message + padding + extension) without knowing the secret. This skill covers authorized testing: spotting the vulnerable construction, forging payloads, and recommending HMAC. Test only systems you may assess.

Quick Workflow

  1. Find the construction: hash(secret + message) used as a MAC, in

URLs, cookies, or API signatures.

  1. Confirm the hash function is Merkle Damgard (MD5, SHA-1,

SHA-256).

  1. Get a valid (message, hash) pair from normal use.
  2. Forge: append your extension with the right padding for a

guessed secret length.

  1. Try secret lengths across the plausible range; the server tells

you when you hit it.

  1. Prove impact with the forged payload (authorized target).
  2. Recommend HMAC with a proper key, or a non extendable hash.
  3. Document the exact forgery that worked.

1. Forging the payload

python
#!/usr/bin/env python3
"""Length extension forge (hashlib only; authorized targets)."""
import hashlib, struct
def md_pad(msg_len):
pad = b"\x80"
pad += b"\x00" * ((56 - (msg_len + 1) % 64) % 64)
pad += struct.pack(">Q", msg_len * 8)
return pad
def forge(orig_msg, orig_hex, extension, secret_len):
# reconstruct the internal state is complex in pure hashlib;
# use the standard approach: this sketch shows the padding math
glue = md_pad(secret_len + len(orig_msg))
forged_msg = orig_msg + glue + extension
print(f"try secret_len={secret_len}: forged length {len(forged_msg)}")
return forged_msg
# In practice use hashpump/hash_extender as assessment tooling:
# hashpump -s <orig_hex> -d <orig_msg> -a <extension> -k <secret_len>
print("tooling: hashpump computes the extended hash for each secret length")
bash
# Workflow with hashpump (assessment tooling, authorized target):
# 1. capture a signed URL: /download?file=a.pdf&sig=abc123
# 2. for k in 8 10 12 14 16 20 24 32; do
# hashpump -s abc123 -d "file=a.pdf" -a "&admin=1" -k $k
# done
# 3. try each forged (msg, sig); the one the server accepts reveals k
for k in 8 10 12 14 16 20 24 32; do echo "secret length candidate: $k"; done

2. Code review for the pattern

bash
# Search for the vulnerable construction
grep -rn "sha256(secret\|md5(secret\|hashlib.*secret.*+\|secret.*+.*message" \
--include="*.py" --include="*.js" --include="*.php" src/ | head -20
# Vulnerable: sig = sha256(SECRET + params)
# Safe: hmac.new(SECRET, params, sha256).hexdigest()

Edge cases

  • The hash is SHA-3 or BLAKE2. Not vulnerable to extension; verify

the algorithm before claiming.

  • The secret length is unusual. Extend the candidate range; the

server's acceptance is the oracle.

  • The MAC includes a length prefix or uses HMAC already. Then it is

safe; verify the HMAC key handling instead.

Escalation

  • Forgery works: demonstrate the impact (privilege parameter,

file path) once, then stop.

  • Construction unclear: test with a chosen message pair to

distinguish HMAC from plain hash.

Detection and defender view

Defenders see length extension as requests with unusually long signed parameters that still validate. The fix is constructional: HMAC-SHA-256 with a secret key, never hash(secret + message). Detect the pattern in code review with the grep above, and in traffic by validating that signed payloads match expected formats.

Key references

  • CWE-328 (Use of Weak Hash): Merkle Damgard MAC misuse.
  • CWE-354 (Improper Validation of Integrity Check Value).
  • Length extension attack literature (Ferguson-Schneier).

Security

  • Security scanPassed, 90 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

7-day trend score
0

Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/mizazhaider-ceh/agentarsenal/hash-length-extension/badge)](https://verified-skill.com/skills/mizazhaider-ceh/agentarsenal/hash-length-extension)

Something wrong with this skill or its page? Tell us.