Skip to content

Latest commit

Β 

History

7 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

LibPass: An Entropy-Guided Black-Box Adversarial Attack against Third-Party Library Detection Tools

License Java Python

LibPass is a black-box adversarial attack framework designed to evade third-party library (TPL) detection tools. It uses entropy-guided perturbation strategies to generate adversarial APKs that can bypass state-of-the-art TPL detection tools while maintaining functionality.

πŸ“„ Paper

This repository contains the implementation of the following paper:

"LibPass: An Entropy-Guided Black-Box Adversarial Attack against Third-Party Library Detection Tools in the Wild"

Citation

If you use LibPass in your research, please cite our paper:

@article{libpass2025,
  title={LibPass: An Entropy-Guided Black-Box Adversarial Attack against Third-Party Library Detection Tools in the Wild},
  author={Zhou, Jian and others},
  journal={IEEE Transactions on Dependable and Secure Computing},
  year={2025},
  publisher={IEEE Computer Society}
}

✨ Features

  • 🎯 Black-Box Attack: Works without knowledge of the detection tool's internal mechanisms
  • πŸ“Š Entropy-Guided Search: Uses graph entropy (dependency entropy and structural entropy) to guide perturbation search
  • πŸ”„ Firefly Algorithm: Enhanced Firefly algorithm with KDTree spatial indexing for efficient perturbation search
  • πŸ›‘οΈ Function-Preserving Perturbations: Adds and merges nodes while maintaining APK functionality
  • πŸ” Multi-Detector Support: Supports multiple TPL detection tools:
    • LibScan: Signature-based detection
    • LibLoom: Bloom filter-based detection
    • LibPecker: Profile-based detection
    • LibHunter: Graph-based detection
    • LiteRadar: Lightweight detection
  • ⚑ Parallel Execution: Multi-threaded batch processing for efficient large-scale attacks
  • πŸ“ˆ Attack Modes:
    • black_box: Uses detector confidence scores
    • black_box_plus: Uses graph entropy for guidance
  • 🎚️ Attack Levels:
    • library_level: Evade entire library detection
    • version_level: Evade specific version detection
  • πŸ“ Comprehensive Logging: Configurable log levels with detailed attack statistics

πŸ—οΈ Architecture

Core Components

  1. TPL Decoupler: Identifies and isolates third-party library classes from app code
  2. Heterogeneous Graph Builder: Constructs multi-typed graphs capturing semantic and structural information
  3. Entropy Calculator: Computes dependency entropy and structural entropy to quantify graph complexity
  4. Perturbation Applier: Applies function-preserving perturbations (add/merge operations)
  5. Firefly Algorithm: Searches for optimal perturbation sequences using entropy as fitness function
  6. APK Repackager: Converts modified Jimple code back to DEX and repackages APK

Attack Flow

APK Input β†’ TPL Decoupling β†’ Graph Construction β†’ Entropy Calculation 
    β†’ Firefly Search β†’ Perturbation Application β†’ APK Repackaging 
    β†’ Detection Verification β†’ Adversarial APK Output

πŸ“‹ Requirements

  • Java: 11 or higher
  • Python: 3.7 or higher
  • Gradle: 6.0+ (or use included Gradle Wrapper)
  • Android SDK: For android.jar files (API level 20+)
  • Soot Framework: 4.5.0

πŸš€ Quick Start

1. Clone the Repository

git clone https://github.com/yourusername/LibPass.git
cd LibPass/src

2. Install Dependencies

# Install Python dependencies
pip install -r requirements.txt

# Build Java project
./gradlew build

3. Configure Android SDK

Download Android SDK and set the path to android.jar:

# Example: Android API 30
export ANDROID_JAR=/path/to/android-sdk/platforms/android-30/android.jar

4. Run a Single Attack

java -cp build/libs/src-1.0.0.jar \
    com.libpass.attack.AutomatedAttackMain \
    apk \
    /path/to/app.apk \
    /path/to/library.jar \
    library-name \
    /path/to/android.jar \
    ./output \
    LibScan \
    100 \
    INFO \
    1 \
    black_box \
    library_level

5. Run Batch Attacks

