How to use the censys.ipv4 function in censys

To help you get started, we’ve selected a few censys examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github shaanen / osint-combiner / test-censys-search.py View on Github external
#!/usr/bin/env python3
import censys.ipv4
import configparser
import json
from base import censys_get_user_input

config = configparser.ConfigParser()
config.read("config.ini")
CENSYS_API_ID = (config['SectionOne']['CENSYS_API_ID'])
CENSYS_API_KEY = (config['SectionOne']['CENSYS_API_KEY'])
nrOfResults = 0

chosen_query = censys_get_user_input()

c = censys.ipv4.CensysIPv4(api_id=CENSYS_API_ID, api_secret=CENSYS_API_KEY)
for record in c.search(chosen_query):
    nrOfResults += 1
    print(json.dumps(record))
print("Results received:", nrOfResults)
github shaanen / osint-combiner / fill_censys-surfnet.py View on Github external
import socket
import sys
from base import censys_get_user_input

HOST = 'localhost'
PORT = 5041
config = configparser.ConfigParser()
config.read("config.ini")
CENSYS_API_ID = (config['SectionOne']['CENSYS_API_ID'])
CENSYS_API_KEY = (config['SectionOne']['CENSYS_API_KEY'])
nrOfResults = 0
nrOfResultsSent = 0

chosen_query = censys_get_user_input()

c = censys.ipv4.CensysIPv4(api_id=CENSYS_API_ID, api_secret=CENSYS_API_KEY)
for record in c.search(chosen_query):
    nrOfResults += 1
    msg = json.dumps(record).encode('utf-8')
    try:
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    except socket.error as msg:
        sys.stderr.write("[ERROR] %s\n" % msg[1])
        sys.exit(1)
    try:
        sock.connect((HOST, PORT))
        sock.send(msg)
        nrOfResultsSent += 1
    except socket.error as msg:
        sys.stderr.write("[ERROR] %s\n" % msg[1])
        sys.exit(2)
print("Results received:", nrOfResults)
github Warflop / CloudBunny / censys_search.py View on Github external
def censys_search(title):
    try:
        api = censys.ipv4.CensysIPv4(api_id=UID, api_secret=TOKEN)
        query = api.search('80.http.get.title: "{0}"'.format(title))
        title_result = set([host['ip'] for host in query])
        if title_result:
            return title_result
    except:
        print("[-] We got an error here, maybe with your credentials!")
        exit(1)
github Warflop / CloudBunny / censys_search.py View on Github external
def censys_search_certs(host):
    try:
        certificates = censys.certificates.CensysCertificates(api_id=UID, api_secret=TOKEN)

        cert_query = certificates.search("parsed.names: {0} AND tags.raw: trusted AND NOT parsed.names: cloudflaressl.com".format(host))        
        result = set([cert['parsed.fingerprint_sha256'] for cert in cert_query])        
        hosts_query = censys.ipv4.CensysIPv4(api_id=UID, api_secret=TOKEN)
        hosts = ' OR '.join(result)
        if hosts:
            searching = hosts_query.search(hosts)
            host_result = set([ search_result['ip'] for search_result in searching ])
            return host_result
    except:
        print("[-] We got an error here, maybe with your credentials!")
        exit(1)
github gyoisamurai / GyoiThon / modules / Gyoi_Censys.py View on Github external
def search_censys(self, ip_addr, fqdn):
        self.utility.print_message(NOTE, 'Search Censys.')
        msg = self.utility.make_log_msg(self.utility.log_in,
                                        self.utility.log_dis,
                                        self.file_name,
                                        action=self.action_name,
                                        note='Search Censys',
                                        dest=self.utility.target_host)
        self.utility.write_log(20, msg)

        server_info = []
        cert_info = []
        try:
            # Check network expose information.
            is_https = False
            api = censys.ipv4.CensysIPv4(api_id=self.api_id, api_secret=self.secret)
            self.utility.print_message(OK, 'Check open web ports.')

            # Extract search result.
            for result in api.search('ip:{}'.format(ip_addr)):
                for idx, items in enumerate(result['protocols']):
                    # Get port number and protocol type.
                    server_info.append({'Open Port': items.split('/')[0], 'Protocol': items.split('/')[1]})
                    self.utility.print_message(WARNING, 'Open web port {}: {}'.format(idx+1, items))
                    if items.split('/')[1] == 'https':
                        is_https = True

            # Check certification.
            if is_https is True:
                self.utility.print_message(OK, 'Check certification.')
                api = censys.certificates.CensysCertificates(api_id=self.api_id, api_secret=self.secret)
                fields = ['parsed.subject_dn', 'parsed.validity', 'parsed.signature_algorithm', 'parsed.subject']
