Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- from sys import argv, exit
- from datetime import datetime, timedelta
- '''
- about:
- Kippo is a ssh honeypot written in Python.
- It's not my own project, but I liked to write
- a munin plugin, so here it is.
- more about kippo: http://code.google.com/p/kippo/
- license:
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- '''
- config = ['graph_title attackers',
- 'graph_args --base 1000 -l 0',
- 'graph_scale no',
- 'graph_vlabel attempts',
- 'graph_category network',
- 'attackers.label attackers',
- 'attempts.label attempts',
- 'succeeded.label succedded']
- if len(argv) > 1 and argv[1] == 'config':
- for line in config:
- print(line)
- exit(0)
- def muninlog(path, lastminutes=5, lasthours=0):
- collect = {}
- with open(path, 'r') as fp:
- for line in fp.readlines():
- data = line.split(' ')
- if len(data) > 6:
- ts = datetime.strptime(data[0] + ' ' + data[1],
- '''%Y-%m-%d %H:%M:%S+0200''')
- tdiff = datetime.now() - ts
- if tdiff < timedelta(hours=lasthours,
- minutes=lastminutes):
- if 'attempt' in line:
- sec = line.split(' ')
- ip = sec[5].split(',')[2][:-1]
- if ip not in collect:
- collect[ip] = {'attempts': 0, 'succeeded': 0}
- collect[ip]['attempts'] += 1
- if sec[-1].strip() == 'succeeded':
- collect[ip]['succeeded'] += 1
- return collect
- if __name__ == '__main__':
- logfile = '/path/to/your/kippo-ssh-honeypot/log/kippo.log'
- collect = muninlog(logfile)
- attackers, attempts, succ = 0, 0, 0
- for ip, stats in collect.items():
- attackers += 1
- attempts += stats['attempts']
- succ += stats['succeeded']
- print('attackers.value {}'.format(attackers))
- print('attempts.value {}'.format(attempts))
- print('succeeded.value {}'.format(succ))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement