Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions kippo.cfg.dist
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,29 @@ interact_enabled = false
# (default: 5123)
interact_port = 5123

# SMTP module
#
# Email notification on:
# + Probe (recommended for LAN use only)
# + Successful login
# + User quit
#
# You are able to use 'ssl' or 'tls' or 'none' to send the message by setting 'smtp_enc'.
#
# To enable this module, remove all comments below, including the [smtp] line.

#[smtp]
#smtp_host = smtp.localhost.net
#smtp_username = localhost.net
#smtp_password = password
#smtp_port = 587
#smtp_enc = tls
#email_to = admin@localhost.net
#email_from = kippo@localhost.net
#alert_probe = false
#alert_login = false
#alert_quit = true

# MySQL logging module
#
# Database structure for this module is supplied in doc/sql/mysql.sql
Expand Down
22 changes: 22 additions & 0 deletions kippo/core/honeypot.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from kippo.core import ttylog, fs, utils
from kippo.core.userdb import UserDB
from kippo.core.config import config
from kippo.core.sendemail import sendEmail
import commands

import ConfigParser
Expand Down Expand Up @@ -515,13 +516,22 @@ class HoneyPotTransport(transport.SSHServerTransport):
hadVersion = False

def connectionMade(self):
cfg = config()
print 'New connection: %s:%s (%s:%s) [session: %d]' % \
(self.transport.getPeer().host, self.transport.getPeer().port,
self.transport.getHost().host, self.transport.getHost().port,
self.transport.sessionno)
self.interactors = []
self.logintime = time.time()
self.ttylog_open = False
if cfg.has_option('smtp', 'alert_probe'):
if cfg.get('smtp', 'alert_probe') == 'true':
print 'Emailing about SSH probe (alert_probe = true).'
emailMessage = 'There was an SSH probe request.\nFrom: %s:%s.\nTo: %s:%s.\nKippo Session: %s.' % \
(self.transport.getPeer().host, self.transport.getPeer().port,
self.transport.getHost().host, self.transport.getHost().port,
self.transport.sessionno)
sendEmail('[Kippo] SSH Probe', emailMessage)
transport.SSHServerTransport.connectionMade(self)

def sendKexInit(self):
Expand Down Expand Up @@ -554,6 +564,7 @@ def lastlogExit(self):

# this seems to be the only reliable place of catching lost connection
def connectionLost(self, reason):
cfg = config()
for i in self.interactors:
i.sessionClosed()
if self.transport.sessionno in self.factory.sessions:
Expand All @@ -562,6 +573,11 @@ def connectionLost(self, reason):
if self.ttylog_open:
ttylog.ttylog_close(self.ttylog_file, time.time())
self.ttylog_open = False
if cfg.has_option('smtp', 'alert_quit'):
if cfg.get('smtp', 'alert_quit') == 'true':
print 'Emailing about attack being over (alert_quit = true).'
emailMessage = 'The attacker quit.\n\nPlease check the logs (%s)!' % (self.ttylog_file)
sendEmail('[Kippo] SSH Attack Finished', emailMessage)
transport.SSHServerTransport.connectionLost(self, reason)

from twisted.conch.ssh.common import NS, getNS
Expand Down Expand Up @@ -700,8 +716,14 @@ def cbCheckPamUser(self, responses, username):
return defer.fail(error.UnauthorizedLogin())

def checkUserPass(self, username, password):
cfg = config()
if UserDB().checklogin(username, password):
print 'login attempt [%s/%s] succeeded' % (username, password)
if cfg.has_option('smtp', 'alert_login'):
if cfg.get('smtp', 'alert_login') == 'true':
print 'Emailing about login notification (alert_login = true).'
emailMessage = 'There was a successful login: (%s/%s).' % (username, password)
sendEmail('[Kippo] Successful Login', emailMessage)
return True
else:
print 'login attempt [%s/%s] failed' % (username, password)
Expand Down
30 changes: 30 additions & 0 deletions kippo/core/sendmail.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import smtplib
from email.mime.text import MIMEText
from kippo.core.config import config

def sendEmail(subject, message):
cfg = config()

msg = MIMEText(message)
msg['Subject'] = subject

toEmail = cfg.get('smtp', 'email_to')
msg['To'] = toEmail

fromEmail = cfg.get('smtp', 'email_from')
msg['From'] = fromEmail

smtpHost = cfg.get('smtp', 'smtp_host')
smtpPort = cfg.get('smtp', 'smtp_port')
smtpUsername = cfg.get('smtp', 'smtp_username')
smtpPassword = cfg.get('smtp', 'smtp_Password')
smtpEnc = cfg.get('smtp', 'smtp_enc')

s = smtplib.SMTP(smtpHost, smtpPort)
if smtpEnc == 'ssl':
s = smtplib.SMTP_SSL(smtpHost, smtpPort)
elif smtpEnc == 'tls':
s.starttls()
s.login(smtpUsername, smtpPassword)
s.sendmail(fromEmail, [toEmail], msg.as_string())
s.quit()