mirror of
https://github.com/aljazceru/cowrie.git
synced 2026-02-22 14:54:28 +01:00
more
This commit is contained in:
@@ -87,27 +87,6 @@ class UserDB(object):
|
||||
return False
|
||||
|
||||
|
||||
def getUID(self, loginname):
|
||||
"""
|
||||
"""
|
||||
for (login, uid, passwd) in self.userdb:
|
||||
if loginname == login:
|
||||
return uid
|
||||
return 1001
|
||||
|
||||
|
||||
def allocUID(self):
|
||||
"""
|
||||
allocate the next UID
|
||||
"""
|
||||
|
||||
min_uid = 0
|
||||
for (login, uid, passwd) in self.userdb:
|
||||
if uid > min_uid:
|
||||
min_uid = uid
|
||||
return min_uid + 1
|
||||
|
||||
|
||||
def adduser(self, login, uid, passwd):
|
||||
"""
|
||||
"""
|
||||
|
||||
114
cowrie/core/passwd.py
Normal file
114
cowrie/core/passwd.py
Normal file
@@ -0,0 +1,114 @@
|
||||
# Copyright (c) 2015 Michel Oosterhof <michel@oosterhof.net>
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in the
|
||||
# documentation and/or other materials provided with the distribution.
|
||||
# 3. The names of the author(s) may not be used to endorse or promote
|
||||
# products derived from this software without specific prior written
|
||||
# permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
|
||||
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
# IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
# SUCH DAMAGE.
|
||||
|
||||
"""
|
||||
This module contains ...
|
||||
"""
|
||||
|
||||
from twisted.python import log
|
||||
|
||||
|
||||
class Passwd(object):
|
||||
"""
|
||||
"""
|
||||
|
||||
def __init__(self, cfg):
|
||||
self.passwd_file = '%s/etc/passwd' % cfg.get('honeypot', 'contents_path')
|
||||
self.load()
|
||||
|
||||
|
||||
def load(self):
|
||||
"""
|
||||
load the passwd db
|
||||
"""
|
||||
self.passwd = []
|
||||
with open(self.passwd_file, 'r') as f:
|
||||
while True:
|
||||
rawline = f.readline()
|
||||
if not rawline:
|
||||
break
|
||||
|
||||
line = rawline.strip()
|
||||
if not line:
|
||||
continue
|
||||
|
||||
if line.startswith('#'):
|
||||
continue
|
||||
|
||||
(pw_name, pw_passwd, pw_uid, pw_gid, pw_gecos, pw_dir, pw_shell) = line.split(':')
|
||||
|
||||
e = {}
|
||||
e["pw_name"] = pw_name
|
||||
e["pw_passwd"] = pw_passwd
|
||||
e["pw_gecos"] = pw_gecos
|
||||
e["pw_dir"] = pw_dir
|
||||
e["pw_shell"] = pw_shell
|
||||
try:
|
||||
e["pw_uid"] = int(pw_uid)
|
||||
except ValueError:
|
||||
e["pw_uid"] = 1001
|
||||
try:
|
||||
e["pw_gid"] = int(pw_gid)
|
||||
except ValueError:
|
||||
e["pw_gid"] = 1001
|
||||
|
||||
self.passwd.append(e)
|
||||
|
||||
|
||||
def save(self):
|
||||
"""
|
||||
save the user db
|
||||
Note: this is subject to races between cowrie instances, but hey ...
|
||||
"""
|
||||
# with open(self.passwd_file, 'w') as f:
|
||||
# for (login, uid, passwd) in self.userdb:
|
||||
# f.write('%s:%d:%s\n' % (login, uid, passwd))
|
||||
|
||||
pass
|
||||
|
||||
def getpwnam(self, name):
|
||||
"""
|
||||
get passwd entry for username
|
||||
"""
|
||||
for _ in self.passwd:
|
||||
if name == _["pw_name"]:
|
||||
return _
|
||||
return None
|
||||
|
||||
|
||||
def getpwuid(self, uid):
|
||||
"""
|
||||
get passwd entry for uid
|
||||
"""
|
||||
for _ in self.passwd:
|
||||
if uid == _["pw_uid"]:
|
||||
return _
|
||||
return None
|
||||
|
||||
|
||||
# vim: set sw=4 et:
|
||||
Reference in New Issue
Block a user