Skip to content

Instantly share code, notes, and snippets.

@clive819
Forked from Inndy/download_ccleaner.py
Last active August 29, 2015 14:19
Show Gist options
  • Save clive819/f197218a9c916d5f0e63 to your computer and use it in GitHub Desktop.
Save clive819/f197218a9c916d5f0e63 to your computer and use it in GitHub Desktop.
Download CCleaner and extract
import re, requests, subprocess, os
"""
Download CCleaner and extracting
Tips: make 7z within PATH environment
2014/04/22
Inndy
"""
fnull = open(os.devnull)
def detect_7z():
try:
subprocess.call("7z", stdout = fnull)
return True
except:
return False
def get_download_url(page_url):
content = requests.get(page_url).content
match = re.search(r'"(http://.+exe)"', content)
if match == None:
print "[-] Error: Pattern not found"
return False
else:
return match.group(1)
def main():
url = get_download_url("http://www.piriform.com/ccleaner/download/standard")
if not url:
print "[-] Error: Pattern not found"
exit(1)
print "[+] URL: %s" % url
print "[+] Downloading..."
f = open("ccleaner.exe", "wb")
f.write(requests.get(url).content)
f.close()
print "[+] Download done!"
if not detect_7z():
print "[*] You need 7z to extract"
exit()
print "[+] Extracting"
subprocess.call("mkdir ccleaner", shell = True, stderr = fnull, stdout = fnull)
ret = subprocess.call([ \
"7z", "x", "-y", "-occleaner", "ccleaner.exe", "Lang", \
"CCleaner.exe", "CCleaner64.exe"], stderr = fnull, stdout = fnull)
if ret == 0:
print "[+] Done!"
print "[+] Cleanup..."
os.unlink("ccleaner.exe")
else:
print "[-] 7z returned status code %d" % ret
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment