version = "2.2.2" import os from subprocess import PIPE, Popen import ctypes import ssl import urllib2 import datetime import time import shutil import re class disable_file_system_redirection: _disable = ctypes.windll.kernel32.Wow64DisableWow64FsRedirection _revert = ctypes.windll.kernel32.Wow64RevertWow64FsRedirection def __enter__(self): self.old_value = ctypes.c_long() self.success = self._disable(ctypes.byref(self.old_value)) def __exit__(self, type, value, traceback): if self.success: self._revert(self.old_value) with disable_file_system_redirection(): arch=os.popen("wmic os get OSArchitecture").read() userout = os.popen('query user').read() username = re.findall("(.*)Active",userout)[0].split()[0] sid = os.popen("wmic useraccount where name=\"%s\" get sid"%(username)).read().splitlines()[1].strip() if '64' in arch: url = "https://cdn-patchportal-one.comodo.com/portal/packages/spm/Authy%20Desktop/x64/Authy%20Desktop%20Setup%202.2.2_64.exe" fileName = "Authy Desktop Setup 2.2.2_64.exe" installpath = "SysWOW64" else: url = "https://cdn-patchportal-one.comodo.com/portal/packages/spm/Authy%20Desktop/x86/Authy%20Desktop%20Setup%202.2.2_32.exe" fileName = "Authy Desktop Setup 2.2.2_32.exe" installpath = "System32" regUrl ="https://script-downloads.itarian.com/AUTHY.reg" Down_path=os.environ['TEMP'] DownTo = os.path.join(Down_path, fileName) RegName = regUrl.split('/')[-1] RegDownTo = os.path.join(Down_path, RegName) batchfile = """ "%s" -s xcopy C:\Windows\%s\config\systemprofile\AppData\Local\\authy "C:\Program Files\\authy" /E /H /C /I "C:\Windows\%s\config\systemprofile\AppData\Local\\authy\Update.exe" --uninstall -s RD /S /Q C:\Windows\%s\config\systemprofile\AppData\Local\\authy reg delete "HKEY_USERS\.DEFAULT\Software\Microsoft\Windows\CurrentVersion\Uninstall\\authy" /f reg import %s REG ADD HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\\authy /v InstallDate /t REG_SZ /d %s REG ADD HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\\authy /v DisplayVersion /t REG_SZ /d %s """%(DownTo,installpath,installpath,installpath,RegDownTo,"".join(str(datetime.date.today()).split("-")),version) ps_content = """ $TargetFile = "C:\Program Files\\authy\Authy Desktop.exe" $ShortcutFile = "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Authy Desktop.lnk" $WScriptShell = New-Object -ComObject WScript.Shell $Shortcut = $WScriptShell.CreateShortcut($ShortcutFile) $Shortcut.TargetPath = $TargetFile $Shortcut.Save() $TargetFile = "C:\Program Files\\authy\Authy Desktop.exe" $ShortcutFile = "C:\Users\Public\Desktop\Authy Desktop.lnk" $WScriptShell = New-Object -ComObject WScript.Shell $Shortcut = $WScriptShell.CreateShortcut($ShortcutFile) $Shortcut.TargetPath = $TargetFile $Shortcut.Save() """ uninstallbatchfile = """ del "C:\Users\Public\Desktop\Authy Desktop.lnk" /s /q del "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Authy Desktop.lnk" /s /q reg delete "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\\authy" /f RD /S /Q "C:\Program Files\\authy" """ useruninstallbatch = """ RD /S /Q "C:\Users\%s\AppData\Local\\authy" del "C:\Users\%s\Desktop\Authy Desktop.lnk" /s /q del "C:\Users\%s\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Twilio Inc\Authy Desktop.lnk" /s /q reg delete "HKEY_USERS\%s\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\\authy" /f """%(username,username,username,sid) def ecmd(command): from subprocess import Popen, PIPE import ctypes with disable_file_system_redirection(): obj = Popen(command, shell = True, stdout = PIPE, stderr = PIPE) out, err = obj.communicate() ret=obj.returncode if ret==0: if out: return out.strip() else: return ret else: if err: return err.strip() else: return ret def downloadFile(DownTo, fromURL): headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36'} context = ssl._create_unverified_context() request = urllib2.Request(fromURL, headers=headers) req = urllib2.urlopen(request,context=context) try: with open(DownTo, 'wb') as f: while True: chunk = req.read(100*1000*1000) if chunk: f.write(chunk) else: break if os.path.isfile(DownTo): return '{} - {}KB'.format(DownTo, os.path.getsize(DownTo)/1024) except: return 'Please Check URL or Download Path!' def spm_install(dir, args): with disable_file_system_redirection(): ps_name='powershell_file.ps1' ps_path=os.path.join(os.environ['TEMP'], ps_name) with open(ps_path, 'wb') as wr: wr.write(ps_content) batch_name = 'batch_file.bat' batch_path=os.path.join(os.environ['TEMP'], batch_name) with open(batch_path, 'wb') as wr: wr.write(batchfile) print(downloadFile(DownTo, url)) print(downloadFile(RegDownTo, regUrl)) print(ecmd(batch_path)) uninstall_name = 'uninstall.bat' uninstall_path=os.path.join(r"C:\Program Files\authy", uninstall_name) with open(uninstall_path, 'wb') as wr: wr.write(uninstallbatchfile) ecmd('powershell "Set-ExecutionPolicy RemoteSigned"') print ecmd('powershell "%s"'%ps_path) os.remove(batch_path) os.remove(DownTo) os.remove(RegDownTo) os.remove(ps_path) def spm_uninstall(dir, args): with disable_file_system_redirection(): if os.path.exists("C:\Users\%s\AppData\Local\\authy\Update.exe"%(username)): batch_name = 'uninstall.bat' batch_path=os.path.join(os.environ['TEMP'], batch_name) with open(batch_path, 'wb') as wr: wr.write(useruninstallbatch) print(ecmd(batch_path)) os.remove(batch_path) elif os.path.exists("C:\Program Files\\authy"): batch_name = 'uninstall.bat' batch_path=os.path.join(os.environ['TEMP'], batch_name) with open(batch_path, 'wb') as wr: wr.write(uninstallbatchfile) print(ecmd(batch_path)) os.remove(batch_path) def spm_update(dir, args): with disable_file_system_redirection(): spm_uninstall(None, None) time.sleep(20) spm_install(None, None)