Skip to content

Instantly share code, notes, and snippets.

@gteissier
Created May 10, 2019 09:29
Show Gist options
  • Save gteissier/07549041944837a3dcc27b42d902e2d6 to your computer and use it in GitHub Desktop.
Save gteissier/07549041944837a3dcc27b42d902e2d6 to your computer and use it in GitHub Desktop.
Look for FLAG[0-9a-zA-Z/+=]+ pattern everywhere, even in jar contained in zip contained in ear
#!/usr/bin/env python
import os
import re
import zipfile
from cStringIO import StringIO
def process_file(f):
data = f.read()
for m in re.finditer(r'(FLAG[0-9a-zA-Z/+=]+)', data):
print(m.group(1))
f.seek(0)
if zipfile.is_zipfile(f):
try:
zf = zipfile.ZipFile(f, 'r')
for info in zf.infolist():
data = zf.read(info)
g = StringIO(data)
process_file(g)
except zipfile.BadZipfile:
pass
for (path, dirs, files) in os.walk('.'):
for file in files:
fullpath = os.path.join(path, file)
f = open(fullpath, 'rb')
process_file(f)
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment