├── .gitignore ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── censys_companies.py ├── censys_domain.py ├── censys_email_address.py ├── censys_email_to_domains.py ├── censys_hostname.py ├── censys_ip.py ├── censys_netblock.py ├── censys_netblock_company.py ├── censys_org.py ├── censys_query.py ├── censys_subdomains.py ├── censys_tls_subjects.py ├── install.sh ├── pyproject.toml ├── requirements.txt └── setup.cfg /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # Distribution / packaging 7 | .Python 8 | build/ 9 | develop-eggs/ 10 | dist/ 11 | downloads/ 12 | eggs/ 13 | .eggs/ 14 | lib/ 15 | lib64/ 16 | parts/ 17 | sdist/ 18 | var/ 19 | wheels/ 20 | share/python-wheels/ 21 | *.egg-info/ 22 | .installed.cfg 23 | *.egg 24 | MANIFEST 25 | 26 | # Unit test / coverage reports 27 | htmlcov/ 28 | .tox/ 29 | .nox/ 30 | .coverage 31 | .coverage.* 32 | .cache 33 | nosetests.xml 34 | coverage.xml 35 | *.cover 36 | *.py,cover 37 | .hypothesis/ 38 | .pytest_cache/ 39 | cover/ 40 | 41 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 42 | __pypackages__/ 43 | 44 | # Environments 45 | .env 46 | .venv 47 | env/ 48 | venv/ 49 | ENV/ 50 | env.bak/ 51 | venv.bak/ 52 | 53 | # mypy 54 | .mypy_cache/ 55 | .dmypy.json 56 | dmypy.json 57 | 58 | # macOS 59 | .DS_Store 60 | .AppleDouble 61 | .LSOverride 62 | 63 | # IDE 64 | .vscode/ 65 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to censys-recon-ng 2 | 3 | Contributions to this project are welcome! Please follow the simple instructions below. 4 | 5 | 1. Clone this project into your own Github code repository 6 | 2. Create a new branch within your project. All development work will need to take place within your branch. 7 | 3. Please name your branch using this format: `USERNAME/FEATURENAME` 8 | 4. Make changes within your branch and upload to your repository. 9 | 5. Submit a pull request to our project and someone will evaluate and likely merge your changes. 10 | 11 | We will do the best we can to review your code as quickly as possible and communicate expectations about what changes, if any, are needed before we can merge your changes. 12 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Censys `recon-ng` Modules 2 | 3 | [![License](https://img.shields.io/github/license/censys/censys-recon-ng)](LICENSE) 4 | [![Code Style](https://img.shields.io/badge/code%20style-black-000000)](https://github.com/psf/black) 5 | [![Code Style](https://img.shields.io/badge/code%20style-pycodestyle-blue)](https://github.com/PyCQA/pycodestyle) 6 | [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](http://makeapullrequest.com) 7 | 8 | We have written several modules for [`recon-ng`](https://github.com/lanmaster53/recon-ng) adding data via the Censys API. These were inspired by the work that [@scumsec](https://github.com/scumsec/Recon-ng-modules) did on the original recon-ng additions from their add-on modules, and also from the subdomain enumeration techniques that use Censys data like from [@christophetd](https://github.com/christophetd/censys-subdomain-finder). 9 | 10 | ## Installation 11 | 12 | We have provided two pieces you need to install these modules and begin using them. 13 | 14 | - `requirements.txt` - Use this via `pip install -r requirements.txt` to install Python dependencies. 15 | - `install.sh`- Run this script and it will both install the modules in your home directory (recon-ng supports modules added for the local user in `~/.recon-ng`) and configures the database to add support for your Censys API ID and secret. See your Censys [account](https://search.censys.io/account/api) for your credentials, and add them to the database as you would any other credential - `keys add ...`. 16 | 17 | One you have completed these you can fire up `recon-ng`. 18 | 19 | Configure your Censys API ID and secret variables using `keys add` to `censysio_id` and `censysio_secret`. 20 | 21 | ## Usage 22 | 23 | These are normal recon-ng modules, use them like any other. Pivot away! This repository adds the following new modules: 24 | 25 | ```recon-ng 26 | [recon-ng][default] > modules search censys 27 | [*] Searching for 'censys'... 28 | 29 | Recon 30 | ----- 31 | recon/companies-contacts/censys_email_address 32 | recon/companies-domains/censys_subdomains 33 | recon/companies-multi/censys_org 34 | recon/companies-multi/censys_tls_subjects 35 | recon/contacts-domains/censys_email_to_domains 36 | recon/domains-companies/censys_companies 37 | recon/domains-hosts/censys_domain 38 | recon/hosts-hosts/censys_query 39 | recon/hosts-ports/censys_hostname 40 | recon/hosts-ports/censys_ip 41 | recon/netblocks-companies/censys_netblock_company 42 | recon/netblocks-hosts/censys_netblock 43 | ``` 44 | -------------------------------------------------------------------------------- /censys_companies.py: -------------------------------------------------------------------------------- 1 | from recon.core.module import BaseModule 2 | 3 | from censys.search import CensysHosts 4 | from censys.common.exceptions import CensysException 5 | 6 | 7 | class Module(BaseModule): 8 | meta = { 9 | "name": "Censys - Companies by Domain", 10 | "author": "Censys, Inc. ", 11 | "version": 2.1, 12 | "description": ( 13 | "Retrieves the TLS certificates for a domain. This module queries" 14 | " the 'services.tls.certificates.leaf_data.names' field and" 15 | " updates the 'companies' table with the results." 16 | ), 17 | "query": ( 18 | "SELECT DISTINCT domain FROM domains WHERE domain IS NOT NULL" 19 | ), 20 | "options": [ 21 | ( 22 | "num_buckets", 23 | "100", 24 | False, 25 | "maximum number of buckets to retrieve", 26 | ) 27 | ], 28 | "required_keys": ["censysio_id", "censysio_secret"], 29 | "dependencies": ["censys>=2.1.2"], 30 | } 31 | 32 | def module_run(self, domains): 33 | api_id = self.get_key("censysio_id") 34 | api_secret = self.get_key("censysio_secret") 35 | c = CensysHosts(api_id, api_secret) 36 | for domain in domains: 37 | domain = domain.strip('"') 38 | self.heading(domain, level=0) 39 | try: 40 | report = c.aggregate( 41 | "same_service(services.tls.certificates.leaf_data.names:" 42 | f" {domain} and" 43 | " services.tls.certificates.leaf_data.subject.organization: *)", 44 | field="services.tls.certificates.leaf_data.subject.organization", 45 | num_buckets=int(self.options.get("NUM_BUCKETS", "100")), 46 | ) 47 | except CensysException: 48 | self.print_exception() 49 | continue 50 | for bucket in report.get("buckets", []): 51 | company = bucket.get("key") 52 | self.insert_companies( 53 | company=company, description=f"Domain: {domain}" 54 | ) 55 | -------------------------------------------------------------------------------- /censys_domain.py: -------------------------------------------------------------------------------- 1 | from recon.core.module import BaseModule 2 | 3 | from censys.search import CensysHosts 4 | from censys.common.exceptions import CensysException 5 | 6 | 7 | class Module(BaseModule): 8 | meta = { 9 | "name": "Censys - Hosts by domain", 10 | "author": "Censys, Inc. ", 11 | "version": 2.1, 12 | "description": ( 13 | "Retrieves hosts for a domain. This module queries queries domain" 14 | " names and updates the 'hosts' and the 'ports' tables with the" 15 | " results." 16 | ), 17 | "query": ( 18 | "SELECT DISTINCT domain FROM domains WHERE domain IS NOT NULL" 19 | ), 20 | "required_keys": ["censysio_id", "censysio_secret"], 21 | "options": [ 22 | ( 23 | "virtual_hosts", 24 | "ONLY", 25 | False, 26 | "Whether to include virtual hosts in the results", 27 | ), 28 | ( 29 | "per_page", 30 | "100", 31 | False, 32 | "The number of results to return per page", 33 | ), 34 | ( 35 | "pages", 36 | "1", 37 | False, 38 | "The number of pages to retrieve", 39 | ), 40 | ], 41 | "dependencies": ["censys>=2.1.2"], 42 | } 43 | 44 | def module_run(self, domains): 45 | api_id = self.get_key("censysio_id") 46 | api_secret = self.get_key("censysio_secret") 47 | c = CensysHosts(api_id, api_secret) 48 | for domain in domains: 49 | domain = domain.strip('"') 50 | self.heading(domain, level=0) 51 | try: 52 | query = c.search( 53 | f"{domain}", 54 | per_page=int(self.options.get("PER_PAGE", "100")), 55 | pages=int(self.options.get("PAGES", "1")), 56 | virtual_hosts=self.options.get("VIRTUAL_HOSTS", "ONLY"), 57 | ) 58 | except CensysException: 59 | self.print_exception() 60 | continue 61 | for hit in query(): 62 | common_kwargs = { 63 | "ip_address": hit["ip"], 64 | "host": hit.get("name"), 65 | } 66 | location = hit.get("location", {}) 67 | coords = location.get("coordinates", {}) 68 | self.insert_hosts( 69 | region=location.get("continent"), 70 | country=location.get("country"), 71 | latitude=coords.get("latitude"), 72 | longitude=coords.get("longitude"), 73 | **common_kwargs, 74 | ) 75 | for service in hit.get("services", []): 76 | self.insert_ports( 77 | port=service["port"], 78 | protocol=service["transport_protocol"], 79 | notes=service["service_name"], 80 | **common_kwargs, 81 | ) 82 | -------------------------------------------------------------------------------- /censys_email_address.py: -------------------------------------------------------------------------------- 1 | from recon.core.module import BaseModule 2 | 3 | from censys.search import CensysHosts 4 | from censys.common.exceptions import CensysException 5 | 6 | 7 | class Module(BaseModule): 8 | meta = { 9 | "name": "Censys - Emails by Company", 10 | "author": "Censys, Inc. ", 11 | "version": 2.1, 12 | "description": ( 13 | "Retrieves email addresses from the TLS certificates for a" 14 | " company. This module queries the" 15 | " 'services.tls.certificates.leaf_data.subject.email_address'" 16 | " field and updates the 'contacts' table with the results." 17 | ), 18 | "query": ( 19 | "SELECT DISTINCT company FROM companies WHERE company IS NOT NULL" 20 | ), 21 | "options": [ 22 | ( 23 | "num_buckets", 24 | "100", 25 | False, 26 | "maximum number of buckets to retrieve", 27 | ) 28 | ], 29 | "required_keys": ["censysio_id", "censysio_secret"], 30 | "dependencies": ["censys>=2.1.2"], 31 | } 32 | 33 | def module_run(self, companies): 34 | api_id = self.get_key("censysio_id") 35 | api_secret = self.get_key("censysio_secret") 36 | c = CensysHosts(api_id, api_secret) 37 | for company in companies: 38 | company = company.strip('"') 39 | self.heading(company, level=0) 40 | try: 41 | report = c.aggregate( 42 | "same_service(services.tls.certificates.leaf_data.subject.email_address:*" 43 | " and " 44 | f'services.tls.certificates.leaf_data.subject.organization:"{company}")', 45 | field="services.tls.certificates.leaf_data.subject.email_address", 46 | num_buckets=int(self.options.get("NUM_BUCKETS", "100")), 47 | ) 48 | except CensysException: 49 | self.print_exception() 50 | continue 51 | for bucket in report.get("buckets", []): 52 | email = bucket.get("key") 53 | self.insert_contacts(email=email) 54 | -------------------------------------------------------------------------------- /censys_email_to_domains.py: -------------------------------------------------------------------------------- 1 | from recon.core.module import BaseModule 2 | 3 | from censys.search import CensysHosts 4 | from censys.common.exceptions import CensysException 5 | 6 | 7 | class Module(BaseModule): 8 | meta = { 9 | "name": "Censys - Domains by Email", 10 | "author": "Censys, Inc. ", 11 | "version": 2.1, 12 | "description": ( 13 | "Retrieves domains from the TLS certificates for an email address." 14 | " This module queries the 'parsed.subject.email_address' field and" 15 | " updates the 'domains' table with the results." 16 | ), 17 | "query": "SELECT DISTINCT email FROM contacts WHERE email IS NOT NULL", 18 | "options": [ 19 | ("num_buckets", 100, True, "maximum number of buckets to retrieve") 20 | ], 21 | "required_keys": ["censysio_id", "censysio_secret"], 22 | "dependencies": ["censys>=2.1.2"], 23 | } 24 | 25 | def module_run(self, emails): 26 | api_id = self.get_key("censysio_id") 27 | api_secret = self.get_key("censysio_secret") 28 | c = CensysHosts(api_id, api_secret) 29 | for email in emails: 30 | email = email.strip('"') 31 | self.heading(email, level=0) 32 | try: 33 | report = c.aggregate( 34 | f'services.tls.certificates.leaf_data.subject.email_address:"{email}"', 35 | field="services.tls.certificates.leaf_data.names", 36 | num_buckets=self.options.get("num_buckets", 100), 37 | ) 38 | except CensysException: 39 | self.print_exception() 40 | continue 41 | for bucket in report.get("buckets", []): 42 | domain = bucket.get("key") 43 | self.insert_domains(domain=domain, notes=f"Email: {email}") 44 | -------------------------------------------------------------------------------- /censys_hostname.py: -------------------------------------------------------------------------------- 1 | from recon.core.module import BaseModule 2 | 3 | from censys.search import CensysHosts 4 | from censys.common.exceptions import CensysException 5 | 6 | 7 | class Module(BaseModule): 8 | meta = { 9 | "name": "Censys - Hosts by Hostname", 10 | "author": "Censys, Inc. ", 11 | "version": 2.1, 12 | "description": ( 13 | "Retrieves all IPs for a given hostname. This module queries the" 14 | " 'name' field and updates the 'hosts' and 'ports' tables with the" 15 | " results." 16 | ), 17 | "query": "SELECT DISTINCT host FROM hosts WHERE host IS NOT NULL", 18 | "required_keys": ["censysio_id", "censysio_secret"], 19 | "dependencies": ["censys>=2.1.2"], 20 | } 21 | 22 | def module_run(self, hosts): 23 | api_id = self.get_key("censysio_id") 24 | api_secret = self.get_key("censysio_secret") 25 | c = CensysHosts(api_id, api_secret) 26 | for host in hosts: 27 | host = host.strip('"') 28 | self.heading(host, level=0) 29 | try: 30 | query = c.search(f"name:{host}", virtual_hosts="ONLY") 31 | except CensysException: 32 | self.print_exception() 33 | continue 34 | for hit in query(): 35 | common_kwargs = { 36 | "ip_address": hit["ip"], 37 | "host": hit.get("name"), 38 | } 39 | location = hit.get("location", {}) 40 | coords = location.get("coordinates", {}) 41 | self.insert_hosts( 42 | region=location.get("continent"), 43 | country=location.get("country"), 44 | latitude=coords.get("latitude"), 45 | longitude=coords.get("longitude"), 46 | **common_kwargs, 47 | ) 48 | for service in hit.get("services", []): 49 | self.insert_ports( 50 | port=service["port"], 51 | protocol=service["transport_protocol"], 52 | notes=service["service_name"], 53 | **common_kwargs, 54 | ) 55 | -------------------------------------------------------------------------------- /censys_ip.py: -------------------------------------------------------------------------------- 1 | import itertools 2 | 3 | from recon.core.module import BaseModule 4 | 5 | from censys.search import CensysHosts 6 | from censys.common.exceptions import CensysException 7 | 8 | 9 | def grouper(n, iterable): 10 | # via https://stackoverflow.com/a/8991553 11 | it = iter(iterable) 12 | while True: 13 | chunk = tuple(itertools.islice(it, n)) 14 | if not chunk: 15 | return 16 | yield chunk 17 | 18 | 19 | class Module(BaseModule): 20 | meta = { 21 | "name": "Censys - Ports by IP", 22 | "author": "Censys, Inc. ", 23 | "version": 2.1, 24 | "description": ( 25 | "Retrieves the open ports for each IP address. " 26 | "Updates the 'ports' table with the results." 27 | ), 28 | "query": ( 29 | "SELECT DISTINCT ip_address FROM hosts WHERE ip_address IS NOT" 30 | " NULL" 31 | ), 32 | "required_keys": ["censysio_id", "censysio_secret"], 33 | "dependencies": ["censys>=2.1.2"], 34 | } 35 | 36 | def module_run(self, hosts): 37 | api_id = self.get_key("censysio_id") 38 | api_secret = self.get_key("censysio_secret") 39 | c = CensysHosts(api_id, api_secret) 40 | for ip in hosts: 41 | ip = ip.strip('"') 42 | self.heading(ip, level=0) 43 | try: 44 | host = c.view(ip) 45 | except CensysException: 46 | self.print_exception() 47 | continue 48 | for service in host.get("services", []): 49 | self.insert_ports( 50 | ip_address=ip, 51 | port=service["port"], 52 | protocol=service["transport_protocol"], 53 | banner=service.get("banner"), 54 | notes=service["service_name"], 55 | ) 56 | -------------------------------------------------------------------------------- /censys_netblock.py: -------------------------------------------------------------------------------- 1 | from recon.core.module import BaseModule 2 | 3 | from censys.search import CensysHosts 4 | from censys.common.exceptions import CensysException 5 | 6 | 7 | class Module(BaseModule): 8 | meta = { 9 | "name": "Censys - Hosts by Netblock", 10 | "author": "Censys, Inc. ", 11 | "version": 2.1, 12 | "description": ( 13 | "Retrieves hosts and ports for a netblock. " 14 | "Updates the 'hosts' and the 'ports' tables with the results." 15 | ), 16 | "query": ( 17 | "SELECT DISTINCT netblock FROM netblocks WHERE netblock IS NOT" 18 | " NULL" 19 | ), 20 | "required_keys": ["censysio_id", "censysio_secret"], 21 | "options": [ 22 | ( 23 | "virtual_hosts", 24 | "EXCLUDE", 25 | False, 26 | "Whether to include virtual hosts in the results", 27 | ), 28 | ( 29 | "per_page", 30 | "100", 31 | False, 32 | "The number of results to return per page", 33 | ), 34 | ( 35 | "pages", 36 | "1", 37 | False, 38 | "The number of pages to retrieve", 39 | ), 40 | ], 41 | "dependencies": ["censys>=2.1.2"], 42 | } 43 | 44 | def module_run(self, netblocks): 45 | api_id = self.get_key("censysio_id") 46 | api_secret = self.get_key("censysio_secret") 47 | c = CensysHosts(api_id, api_secret) 48 | for netblock in netblocks: 49 | self.heading(netblock, level=0) 50 | try: 51 | query = c.search( 52 | f"ip:{netblock}", 53 | per_page=int(self.options.get("PER_PAGE", "100")), 54 | pages=int(self.options.get("PAGES", "1")), 55 | virtual_hosts=self.options.get("VIRTUAL_HOSTS", "EXCLUDE"), 56 | ) 57 | except CensysException: 58 | self.print_exception() 59 | continue 60 | for hit in query(): 61 | common_kwargs = { 62 | "ip_address": hit["ip"], 63 | "host": hit.get("name"), 64 | } 65 | location = hit.get("location", {}) 66 | coords = location.get("coordinates", {}) 67 | self.insert_hosts( 68 | region=location.get("continent"), 69 | country=location.get("country"), 70 | latitude=coords.get("latitude"), 71 | longitude=coords.get("longitude"), 72 | **common_kwargs, 73 | ) 74 | for service in hit.get("services", []): 75 | self.insert_ports( 76 | port=service["port"], 77 | protocol=service["transport_protocol"], 78 | notes=service["service_name"], 79 | **common_kwargs, 80 | ) 81 | -------------------------------------------------------------------------------- /censys_netblock_company.py: -------------------------------------------------------------------------------- 1 | from recon.core.module import BaseModule 2 | 3 | from censys.search import CensysHosts 4 | from censys.common.exceptions import CensysException 5 | 6 | 7 | class Module(BaseModule): 8 | meta = { 9 | "name": "Censys - Companies by Netblock", 10 | "author": "Censys, Inc. ", 11 | "version": 2.1, 12 | "description": ( 13 | "Retrieves organizations for a company's netblocks. " 14 | "Updates the 'companies' table with the results." 15 | ), 16 | "query": ( 17 | "SELECT DISTINCT netblock FROM netblocks WHERE netblock IS NOT" 18 | " NULL" 19 | ), 20 | "options": [ 21 | ( 22 | "num_buckets", 23 | "100", 24 | False, 25 | "maximum number of buckets to retrieve", 26 | ) 27 | ], 28 | "required_keys": ["censysio_id", "censysio_secret"], 29 | "dependencies": ["censys>=2.1.2"], 30 | } 31 | 32 | def module_run(self, netblocks): 33 | api_id = self.get_key("censysio_id") 34 | api_secret = self.get_key("censysio_secret") 35 | c = CensysHosts(api_id, api_secret) 36 | for netblock in netblocks: 37 | self.heading(netblock, level=0) 38 | try: 39 | # we only need one per netblock since they'll all have the same by ASN 40 | report = c.aggregate( 41 | f"ip:{netblock}", 42 | fields="autonomous_system.name", 43 | num_buckets=int(self.options.get("NUM_BUCKETS", "100")), 44 | ) 45 | except CensysException: 46 | self.print_exception() 47 | continue 48 | for bucket in report.get("buckets", []): 49 | company = bucket.get("key") 50 | self.insert_companies(company=company) 51 | -------------------------------------------------------------------------------- /censys_org.py: -------------------------------------------------------------------------------- 1 | from recon.core.module import BaseModule 2 | 3 | from censys.search import CensysHosts 4 | from censys.common.exceptions import CensysException 5 | 6 | 7 | class Module(BaseModule): 8 | meta = { 9 | "name": "Censys - Hosts by Company", 10 | "author": "Censys, Inc. ", 11 | "version": 2.1, 12 | "description": ( 13 | "Retrieves hosts for a company's ASN. This module queries the" 14 | " 'autonomous_system.name' field and updates the 'hosts' and" 15 | " 'ports' tables with the results." 16 | ), 17 | "query": ( 18 | "SELECT DISTINCT company FROM companies WHERE company IS NOT NULL" 19 | ), 20 | "required_keys": ["censysio_id", "censysio_secret"], 21 | "options": [ 22 | ( 23 | "virtual_hosts", 24 | "EXCLUDE", 25 | False, 26 | "Whether to include virtual hosts in the results", 27 | ), 28 | ( 29 | "per_page", 30 | "100", 31 | False, 32 | "The number of results to return per page", 33 | ), 34 | ( 35 | "pages", 36 | "1", 37 | False, 38 | "The number of pages to retrieve", 39 | ), 40 | ], 41 | "dependencies": ["censys>=2.1.2"], 42 | } 43 | 44 | def module_run(self, companies): 45 | api_id = self.get_key("censysio_id") 46 | api_secret = self.get_key("censysio_secret") 47 | c = CensysHosts(api_id, api_secret) 48 | for company in companies: 49 | company = company.strip('"') 50 | self.heading(company, level=0) 51 | try: 52 | query = c.search( 53 | f'autonomous_system.name:"{company}"', 54 | per_page=int(self.options.get("PER_PAGE", "100")), 55 | pages=int(self.options.get("PAGES", "1")), 56 | virtual_hosts=self.options.get("VIRTUAL_HOSTS", "EXCLUDE"), 57 | ) 58 | except CensysException: 59 | self.print_exception() 60 | continue 61 | for hit in query(): 62 | ip = hit["ip"] 63 | name = hit.get("name") 64 | if name: 65 | self.insert_domains( 66 | domain=name, notes="+".join((ip, name)) 67 | ) 68 | common_kwargs = { 69 | "ip_address": ip, 70 | "host": name, 71 | } 72 | location = hit.get("location", {}) 73 | coords = location.get("coordinates", {}) 74 | self.insert_hosts( 75 | region=location.get("continent"), 76 | country=location.get("country"), 77 | latitude=coords.get("latitude"), 78 | longitude=coords.get("longitude"), 79 | **common_kwargs, 80 | ) 81 | for service in hit.get("services", []): 82 | self.insert_ports( 83 | port=service["port"], 84 | protocol=service["transport_protocol"], 85 | notes=service["service_name"], 86 | **common_kwargs, 87 | ) 88 | -------------------------------------------------------------------------------- /censys_query.py: -------------------------------------------------------------------------------- 1 | from recon.core.module import BaseModule 2 | 3 | from censys.search import CensysHosts 4 | from censys.common.exceptions import CensysException 5 | 6 | 7 | class Module(BaseModule): 8 | meta = { 9 | "name": "Censys - Hosts by Search Query", 10 | "author": "Censys, Inc. ", 11 | "version": 2.1, 12 | "description": ( 13 | "Retrieves details for hosts matching an arbitrary Censys query." 14 | " Updates the 'hosts', 'domains', and 'ports' tables with the" 15 | " results." 16 | ), 17 | "required_keys": ["censysio_id", "censysio_secret"], 18 | "options": [ 19 | ( 20 | "censys_query", 21 | 'services.http.response.html_title: "Welcome to recon-ng"', 22 | True, 23 | "The Censys Search Query to execute", 24 | ), 25 | ( 26 | "virtual_hosts", 27 | "EXCLUDE", 28 | False, 29 | "Whether to include virtual hosts in the results", 30 | ), 31 | ( 32 | "per_page", 33 | "100", 34 | False, 35 | "The number of results to return per page", 36 | ), 37 | ( 38 | "pages", 39 | "1", 40 | False, 41 | "The number of pages to retrieve", 42 | ), 43 | ], 44 | "dependencies": ["censys>=2.1.2"], 45 | } 46 | 47 | def module_run(self): 48 | api_id = self.get_key("censysio_id") 49 | api_secret = self.get_key("censysio_secret") 50 | c = CensysHosts(api_id, api_secret) 51 | try: 52 | query = c.search( 53 | self.options["CENSYS_QUERY"], 54 | per_page=int(self.options.get("PER_PAGE", "100")), 55 | pages=int(self.options.get("PAGES", "1")), 56 | virtual_hosts=self.options.get("VIRTUAL_HOSTS", "EXCLUDE"), 57 | ) 58 | except CensysException: 59 | self.print_exception() 60 | return 61 | for hit in query(): 62 | ip = hit["ip"] 63 | name = hit.get("name") 64 | if name: 65 | self.insert_domains(domain=name, notes="+".join((ip, name))) 66 | common_kwargs = { 67 | "ip_address": ip, 68 | "host": name, 69 | } 70 | location = hit.get("location", {}) 71 | coords = location.get("coordinates", {}) 72 | self.insert_hosts( 73 | region=location.get("continent"), 74 | country=location.get("country"), 75 | latitude=coords.get("latitude"), 76 | longitude=coords.get("longitude"), 77 | **common_kwargs, 78 | ) 79 | for service in hit.get("services", []): 80 | self.insert_ports( 81 | port=service["port"], 82 | protocol=service["transport_protocol"], 83 | notes=service["service_name"], 84 | **common_kwargs, 85 | ) 86 | -------------------------------------------------------------------------------- /censys_subdomains.py: -------------------------------------------------------------------------------- 1 | from recon.core.module import BaseModule 2 | 3 | from censys.search import CensysCertificates 4 | from censys.common.exceptions import CensysException 5 | 6 | 7 | class Module(BaseModule): 8 | meta = { 9 | "name": "Censys - Subdomains by Company", 10 | "author": "Censys, Inc. ", 11 | "version": 2.1, 12 | "description": ( 13 | "Retrieves subdomains for a company. This module queries the" 14 | " 'parsed.subject.organization' field and updates the 'domains'" 15 | " table with the results." 16 | ), 17 | "query": ( 18 | "SELECT DISTINCT company FROM companies WHERE company IS NOT NULL" 19 | ), 20 | "options": [ 21 | ("max_records", 100, True, "maximum number of records to retrieve") 22 | ], 23 | "required_keys": ["censysio_id", "censysio_secret"], 24 | "dependencies": ["censys>=2.1.2"], 25 | } 26 | 27 | def module_run(self, companies): 28 | api_id = self.get_key("censysio_id") 29 | api_secret = self.get_key("censysio_secret") 30 | c = CensysCertificates(api_id, api_secret) 31 | SEARCH_FIELDS = [ 32 | "parsed.subject.organization", 33 | "parsed.subject.organizational_unit", 34 | ] 35 | for company in companies: 36 | company = company.strip('"') 37 | self.heading(company, level=0) 38 | try: 39 | query = " OR ".join( 40 | ['{0}:"{1}"'.format(x, company) for x in SEARCH_FIELDS] 41 | ) 42 | res = c.search( 43 | query, 44 | ["parsed.names"], 45 | max_records=self.options.get("max_records", 100), 46 | ) 47 | except CensysException: 48 | self.print_exception() 49 | continue 50 | domains = set() 51 | for result in res: 52 | for name in result.get("parsed.names", []): 53 | if name.startswith("*."): 54 | name = name.replace("*.", "") 55 | domains.add(name) 56 | for domain in domains: 57 | self.insert_domains(domain=domain) 58 | -------------------------------------------------------------------------------- /censys_tls_subjects.py: -------------------------------------------------------------------------------- 1 | from recon.core.module import BaseModule 2 | 3 | from censys.search import CensysHosts 4 | from censys.common.exceptions import CensysException 5 | 6 | 7 | class Module(BaseModule): 8 | meta = { 9 | "name": "Censys - Domains by Company", 10 | "author": "Censys, Inc. ", 11 | "version": 2.1, 12 | "description": ( 13 | "Retrieves the TLS certificates for a domain. This module queries" 14 | " the 'services.tls.certificates.leaf_data.subject.organization'" 15 | " field and updates the 'hosts' and 'ports' tables with the" 16 | " results." 17 | ), 18 | "query": ( 19 | "SELECT DISTINCT company FROM companies WHERE company IS NOT NULL" 20 | ), 21 | "required_keys": ["censysio_id", "censysio_secret"], 22 | "dependencies": ["censys>=2.1.2"], 23 | } 24 | 25 | def module_run(self, companies): 26 | api_id = self.get_key("censysio_id") 27 | api_secret = self.get_key("censysio_secret") 28 | c = CensysHosts(api_id, api_secret) 29 | for company in companies: 30 | company = company.strip('"') 31 | self.heading(company, level=0) 32 | try: 33 | query = c.search( 34 | f'services.tls.certificates.leaf_data.subject.organization:"{company}"', 35 | virtual_hosts="INCLUDE", 36 | ) 37 | except CensysException: 38 | self.print_exception() 39 | continue 40 | for hit in query(): 41 | ip = hit["ip"] 42 | name = hit.get("name") 43 | if name: 44 | self.insert_domains( 45 | domain=name, notes="+".join((ip, name)) 46 | ) 47 | common_kwargs = { 48 | "ip_address": ip, 49 | "host": name, 50 | } 51 | location = hit.get("location", {}) 52 | coords = location.get("coordinates", {}) 53 | self.insert_hosts( 54 | region=location.get("continent"), 55 | country=location.get("country"), 56 | latitude=coords.get("latitude"), 57 | longitude=coords.get("longitude"), 58 | **common_kwargs, 59 | ) 60 | for service in hit.get("services", []): 61 | self.insert_ports( 62 | port=service["port"], 63 | protocol=service["transport_protocol"], 64 | notes=service["service_name"], 65 | **common_kwargs, 66 | ) 67 | -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | RECON_DIR=~/.recon-ng/modules/recon 4 | 5 | mkdir -p $RECON_DIR/companies-contacts 6 | cp censys_email_address.py $RECON_DIR/companies-contacts 7 | 8 | mkdir -p $RECON_DIR/companies-domains 9 | cp censys_subdomains.py $RECON_DIR/companies-domains 10 | 11 | mkdir -p $RECON_DIR/companies-multi 12 | cp censys_org.py $RECON_DIR/companies-multi 13 | cp censys_tls_subjects.py $RECON_DIR/companies-multi 14 | 15 | mkdir -p $RECON_DIR/contacts-domains 16 | cp censys_email_to_domains.py $RECON_DIR/contacts-domains 17 | 18 | mkdir -p $RECON_DIR/domains-companies 19 | cp censys_companies.py $RECON_DIR/domains-companies 20 | 21 | mkdir -p $RECON_DIR/domains-hosts 22 | cp censys_domain.py $RECON_DIR/domains-hosts 23 | 24 | mkdir -p $RECON_DIR/hosts-hosts 25 | cp censys_query.py $RECON_DIR/hosts-hosts 26 | 27 | mkdir -p $RECON_DIR/hosts-ports 28 | cp censys_hostname.py $RECON_DIR/hosts-ports 29 | cp censys_ip.py $RECON_DIR/hosts-ports 30 | 31 | mkdir -p $RECON_DIR/netblocks-companies 32 | cp censys_netblock_company.py $RECON_DIR/netblocks-companies 33 | 34 | mkdir -p $RECON_DIR/netblocks-hosts 35 | cp censys_netblock.py $RECON_DIR/netblocks-hosts 36 | 37 | for key in censysio_id censysio_secret; do 38 | echo "INSERT or IGNORE INTO keys (name) VALUES (\"$key\");" | sqlite3 ~/.recon-ng/keys.db 39 | done 40 | 41 | echo "Successfully installed Censys recon-ng modules." 42 | exit 0 -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [tool.black] 2 | line-length = 79 3 | skip-string-normalization = 1 4 | target-version = ['py37'] 5 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | censys>=2.1.2 2 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [flake8] 2 | max-line-length = 79 3 | extend-ignore = E501 4 | 5 | [pycodestyle] 6 | max-line-length = 79 7 | ignore = E501 8 | --------------------------------------------------------------------------------