Skip to content

Instantly share code, notes, and snippets.

@kindlyfire
Created August 2, 2016 13:28
Show Gist options
  • Save kindlyfire/4b2eb61b1df00e74e1843f8afab82620 to your computer and use it in GitHub Desktop.
Save kindlyfire/4b2eb61b1df00e74e1843f8afab82620 to your computer and use it in GitHub Desktop.
from gevent import monkey; monkey.patch_all()
import gevent.server
from telnetsrv.paramiko_ssh import SSHHandler, getRsaKeyFile
from telnetsrv.green import TelnetHandler, command
class MyTelnetHandler(TelnetHandler):
WELCOME = 'Welcome to my portfolio ! Want anything ?\n\n' + 'Get help with the help command.'
PROMPT = "anonymous@cloud:~$ "
@command('help')
def command_help(self, params):
'''
Some commands
'''
self.writeresponse(
'Hey ! You are visiting my telnet-thru-ssh portfolio. Here are some commands you can use: \n\n' +
'help, mail\n\n' +
'I hope you like it as much as I do !'
)
@command('mail')
def command_mail(self, params):
'''
Returns my email address
'''
self.writeresponse('You can get me at: \n\n' +
'- kindlyfire@protonmail.com\n' +
'- me@kindlyfire.me <= you can use my PGP key here \n\n' +
'Get my PGP key using the command "pgp"')
@command('pgp')
def command_pgp(self, params):
'''
Returns links to my PGP keys
'''
self.writeresponse('Need my PGP key ? Here\'s where you can get it:\n\n' +
'- http://pgp.mit.edu/pks/lookup?op=get&search=0x2F4A7417FC0319BF\n' +
'- zero://kindlyfire.bit/pgp.pub (Using ZeroNet only)')
class MySSHHandler(SSHHandler):
# Set the unique host key
host_key = getRsaKeyFile('server_fingerprint.key')
# Instruct this SSH handler to use MyTelnetHandler for any PTY connections
telnet_handler = MyTelnetHandler
# Start a telnet server for just the localhost on port 8023. (Will not request any authentication.)
telnetserver = gevent.server.StreamServer(('127.0.0.1', 8023), MyTelnetHandler.streamserver_handle)
telnetserver.start()
# Start an SSH server for any local or remote host on port 8022
sshserver = gevent.server.StreamServer(("", 8022), MySSHHandler.streamserver_handle)
sshserver.serve_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment