Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def cleanup(self):
self.c.connectionLost(failure.Failure(main.CONNECTION_DONE))
self.s.connectionLost(failure.Failure(main.CONNECTION_DONE))
reactor.iterate() # last gasp before I go away
def upnp_ImportResource(self, *args, **kwargs):
print 'upnp_ImportResource', args, kwargs
SourceURI = kwargs['SourceURI']
DestinationURI = kwargs['DestinationURI']
if DestinationURI.endswith('?import'):
id = DestinationURI.split('/')[-1]
id = id[:-7] # remove the ?import
else:
return failure.Failure(errorCode(718))
item = self.get_by_id(id)
if item == None:
return failure.Failure(errorCode(718))
def gotPage(result):
try:
import cStringIO as StringIO
except ImportError:
import StringIO
self.backend_import(item, StringIO.StringIO(result[0]))
def gotError(error, url):
self.warning("error requesting %s", url)
self.info(error)
return failure.Failure(errorCode(718))
d = getPage(SourceURI)
def block(self):
if self.consuming:
try:
data = self.fdes.writeQ.get_nowait()
except Queue.Empty:
self.producing = 0
self.q.put((self.fdes.produceMore, 1))
data = self.fdes.writeQ.get()
else:
data = self.fdes.writeQ.get()
if data is None:
self.stop()
return (self.fdes.connectionLost, failure.Failure())
elif data == BEGIN_CONSUMING:
self.consuming = 1
elif data == END_CONSUMING:
self.consuming = 0
else:
# bytes = jarray.array(map(ord, data), 'b')
try:
self.fdes.ostream.write(data)
self.fdes.ostream.flush()
except SocketException:
self.stop()
return (self.fdes.connectionLost, failure.Failure())
def _connectionFailed(self, reason):
msg = ("Authentication handshake to {} failed. Reason: {}."
.format(self.micro_status_entry.fingerprint, reason))
logging.debug(msg)
if self._failed is False:
self._failed = True
self.transport.abortConnection()
self._connection_manager.connectionTaskFailed(
self, Failure(Exception(reason)))
def errbackDefers(self, failure):
defers = self.defers
self.defers = []
for d in defers:
if not d.called:
d.errback(Failure())
def requestAvatarId(self, credentials):
_pubKey = keys.Key.fromString(credentials.blob)
log.msg(eventid='cowrie.client.fingerprint',
format='public key attempt for user %(username)s of type %(type)s with fingerprint %(fingerprint)s',
username=credentials.username,
fingerprint=_pubKey.fingerprint(),
key=_pubKey.toString('OPENSSH'),
type=_pubKey.sshType())
return failure.Failure(error.ConchError('Incorrect signature'))
def connectionMade(self):
msg = "Connection made to {}.".format(self.micro_status_entry.address)
logging.debug(msg)
try:
self._tasks = self._sendVersionsCell()
self._tasks.addCallback(self._processVersionsCell)
self._tasks.addCallback(self._processCertsCell)
self._tasks.addCallback(self._processAuthChallengeCell)
self._tasks.addCallback(self._processNetInfoCell)
self._tasks.addCallback(self._sendNetInfoCell)
self._tasks.addCallback(self._connectionSucceeded)
self._tasks.addErrback(self._connectionFailed)
except Exception as e:
self._connectionFailed(Failure(e))
lambda body: Failure(Exception(response.code, body)),
)