不向人们正在渗透测试我的 node/express 网站的网址发送回复可以吗?
Is it okay to not send a response to urls that people are pentesting my node/express site?
我在我的网站上记录了所有 404。我一直在为我没有链接到的页面获取它们,很明显有人(机器人)试图在我的网站上查找管理页面/安全文件,例如 /wp-admin.php
;
router.get('/wp-admin.php', function(req, res, next) {});
我试过了,它似乎没有阻止服务器,它只是在一分钟后输出如下内容:
GET /wp-admin.php - - ms - -
添加这样的路由是否有任何不利之处,没有发送响应,可能会浪费他们的时间?
router.get('/wp-admin.php', function(req, res, next) {});
这会导致express超时并关闭连接。这将使黑客更容易进行拒绝服务攻击并阻塞您的节点服务器。
您始终可以使用某种速率限制器来防止来自某个 IP 的连续请求。
express-rate-limit
是一个可以用于此。它是简单的 express 中间件
如已接受的答案中所述,像这样的 Express 路线会让您容易受到攻击。
我建议更进一步,使用 req.destroy
取消这些请求。
不过,我不确定此处包含 Express 的含义。例如,请求正文是否由您显示的此请求处理程序上游的中间件自动读取?如果是这样,那将是一种攻击媒介,使我建议的缓解措施毫无用处。
无论如何,为了证明我对 vanilla HTTP 服务器的建议:
var h = require('http')
h.createServer(function(req, res) {
// tear down the socket as soon as the request event is emitted
req.destroy()
}).listen(8888, function() {
// send a request to the server we just created
var r = h.request({port: 8888})
r.on('response', console.log.bind(console, 'on_response'))
r.on('error', console.log.bind(console, 'on_error'))
r.on('timeout', console.log.bind(console, 'on_timeout'))
// abort will be emitted to the caller, but nothing else
r.on('abort', console.log.bind(console, 'on_abort'))
r.end()
})
如果您能够以某种方式将调用代理识别为机器人(或其他),您也可以在 HTTP 服务器的 connection
事件中调用 socket.destroy
。
var h = require('http')
h.createServer(function(req, res) {
res.send('foo')
}).on('connection', function(socket) {
// pretend this ip address is the remote address of an attacker, for example
if (socket.remoteAddress === '10.0.0.0') {
socket.destroy()
}
}).listen(8888, function() {
// send a request to the server we just created
var r = h.request({port: 8888})
r.on('response', console.log.bind(console, 'on_response'))
r.on('error', console.log.bind(console, 'on_error'))
r.on('timeout', console.log.bind(console, 'on_timeout'))
// abort will be emitted to the caller, but nothing else
r.on('abort', console.log.bind(console, 'on_abort'))
r.end()
})
我在我的网站上记录了所有 404。我一直在为我没有链接到的页面获取它们,很明显有人(机器人)试图在我的网站上查找管理页面/安全文件,例如 /wp-admin.php
;
router.get('/wp-admin.php', function(req, res, next) {});
我试过了,它似乎没有阻止服务器,它只是在一分钟后输出如下内容:
GET /wp-admin.php - - ms - -
添加这样的路由是否有任何不利之处,没有发送响应,可能会浪费他们的时间?
router.get('/wp-admin.php', function(req, res, next) {});
这会导致express超时并关闭连接。这将使黑客更容易进行拒绝服务攻击并阻塞您的节点服务器。 您始终可以使用某种速率限制器来防止来自某个 IP 的连续请求。
express-rate-limit 是一个可以用于此。它是简单的 express 中间件
如已接受的答案中所述,像这样的 Express 路线会让您容易受到攻击。
我建议更进一步,使用 req.destroy
取消这些请求。
不过,我不确定此处包含 Express 的含义。例如,请求正文是否由您显示的此请求处理程序上游的中间件自动读取?如果是这样,那将是一种攻击媒介,使我建议的缓解措施毫无用处。
无论如何,为了证明我对 vanilla HTTP 服务器的建议:
var h = require('http')
h.createServer(function(req, res) {
// tear down the socket as soon as the request event is emitted
req.destroy()
}).listen(8888, function() {
// send a request to the server we just created
var r = h.request({port: 8888})
r.on('response', console.log.bind(console, 'on_response'))
r.on('error', console.log.bind(console, 'on_error'))
r.on('timeout', console.log.bind(console, 'on_timeout'))
// abort will be emitted to the caller, but nothing else
r.on('abort', console.log.bind(console, 'on_abort'))
r.end()
})
如果您能够以某种方式将调用代理识别为机器人(或其他),您也可以在 HTTP 服务器的 connection
事件中调用 socket.destroy
。
var h = require('http')
h.createServer(function(req, res) {
res.send('foo')
}).on('connection', function(socket) {
// pretend this ip address is the remote address of an attacker, for example
if (socket.remoteAddress === '10.0.0.0') {
socket.destroy()
}
}).listen(8888, function() {
// send a request to the server we just created
var r = h.request({port: 8888})
r.on('response', console.log.bind(console, 'on_response'))
r.on('error', console.log.bind(console, 'on_error'))
r.on('timeout', console.log.bind(console, 'on_timeout'))
// abort will be emitted to the caller, but nothing else
r.on('abort', console.log.bind(console, 'on_abort'))
r.end()
})