π¦ Rusty Pipes Supply Chain Attack Demo
Educational Proof-of-Concept for Supply Chain Attack Demonstration
This project demonstrates the theoretical concepts behind supply chain attacks in the npm ecosystem, specifically the "Rusty Pipes" exploit described in the blog series. This is a harmless educational tool that demonstrates how a malicious package could inject Rust binaries into Node.js installations and spread across all projects.
β οΈ Educational Purpose Only
This project is designed for:
- Security researchers studying supply chain attacks
- Developers learning about npm security vulnerabilities
- Educational institutions teaching cybersecurity concepts
- Penetration testers understanding attack vectors
This tool does NOT execute any malicious code or cause harm to your system.
π― What This Demo Does
- Infects Node.js Installations: Compiles Rust code to
.nodebinaries and injects them into global Node.js installations - Creates Hidden Dependencies: Adds invisible dependencies to all npm projects on the system
- Injects Hidden Components: Adds React components that secretly load the hidden binaries
- Demonstrates Supply Chain Spread: Shows how one package can infect an entire development environment
ποΈ Architecture
rusty-pipes-demo/
βββ src/lib.rs # Rust library using Neon
βββ index.js # Node.js interface
βββ postinstall.js # Automatic execution script
βββ test.js # Test suite
βββ Cargo.toml # Rust dependencies
Key Components
- Rust Library: High-performance binary compilation and injection
- Neon Integration: Seamless Rust/Node.js interoperability
- Postinstall Hook: Demonstrates automatic execution on
npm install - Hidden Module System: Creates invisible dependencies in global node_modules
π Quick Start
Prerequisites
- Node.js 16+
- Rust toolchain
- npm or yarn
Installation
# Clone the repository
git clone <repository-url>
cd rusty-pipes-demo
# Install dependencies
npm install
# Build the Rust binary
npm run build
# Run the demo
npm test
Manual Testing
# Run the main demo
node index.js
# Simulate postinstall behavior
npm run postinstall
# Run the test suite
npm test
π How the Supply Chain Attack Works
1. Binary Injection
The Rust library compiles to a .node binary and injects it into Node.js installations:
/usr/local/lib/node_modules/@hidden/rusty-pipes-core/index.node/usr/lib/node_modules/@hidden/rusty-pipes-core/index.node
2. Hidden Dependency Creation
Every npm project's package.json gets silently modified to include:
{
"dependencies": {
"@hidden/rusty-pipes-core": "^1.0.0"
}
}
3. Component Injection
React components get injected that secretly load the hidden binary:
import React from 'react';
import '@hidden/rusty-pipes-core'; // β Hidden dependency
const SystemUtils = () => {
// Component appears normal but loads our binary
return <div style={{ display: 'none' }} />;
};
4. Supply Chain Spread
Once infected, every project the developer works on will:
- Automatically include the hidden dependency
- Load the Rust binary invisibly
- Spread the infection to new projects
π‘οΈ Security Implications
This demo illustrates several critical security concerns:
- Binary Injection: npm packages can inject compiled binaries into system directories
- Hidden Dependencies: Dependencies can be added silently to all projects
- Global Infection: One package can infect an entire development environment
- Persistent Spread: Infections persist across projects and installations
- Invisible Execution: Malicious code runs without user knowledge
π οΈ Mitigation Strategies
For Developers
- Audit Dependencies: Use
npm auditandnpm lsregularly - Lock Files: Use
package-lock.jsonoryarn.lockand commit them - Ignore Scripts: Use
--ignore-scriptswhen possible - Sandboxed Environments: Use containers or VMs for development
- Monitor Changes: Track changes to
package.jsonfiles
For Organizations
- Dependency Scanning: Implement automated security scanning
- Approved Packages: Maintain a whitelist of trusted packages
- Network Isolation: Limit internet access in development environments
- Regular Updates: Keep dependencies updated
- Binary Analysis: Scan for suspicious
.nodefiles in node_modules
π Educational Resources
- Original Rusty Pipes Blog Series
- npm Security Best Practices
- Supply Chain Attack Prevention
- Neon Rust/Node.js Integration
π¬ Technical Details
Rust Implementation
The Rust code uses:
- Neon: For Node.js integration and binary compilation
- walkdir: For efficient directory traversal
- serde_json: For JSON parsing and modification
- std::fs: For file system operations and binary injection
Node.js Integration
The Node.js layer provides:
- Error Handling: Graceful fallbacks when Rust binary is unavailable
- Async Operations: Non-blocking file system operations
- Logging: Detailed output for educational purposes
- Postinstall Automation: Demonstrates automatic execution
Hidden Module System
The hidden module system:
- Creates
@hidden/rusty-pipes-corein global node_modules - Compiles Rust code to
.nodebinary - Modifies all
package.jsonfiles to include the dependency - Injects React components that load the binary
π§ͺ Testing
The project includes comprehensive tests:
# Run all tests
npm test
# Test specific functionality
node test.js
# Create mock React project for testing
node -e "require('./test').createMockReactProject()"
# Test hidden dependency mechanism
node -e "require('./test').testHiddenDependency()"
π License
MIT License - This project is for educational purposes only.
π€ Contributing
Contributions are welcome! Please ensure all code changes maintain the educational and non-malicious nature of this project.
βοΈ Disclaimer
This software is provided "as is" for educational purposes only. The authors are not responsible for any misuse of this software. Users should only run this in controlled, isolated environments for learning purposes.
Remember: This is a proof-of-concept designed to educate developers about supply chain security. Always use in isolated testing environments.