0

I don't understand why running the tcpdump program doesn't work but with other commands and programs it does, for example: Ping, openSSL, ...

When I run it for example with Ping and OpenSSL, data appears in the console, but tcpdump does nothing, it just ends and that's it.

Somebody could help me? Thanks.

const {spawn} = require('child_process');
spawn('tcpdump', ['-D']).stdout.on('data', (data) => console.log(data.toString()))

//spawn('ping', ['127.0.0.1']).stdout.on('data', (data) => console.log(data.toString()))
//spawn('openssl', ['req', '-x509', '-newkey','rsa:4096','-keyout', 'key.pem', '-out', 'cert.pem', '-days', '365']).stdout.on('data', (data) => console.log(data.toString()))
stillborn1
  • 507
  • 1
  • 4
  • 10
  • A guess. Perhaps tcpdump requires elevated privileges? – jfriend00 Feb 27 '21 at 17:31
  • Try logging `stderr` to see what it says. – jfriend00 Feb 27 '21 at 17:44
  • @jfriend00 It is necessary, but it is not the case, I have already tried giving permissions but it still does not do anything. I have also checked with stderr but there is no error, it does not show anything, it is very rare. I shared image: https://drive.google.com/file/d/1v3aKGmJ3m0gfw7uHYHHUsvuEty5c3BY2/view?usp=sharing – stillborn1 Feb 27 '21 at 18:03
  • And, tcpdump works when you just run it from the command line in a console? – jfriend00 Feb 27 '21 at 18:04
  • yes! I don't have any problem D: – stillborn1 Feb 27 '21 at 18:04
  • @jfriend00 Finally if it was user permissions problems, the problem is that I had used root privileges, but I have found that it does work if I use root permissions (which means "sudo su -"), thanks for your help :) – stillborn1 Feb 27 '21 at 21:30

1 Answers1

0

In the end the problem was due to permissions, but in my case it worked using the super user (root), tcpdump finally worked with some commands with root privileges, but not all of them could be used such as capturing traffic.

Keep in mind that you have the necessary permissions to be able to use the applications.

stillborn1
  • 507
  • 1
  • 4
  • 10