import optparse from PIL import Image from PIL.ExifTags import TAGS import urllib2 from bs4 import BeautifulSoup as BS from os.path import basename from urlparse import urlsplit
def findImages(url): print '[+] Finding images on ' + url urlContent = urllib2.urlopen(url).read() soup = BS(urlContent, 'lxml') imgTags = soup.findAll('img') return imgTags
def downloadImage(imgTag): try: print '[+] Dowloading image...' imgSrc = imgTag['src'] imgContent = urllib2.urlopen(imgSrc).read() imgFileName = basename(urlsplit(imgSrc)[2]) imgFile = open(imgFileName, 'wb') imgFile.write(imgContent) imgFile.close() return imgFileName except: return ' '
def testForExif(imgFileName): try: exifData = {} imgFile = Image.open(imgFileName) info = imgFile._getexif() if info: for (tag, value) in info.items(): decoded = TAGS.get(tag, tag) exifData[decoded] = value exifGPS = exifData['GPSInfo'] if exifGPS: print '[*] ' + imgFileName + ' contains GPS MetaData' except: pass
def main(): parser = optparse.OptionParser('[*]Usage: python Exif.py -u <target url>') parser.add_option('-u', dest='url', type='string', help='specify url address') (options, args) = parser.parse_args() url = options.url if url == None: print parser.usage exit(0) else: imgTags = findImages(url) for imgTag in imgTags: imgFileName = downloadImage(imgTag) testForExif(imgFileName)
if name == 'main': main()