Team Ai
Apppublic

Nouussair/attack-surface-mapper

sourceHugging Faceupdated 5mo agoView on Hugging Face
0likes
App README

๐Ÿ” Attack Surface Mapper

A comprehensive Android APK security analysis tool that extracts manifests, detects vulnerabilities, and generates detailed security reports with ML-powered risk scoring.

๐Ÿ“‹ Features

  • โ€”โœ… APK Manifest Extraction - Parse Android manifests and extract components
  • โ€”โœ… Vulnerability Detection - Identify exposed components, risky permissions, debuggable apps
  • โ€”โœ… ML-Based Risk Scoring - Predict attack surface severity with scikit-learn
  • โ€”โœ… Interactive Web Interface - Upload APKs and view reports in real-time
  • โ€”โœ… Export Options - Download reports as HTML or PDF
  • โ€”โœ… Docker Support - Fully containerized for easy deployment
  • โ€”โœ… Graph Visualization - Mermaid-based component relationship graphs

๐Ÿš€ Quick Start (Docker - Recommended)

Prerequisites

  • โ€”Docker & Docker Desktop installed

Run the Web Interface

bash
docker build -t attack-surface-mapper .
docker run -p 5000:5000 attack-surface-mapper

Then open: http://localhost:5000

Upload an APK file and get a detailed security report instantly!


๐Ÿ’ป Local Development Setup

Prerequisites

  • โ€”Python 3.12+ (or 3.13+)
  • โ€”Virtual environment at .venv
  • โ€”Java (for apktool)
  • โ€”apktool.bat available at C:\xampp\htdocs\projet\apktool.bat

Installation

powershell
# Activate virtual environment
& ".venv\Scripts\Activate.ps1"

# Install dependencies
pip install -r requirements.txt

Run Tests

powershell
& ".venv\Scripts\python.exe" -m pytest tests\test_apk_extractor.py

Run CLI Parser (Example)

powershell
& ".venv\Scripts\python.exe" -c "from core.apk_extractor import analyze_apk; m = analyze_apk(r'C:\xampp\htdocs\projet\UnCrackable-Level2.apk'); print(m.package); print(len(m.activities)); print(len(m.services)); print(len(m.receivers)); print(len(m.providers))"

Expected result for UnCrackable Level 2:

Package: owasp.mstg.uncrackable2
Activities: 1
Services: 0
Receivers: 0
Providers: 0

Run Web Interface Locally

powershell
python ui_app.py

Then navigate to: http://localhost:5000


๐Ÿ“ Project Structure

attack-surface-mapper/
โ”œโ”€โ”€ core/                    # APK parsing & manifest extraction
โ”‚   โ”œโ”€โ”€ apk_extractor.py    # Main APK analysis
โ”‚   โ”œโ”€โ”€ manifest_parser.py  # Manifest XML parsing
โ”‚   โ”œโ”€โ”€ component_model.py  # Data models
โ”‚   โ””โ”€โ”€ test_parser.py
โ”œโ”€โ”€ detection/              # Security vulnerability detection
โ”‚   โ”œโ”€โ”€ risk_patterns.py    # Risk rule definitions
โ”‚   โ”œโ”€โ”€ pattern_registry.py # Pattern matching engine
โ”‚   โ””โ”€โ”€ fileprovider_checker.py
โ”œโ”€โ”€ ai/                     # ML-based threat scoring
โ”‚   โ”œโ”€โ”€ feature_extractor.py      # Feature engineering
โ”‚   โ”œโ”€โ”€ surface_scorer.py         # Risk scoring model
โ”‚   โ”œโ”€โ”€ predict_large_model.py    # Large model predictions
โ”‚   โ”œโ”€โ”€ explainer.py              # Model explainability
โ”‚   โ””โ”€โ”€ recommendation_engine.py  # Security recommendations
โ”œโ”€โ”€ graph/                  # Component visualization
โ”‚   โ”œโ”€โ”€ graph_model.py      # Graph structure
โ”‚   โ”œโ”€โ”€ mermaid_builder.py  # Mermaid diagram generation
โ”‚   โ””โ”€โ”€ graph_exporter.py   # Export formats
โ”œโ”€โ”€ reports/                # Report generation
โ”‚   โ””โ”€โ”€ report_generator.py # HTML report creation
โ”œโ”€โ”€ ui/                     # Web interface
โ”‚   โ”œโ”€โ”€ cli.py             # CLI commands
โ”‚   โ””โ”€โ”€ report_generator.py
โ”œโ”€โ”€ tests/                  # Unit & integration tests
โ”œโ”€โ”€ Dockerfile             # Docker configuration
โ”œโ”€โ”€ requirements.txt       # Python dependencies
โ”œโ”€โ”€ demo.py               # CLI demo script
โ”œโ”€โ”€ ui_app.py             # Flask web application
โ”œโ”€โ”€ main.py               # Entry point
โ””โ”€โ”€ config.yaml           # Configuration file

