Skip to content

Commit 2a9146f

Browse files
committed
fix: upgrade packages to the latest versions
1 parent 62cd9a2 commit 2a9146f

15 files changed

+2805
-186
lines changed

examples/basic-client.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
var netcat = require('../index')
2-
var NetcatClient = netcat.client
1+
const netcat = require('../index')
2+
const NetcatClient = netcat.client
33

4-
var nc = new NetcatClient()
4+
const nc = new NetcatClient()
55

66
process.stdin.pipe(nc.addr('127.0.0.1').port(6666).connect().pipe(process.stdout).stream())

examples/basic-server.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
var netcat = require('../index')
2-
var NetcatServer = netcat.server
1+
const netcat = require('../index')
2+
const NetcatServer = netcat.server
33

4-
var nc = new NetcatServer()
4+
const nc = new NetcatServer()
55

66
nc.k().port(6666).addr('127.0.0.1').listen().exec('/bin/sh')

lib/Client.js

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22
const log = require('debug')
3-
var debug = log('netcat:client')
3+
let debug = log('netcat:client')
44
const Netcat = require('./Netcat')
55
const portScan = require('./portScan')
66
const tcpClient = require('./tcpClient')
@@ -13,10 +13,12 @@ class Client extends Netcat {
1313
opts = opts || {}
1414
super(opts)
1515

16-
debug = opts.verbose ? function () {
17-
var args = Array.prototype.slice.call(arguments)
18-
process.stderr.write(args.join(' ') + '\n')
19-
} : debug
16+
debug = opts.verbose
17+
? function () {
18+
const args = Array.prototype.slice.call(arguments)
19+
process.stderr.write(args.join(' ') + '\n')
20+
}
21+
: debug
2022
this.debug = debug
2123
this._verbose = opts.verbose || false
2224
this._address = opts.address || '127.0.0.1'
@@ -73,12 +75,12 @@ class Client extends Netcat {
7375
}
7476

7577
send (data, cb) {
76-
var cbOrHost = (this._protocol === 'tcp') ? (cb || noop) : (cb || null)
78+
const cbOrHost = (this._protocol === 'tcp') ? (cb || noop) : (cb || null)
7779

7880
if (data && !Buffer.isBuffer(data)) {
7981
data = Buffer.from(data)
8082
}
81-
var self = this
83+
const self = this
8284
if (!this.client) return this
8385
if (self._interval) { /* delay */
8486
setTimeout(function () {
@@ -92,7 +94,7 @@ class Client extends Netcat {
9294

9395
end (d) {
9496
if (this._protocol === 'udp') throw Error('end() method is tcp only')
95-
var self = this
97+
const self = this
9698
if (this._interval) {
9799
setTimeout(function () { /* delay */
98100
if (self.client) self.client.end(d) /* send data + EOF */

lib/Netcat.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'use strict'
2-
var debug = require('debug')('netcat:netcat')
2+
const debug = require('debug')('netcat:netcat')
33
const EventEmitter = require('events').EventEmitter
44
const through2 = require('through2')
55

lib/Server.js

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22
const log = require('debug')
3-
var debug = log('netcat:server')
3+
let debug = log('netcat:server')
44
const fs = require('fs')
55
const Netcat = require('./Netcat')
66
const tcpServer = require('./tcpServer')
@@ -14,10 +14,12 @@ class Server extends Netcat {
1414
opts = opts || {}
1515
super(opts)
1616

17-
debug = opts.verbose ? function () {
18-
var args = Array.prototype.slice.call(arguments)
19-
process.stderr.write(args.join(' ') + '\n')
20-
} : debug
17+
debug = opts.verbose
18+
? function () {
19+
const args = Array.prototype.slice.call(arguments)
20+
process.stderr.write(args.join(' ') + '\n')
21+
}
22+
: debug
2123
this.debug = debug
2224
this._verbose = opts.verbose || false
2325
this._address = opts.address || '0.0.0.0'
@@ -38,7 +40,7 @@ class Server extends Netcat {
3840
close (cb) {
3941
debug('Server: closing sockets...')
4042
cb = cb || noop
41-
for (var c in this._clients) {
43+
for (const c in this._clients) {
4244
this._clients[c].destroy() // closing existing sockets
4345
}
4446
try {

lib/portScan.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
const eachSeries = require('async-each-series')
22

33
module.exports = function (client, portsInterval, cb) {
4-
var ports = []
4+
let ports = []
55
/* get and validate ports range */
66
if (Number.isInteger(portsInterval)) {
77
ports.push(portsInterval) // single port
88
} else if (typeof portsInterval === 'string') {
9-
var i = portsInterval.split('-')
10-
var lowEnd = +i[0]
11-
var highEnd = +i[1]
9+
const i = portsInterval.split('-')
10+
let lowEnd = +i[0]
11+
const highEnd = +i[1]
1212
if (isNaN(lowEnd) || isNaN(highEnd)) throw Error('Scan: invalid ports range')
1313
while (lowEnd <= highEnd) {
1414
ports.push(lowEnd++)
@@ -26,7 +26,7 @@ module.exports = function (client, portsInterval, cb) {
2626
}
2727

2828
function startScan (client, ports, cb) {
29-
var outcome = {}
29+
const outcome = {}
3030

3131
eachSeries(ports, function (port, done) {
3232
client.port(port).connect()

lib/tcpClient.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ const waitTimer = util.waitTimer
66
const hex = require('hexer')
77

88
const noop = function () {}
9-
var hexer = hex.Transform({ prefix: '> ' }) // outcoming
10-
var hexPipeStarted = false
9+
const hexer = hex.Transform({ prefix: '> ' }) // outcoming
10+
let hexPipeStarted = false
1111

1212
module.exports = function (debug, cb) {
1313
debug('connect() called')
14-
var self = this
14+
const self = this
1515
cb = cb || noop
1616

1717
function _send (data, cb) {

lib/tcpServer.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ const fs = require('fs')
55
const net = require('net')
66
const stream = require('stream')
77
const through2 = require('through2')
8-
const generate = require('nanoid/generate')
8+
const nanoid = require('nanoid')
99
const hex = require('hexer')
1010

11-
var hexerIn = hex.Transform({ prefix: '< ' })
12-
var hexerOut = hex.Transform({ prefix: '> ' })
11+
const hexerIn = hex.Transform({ prefix: '< ' })
12+
const hexerOut = hex.Transform({ prefix: '> ' })
1313

1414
module.exports = function (debug) {
15-
var self = this
15+
const self = this
1616
this.server = net.createServer()
1717

1818
function listening () {
@@ -40,12 +40,12 @@ module.exports = function (debug) {
4040
hexerOut.pipe(self._output)
4141
}
4242

43-
socket.id = generate('1234567890abcdefghpsxz', 7)
43+
socket.id = nanoid.customAlphabet('1234567890abcdefghpsxz', 7)
4444
socket.setKeepAlive(!!self._keepalive)
4545
if (self._encoding) socket.setEncoding(self._encoding)
4646
self.emit('connection', socket)
4747

48-
var IPandPort = socket.remoteAddress + ':' + socket.remotePort
48+
const IPandPort = socket.remoteAddress + ':' + socket.remotePort
4949
debug('New connection', socket.id, IPandPort)
5050
self._clients[socket.id] = socket
5151

@@ -59,7 +59,7 @@ module.exports = function (debug) {
5959
} else if (self._serveStream) {
6060
debug('Serving given stream to the client', socket.id)
6161
if (Buffer.isBuffer(self._serveStream)) {
62-
var pt = new stream.PassThrough()
62+
const pt = new stream.PassThrough()
6363
pt.end(self._serveStream)
6464
pt.pipe(socket)
6565
} else {
@@ -140,7 +140,7 @@ module.exports = function (debug) {
140140
}
141141

142142
function streamDebug (debug, IPandPort) {
143-
var self = this
143+
const self = this
144144
return through2(function (chunk, enc, cb) {
145145
debug('Got data from', IPandPort, '->', chunk)
146146
if (self._output) hexerIn.write(chunk) // hex Dump

lib/udpClient.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ const dgram = require('dgram')
33
const stream = require('stream')
44
const through2 = require('through2')
55
const waitTimer = require('./util').waitTimer
6-
var pipe = stream.prototype.pipe
6+
const pipe = stream.prototype.pipe
77

88
const hex = require('hexer')
9-
var hexerIn = hex.Transform({ prefix: '< ' })
10-
var hexerOut = hex.Transform({ prefix: '> ' })
9+
const hexerIn = hex.Transform({ prefix: '< ' })
10+
const hexerOut = hex.Transform({ prefix: '> ' })
1111

1212
/* Inspired by https://github.com/dominictarr/broadcast-stream for piping */
1313

1414
module.exports = function (debug) {
15-
var self = this
15+
const self = this
1616

1717
self.client = dgram.createSocket({ type: 'udp4', reuseAddr: true })
1818

@@ -37,10 +37,10 @@ module.exports = function (debug) {
3737
waitTimer.call(self)
3838
}
3939

40-
var latest = null
40+
let latest = null
4141

4242
function message (msg, rinfo) {
43-
var _msg = self._encoding ? msg.toString(self._encoding) : msg
43+
const _msg = self._encoding ? msg.toString(self._encoding) : msg
4444
debug('Msg from %s:%d : %s', rinfo.address, rinfo.port, _msg)
4545
msg = { data: _msg, rinfo: rinfo }
4646
// if paused, remember the latest item.
@@ -79,7 +79,7 @@ module.exports = function (debug) {
7979
self.client.resume = function () {
8080
self.client.paused = false
8181
if (latest) {
82-
var msg = latest
82+
const msg = latest
8383
latest = null
8484
self.client.emit('data', msg)
8585
self.emit('data', msg)

lib/udpServer.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ const udp = require('datagram-stream')
77
const waitTimer = require('./util').waitTimer
88

99
const hex = require('hexer')
10-
var hexerIn = hex.Transform({ prefix: '< ' })
11-
var hexerOut = hex.Transform({ prefix: '> ' })
10+
const hexerIn = hex.Transform({ prefix: '< ' })
11+
const hexerOut = hex.Transform({ prefix: '> ' })
1212

1313
module.exports = function (debug) {
14-
var self = this
15-
var addresses = {}
14+
const self = this
15+
const addresses = {}
1616

1717
self.server = udp({
1818
address: self._address,
@@ -22,8 +22,8 @@ module.exports = function (debug) {
2222
unicast: self._destination
2323
}, function (err) {
2424
if (err) return self.emit('error', err)
25-
var ifaces = os.networkInterfaces()
26-
for (var k in ifaces) {
25+
const ifaces = os.networkInterfaces()
26+
for (const k in ifaces) {
2727
ifaces[k].forEach(function (address) {
2828
addresses[address.address] = true
2929
})
@@ -47,11 +47,11 @@ module.exports = function (debug) {
4747
}
4848

4949
self.server.on('data', function (d) {
50-
var msg = self._encoding ? d.toString(self._encoding) : d
51-
var rinfo = d.rinfo
50+
const msg = self._encoding ? d.toString(self._encoding) : d
51+
const rinfo = d.rinfo
5252
delete msg.rinfo
5353

54-
var addr = self.server.address()
54+
const addr = self.server.address()
5555
if (addresses[rinfo.address] && rinfo.port === addr.port) {
5656
if (self._loopback === false) return
5757
rinfo.loopback = true
@@ -85,7 +85,7 @@ module.exports = function (debug) {
8585
} else if (self._serveStream) {
8686
debug('Serving given stream over UDP to', self._destination)
8787
if (Buffer.isBuffer(self._serveStream)) {
88-
var pt = new stream.PassThrough()
88+
const pt = new stream.PassThrough()
8989
pt.end(self._serveStream)
9090
pt.pipe(self.server)
9191
} else {

lib/util.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ const spawn = require('child_process').spawn
55

66
/* Used from both Server and Client */
77
function spawnProcess (inStream, outStream) {
8-
var self = this
9-
var debug = self.debug
10-
var debugExec = log('netcat:exec')
8+
const self = this
9+
const debug = self.debug
10+
const debugExec = log('netcat:exec')
1111
/* spawn exec */
1212
if (self._exec) {
1313
debug('Spawning', self._exec)
14-
var sh = null
14+
let sh = null
1515
if (self._exec.indexOf('|') !== -1) {
16-
var cmd = (os.platform() === 'win32') ? 'cmd.exe' : 'sh'
17-
var cmdO = (os.platform() === 'win32') ? '/C' : '-c'
16+
const cmd = (os.platform() === 'win32') ? 'cmd.exe' : 'sh'
17+
const cmdO = (os.platform() === 'win32') ? '/C' : '-c'
1818
debug('multiple commands detected, executing under shell:', cmd, cmdO)
1919
sh = spawn(cmd, [cmdO, self._exec], self._execOptions)
2020
} else {

0 commit comments

Comments
 (0)