Type Confusion Detection
Detection Workflow
- Identify type operations: Find all type casts, virtual function calls, union usage, class hierarchies
- Analyze type safety: Check cast validation, assess vtable integrity, verify union usage correctness
- Trace object flow: Use
xrefs_to to trace objects, identify type changes, assess type consistency
- Assess exploitability: Can attacker control object type? Is there useful type confusion? Can attacker corrupt vtable?
Key Patterns
- Unsafe type casting: C-style casts without validation, reinterpret_cast without checks
- Vtable corruption: virtual function calls on corrupted objects, vtable pointer manipulation
- Union misuse: writing to one union member, reading another
- Polymorphism issues: base pointer used as derived without dynamic_cast
Output Format
Report with: id, type, subtype, severity, confidence, location, vulnerability, cast operation, base type, derived type, validation, vtable access, exploitability, attack scenario, impact, mitigation.
Severity Guidelines
- CRITICAL: Type confusion with code execution
- HIGH: Type confusion with data corruption
- MEDIUM: Type confusion with limited impact
- LOW: Type confusion with minor issues
See Also
patterns.md - Detailed detection patterns and exploitation scenarios
examples.md - Example analysis cases and code samples
references.md - CWE references and mitigation strategies
1---
2name: detecting-type-confusion
3description: Detects type confusion vulnerabilities by identifying unsafe type casts, vtable corruption, and polymorphism issues. Use when analyzing object-oriented code, type casting, or investigating C++ memory safety issues.
4metadata:
5 source: https://skillmd.com/skills/aibot88/detecting-type-confusion
6---
7
8# Type Confusion Detection
9
10## Detection Workflow
11
121. **Identify type operations**: Find all type casts, virtual function calls, union usage, class hierarchies
132. **Analyze type safety**: Check cast validation, assess vtable integrity, verify union usage correctness
143. **Trace object flow**: Use `xrefs_to` to trace objects, identify type changes, assess type consistency
154. **Assess exploitability**: Can attacker control object type? Is there useful type confusion? Can attacker corrupt vtable?
16
17## Key Patterns
18
19- Unsafe type casting: C-style casts without validation, reinterpret_cast without checks
20- Vtable corruption: virtual function calls on corrupted objects, vtable pointer manipulation
21- Union misuse: writing to one union member, reading another
22- Polymorphism issues: base pointer used as derived without dynamic_cast
23
24## Output Format
25
26Report with: id, type, subtype, severity, confidence, location, vulnerability, cast operation, base type, derived type, validation, vtable access, exploitability, attack scenario, impact, mitigation.
27
28## Severity Guidelines
29
30- **CRITICAL**: Type confusion with code execution
31- **HIGH**: Type confusion with data corruption
32- **MEDIUM**: Type confusion with limited impact
33- **LOW**: Type confusion with minor issues
34
35## See Also
36
37- `patterns.md` - Detailed detection patterns and exploitation scenarios
38- `examples.md` - Example analysis cases and code samples
39- `references.md` - CWE references and mitigation strategies