Ich baue eine Website mit Node und Express JS und möchte ungültige Anmeldeversuche drosseln. Beides, um Online-Cracking zu verhindern und unnötige Datenbankaufrufe zu reduzieren. Auf welche Weise kann ich das umsetzen?Verhindern von Brute Force mit Knoten und Express JS
Antwort
Vielleicht hilft Ihnen so etwas beim Einstieg.
var failures = {};
function tryToLogin() {
var f = failures[remoteIp];
if (f && Date.now() < f.nextTry) {
// Throttled. Can't try yet.
return res.error();
}
// Otherwise do login
...
}
function onLoginFail() {
var f = failures[remoteIp] = failures[remoteIp] || {count: 0, nextTry: new Date()};
++f.count;
f.nextTry.setTime(Date.now() + 2000 * f.count); // Wait another two seconds for every failed attempt
}
function onLoginSuccess() { delete failures[remoteIp]; }
// Clean up people that have given up
var MINS10 = 600000, MINS30 = 3 * MINS10;
setInterval(function() {
for (var ip in failures) {
if (Date.now() - failures[ip].nextTry > MINS10) {
delete failures[ip];
}
}
}, MINS30);
So, nachdem einige der Suche zu tun, ich war ich so schrieb ich meine eigenen mochte, eine Lösung zu finden, nicht in der Lage, basierend auf Trevors Lösung und Express-Tier. Sie können es here finden.
okk, ich fand die Lösung von max Login versuch auf falsches Passwort in mongoose und expressjs.there ist eine Lösung. * Zuerst werden wir das Benutzerschema definieren * Sekunde werden wir die maximale Anmeldung auf falsepassword Handler-Funktion definieren. * Drittel, wenn wir die Login api schaffen, dann werden wir diese Funktion prüfen, ob, wie oft User-Login mit falscher password.so für Code bereit seine
var config = require('../config');
var userSchema = new mongoose.Schema({
email: { type: String, unique: true, required: true },
password: String,
verificationToken: { type: String, unique: true, required: true },
isVerified: { type: Boolean, required: true, default: false },
passwordResetToken: { type: String, unique: true },
passwordResetExpires: Date,
loginAttempts: { type: Number, required: true, default: 0 },
lockUntil: Number,
role: String
});
userSchema.virtual('isLocked').get(function() {
return !!(this.lockUntil && this.lockUntil > Date.now());
});
userSchema.methods.incrementLoginAttempts = function(callback) {
console.log("lock until",this.lockUntil)
// if we have a previous lock that has expired, restart at 1
var lockExpired = !!(this.lockUntil && this.lockUntil < Date.now());
console.log("lockExpired",lockExpired)
if (lockExpired) {
return this.update({
$set: { loginAttempts: 1 },
$unset: { lockUntil: 1 }
}, callback);
}
// otherwise we're incrementing
var updates = { $inc: { loginAttempts: 1 } };
// lock the account if we've reached max attempts and it's not locked already
var needToLock = !!(this.loginAttempts + 1 >= config.login.maxAttempts && !this.isLocked);
console.log("needToLock",needToLock)
console.log("loginAttempts",this.loginAttempts)
if (needToLock) {
updates.$set = { lockUntil: Date.now() + config.login.lockoutHours };
console.log("config.login.lockoutHours",Date.now() + config.login.lockoutHours)
}
//console.log("lockUntil",this.lockUntil)
return this.update(updates, callback);
};
hier ist meine Login-Funktion, wo wir das überprüft haben max Anmeldeversuch auf falsche password.so nennen wir diese Funktion
User.findOne({ email: email }, function(err, user) {
console.log("i am aurhebengdfhdbndbcxnvndcvb")
if (!user) {
return done(null, false, { msg: 'No user with the email ' + email + ' was found.' });
}
if (user.isLocked) {
return user.incrementLoginAttempts(function(err) {
if (err) {
return done(err);
}
return done(null, false, { msg: 'You have exceeded the maximum number of login attempts. Your account is locked until ' + moment(user.lockUntil).tz(config.server.timezone).format('LT z') + '. You may attempt to log in again after that time.' });
});
}
if (!user.isVerified) {
return done(null, false, { msg: 'Your email has not been verified. Check your inbox for a verification email.<p><a href="/user/verify-resend/' + email + '" class="btn waves-effect white black-text"><i class="material-icons left">email</i>Re-send verification email</a></p>' });
}
user.comparePassword(password, function(err, isMatch) {
if (isMatch) {
return done(null, user);
}
else {
user.incrementLoginAttempts(function(err) {
if (err) {
return done(err);
}
return done(null, false, { msg: 'Invalid password. Please try again.' });
});
}
});
});
}));
meine config.js Datei ist hier –
Werfen Sie einen Blick auf diese: https://github.com/AdamPflug/express-brute A brute-force protection middleware for express routes that rate-limits incoming requests, increasing the delay with each request in a fibonacci-like sequence.
- 1. Parallel Brute-Force-Algorithmus
- 2. CUDA Brute Force Spaß
- 3. Unterschied zwischen Knoten js und express js
- 4. Wie verhindern Sie Brute-Force-Angriffe auf REST-konforme Datendienste?
- 5. Partition Probleme Brute-Force-Algorithmus
- 6. Wie Brute Force arithmetisches Puzzle?
- 7. Regenbogen Cracken Angriffe und Brute-Force-Angriff
- 8. sind Sicherheitslösung für Brute-Force
- 9. Brute-Force-7z-Passwort-Test
- 10. Erstellen eines Iterators zu Brute-Force
- 11. Python-Sudoku-Rekursion mit Brute-Force-Backtracking-Fehler
- 12. Brute-Force-eigene Verschlüsselung in Java
- 13. Verhindern von Brute-Force-Angriffen beim Authentifizieren eines Benutzers in Laravel
- 14. Vorrouting mit Querystrings mit Express in Knoten JS
- 15. Auf was für Knoten Js-Modulen basiert die Express Js?
- 16. Arbeiten mit eckigen js, Node js server und express js
- 17. Brute-Force in OpenCL (Hafen von CUDA) funktioniert nicht
- 18. Machen Sie dynamischen Pfad in Knoten und express js
- 19. Serving HTML-Dateien in Knoten js mit Express
- 20. Benutzerverwaltung in Knoten js mit Express, mongodb als Server-Datenbank
- 21. Constrained d3.js Force-Anzeige
- 22. Facebook Open Authentication mit Knoten JS und Angular JS
- 23. RegExp und Knoten JS
- 24. Speicher Wahl für die Anmeldung Brute Force Gegenmaßnahmen
- 25. Java - ein Binary Tree Guthaben bei der "Brute Force"
- 26. Zusammenklappbare/hierarchische UND Force-gerichtete Grafik in d3.js
- 27. Wie würde ich diesen Brute Force Median Search-Algorithmus implementieren?
- 28. Brute-Force Prolog SAT-Löser für boolesche Formeln
- 29. Wie Brute-Force-Algorithmus für String-Matching in PHP implementieren?
- 30. Knoten js - Loading Loop
Dies füllt langsam Ihren Arbeitsspeicher, da die fehlgeschlagenen IPs niemals aus "Fehlern" gelöscht werden, wenn ein Login niemals erfolgreich ist. – josh3736
@ josh3736 Guter Punkt. Eine Funktion hinzugefügt, um es alle 30 Minuten zu reinigen. –
Was halten Sie von Lösungen wie Express-Brute? https://npmjs.org/package/express-brute – Dave