def unpack_zip(cls, zip_file_path, tmp_dir, password=None): """解压zip文件 :param zip_file_path: zip文件路径 :param tmp_dir: 临时解压路径 :param password: 解压密码 """ pyminizip.uncompress(zip_file_path, password, tmp_dir, False)
def zip_decrypt_file(file_to_decrypt, password): """ Zip decompress file with password """ print("[i] Decompressing file: ", file_to_decrypt) dst_directory = os.path.dirname(file_to_decrypt) # Ignore deprecation warnings so we don't flood the console with garbage # This is a known issue in pyminizip; see: https://github.com/smihica/pyminizip/issues/34 with warnings.catch_warnings(): warnings.filterwarnings("ignore", category=DeprecationWarning) pyminizip.uncompress(file_to_decrypt, password, dst_directory, 0)
def unprotectfile(inputfile, password): if os.path.exists(inputfile[:-4]): print('ERROR: There is already a folder in this directory with the name: '+inputfile[:-4]) else: os.makedirs(inputfile[:-4]) try: if password: pyminizip.uncompress(inputfile, password, inputfile[:-4], True) else: pyminizip.uncompress(inputfile, "infected", inputfile[:-4], True) except: print('ERROR: An error occured trying to extract the file.') return
def extract(archive_path, password, target_path="."): """ Extracts archive using password to given target location :param archive_path: str path to archive :param password: str archive password :param target_path: str target path :return: path where the archive was extracted """ logger.info('extracting data from {}'.format(archive_path)) pyminizip.uncompress(archive_path, password, target_path, 0) return target_path
def main(argv): password = None home = str(Path.home()) password_file = os.path.join(home, '.amli') if os.path.exists(password_file): with open(password_file) as f: password = f.read().replace('\n', '') else: password = getpass.getpass("Password: ") for root, _, files in os.walk('content'): for name in files: if name.endswith('-key.zip'): zname = os.path.join(root, name) pyminizip.uncompress(zname, password, None, 0)
def load(self, path=None, password=None, ask=False, remove=True, **kwargs): """ This method decompresses the given archive, eventually given a password. :param path: path to the archive to be extracted :param password: password string to be passed :param ask: whether a password should be asked or not :param remove: remove after decompression """ if not self.is_archive: raise ValueError("Not an archive") password = getpass() if ask else password dst = Path(path or str(self.dirname.joinpath(self.stem)), create=True) # Pyminizip changes the current working directory after extraction of an archive ; so backup the current # working directory to restore it after decompression cwd = os.getcwd() uncompress(str(self), password or "", str(dst), False) os.chdir(cwd) if remove: self.remove() return ProjectPath(dst)
def _secure_save_data(self): """ Stores partner name and address in a CSV file on NAS, inside a password-protected ZIP file. :return: None """ sftp = self._get_sftp_connection() if sftp: config_obj = self.env["ir.config_parameter"].sudo() store_path = config_obj.get_param("partner_compassion.store_path") src_zip_file = tempfile.NamedTemporaryFile() file_size = sftp.getfo(store_path, src_zip_file) if file_size: src_zip_file.flush() zip_dir = tempfile.mkdtemp() pyminizip.uncompress(src_zip_file.name, SftpConfig.file_pw, zip_dir, 0) csv_path = zip_dir + "/partner_data.csv" with open(csv_path, "a", newline="", encoding="utf-8") as csv_file: csv_writer = csv.writer(csv_file) csv_writer.writerow([ str(self.id), self.ref, self.contact_address, fields.Date.today(), ]) dst_zip_file = tempfile.NamedTemporaryFile() pyminizip.compress(csv_path, "", dst_zip_file.name, SftpConfig.file_pw, 5) try: sftp.putfo(dst_zip_file, store_path) except Exception: logger.error( "Couldn't store secure partner data on NAS. " "Please do it manually by replicating the following " "file: " + dst_zip_file.name) finally: src_zip_file.close() dst_zip_file.close()
def _secure_save_data(self): """ Stores partner name and address in a CSV file on NAS, inside a password-protected ZIP file. :return: None """ smb_conn = self._get_smb_connection() if smb_conn and smb_conn.connect(SmbConfig.smb_ip, SmbConfig.smb_port): config_obj = self.env["ir.config_parameter"].sudo() share_nas = config_obj.get_param("partner_compassion.share_on_nas") store_path = config_obj.get_param("partner_compassion.store_path") src_zip_file = tempfile.NamedTemporaryFile() attrs = smb_conn.retrieveFile(share_nas, store_path, src_zip_file) file_size = attrs[1] if file_size: src_zip_file.flush() zip_dir = tempfile.mkdtemp() pyminizip.uncompress(src_zip_file.name, SmbConfig.file_pw, zip_dir, 0) csv_path = zip_dir + "/partner_data.csv" with open(csv_path, "a", newline="", encoding="utf-8") as csv_file: csv_writer = csv.writer(csv_file) csv_writer.writerow([ str(self.id), self.ref, self.contact_address, fields.Date.today(), ]) dst_zip_file = tempfile.NamedTemporaryFile() pyminizip.compress(csv_path, "", dst_zip_file.name, SmbConfig.file_pw, 5) try: smb_conn.storeFile(share_nas, store_path, dst_zip_file) except OperationFailure: logger.error( "Couldn't store secure partner data on NAS. " "Please do it manually by replicating the following " "file: " + dst_zip_file.name)
def unpack(tempname): print('') print(' パッケージのインストール中しばらくお待ちください') tempname1 = tempname + "\\" + "pack" plaintext = "rinasvideo" pass2 = xcode.xencode(plaintext) name = ".\\inputpack\\pack.dec" c = os.path.isfile(name) if c == 1: pyminizip.uncompress(name.encode('cp932'), pass2, ".\\", 0) with tarfile.open('./pack.tar', 'r:*') as tar: tar.extractall(tempname1) os.remove('./pack.tar') ws.Beep(494, 100) time.sleep(0.1) ws.Beep(494, 100) else: print(' パッケージが見つかりませんでした。') ws.Beep(494, 1000) time.sleep(0.1) ws.Beep(523, 1000) time.sleep(5)
def main(argv): password = None home = str(Path.home()) password_file = os.path.join(home, '.amli') if os.path.exists(password_file): with open(password_file) as f: password = f.read().replace('\n', '') else: password = getpass.getpass("Password: ") for root, _, files in os.walk('content'): for name in files: if name.endswith('-key.zip'): zname = os.path.join(root, name) key_name = zname.replace('.zip', '.ipynb') pyminizip.uncompress(zname, password, None, 0) lab_name = zname.replace('-key.zip', '.ipynb') nb = nbformat.read(key_name, as_version=4) cells = [] in_answer_key = False for cell in nb.cells: if in_answer_key: if cell.cell_type == 'markdown' and cell.source == '---': in_answer_key = False if cell.cell_type == 'markdown' and cell.source.startswith( '#'): raise Exception(dest_f, cell) else: if cell.cell_type == 'markdown' and '# Answer Key' in cell.source: in_answer_key = True else: cells.append(cell) nb.cells = cells nbformat.write(nb, lab_name) os.remove(key_name)
#!/usr/bin/python3 import sys import os from zipfile import ZipFile from pyminizip import uncompress if len(sys.argv) < 2: print("Usage: %s <zip name>" % sys.argv[0]) exit() else: zip_name = sys.argv[1] next_zip = "" while next_zip != "flag.zip": zip_f = ZipFile(zip_name) next_zip = zip_f.namelist()[0] password = next_zip.split(".")[0] uncompress(zip_name, password, ".", 0) os.remove(zip_name) zip_name = next_zip
def unzip_file(source_zip, target_path, password=None): pyminizip.uncompress(source_zip, password, target_path, 1)
def openfile_pyminizip(path, password): try: pyminizip.uncompress(path,password,"./",0) print('password: ' + password) except: pass
import os import random import pyminizip from parse_pwd import parsePwd for i in range(100, 0, -1): password = parsePwd(f"pwd{i}.png") nextZip = f"{i}.zip" print(password) pyminizip.uncompress(nextZip, password, ".", True) os.remove(nextZip) os.remove(f"pwd{i}.png") flagZip = "flag.zip" flagPwd = f"pwd{0}.png" password = parsePwd(flagPwd) pyminizip.uncompress(flagZip, password, ".", True) os.remove(flagZip) os.remove(flagPwd)
def _decompress(self): data = pyminizip.uncompress( self.__zip_path, self.__password, os.path.abspath(os.path.dirname(self.__auth_file)), 0)