本文整理汇总了Python中twisted.conch.ssh.common.getNS函数的典型用法代码示例。如果您正苦于以下问题:Python getNS函数的具体用法?Python getNS怎么用?Python getNS使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了getNS函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: request_env
def request_env(self, data):
name, rest = getNS(data)
value, rest = getNS(rest)
if rest:
raise ValueError("Bad data given in env request")
log.msg(eventid='KIPP0013', format='request_env: %(name)s=%(value)s', name=name, value=value)
return 0
开发者ID:andrew-morris,项目名称:cowrie,代码行数:7,代码来源:ssh.py
示例2: _parseAttributes
def _parseAttributes(self, data):
flags ,= struct.unpack('!L', data[:4])
attrs = {}
data = data[4:]
if flags & FILEXFER_ATTR_SIZE == FILEXFER_ATTR_SIZE:
size ,= struct.unpack('!Q', data[:8])
attrs['size'] = size
data = data[8:]
if flags & FILEXFER_ATTR_OWNERGROUP == FILEXFER_ATTR_OWNERGROUP:
uid, gid = struct.unpack('!2L', data[:8])
attrs['uid'] = uid
attrs['gid'] = gid
data = data[8:]
if flags & FILEXFER_ATTR_PERMISSIONS == FILEXFER_ATTR_PERMISSIONS:
perms ,= struct.unpack('!L', data[:4])
attrs['permissions'] = perms
data = data[4:]
if flags & FILEXFER_ATTR_ACMODTIME == FILEXFER_ATTR_ACMODTIME:
atime, mtime = struct.unpack('!2L', data[:8])
attrs['atime'] = atime
attrs['mtime'] = mtime
data = data[8:]
if flags & FILEXFER_ATTR_EXTENDED == FILEXFER_ATTR_EXTENDED:
extended_count ,= struct.unpack('!L', data[:4])
data = data[4:]
for i in xrange(extended_count):
extended_type, data = getNS(data)
extended_data, data = getNS(data)
attrs['ext_%s' % extended_type] = extended_data
return attrs, data
开发者ID:12019,项目名称:OpenWrt_Luci_Lua,代码行数:30,代码来源:filetransfer.py
示例3: request_env
def request_env(self, data):
name, rest = getNS(data)
value, rest = getNS(rest)
if rest:
raise ValueError("Bad data given in env request")
log.msg('request_env: %s=%s' % (name, value) )
return 0
开发者ID:localh0rzd,项目名称:kippo,代码行数:7,代码来源:ssh.py
示例4: auth_publickey
def auth_publickey(self, packet):
# This is copied and pasted from twisted/conch/ssh/userauth.py in
# Twisted 8.0.1. We do this so we can customize how the credentials
# are built and pass a mind to self.portal.login.
hasSig = ord(packet[0])
algName, blob, rest = getNS(packet[1:], 2)
pubKey = keys.Key.fromString(blob).keyObject
signature = hasSig and getNS(rest)[0] or None
if hasSig:
b = (
NS(self.transport.sessionID)
+ chr(userauth.MSG_USERAUTH_REQUEST)
+ NS(self.user)
+ NS(self.nextService)
+ NS("publickey")
+ chr(hasSig)
+ NS(keys.objectType(pubKey))
+ NS(blob)
)
# The next three lines are different from the original.
c = self.makePublicKeyCredentials(self.user, algName, blob, b, signature)
return self.portal.login(c, self.getMind(), IConchUser)
else:
# The next four lines are different from the original.
c = self.makePublicKeyCredentials(self.user, algName, blob, None, None)
return self.portal.login(c, self.getMind(), IConchUser).addErrback(self._ebCheckKey, packet[1:])
开发者ID:vitaminmoo,项目名称:unnaturalcode,代码行数:26,代码来源:auth.py
示例5: auth_publickey
def auth_publickey(self, packet):
"""
Public key authentication. Payload::
byte has signature
string algorithm name
string key blob
[string signature] (if has signature is True)
Create a SSHPublicKey credential and verify it using our portal.
"""
hasSig = ord(packet[0:1])
algName, blob, rest = getNS(packet[1:], 2)
try:
pubKey = keys.Key.fromString(blob)
except keys.BadKeyError:
error = "Unsupported key type %s or bad key" % (
algName.decode('ascii'),)
log.msg(error)
return defer.fail(UnauthorizedLogin(error))
signature = hasSig and getNS(rest)[0] or None
if hasSig:
b = (NS(self.transport.sessionID) + chr(MSG_USERAUTH_REQUEST) +
NS(self.user) + NS(self.nextService) + NS(b'publickey') +
chr(hasSig) + NS(pubKey.sshType()) + NS(blob))
c = credentials.SSHPrivateKey(self.user, algName, blob, b,
signature)
return self.portal.login(c, None, interfaces.IConchUser)
else:
c = credentials.SSHPrivateKey(self.user, algName, blob, None, None)
return self.portal.login(c, None,
interfaces.IConchUser).addErrback(self._ebCheckKey,
packet[1:])
开发者ID:JohnDoes95,项目名称:project_parser,代码行数:34,代码来源:userauth.py
示例6: verify
def verify(self, signature, data):
"""
Returns true if the signature for data is valid for this Key.
@type signature: C{str}
@type data: C{str}
@rtype: C{bool}
"""
if len(signature) == 40:
# DSA key with no padding
signatureType, signature = 'ssh-dss', common.NS(signature)
else:
signatureType, signature = common.getNS(signature)
if signatureType != self.sshType():
return False
if self.type() == 'RSA':
numbers = common.getMP(signature)
digest = pkcs1Digest(data, self.keyObject.size() / 8)
elif self.type() == 'DSA':
signature = common.getNS(signature)[0]
numbers = [
Util.number.bytes_to_long(n) for n in
(signature[:20], signature[20:])
]
digest = sha1(data).digest()
return self.keyObject.verify(digest, numbers)
开发者ID:ssilverek,项目名称:kodb,代码行数:26,代码来源:keys.py
示例7: auth_publickey
def auth_publickey(self, packet):
"""
Public key authentication. Payload::
byte has signature
string algorithm name
string key blob
[string signature] (if has signature is True)
Create a SSHPublicKey credential and verify it using our portal.
"""
hasSig = ord(packet[0])
algName, blob, rest = getNS(packet[1:], 2)
pubKey = keys.Key.fromString(blob)
signature = hasSig and getNS(rest)[0] or None
if hasSig:
b = (NS(self.transport.sessionID) + chr(MSG_USERAUTH_REQUEST) +
NS(self.user) + NS(self.nextService) + NS('publickey') +
chr(hasSig) + NS(pubKey.sshType()) + NS(blob))
c = credentials.SSHPrivateKey(self.user, algName, blob, b,
signature)
return self.portal.login(c, None, interfaces.IConchUser)
else:
c = credentials.SSHPrivateKey(self.user, algName, blob, None, None)
return self.portal.login(c, None,
interfaces.IConchUser).addErrback(self._ebCheckKey,
packet[1:])
开发者ID:timkrentz,项目名称:SunTracker,代码行数:26,代码来源:userauth.py
示例8: ssh_USERAUTH_PK_OK
def ssh_USERAUTH_PK_OK(self, packet):
if self.lastAuth == 'publickey':
# this is ok
publicKey = self.lastPublicKey
keyType = getNS(publicKey)[0]
b = NS(self.transport.sessionID) + chr(MSG_USERAUTH_REQUEST) + \
NS(self.user) + NS(self.instance.name) + NS('publickey') + '\xff' +\
NS(keyType) + NS(publicKey)
d = self.signData(publicKey, b)
if not d:
self.askForAuth('none', '')
# this will fail, we'll move on
return
d.addCallback(self._cbSignedData)
d.addErrback(self._ebAuth)
elif self.lastAuth == 'password':
prompt, language, rest = getNS(packet, 2)
self._oldPass = self._newPass = None
self.getPassword('Old Password: ').addCallbacks(self._setOldPass, self._ebAuth)
self.getPassword(prompt).addCallbacks(self._setNewPass, self._ebAuth)
elif self.lastAuth == 'keyboard-interactive':
name, instruction, lang, data = getNS(packet, 3)
numPrompts = struct.unpack('!L', data[:4])[0]
data = data[4:]
prompts = []
for i in range(numPrompts):
prompt, data = getNS(data)
echo = bool(ord(data[0]))
data = data[1:]
prompts.append((prompt, echo))
d = self.getGenericAnswers(name, instruction, prompts)
d.addCallback(self._cbGenericAnswers)
d.addErrback(self._ebAuth)
开发者ID:clayball,项目名称:hector,代码行数:33,代码来源:userauth.py
示例9: auth_publickey
def auth_publickey(self, packet):
try:
#extract the public key blob from the SSH packet
key_blob = getNS(getNS(packet[1:])[1])[0]
except:
key_blob = "No public key found."
try:
#convert blob into openssh key format
key = keys.Key.fromString(key_blob).toString('openssh')
except:
key = "Invalid SSH Public Key Submitted: {key_blob}".format(key_blob=key_blob.encode('hex'))
for keytype in ['ecdsa-sha2-nistp256','ecdsa-sha2-nistp384','ecdsa-sha2-nistp521','ssh-ed25519']:
if keytype in key_blob:
key = '{keytype} {keydata}'.format(
keytype=keytype,
keydata=base64.b64encode(key_blob))
print 'Key was {key}'.format(key=key)
c = credentials.SSHPrivateKey(None,None,None,None,None)
#self.log(key=key)
return self.portal.login(c, None, conchinterfaces.IConchUser).addErrback(
self._ebPassword)
开发者ID:beelives,项目名称:opencanary,代码行数:27,代码来源:ssh.py
示例10: packet_SYMLINK
def packet_SYMLINK(self, data):
requestId = data[:4]
data = data[4:]
linkPath, data = getNS(data)
targetPath, data = getNS(data)
d = defer.maybeDeferred(self.client.makeLink, linkPath, targetPath)
d.addCallback(self._cbStatus, requestId, 'symlink succeeded')
d.addErrback(self._ebStatus, requestId, 'symlink failed')
开发者ID:12019,项目名称:OpenWrt_Luci_Lua,代码行数:8,代码来源:filetransfer.py
示例11: unpackOpen_direct_tcpip
def unpackOpen_direct_tcpip(data):
"""Unpack the data to a usable format.
"""
connHost, rest = common.getNS(data)
connPort = int(struct.unpack('>L', rest[:4])[0])
origHost, rest = common.getNS(rest[4:])
origPort = int(struct.unpack('>L', rest[:4])[0])
return (connHost, connPort), (origHost, origPort)
开发者ID:alfonsjose,项目名称:international-orders-app,代码行数:8,代码来源:forwarding.py
示例12: packet_RENAME
def packet_RENAME(self, data):
requestId = data[:4]
data = data[4:]
oldPath, data = getNS(data)
newPath, data = getNS(data)
assert data == '', 'still have data in RENAME: %s' % repr(data)
d = defer.maybeDeferred(self.client.renameFile, oldPath, newPath)
d.addCallback(self._cbStatus, requestId, "rename succeeded")
d.addErrback(self._ebStatus, requestId, "rename failed")
开发者ID:12019,项目名称:OpenWrt_Luci_Lua,代码行数:9,代码来源:filetransfer.py
示例13: packet_HANDLE
def packet_HANDLE(self, data):
d, data = self._parseRequest(data)
isFile, name = self.wasAFile.pop(d)
if isFile:
cb = ClientFile(self, getNS(data)[0])
else:
cb = ClientDirectory(self, getNS(data)[0])
cb.name = name
d.callback(cb)
开发者ID:12019,项目名称:OpenWrt_Luci_Lua,代码行数:9,代码来源:filetransfer.py
示例14: packet_VERSION
def packet_VERSION(self, data):
version, = struct.unpack('!L', data[:4])
data = data[4:]
d = {}
while data:
k, data = getNS(data)
v, data = getNS(data)
d[k]=v
self.version = version
self.gotServerVersion(version, d)
开发者ID:12019,项目名称:OpenWrt_Luci_Lua,代码行数:10,代码来源:filetransfer.py
示例15: parseRequest_pty_req
def parseRequest_pty_req(data):
"""Parse the data from a pty-req request into usable data.
@returns: a tuple of (terminal type, (rows, cols, xpixel, ypixel), modes)
"""
term, rest = common.getNS(data)
cols, rows, xpixel, ypixel = struct.unpack('>4L', rest[: 16])
modes, ignored= common.getNS(rest[16:])
winSize = (rows, cols, xpixel, ypixel)
modes = [(ord(modes[i]), struct.unpack('>L', modes[i+1: i+5])[0]) for i in range(0, len(modes)-1, 5)]
return term, winSize, modes
开发者ID:AnthonyNystrom,项目名称:YoGoMee,代码行数:11,代码来源:session.py
示例16: packet_NAME
def packet_NAME(self, data):
d, data = self._parseRequest(data)
count, = struct.unpack('!L', data[:4])
data = data[4:]
files = []
for i in range(count):
filename, data = getNS(data)
longname, data = getNS(data)
attrs, data = self._parseAttributes(data)
files.append((filename, longname, attrs))
d.callback(files)
开发者ID:12019,项目名称:OpenWrt_Luci_Lua,代码行数:11,代码来源:filetransfer.py
示例17: unpackOpen_direct_tcpip
def unpackOpen_direct_tcpip(data):
"""Unpack the data to a usable format.
"""
connHost, rest = common.getNS(data)
if _PY3 and isinstance(connHost, bytes):
connHost = connHost.decode("utf-8")
connPort = int(struct.unpack('>L', rest[:4])[0])
origHost, rest = common.getNS(rest[4:])
if _PY3 and isinstance(origHost, bytes):
origHost = origHost.decode("utf-8")
origPort = int(struct.unpack('>L', rest[:4])[0])
return (connHost, connPort), (origHost, origPort)
开发者ID:JohnDoes95,项目名称:project_parser,代码行数:12,代码来源:forwarding.py
示例18: agentc_SIGN_REQUEST
def agentc_SIGN_REQUEST(self, data):
"""
Data is a structure with a reference to an already added key object and
some data that the clients wants signed with that key. If the key
object wasn't loaded, return AGENT_FAILURE, else return the signature.
"""
blob, data = getNS(data)
if blob not in self.factory.keys:
return self.sendResponse(AGENT_FAILURE, '')
signData, data = getNS(data)
assert data == '\000\000\000\000'
self.sendResponse(AGENT_SIGN_RESPONSE, NS(self.factory.keys[blob][0].sign(signData)))
开发者ID:AnthonyNystrom,项目名称:YoGoMee,代码行数:12,代码来源:agent.py
示例19: request_env
def request_env(self, data):
"""
"""
name, rest = getNS(data)
value, rest = getNS(rest)
if rest:
raise ValueError("Bad data given in env request")
log.msg(eventid='KIPP0013', format='request_env: %(name)s=%(value)s',
name=name, value=value)
# Environment variables come after shell or before exec command
if self.session:
self.session.environ[name] = value
return 0
开发者ID:benzeng,项目名称:cowrie,代码行数:13,代码来源:ssh.py
示例20: verify
def verify(self, signature, data):
"""
Verify a signature using this key.
@type signature: L{bytes}
@param signature: The signature to verify.
@type data: L{bytes}
@param data: The signed data.
@rtype: L{bool}
@return: C{True} if the signature is valid.
"""
if len(signature) == 40:
# DSA key with no padding
signatureType, signature = b'ssh-dss', common.NS(signature)
else:
signatureType, signature = common.getNS(signature)
if signatureType != self.sshType():
return False
if self.type() == 'RSA':
k = self._keyObject
if not self.isPublic():
k = k.public_key()
verifier = k.verifier(
common.getNS(signature)[0],
padding.PKCS1v15(),
hashes.SHA1(),
)
elif self.type() == 'DSA':
concatenatedSignature = common.getNS(signature)[0]
r = int_from_bytes(concatenatedSignature[:20], 'big')
s = int_from_bytes(concatenatedSignature[20:], 'big')
signature = encode_dss_signature(r, s)
k = self._keyObject
if not self.isPublic():
k = k.public_key()
verifier = k.verifier(
signature, hashes.SHA1())
else:
raise BadKeyError("unknown key type %s" % (self.type(),))
verifier.update(data)
try:
verifier.verify()
except InvalidSignature:
return False
else:
return True
开发者ID:daweasel27,项目名称:PhobiaEnemy,代码行数:49,代码来源:keys.py
注:本文中的twisted.conch.ssh.common.getNS函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论