zoukankan      html  css  js  c++  java
  • Python 提取图片中的GPS信息

    JPG图片中默认存在敏感数据,例如位置,相机类型等,可以使用Python脚本提取出来,加以利用,自己手动拍摄一张照片,然后就能解析出这些敏感数据了,对于渗透测试信息搜索有一定帮助,但有些相机默认会抹除这些参数。

    提取图片EXIF参数: 通过提取指定图片的EXIF参数结合GPS数据定位到当时拍摄图片的物理位置.

    import os,sys,json
    import exifread
    import urllib.request
    
    #调用百度地图API通过经纬度获取位置
    def getlocation(lat,lon):   
        url = "http://api.map.baidu.com/reverse_geocoding/v3/?ak=GPqF0q0uFT4zOmVKmPU7 \
        gu3SmB9z3jFV&output=json&coordtype=wgs84ll&location="+lat+","+lon
        req = urllib.request.urlopen(url)
        res = req.read().decode("utf-8")
        string = json.loads(res)
        jsonResult = string.get("result")
        formatted_address = jsonResult.get("formatted_address")
        print("目标所在城市: {}".format(formatted_address))
    
    if __name__ == "__main__":
        if len(sys.argv) < 2:
            print("[-] 请传递一个图片地址")
        else:
            ImageName = str(sys.argv[1])
            with open(ImageName,'rb') as f:
                tags = exifread.process_file(f)
                print("设备品牌: {}".format(tags['Image Make']))
                print("具体型号: {}".format(tags['Image Model']))
                print('照片尺寸: {} x {}'.format(tags['EXIF ExifImageWidth'], tags['EXIF ExifImageLength']))
                print("创建日期: {}".format(tags['Image DateTime']))
                print("拍摄时间: {}".format(tags["EXIF DateTimeOriginal"].printable))
                print("GPS处理方法: {}".format(tags['GPS GPSProcessingMethod']))
                print("GPSTimeStamp: {}".format(tags['GPS GPSTimeStamp']))
                print("拍摄软件版本: {}".format(tags['Image Software']))
                #纬度
                LatRef=tags["GPS GPSLatitudeRef"].printable
                Lat=tags["GPS GPSLatitude"].printable[1:-1].replace(" ","").replace("/",",").split(",")
                Lat=float(Lat[0])+float(Lat[1])/60+float(Lat[2])/float(Lat[3])/3600
                if LatRef != "N":
                    Lat=Lat*(-1)
                #经度
                LonRef=tags["GPS GPSLongitudeRef"].printable
                Lon=tags["GPS GPSLongitude"].printable[1:-1].replace(" ","").replace("/",",").split(",")
                Lon=float(Lon[0])+float(Lon[1])/60+float(Lon[2])/float(Lon[3])/3600
                if LonRef!="E":
                    Lon=Lon*(-1)
                f.close()
                print("目标所在经纬度: {},{}".format(Lat,Lon))
                getlocation(str(Lat),str(Lon))
    

    将图片转为字符图片: 通过pillow图片处理库,对图片进行扫描,然后用特殊字符替换图片的每一个位,生成的字符图片.

    from PIL import Image
    import argparse
    
    # 将256灰度平均映射到70个字符上
    def get_char(r,g,b,alpha = 256):
        ascii_char = list("~!@#$%^&*()_+ ")
        if alpha == 0:
            return " "
        length = len(ascii_char)
        gray = int(0.2126 * r + 0.7152 * g + 0.0722 * b)
        unit = (256.0 + 1)/length
        return ascii_char[int(gray/unit)]
    
    if __name__ == "__main__":
        parser = argparse.ArgumentParser()
        parser.add_argument("--file",dest="file",help="指定一个图片文件")
        parser.add_argument("--width",dest="width",type=int,default=50,help="指定图片宽度")
        parser.add_argument("--height",dest="height",type=int,default=25,help="指定图片高度")
        args = parser.parse_args()
        # 使用方式: pip install pillow | main.py --file=xxx.jpg
        if args.file != None:
            img = Image.open(args.file)
            img = img.resize((args.width,args.height), Image.NEAREST)
            txt = ""
            for row in range(args.height):
                for cow in range(args.width):
                    txt += get_char(*img.getpixel((cow,row)))
                txt += "\n"
            print(txt)
        else:
            parser.print_help()
    
    文章出处:https://www.cnblogs.com/LyShark/p/12442710.html
    版权声明:本博客文章与代码均为学习时整理的笔记,博客中除去明确标注有参考文献的文章,其他文章 [均为原创] 作品,转载请 [添加出处] ,您添加出处是我创作的动力!

    如果您恶意转载本人文章并被本人发现,则您的整站文章,将会变为我的原创作品,请相互尊重 !
    转载规范 点击阅读 如果您转载本人文章,则视为您默认同意此规范约定。
  • 相关阅读:
    Salesforce的数据权限机制
    Java并发编程:Java内存模型和volatile
    Java并发编程:synchronized和锁优化
    权限控制和OAuth
    MySQL explain详解
    ConcurrentHashMap源码阅读
    HashMap源码阅读
    领域驱动设计的基础知识总结
    Chris Richardson微服务翻译:重构单体服务为微服务
    Chris Richardson微服务翻译:微服务部署
  • 原文地址:https://www.cnblogs.com/LyShark/p/12442710.html
Copyright © 2011-2022 走看看