github am0nt31r0 / OSINT-Search / osintS34rCh.py View on Github external
def censysSearch(target, censys_id, censys_secret):

	print ("\n-> Censys Results\n")

	if validators.ip_address.ipv4(target):

		c = censys.ipv4.CensysIPv4(api_id=censys_id, api_secret=censys_secret)

		data = c.view(target)

		print ('[*] IP: ' + data['ip'])

		for protocol in data['protocols']:
			print ('[*] Protocol: ' + protocol)

		print ("""[*] Country: {}
[*] Registered Country: {}
[*] Longitude: {}
[*] Latitude: {}
[*] Continent: {}
[*] Timezone: {}""".format(data['location'].get('country', 'N/A'), data['location'].get('registered_country', 'N/A'), data['location'].get('longitude', 'N/A'), data['location'].get('latitude', 'N/A'), data['location'].get('continent', 'N/A'), data['location'].get('timezone', 'N/A')))

		print ("""[*] AS Name: {}
github M0tHs3C / Argo / lib / censysSearch.py View on Github external
pass
                    #query = '/wap.htm'
                elif selection == 4:
                    query = 'My-Home bticino'
                elif selection == 5:
                    query = 'linux upnp avtech'
                elif selection == 6:
                    query = 'GoAhead 5ccc069c403ebaf9f0171e9517f40e41'
                elif selection == 7 or selection == 3:
                    query = '80.http.get.headers.server:Boa 0.94.14rc21'
                elif selection == 8:
                    query = 'WWW-Authenticate: Basic realm="Embedded-Device"'
                elif selection == 9:
                    query = input('[-]Enter your custom query: ')
                print(query)
                for record in censys.ipv4.CensysIPv4(api_id=uid, api_secret=secret).search(query):
                    ip = record['ip']
                    port = record['protocols']
                    port_raw = port[0]
                    port = re.findall(r'\d+', port_raw)
                    with open(path + '/Host/host.txt', "a") as cen:
                        cen.write(ip + ":" + str(port[0]))
                        cen.write("\n")
            except KeyboardInterrupt:
                print("[*]Exiting...")
            except CensysException:
                pass
            except UnboundLocalError:
                print("[No query passed]")
github gradiuscypher / bounty_tools / enrichment / censys.py View on Github external
def ip_info(config, ip_address):
    api_id = config.get("Censys", "api_id")
    api_secret = config.get("Censys", "api_secret")
    censys_ip = censys.ipv4.CensysIPv4(api_id=api_id, api_secret=api_secret)
    return censys_ip.view(ip_address)
github black-security / cyber-security-framework / apis / censys.py View on Github external
def __init__(self, api_id: str = "", api_secret: str = ""):
        self.api_id = self.api_secret = ""
        if api_id:
            self.api_id = api_id
            self.api_secret = api_secret
        self.ipv4 = ipv4.CensysIPv4(self.api_id, self.api_secret)
        self.websites = websites.CensysWebsites(self.api_id, self.api_secret)
        self.certificates = certificates.CensysCertificates(self.api_id, self.api_secret)
        self.export = export.CensysExport(self.api_id, self.api_secret)
github Te-k / harpoon / harpoon / commands / censyscmd.py View on Github external
def run(self, conf, args, plugins):
        if 'subcommand' in args:
            if args.subcommand == 'ip':
                api = ipv4.CensysIPv4(conf['Censys']['id'], conf['Censys']['secret'])
                if args.search:
                    res = api.search(args.IP)
                    for r in res:
                        if len(r['ip']) > 11:
                            print("[+] %s\t[Location: %s] [Ports: %s]" % (
                                    r['ip'],
                                    r['location.country'],
                                    " ".join(r['protocols'])
                                )
                            )
                        else:
                            print("[+] %s\t\t[Location: %s] [Ports: %s]" % (
                                    r['ip'],
                                    r['location.country'],
                                    " ".join(r['protocols'])
                                )