Created
April 22, 2014 01:35
-
-
Save Inndy/11162537 to your computer and use it in GitHub Desktop.
Download CCleaner and extract
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
fnull是做什麼用的?? 不懂