admin管理员组文章数量:1335861
I am creating a nestjs app that uses node-nmap-hosts
npm package to scan a network for connected devices but keeps getting an error of root privileges when I start my server.
Here is the code that runs the scan
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { INestApplication, ValidationPipe } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
import { runNmapScan } from 'node-nmap-hosts';
runNmapScan('192.168.1.1/24', [])
.then((data) => {
console.log('Nmap Scan Data:', data);
})
.catch((error) => {
console.error('Error during Nmap Scan:', error);
});
async function bootstrap() {
const app: INestApplication = await NestFactory.create(AppModule);
const config = new DocumentBuilder()
.setTitle('AccionMFB Asset Register API')
.setDescription('The AccionMFB Asset Register API description')
.setVersion('0.1')
.build();
const document = SwaggerModule.createDocument(app, config);
SwaggerModule.setup('', app, document);
app.useGlobalPipes(new ValidationPipe({ whitelist: true }));
const configService = app.get(ConfigService);
await app.listen(configService.get<string>('PORT'));
console.log(`Application is running on: ${await app.getUrl()}`);
}
bootstrap();
When I run npm run start:dev
this error message is thrown
Execution Error: Error: Command failed: nmap -sS -T2 -O --osscan-guess -p -sV -oX - 192.168.1.1/24
You requested a scan type which requires root privileges.
QUITTING!
at genericNodeError (node:internal/errors:983:15)
at wrappedFn (node:internal/errors:537:14)
at ChildProcess.exithandler (node:child_process:419:12)
at ChildProcess.emit (node:events:518:28)
at maybeClose (node:internal/child_process:1104:16)
at Socket.<anonymous> (node:internal/child_process:456:11)
at Socket.emit (node:events:518:28)
at Pipe.<anonymous> (node:net:343:12) {
code: 1,
killed: false,
signal: null,
cmd: 'nmap -sS -T2 -O --osscan-guess -p -sV -oX - 192.168.1.1/24'
}
Error during Nmap Scan: Error: Command failed: nmap -sS -T2 -O --osscan-guess -p -sV -oX - 192.168.1.1/24
You requested a scan type which requires root privileges.
QUITTING!
at genericNodeError (node:internal/errors:983:15)
at wrappedFn (node:internal/errors:537:14)
at ChildProcess.exithandler (node:child_process:419:12)
at ChildProcess.emit (node:events:518:28)
at maybeClose (node:internal/child_process:1104:16)
at Socket.<anonymous> (node:internal/child_process:456:11)
at Socket.emit (node:events:518:28)
at Pipe.<anonymous> (node:net:343:12) {
code: 1,
killed: false,
signal: null,
cmd: 'nmap -sS -T2 -O --osscan-guess -p -sV -oX - 192.168.1.1/24'
}
npm run start dev
is a script to execute nest start --watch
The runNmapScan
is internally calling nmap -sS -T2 -O --osscan-guess -p -sV -oX - 192.168.1.1/24
which require the sudo access.
I have tried running sudo npm run start:dev
after inputing the password it returned sudo: npm: command not found
, tried modifying my sudoers
file to grant access to any program calling nmap
internally but the error persist.
I need assistance on how i can run the program with sudo or preventing the prompt for sudo access.
本文标签: nodejsRunning a nestjs app using nmap with a sudo accessStack Overflow
版权声明:本文标题:node.js - Running a nestjs app using nmap with a sudo access - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742394523a2466651.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论