扭曲的海螺,覆盖认证

时间:2011-03-06 15:54:00

标签: python ssh twisted

我一直试图在扭曲的海螺模块中覆盖默认的身份验证方案。我认为我明白该怎么做的东西。脚本本身就是this的答案 题。我按以下方式对SSHUserAuthClient进行了子类化:

class ClientUserAuth(SSHUserAuthClient):
    def getPassword(self, prompt = None):
        return defer.succeed("*****")

我显然是在脚本中调用我的类来替换SSHUserAuthClient调用。由于原因我无法理解脚本不是在我的类中执行getPassword方法而是在超类getPassword方法中执行。有谁知道我做错了什么? 我做的脚本的唯一其他更改是我添加了以下模块导入

from twisted.internet import defer

谢谢!

编辑:奇怪的是正确调用了子类方法getPublicKey。只是getPassword方法表现得很奇怪。

2 个答案:

答案 0 :(得分:3)

您可能实际上看到了键盘交互式身份验证。这就像密码验证,但是分开。您在Linux和OS X之间看到不同行为的原因只是您的Linux和OS X SSH服务器配置不同。

覆盖getGenericAnswers以处理此问题。

答案 1 :(得分:3)

有关如何实现键盘交互式身份验证的一些其他详细信息。

我以为我第一次使用它,但是我的服务器发送了两个交互式请求。第一个请求包含prompt = [('Password: ', False)]
第二个包含空提示= []

下面的代码适用于我目前测试过的每台服务器(Redhat,Ubuntu,OpenSUSE)

from twisted.conch.ssh import keys, userauth

class ClientUserAuth(userauth.SSHUserAuthClient):
    def getPassword(self, prompt = None):
        #normal password authentication
        print "PASSWORD AUTH"
        return defer.succeed('*****') # <-- YOUR PASSWORD

    def getGenericAnswers(self, name, instruction, prompts):
        #interactive password authentication
        print "INTERACTIVE AUTH"
        response = ['']*len(prompts)
        for i, p in enumerate(prompts):
            try:
                if('password' in p[0].lower()):
                    response[i] = '*****' # <-- YOUR PASSWORD
            except:
                pass
        #The response is always a sequence, and the length of it is always
        #identical to the length of prompts
        return defer.succeed(response)

class ClientUserAuth(userauth.SSHUserAuthClient): def getPassword(self, prompt = None): #normal password authentication print "PASSWORD AUTH" return defer.succeed('*****') # <-- YOUR PASSWORD def getGenericAnswers(self, name, instruction, prompts): #interactive password authentication print "INTERACTIVE AUTH" response = ['']*len(prompts) for i, p in enumerate(prompts): try: if('password' in p[0].lower()): response[i] = '*****' # <-- YOUR PASSWORD except: pass #The response is always a sequence, and the length of it is always #identical to the length of prompts return defer.succeed(response)

启用Twisted中的Logging也有助于调试Conch在幕后做的事情。

相关问题