SSH honeypot login shell

SSH honeypot login shell

Last modified
Lines 103
Indexable Yes

Parent directory Download CGIread sitemap Main page

Quick links: (none)

  1. #!/usr/bin/python2
  2. import os
  3. import sys
  4. import time
  5. import random
  6. import signal
  7. '''SSH honeypot login shell.'''
  8. signal.signal(signal.SIGTSTP, signal.SIG_IGN)
  9. os.system('mesg n 2> /dev/null')
  10. filename = time.strftime('/var/log/dipshits/%Y-%m-%d_%H:%M:%S')
  11. username = os.getenv('USER')
  12. sys.stderr.write('''
  13. ********************
  14. *                  *
  15. *  ACCESS GRANTED  *
  16. *                  *
  17. ********************
  18. ''')
  19. oldprompt, prompt = 'Fuck you>', '[{}@oskog97 ~]# '.format(username)
  20. os.system('echo User: {} > {}'.format(username, filename))
  21. os.system(
  22.     'echo Host: $(echo $SSH_CLIENT | cut -d " " -f 1) >> {}'.format(
  23.         filename
  24.     )
  25. )
  26. incident_log = open(filename, 'a')
  27. incident_log.write('Time: {}\n'.format(
  28.     time.strftime('%Y-%m-%d %H:%M:%S UTC', time.gmtime())
  29. ))
  30. commandmode = False
  31. if len(sys.argv) == 3:
  32.     if sys.argv[1] == '-c':
  33.         commandmode = True
  34. if commandmode:
  35.     incident_log.write('Command: {}\n'.format(repr(sys.argv[2])))
  36. else:
  37.     if len(sys.argv) != 1:
  38.         for index, arg in enumerate(sys.argv):
  39.             incident_log.write('sys.argv[{}] = {}\n'.format(index, repr(arg)))
  40.     incident_log.write('Script:\n')
  41.     try:
  42.         while True:
  43.             try:
  44.                 sys.stderr.write(prompt)
  45.                 sys.stderr.flush()
  46.                 line = sys.stdin.readline()
  47.                 if not line:
  48.                     break
  49.             except KeyboardInterrupt:
  50.                 sys.stderr.write('\n')
  51.                 continue
  52.             incident_log.write('{}: {}\n'.format(
  53.                 time.strftime('%Y-%m-%d %H:%M:%S UTC', time.gmtime()),
  54.                 repr(line.rstrip('\n'))
  55.             ))
  56.             incident_log.flush()    # Inspect in real time.
  57.             # Let's have some fun with the dipshit.
  58.             # Cut off newline and truncate if NULs.
  59.             line = line[:line.find('\0')]
  60.             if line:
  61.                 if len(line) % 2:
  62.                     line = line[:-1]
  63.                 try:
  64.                     # What moron would ever use UTF-16?
  65.                     sys.stderr.write(
  66.                         'bash: {}: command not found\n'.format(
  67.                             line.decode('utf-16-le').encode('utf-8')
  68.                         )
  69.                     )
  70.                 except:
  71.                     pass
  72.         sys.stderr.write('\n')
  73.     except:
  74.         pass
  75. incident_log.write('%\n')
  76. incident_log.close()
  77. sys.stderr.write('''
  78. This incident will be reported.
  79. Have a bad day, you deserve it.
  80. ''')
  81. os.system(
  82.     'mesg y 2> /dev/null; ' +
  83.     'for username in `who | cut -d" " -f1 | sort | uniq`; do ' +
  84.         'write $username < {} 2> /dev/null; '.format(filename) +
  85.     'done '
  86. )