Last active
September 8, 2016 12:04
-
-
Save HarryR/622eb85a1d7c4b152c8095f1e159b647 to your computer and use it in GitHub Desktop.
Spider .DS_Store files on a website
This file contains hidden or 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
| #!/usr/bin/env python | |
| import requests | |
| import sys | |
| import requests | |
| import os | |
| from tempfile import mkstemp | |
| from ds_store import DSStore | |
| def main(): | |
| if len(sys.argv) < 2: | |
| print("Usage: spider_DS_Store.py <url>") | |
| return | |
| starturl = sys.argv[1] | |
| tmpfile = mkstemp()[1] | |
| all_found = {} | |
| urls = [starturl] | |
| while len(urls): | |
| url = urls.pop() | |
| resp = requests.get(url + '/.DS_Store', stream=True) | |
| try: | |
| resp.raise_for_status() | |
| with open(tmpfile, 'wb') as fh: | |
| fh.write(resp.raw.read()) | |
| with DSStore.open(tmpfile, "r") as d: | |
| print(url) | |
| for entry in d: | |
| data = entry.__dict__ | |
| if 'filename' in data: | |
| newurl = url + '/' + data['filename'] | |
| if newurl not in all_found: | |
| urls.append(newurl) | |
| all_found[newurl] = True | |
| except Exception as ex: | |
| continue | |
| os.unlink(tmpfile) | |
| if __name__ == "__main__": | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment