Skip to content

Instantly share code, notes, and snippets.

@pedrotnascimento
Created May 6, 2017 21:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pedrotnascimento/13c5d04377149325b937b3e27eb4c1f2 to your computer and use it in GitHub Desktop.
Save pedrotnascimento/13c5d04377149325b937b3e27eb4c1f2 to your computer and use it in GitHub Desktop.
fews codes, two solutions, that try to achieve the password of a zip file by bruteforce.
#-*- coding: utf-8 -*-
import sys
from zipfile import *
from itertools import chain, tee, product
#TODO recebe path ou nome do arquivo atraves do args
#TODO: verifica se eh path, se for faz o bind do arquivo, se for sรณ arquivo pega o path onde se encontra o arquivo e faz o bind
zipname = "flag.zip"
zip = ZipFile(zipname)
i =1
def home_made(height, combs=None):
ranging = chain(range(48,58), range(65,91),range(97,123))
if combs is None:
combs = [str(chr(i)) for i in ranging]
temp = []
# print combs[0], len(combs[0])<=height, combs
if len(combs[0])<=height:
# print "fine"
for e in combs:
# for i in xrange(33,127):
# print e
for i in chain(range(48,58), range(65,91),range(97,123)) :
# print i
try_it = e+chr(i)
try:
zip.extractall(pwd=try_it)
except RuntimeError:
# print try_it
temp.append(try_it)
continue
except Exception:
temp.append(try_it)
continue
pass
print "try -> ", try_it
# print try_it
# print("Unexpected error:", sys.exc_info()[0])
# raise
# return
# print temp
return gimme_chr(height, temp)
else:
return combs
def hacker_made(zipname):
ranging = chain(range(48,58), range(65,91),range(97,123))
with open("dump.txt", "w") as f:
if combs is None:
combs = [str(chr(i)) for i in ranging]
for length in range(0,20):
for entry in product(combs, repeat= length):
password = ''.join(entry)
try:
with ZipFile(zipname) as zf:
try:
zf.extractall("flagme", pwd=password)
f.write(password + " ")
# print password
except:
pass
except:
print "erro ao abrir arquivo"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment