• Python中shodan模块的使用


    关于shodan的安装和使用,传送门——> 渗透测试之Shodan的安装和使用

    常用 Shodan 库函数

    • shodan.Shodan(key) :初始化连接API
    • Shodan.count(query, facets=None):返回查询结果数量
    • Shodan.host(ip, history=False):返回一个IP的详细信息
    • Shodan.ports():返回Shodan可查询的端口号
    • Shodan.protocols():返回Shodan可查询的协议
    • Shodan.services():返回Shodan可查询的服务
    • Shodan.queries(page=1, sort='timestamp', order='desc'):查询其他用户分享的查询规则
    • Shodan.scan(ips, force=False):使用Shodan进行扫描,ips可以为字符或字典类型
    • Shodan.search(query, page=1, limit=None, offset=None, facets=None, minify=True): 查询Shodan数据

    先写一个简单的脚本,扫描 apache 的主机

    import shodan    #导入shodan库
    api=shodan.Shodan("cB9sXwb7l95ZhSJaNgcaO7NQpkzfhQVM")  #指定API_KEY,返回句柄
    try:
        results=api.search('apache')    #搜索apache,返回 JSON格式的数据
        print(results)
        print("Results found:%s"%results['total'])
        for result in results['matches']:
            print(result['ip_str'])     #打印出ip地址
    except shoadn.APIError,e:
        print("Error:%s"%e)

    返回的JSON格式的数据 

    {
            'total': 8669969,
            'matches': [
                    {
                            'data': 'HTTP/1.0 200 OK
    Date: Mon, 08 Nov 2010 05:09:59 GMT
    Ser...',
                            'hostnames': ['pl4t1n.de'],
                            'ip': 3579573318,
                            'ip_str': '89.110.147.239',
                            'os': 'FreeBSD 4.4',
                            'port': 80,
                            'timestamp': '2014-01-15T05:49:56.283713'
                    },
                    ...
            ]
    }

    我们也可以加上端口号,并且写入文件中,作为访问链接

    import shodan
    
    api=shodan.Shodan("cB9sXwb7l95ZhSJaNgcaO7NQpkzfhQVM")
    def FindTarget():
        try:
            f=open("target.txt","w")
            results=api.search('JAWS/1.0') 
            print("Results found:%s"%results['total'])
            for result in results['matches']:
                url=result['ip_str']+":"+str(result['port'])
                print(url) 
                f.write(url)
                f.write("
    ")
            f.close()
        except shodan.APIError,e:
            print("Error:%s"%e)
    FindTarget()

  • 相关阅读:
    What is Continuous Integration?
    10 Essential TypeScript Tips And Tricks For Angular Devs
    javascript 的事件绑定和取消事件
    Directive Controller And Link Timing In AngularJS
    做事情的态度——做精做细
    How to simplify a PHP code with the help of the façade pattern?
    Can we say objects have attributes, states and behaviors?
    represent states with objects
    【转】一次是不算数的
    nyoj27-水池数目 (求连通块数目)【dfs】
  • 原文地址:https://www.cnblogs.com/csnd/p/11807796.html
Copyright © 2020-2023  润新知