java -cp build/libs/src-1.0.0.jar \
    com.libpass.attack.AutomatedAttackMain \
    groundtruth \
    /path/to/groundtruth.txt \
    /path/to/apks/ \
    /path/to/libraries/ \
    /path/to/android.jar \
    ./output \
    LibScan \
    100 \
    INFO \
    4 \
    black_box \
    library_level

πŸ“– Usage

Command-Line Interface

Single APK Attack

java -cp build/libs/src-1.0.0.jar \
    com.libpass.attack.AutomatedAttackMain \
    <mode> <apk_path> <tpl_path> <tpl_name> <android_jar> <output_dir> \
    [detector_type] [max_iterations] [log_level] [parallel_workers] \
    [attack_mode] [attack_level]

Parameters:

  • mode: apk for single/batch APK attack
  • apk_path: Path to APK file or directory
  • tpl_path: Path to TPL JAR/DEX file
  • tpl_name: Name of the target library
  • android_jar: Path to Android JAR file
  • output_dir: Output directory for adversarial APKs
  • detector_type: LibScan, LibLoom, LibPecker, LibHunter, or LiteRadar (default: LibScan)
  • max_iterations: Maximum attack iterations (default: 100)
  • log_level: ERROR, WARNING, INFO, or DEBUG (default: INFO)
  • parallel_workers: Number of parallel workers (default: 1)
  • attack_mode: black_box or black_box_plus (default: black_box)
  • attack_level: library_level or version_level (default: library_level)

GroundTruth Batch Attack

java -cp build/libs/src-1.0.0.jar \
    com.libpass.attack.AutomatedAttackMain \
    groundtruth \
    <groundtruth_file> <apk_base_dir> <tpl_base_dir> <android_jar> <output_dir> \
    [detector_type] [max_iterations] [log_level] [parallel_workers] \
    [attack_mode] [attack_level]

GroundTruth File Format:

apk1.apk:library1,library2
apk2.apk:library3
...

Attack Modes

Black-Box Mode (black_box)

  • Uses detector confidence scores to guide attacks
  • Stops when confidence drops below threshold
  • Faster execution

Black-Box Plus Mode (black_box_plus)

  • Uses graph entropy for perturbation guidance
  • More sophisticated search strategy
  • Higher success rate

Attack Levels

Library-Level Attack (library_level)

  • Goal: Make the entire library undetectable
  • Success: Library not detected by the detector

Version-Level Attack (version_level)

  • Goal: Change detected version or make library undetectable
  • Success: Library not detected OR wrong version detected

πŸ“ Project Structure

