TRIGGERcmd
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    Run your commands without the Internet

    General Discussion
    1
    1
    124
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • RussR
      Russ
      last edited by Russ

      I'm not sure how useful this is given that Internet is usually available, but here's something I've experimented with.

      It allows you to trigger commands you've created with your TRIGGERcmd agent from a separate computer on your network.

      Run the server.js script with this command:

      node.exe server.js
      

      Then run your commands from another computer on your network with curl commands like this:

      curl -v -H "Authorization: Basic YWRtaW46cGFzc3dvcmQ=" http://(IP address):3000/api?trigger=Calculator
      

      server.js contents:

      var cp = require('child_process');
      const http = require('http');
      const url = require('url');
      const os = require('os');
      const path = require('path');
      
      const homeFolder = os.homedir();
      const fileName = '.TRIGGERcmdData\\commands.json';
      const filePath = path.join(homeFolder, fileName);
      const data = require(filePath);
      
      // Define your authentication credentials
      const username = 'admin';
      const password = 'password';
      
      // Function to handle HTTP requests
      const server = http.createServer((req, res) => {
          const parsedUrl = url.parse(req.url, true);
      
          // Check if the request is for the API endpoint
          if (parsedUrl.pathname === '/api' && req.method === 'GET') {
              // Check if authentication credentials are provided
              const auth = req.headers['authorization'];
              if (!auth || auth !== `Basic ${Buffer.from(`${username}:${password}`).toString('base64')}`) {
                  res.statusCode = 401;
                  res.setHeader('WWW-Authenticate', 'Basic realm="Restricted"');
                  res.end('Unauthorized');
                  return;
              }
      
              // Get the trigger from the query string
              const trigger = parsedUrl.query.trigger;
      
              // Find the corresponding value in the array of objects
              const result = data.find(obj => obj.trigger === trigger);
      
              // Check if the trigger exists, and if it does, run the command.
              if (result) {
                  theCommand = result.command
                  envVars = {'TCMD_CLIENT': 'local-network'}
                  var ChildProcess = cp.exec(theCommand, {env: envVars});
                  res.setHeader('Content-Type', 'application/json');
                  res.end(JSON.stringify("Command ran."));
              } else {
                  res.statusCode = 404;
                  res.end('trigger not found');
              }
          } else {
              res.statusCode = 404;
              res.end('Not Found');
          }
      });
      
      // Start the server
      const PORT = process.env.PORT || 3000;
      server.listen(PORT, () => {
          console.log(`Server is running on port ${PORT}`);
      });
      

      I used this site to generate that YWRtaW46cGFzc3dvcmQ= string for authentication. It's basically "admin:password" converted to base64.
      https://www.debugbear.com/basic-auth-header-generator

      Russell VanderMey

      1 Reply Last reply Reply Quote 0
      • First post
        Last post