๐Ÿ” Team Task Breakdown

ComponentResponsibility
ParserValidate manifest extraction and component parsing (P1)
DetectionImprove risk rules and exported component checks (P2)
GraphVerify node/edge generation and export formats (P3)
AIML model training, feature engineering, and explainability (P4)
UIWeb interface improvements and report visualization

๐Ÿ“ Usage Examples

Docker (Recommended)

bash
# Build image
docker build -t attack-surface-mapper .

# Run with web interface
docker run -p 5000:5000 attack-surface-mapper

# Use different port if 5000 is busy
docker run -p 5001:5000 attack-surface-mapper
# Then access at http://localhost:5001

Local Python

bash
# Run CLI demo
python demo.py

# Run specific APK analysis
python -c "from demo import run_pipeline; run_pipeline('path/to/app.apk', 'output_report.html')"

# Run tests
pytest tests/ -v

โš™๏ธ Configuration

Edit config.yaml to customize:

  • โ€”Risk scoring thresholds
  • โ€”Graph visualization settings
  • โ€”Report templates
  • โ€”Security patterns and CWE mappings

๐Ÿ“Š Sample Report Output

The generated security report includes:

  • โ€”๐Ÿ“‹ APK metadata (package name, SDK version, etc.)
  • โ€”๐Ÿ”ด Critical/High/Medium/Low vulnerabilities
  • โ€”๐Ÿ“ˆ Attack surface scoring breakdown
  • โ€”๐Ÿ”— Component relationship graph
  • โ€”๐Ÿ’ก Security recommendations

๐Ÿ› ๏ธ Development Notes

  • โ€”The workspace uses .venv, not the global Python installation
  • โ€”Required packages: lxml, dataclasses-json, pytest, flask, androguard, scikit-learn
  • โ€”Docker image is based on python:3.12-slim with Java & apktool pre-installed
  • โ€”Flask development server runs on 0.0.0.0:5000 by default

๐Ÿ“ฆ Dependencies

See requirements.txt for the full list. Key dependencies:

  • โ€”androguard - APK analysis framework
  • โ€”lxml - XML parsing
  • โ€”scikit-learn - ML models
  • โ€”flask - Web framework
  • โ€”jinja2 - Template engine
  • โ€”pyyaml - Configuration
  • โ€”pytest - Testing framework
  • โ€”mermaid-cli - Graph visualization

๐Ÿ› Troubleshooting

Port 5000 already in use?

bash
docker run -p 5001:5000 attack-surface-mapper
# Access at http://localhost:5001

Docker build fails?

bash
docker build -t attack-surface-mapper . --no-cache

Test failures?

bash
pytest tests/ -v --tb=short

๐Ÿ“„ License

See LICENSE file for details.


๐Ÿ‘ฅ Contributing

  1. 1.Create a feature branch
  2. 2.Make your changes
  3. 3.Write/update tests
  4. 4.Ensure tests pass
  5. 5.Submit a pull request

Refer to the team task breakdown above for contribution areas.