sshd.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:idiot 作者: snare 项目源码 文件源码
def run(self):
        with open(os.devnull, 'w') as devnull:
            try:
                # If the service is disabled in Preferences
                # the query returns a non-zero error
                # should use this query better in future
                if subprocess.check_call(['launchctl', 'print', 'system/com.openssh.sshd'], stdout=devnull, stderr=devnull):
                    return (True, "disabled")
                else:
                    return (False, "enabled in Sharing Prefs: Remote Login")
            except subprocess.CalledProcessError as e:
                # this only gets run if sshd isn't enabled by
                # launchd as checked above
                pids = []
                for p in psutil.process_iter():
                    try:
                        if p.name() == 'sshd':
                            pids.append(p.pid)
                    except psutil.NoSuchProcess:
                        pass
                if len(pids):
                    return (False, "enabled manually - see pids: {} ".format(', '.join([str(p) for p in pids])))
                else:
                    return (True, "disabled")
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号