src/
β”œβ”€β”€ java/                                    # Java source code
β”‚   └── com/libpass/attack/
β”‚       β”œβ”€β”€ attack/                          # Core attack engine and configuration
β”‚       β”‚   β”œβ”€β”€ LibPassAttackEngine.java     
β”‚       β”‚   β”œβ”€β”€ AttackMode.java              
β”‚       β”‚   β”œβ”€β”€ AttackLevel.java             
β”‚       β”‚   └── AttackResult.java            
β”‚       β”œβ”€β”€ automation/                      # Automated attack orchestration and batch processing
β”‚       β”‚   β”œβ”€β”€ AutomatedAttackEngine.java   
β”‚       β”‚   β”œβ”€β”€ AutomatedAttackMain.java     
β”‚       β”‚   β”œβ”€β”€ AutomatedAttackResult.java   
β”‚       β”‚   β”œβ”€β”€ BatchAttackResult.java       
β”‚       β”‚   β”œβ”€β”€ GroundTruthBatchAttackResult.java  
β”‚       β”‚   └── AttackStatistics.java        
β”‚       β”œβ”€β”€ detector/                        # TPL detector adapters and interfaces
β”‚       β”‚   β”œβ”€β”€ TPLDetector.java             
β”‚       β”‚   β”œβ”€β”€ DetectionResult.java         
β”‚       β”‚   β”œβ”€β”€ LibScanDetector.java         
β”‚       β”‚   β”œβ”€β”€ LibLoomDetector.java         
β”‚       β”‚   β”œβ”€β”€ LibPeckerDetector.java       
β”‚       β”‚   β”œβ”€β”€ LibHunterDetector.java       
β”‚       β”‚   └── LiteRadarDetector.java       
β”‚       β”œβ”€β”€ perturbation/                    # Perturbation operations and application
β”‚       β”‚   β”œβ”€β”€ AddingPerturbation.java      
β”‚       β”‚   β”œβ”€β”€ MergingPerturbation.java     
β”‚       β”‚   β”œβ”€β”€ PerturbationApplier.java     
β”‚       β”‚   β”œβ”€β”€ ModificationLogger.java      
β”‚       β”‚   └── CallSiteUpdater.java         
β”‚       β”œβ”€β”€ apk/                             # APK processing utilities
β”‚       β”‚   β”œβ”€β”€ APKRepackager.java           
β”‚       β”‚   └── APKSigner.java               
β”‚       β”œβ”€β”€ graph/                           # Graph structures for dependency analysis
β”‚       β”‚   β”œβ”€β”€ HeterogeneousGraph.java      
β”‚       β”‚   β”œβ”€β”€ GraphNode.java               
β”‚       β”‚   └── GraphBuilder.java            
β”‚       β”œβ”€β”€ firefly/                         # Firefly algorithm for optimization
β”‚       β”‚   β”œβ”€β”€ FireflyAlgorithm.java        
β”‚       β”‚   β”œβ”€β”€ Firefly.java                 
β”‚       β”‚   └── KDTree.java                  
β”‚       β”œβ”€β”€ entropy/                         # Entropy calculation for code metrics
β”‚       β”‚   └── GraphEntropyCalculator.java  
β”‚       β”œβ”€β”€ decoupling/                      # TPL decoupling utilities
β”‚       β”‚   └── TPLDecoupler.java            
β”‚       β”œβ”€β”€ util/                            # Utility classes
β”‚       β”‚   └── Logger.java                  
β”‚       β”œβ”€β”€ AttackStrategy.java              # Attack strategy interface
β”‚       β”œβ”€β”€ AttackConfig.java                # Attack configuration
β”‚       β”œβ”€β”€ AttackResult.java                # Attack result (legacy)
β”‚       β”œβ”€β”€ APKModifier.java                 # APK modification utilities
β”‚       └── AutomatedAttackMain.java         # Main entry point for automated attacks (command line)
β”œβ”€β”€ TPL_Detectors/                 # Third-party detection tools
β”‚   β”œβ”€β”€ LibScan/                   # LibScan tool
β”‚   β”œβ”€β”€ LIBLOOM/                   # LibLoom tool
β”‚   β”œβ”€β”€ LibPecker/                 # LibPecker tool
β”‚   β”œβ”€β”€ LibHunter/                 # LibHunter tool
β”‚   └── LiteRadar/                 # LiteRadar tool
β”œβ”€β”€ python/                        # Python scripts
β”‚   β”œβ”€β”€ automated_attack.py
β”‚   └── evaluator.py
β”œβ”€β”€ build.gradle                   # Build configuration
β”œβ”€β”€ requirements.txt               # Python dependencies
β”œβ”€β”€ validate_apk.sh                # End-to-end APK functionality validation
β”œβ”€β”€ sign_apk.sh                    # APK signing tool
β”œβ”€β”€ LICENSE
└── README.md                      

πŸ“Š Results

The attack generates:

  • Adversarial APKs: Modified APKs that evade detection
  • Attack Statistics: Success rate, perturbation count, execution time
  • Detailed Logs: Per-iteration attack progress and results

Example output:

Task #1: SUCCESS - final_confidence=0.000000, perturbations=5, time=12000 ms, types=[add_class, merge_method]
Task #2: FAILED - final_confidence=0.850000, perturbations=100, time=45000 ms

⚠️ Important Notice

This tool is intended for academic research and security testing purposes only.

  • Use only with proper authorization
  • Comply with applicable laws and regulations
  • Follow ethical guidelines for security research

About

Source code for the paper "LibPass: An Entropy-Guided Black-Box Adversarial Attack against Third-Party Library Detection Tools"

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Contributors

Languages