Repository: cowrie/cowrie

Issue:
Unicode-objects must be encoded before hashing
Hello,

**Describe the bug**
When user type ssh user@server the honeypot produce an error.

**To Reproduce**
Steps to reproduce the behavior:
1. Lanch honeypot
2. Connect to fake system
3. type ssh user@qsdqsd.fr
4. See error in logs


**Server (please complete the following information):**
 - OS: Ubutun 18.04
 - Python: 3.6.9

**Additional context**
Traceback:
```
	Traceback (most recent call last):
	  File "/home/valentin/honeypot/cowrie/cowrie-env/lib/python3.6/site-packages/twisted/python/context.py", line 122, in callWithContext
	    return self.currentContext().callWithContext(ctx, func, *args, **kw)
	  File "/home/valentin/honeypot/cowrie/cowrie-env/lib/python3.6/site-packages/twisted/python/context.py", line 85, in callWithContext
	    return func(*args,**kw)
	  File "/home/valentin/honeypot/cowrie/cowrie-env/lib/python3.6/site-packages/twisted/conch/ssh/service.py", line 45, in packetReceived
	    return f(packet)
	  File "/home/valentin/honeypot/cowrie/cowrie-env/lib/python3.6/site-packages/twisted/conch/ssh/connection.py", line 258, in ssh_CHANNEL_DATA
	    log.callWithLogger(channel, channel.dataReceived, data)
	--- <exception caught here> ---
	  File "/home/valentin/honeypot/cowrie/cowrie-env/lib/python3.6/site-packages/twisted/python/log.py", line 103, in callWithLogger
	    return callWithContext({"system": lp}, func, *args, **kw)
	  File "/home/valentin/honeypot/cowrie/cowrie-env/lib/python3.6/site-packages/twisted/python/log.py", line 86, in callWithContext
	    return context.call({ILogContext: newCtx}, func, *args, **kw)
	  File "/home/valentin/honeypot/cowrie/cowrie-env/lib/python3.6/site-packages/twisted/python/context.py", line 122, in callWithContext
	    return self.currentContext().callWithContext(ctx, func, *args, **kw)
	  File "/home/valentin/honeypot/cowrie/cowrie-env/lib/python3.6/site-packages/twisted/python/context.py", line 85, in callWithContext
	    return func(*args,**kw)
	  File "/home/valentin/honeypot/cowrie/cowrie-env/lib/python3.6/site-packages/twisted/conch/ssh/session.py", line 112, in dataReceived
	    self.client.transport.write(data)
	  File "/home/valentin/honeypot/cowrie/cowrie-env/lib/python3.6/site-packages/twisted/conch/ssh/session.py", line 163, in write
	    self.proto.dataReceived(data)
	  File "/home/valentin/honeypot/cowrie/src/cowrie/insults/insults.py", line 98, in dataReceived
	    insults.ServerProtocol.dataReceived(self, data)
	  File "/home/valentin/honeypot/cowrie/cowrie-env/lib/python3.6/site-packages/twisted/conch/insults/insults.py", line 537, in dataReceived
	    self.terminalProtocol.keystrokeReceived(ch, None)
	  File "/home/valentin/honeypot/cowrie/cowrie-env/lib/python3.6/site-packages/twisted/conch/recvline.py", line 225, in keystrokeReceived
	    m()
	  File "/home/valentin/honeypot/cowrie/src/cowrie/shell/protocol.py", line 320, in handle_RETURN
	    return recvline.RecvLine.handle_RETURN(self)
	  File "/home/valentin/honeypot/cowrie/cowrie-env/lib/python3.6/site-packages/twisted/conch/recvline.py", line 292, in handle_RETURN
	    self.lineReceived(line)
	  File "/home/valentin/honeypot/cowrie/src/cowrie/shell/protocol.py", line 182, in lineReceived
	    self.cmdstack[-1].lineReceived(line)
	  File "/home/valentin/honeypot/cowrie/src/cowrie/shell/honeypot.py", line 173, in lineReceived
	    self.runCommand()
	  File "/home/valentin/honeypot/cowrie/src/cowrie/shell/honeypot.py", line 289, in runCommand
	    self.protocol.call_command(pp, cmdclass, *cmd_array[0]['rargs'])
	  File "/home/valentin/honeypot/cowrie/src/cowrie/shell/protocol.py", line 301, in call_command
	    HoneyPotBaseProtocol.call_command(self, pp, cmd, *args)
	  File "/home/valentin/honeypot/cowrie/src/cowrie/shell/protocol.py", line 191, in call_command
	    obj.start()
	  File "/home/valentin/honeypot/cowrie/src/cowrie/commands/ssh.py", line 74, in start
	    s = hashlib.md5(host).hexdigest()
	builtins.TypeError: Unicode-objects must be encoded before hashing
	

```
Thanks


Discussion:
I can't reproduce this. Which version are you on?
Hello, sorry for the late reply
@micheloosterhof tested on trunk
Thanls
Confirmed! Seems to be a python2/3 string/bytes issue.

Resolving patch:
diff --git a/src/cowrie/commands/ssh.py b/src/cowrie/commands/ssh.py
--- a/src/cowrie/commands/ssh.py
+++ b/src/cowrie/commands/ssh.py
@@ -71,7 +71,7 @@ def start(self):
                     Name or service not known\n' % (host,))
                 self.exit()
         else:
-            s = hashlib.md5(host).hexdigest()
+            s = hashlib.md5(host.encode()).hexdigest()
             self.ip = '.'.join([str(int(x, 16)) for x in
                                 (s[0:2], s[2:4], s[4:6], s[6:8])])
 


Test patch: