Skip to content

Instantly share code, notes, and snippets.

@jasperla
Created March 27, 2020 09:34
Show Gist options
  • Save jasperla/cfb8f16c685e40e4ea13db07cd99c2c5 to your computer and use it in GitHub Desktop.
Save jasperla/cfb8f16c685e40e4ea13db07cd99c2c5 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
#
# quick-n-dirty script to download all tags for a given registry.
# Might come in handy when trawling Shodan.
import json
import requests
from urllib3.exceptions import InsecureRequestWarning
public_ips = []
def list_repositories(ip):
uri = 'https://{}/v2/_catalog'.format(ip)
try:
r = requests.get(uri, verify=False)
if r.status_code != 200:
raise
repos = json.loads(r.text)
return repos['repositories']
except Exception as e:
print("Failed to GET {} due to {}, skipping", uri, e)
return []
def list_tags(ip, repo):
uri = 'https://{}/v2/{}/tags/list'.format(ip, repo)
try:
r = requests.get(uri, verify=False)
if r.status_code != 200:
raise
tags = json.loads(r.text)
return tags['tags']
except Exception as e:
print("Failed to GET {} due to {}, skipping", uri, e)
return []
def main():
# Ignore any certificate errors, we don't care whether the certificate expired or is
# self-signed.
requests.packages.urllib3.disable_warnings(category=InsecureRequestWarning)
for ip in public_ips:
repos = list_repositories(ip)
if repos:
print("Tags found at {}:\n".format(ip))
for repo in repos:
tags = list_tags(ip, repo)
for tag in tags:
print("{}:{}".format(repo, tag))
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment