Dockerized Flask API for securely remotely shutting down Windows machines via RPC.
1.1K
Rpc-shutdown is a Dockerized Flask-based service that provides a secure REST API for remotely shutting down Windows machines using the net rpc shutdown command. Designed for streamlined deployment and easy integration, this service ensures that only authorized users can execute shutdown commands, enhancing the security and manageability of your networked systems.
Docker Installed: Ensure Docker is installed on your system. Verify by running:
docker --version
Docker Compose Installed: Ensure Docker Compose is installed. Verify with:
docker compose version
First, log in to Docker Hub:
docker login
Then, pull the rpc-shutdown image:
docker pull lukcz/rpc-shutdown:latest
You can run the container using Docker Compose or directly with Docker.
Using Docker Compose:
Create a docker-compose.yml file:
version: '3.8'
services:
rpc-shutdown:
image: lukcz/rpc-shutdown:latest
container_name: rpc-shutdown
environment:
- API_KEY=your_actual_api_key # Replace with your actual API key
ports:
- "5000:5000"
restart: unless-stopped
Then, start the service:
docker compose up -d
Using Docker Run:
docker run -d \
--name rpc-shutdown \
-p 5000:5000 \
-e API_KEY=your_actual_api_key \ # Replace with your actual API key
lukcz/rpc-shutdown:latest
curl -H "x-api-key: your_actual_api_key" http://localhost:5000/status
Expected Response:
{
"status": "API is running"
}
Execute Shutdown Command without Delay:
curl -X POST http://localhost:5000/shutdown \
-H "Content-Type: application/json" \
-H "x-api-key: your_actual_api_key" \
-d '{
"target_ip": "192.168.1.100",
"username": "admin",
"password": "password123"
}'
Expected Response on Success:
{
"output": "Shutdown command executed successfully."
}
Execute Shutdown Command with Delay and Message:
curl -X POST http://localhost:5000/shutdown \
-H "Content-Type: application/json" \
-H "x-api-key: your_actual_api_key" \
-d '{
"target_ip": "192.168.1.100",
"username": "admin",
"password": "password123",
"delay": 300,
"message": "System maintenance in 5 minutes. Please save your work."
}'
Expected Response on Success:
{
"output": "Shutdown command executed successfully."
}
API_KEY: A strong, unique API key used to authenticate requests to the API.
Ensure this key is kept secret and is not exposed publicly.API Exposure: Since the API is exposed over HTTP on port 5000, ensure that access to this port is restricted to trusted networks or secured using additional network-level protections such as firewalls or VPNs.
API Key Management: Use a strong, unique API key and rotate it regularly to enhance security. Avoid hardcoding sensitive information; consider using Docker Secrets or environment variable files (.env) with proper access controls.
Least Privilege Principle: The Docker container runs the application as a non-root user to minimize potential security risks.
Logging and Monitoring: Regularly monitor the container logs to detect any unauthorized access attempts or anomalies.
docker logs rpc-shutdown
docker-compose.yml and any configuration files to prevent data loss.If the remote shutdown is not working, and you receive errors such as:
Could not initialise pipe winreg. Error was NT_STATUS_OBJECT_NAME_NOT_FOUNDShutdown of remote machine failed result was: WERR_CALL_NOT_IMPLEMENTEDYou may need to adjust settings on the Windows machine you're attempting to shut down.
The Remote Registry service must be running:
services.msc, and press Enter.Allow WMI through the firewall:
Add a specific registry key to allow remote shutdown:
Press Win + R, type regedit, and press Enter to open the Registry Editor.
Navigate to:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System
Right-click on the System folder, select New > DWORD (32-bit) Value.
Name it LocalAccountTokenFilterPolicy.
Double-click the new entry and set the Value data to 1.
Click OK and close the Registry Editor.
Restart the Windows Machine
After making the above changes, restart the Windows machine to ensure all settings take effect.
Permission Denied Errors:
docker group to run Docker commands without sudo.Container Name Conflicts:
smbd Command Not Found:
samba package is correctly installed in the Docker image. Rebuild the image if necessary.Rate Limiting Issues:
api_server.py if legitimate traffic is being restricted.MIT License
For any questions or support, please contact [email protected].
Content type
Image
Digest
sha256:2d95174ed…
Size
40.2 MB
Last updated
about 2 years ago
docker pull lukcz/rpc-shutdown:beta4