Mrks's Blog

Simple SSH tarpit (implemented in Python)

This is a simple SSH tarpit.

import asyncio
import random
import time

async def handler(_reader, writer):
    try:
        while True:
            await asyncio.sleep(10)
            writer.write(b'%x\r\n' % random.randint(0, 2**32))
            addr = writer.get_extra_info('peername')
            print(f"Connection from: {addr}, {time.time()}")
            await writer.drain()
    except ConnectionResetError:
        pass

async def main():
    server = await asyncio.start_server(handler, '0.0.0.0', 22)
    async with server:
        await server.serve_forever()


asyncio.run(main())