Unexpected behaviour with exec code node

Describe the issue/error/question

I’m running multiple exec code nodes in a workflow. In one of them, i’m trying to execute ‘naabu’ (GitHub - projectdiscovery/naabu: A fast port scanner written in go with a focus on reliability and simplicity. Designed to be used in combination with other tools for attack surface discovery in bug bounties and pentests) in the same way as in other exec code which work without issue.
Funnily for that naabu execution, it starts as expected, I can see the process running with ps, but it does not seem to do anything, and execution never stops.
I can run naabu on the host where n8n lives without problems.

What is the error message (if any)?

No error logs at all

Please share the workflow

{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        240,
        300
      ]
    },
    {
      "parameters": {
        "command": "naabu localhost"
      },
      "name": "Execute Command",
      "type": "n8n-nodes-base.executeCommand",
      "typeVersion": 1,
      "position": [
        460,
        300
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Execute Command",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Share the output returned by the last node

Information on your n8n setup

  • n8n version: 0.155.2
  • Database you’re using (default: SQLite): sqlite
  • Running n8n with the execution process [own(default), main]: own
  • Running n8n via [Docker, npm, n8n.cloud, desktop app]: npm

Hi @biastogit, welcome to the community :tada:

Sorry to hear you’re having trouble. I am not familiar with naabu, is it possibly waiting for any user input under certain circumstances (e.g. when running with your n8n user/non-root privileges)?

Hi,
Thanks a lot for your quick reply!

It’s not waiting for input, when run without any arguments, it should reply with an error message (it does when running on the docker host running n8n):

The same executed from the workflow shows a never ending execution:

image

n8n is running as root and the only difference I noticed between the n8n exec environment and the host was no $SHELL variable and a shorter env.

I tried to set the $SHELL with ‘export SHELL=/bin/sh && naabu’ but it reacts exactly the same (never ending execution)

I just noticed now that it seems to be related to the port scan execution itself as if I run
naabu -h or naabu -version, i behaves as expected; but any option that triggers the port scan will end in the never ending execution (I have let it run for more than 10 minutes for an execution that takes 10 seconds on the host).

1 Like

Good observation! I just tested this without n8n at all, executing the below javascript snippet using Node.js:

const { exec } = require('child_process');

exec('./naabu -p 80,5678 -host localhost', (error, stdout, stderr) => {
    console.log('stdout:', stdout);
    console.log('stderr:', stderr);
});

The behaviour was the same, the script wouldn’t finish (until running pkill -f naabu that is) while other naabu commands not initiating the scan work fine. So with this being a problem outside of n8n as well, I am not sure if there’s much we could do.

Would you perhaps be able to alternatively use the ssh node to run this particular program?

1 Like

Thanks a lot for that quick and very detailed answer !

Your suggestion is awesome and does totally satisfy my needs. I’ll just have to find a way to modify my deployment scripts to have the sshd settings allowing the ssh connection…
But I just tested it and that works perfectly :smiley:

Thanks again for the great project and awesome support !

1 Like

Awesome, glad to hear this works for you, thanks so much for confirming!