Kill Switch
How to Create a Kill Switch with JavaScript and a Backend Server
Are you looking for a way to remotely trigger system-level actions using JavaScript? In this tutorial, we'll walk you through creating a basic kill switch that can shut down a system, kill a process, or disable a network interface. This is achieved by sending requests from JavaScript on a Blogger page to a backend server. We'll also introduce some advanced features available in the Pro version.
Step-by-Step Guide
1. Backend Setup
First, you need to set up a backend server that can handle requests and perform the desired system-level actions. We'll use Flask, a Python web framework, for this example.
Install Flask:
pip install flask
Create the Flask Application:
Create a file named app.py
with the following content:
from flask import Flask, request
import os
import signal
import subprocess
app = Flask(__name__)
@app.route('/shutdown', methods=['POST'])
def shutdown():
if os.name == 'nt':
os.system('shutdown /s /f /t 0')
else:
os.system('sudo shutdown -h now')
return "Shutdown initiated", 200
@app.route('/kill', methods=['POST'])
def kill_process():
process_name = request.json.get('process_name')
if process_name:
for line in os.popen("ps ax | grep " + process_name + " | grep -v grep"):
fields = line.split()
pid = fields[0]
os.kill(int(pid), signal.SIGKILL)
return f"Process {process_name} killed", 200
return "Process name not provided", 400
@app.route('/disable_network', methods=['POST'])
def disable_network():
interface = request.json.get('interface')
if interface:
if os.name == 'nt':
os.system(f'netsh interface set interface "{interface}" admin=disable')
else:
os.system(f'sudo ifconfig {interface} down')
return f"Network interface {interface} disabled", 200
return "Interface not provided", 400
if __name__ == '__main__':
app.run(host='0.0.0.0', port=21515)
Run the Flask App:
python app.py
2. API Endpoint
Your backend server now has three endpoints:
/shutdown
for shutting down the system/kill
for killing a process/disable_network
for disabling a network interface
3. JavaScript on Blogger
Embed JavaScript in your Blogger page to call these endpoints.
HTML and JavaScript:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Kill Switch</title>
</head>
<body>
<button id="shutdownBtn">Shutdown</button>
<button id="killProcessBtn">Kill Process</button>
<button id="disableNetworkBtn">Disable Network</button>
<script>
document.getElementById('shutdownBtn').addEventListener('click', function() {
fetch('http://your-server-ip:21515/shutdown', {
method: 'POST'
}).then(response => {
console.log('Shutdown response:', response);
}).catch(error => {
console.error('Error:', error);
});
});
document.getElementById('killProcessBtn').addEventListener('click', function() {
const processName = prompt("Enter the process name to kill:");
fetch('http://your-server-ip:21515/kill', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ process_name: processName })
}).then(response => {
console.log('Kill process response:', response);
}).catch(error => {
console.error('Error:', error);
});
});
document.getElementById('disableNetworkBtn').addEventListener('click', function() {
const interfaceName = prompt("Enter the network interface to disable:");
fetch('http://your-server-ip:21515/disable_network', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ interface: interfaceName })
}).then(response => {
console.log('Disable network response:', response);
}).catch(error => {
console.error('Error:', error);
});
});
</script>
</body>
</html>
Pro Version Features
The Pro version of this kill switch includes advanced features such as:
- Role-Based Access Control: Define roles and permissions for different users.
- Logging and Monitoring: Keep track of all actions triggered through the kill switch.
- Advanced Security Measures: Enhanced authentication mechanisms, such as OAuth or token-based authentication.
- Custom Actions: Define and trigger custom actions specific to your needs.
Upgrade to the Pro version to get these features and ensure robust and secure management of your system-level actions.