update: asiosmtp

This commit is contained in:
Yannik Schmidt
2023-01-06 02:55:43 +01:00
parent ebdf98b4a7
commit 61b4c982aa

View File

@@ -3,35 +3,44 @@
import aiosmtpd.controller import aiosmtpd.controller
import email import email
import email.policy import email.policy
#import aiosmtpd.smtp.AuthResult, aiosmtpd.smtp.LoginPassword from aiosmtpd.smtp import AuthResult, LoginPassword
USER = "test" USER = "test"
PASS = "test123" PASS = "test123"
COUNTER_FAILED_LOGIN = 0
def authenticator_func(server, session, envelope, mechanism, auth_data):
assert isinstance(auth_data, LoginPassword)
username = auth_data.login.decode("utf-8")
password = auth_data.password.decode("utf-8")
if USER == username and PASS == password:
return AuthResult(success=True)
else:
return AuthResult(success=False, handled=False)
class CustomSMTPHandler: class CustomSMTPHandler:
async def handle_DATA(self, server, session, envelope): async def handle_DATA(self, server, session, envelope):
mail = email.message_from_bytes(envelope.content, policy=email.policy.default) global COUNTER_FAILED_LOGIN
print(mail.get("subject"))
print(mail.get_body())
return '250 OK'
async def handleAUTH(server, session, envelope, mechanism, auth_data): mail = email.message_from_bytes(envelope.content, policy=email.policy.default)
username = auth_data.login if "Login error" in mail.get("subject"):
password = auth_data.password COUNTER_FAILED_LOGIN += 1
print("Auth Callback") print(COUNTER_FAILED_LOGIN)
if username == USER and password == PASS: if COUNTER_FAILED_LOGIN > 5:
return '235 Authentication successful' print("Brute Force")
#return aiosmtpd.smtp.AuthResult(success=True) return '250 OK'
else:
assert(False)
return 'None'
#return aiosmtpd.smtp.AuthResult(success=False)
if __name__ == "__main__": if __name__ == "__main__":
handler = CustomSMTPHandler() handler = CustomSMTPHandler()
server = aiosmtpd.controller.Controller(handler, hostname="0.0.0.0", port=8025) server = aiosmtpd.controller.Controller(handler, hostname="0.0.0.0", port=8025,
authenticator=authenticator_func,
auth_required=True,
auth_require_tls=False)
server.start() server.start()
input("Server started. Press Return to quit.") input("Server started. Press Return to quit.")
server.stop() server.stop()