Censys Search Language
The Censys Search Language is what you use to find hosts that are of interest to you. Queries written in the Censys Search Language provide a list of criteria that a host must have have in order to be returned as a hit.
The guide will introduce query writing with examples that you can follow to see in the Search product.
Search Basics: Construct a Query
Full Text Searches
A query that doesn’t specify a specific field will launch a search across all text-based fields for the word or phrase submitted.
Query for Hosts with any field that contains the term “hello”:
You can search for a multiple-word phrase by surrounding it in double quotes.
Query for Hosts with any field that contains the term “Hello World”:
These searches are not case sensitive. You will see results with any capitalization of the letters in your search term.
Querying With Field, Value Pairs
Search structured fields for a value that can be stored there. Fields reflect the nested structure of the host schema using dot notation to separate keys.
Find all devices that have an HTTP Server header with the word "Apache" in it:
Important! The search above does not limit hits to only the exact word specified. So a host with “Apache Server” in the server header would also be returned as a result.
If you want to search for an exact match, use the equals operator (=).
Find all devices whose HTTP Sever header contains exactly the word "Apache":
You can use the asterisk symbol (*) to substitute zero or more unknown characters. Use the question mark (?) to substitute for exactly one unknown character. These symbols are helpful for finding records where you know some part of a value, but not how it will end.
For example, the search above returns hosts with the Server header “Apache” and “Apache Server”, but does not return hosts with “Apache-Serve” in the server header since it matches on whitespace-delimited words.
Search for server header values that start with Apache using the wildcard:
Warning! Censys does not support leading wildcard searches (e.g.,
“* Apache”) because we’re unable to use any indices to complete this search; however, leading wildcards are very desirable when searching fields whose values are DNS-style domain names. Don’t worry — when searching these fields (e.g., the name on a certificate), the search “censys.io” will include results for all subdomains of censys.io by default. To restrict those searches to exactly the string provided, use the equals operator (=).
Censys allows the binary operators and, or, and not, as well as parentheses to combine search criteria.
Return all hosts located either in the United States or Canada:
You can search use a set to shorten what would otherwise be a long or statements.
Return all hosts whose country is among this set of countries in the Americas:
Make a search more specific by providing multiple criteria that must match in order for a host to be considered a hit.
Return hosts with port 443 open (with any service running) and an HTTP service running on any port:
Important! Search criteria applies to a host as a whole, unless specified otherwise. The query above returns hosts with any service on port 443 and HTTP on any port.
Searching in the Same Service
Use the same_service() operator to apply all of the search criteria to a single service.
Hosts that are running an HTTP service on port 8888:
Exclude hosts with a certain characteristics using not.
Find hosts running SSH on a non-standard port (i.e., neither 22 nor 2222):
Ranges allow you to specify a spectrum that a value may fall into in order for the host to be considered a hit. This is useful for numerical values such as dates, version numbers, and even IP addresses.
Search for hosts whose rDNS name was resolved by Censys within a (recent) date range, not including the first value given:
Search for online IPs in a non-standard IP range, including the first and last values given:
Censys also supports CIDR notation of IP ranges, which shows a IPv4 or IPv6 address with a slash followed by a decimal to indicate how many bits (from left to right) are fixed and do not change.
Search for online hosts whose IPv4 address fall between 184.108.40.206 and 220.127.116.11:
Double Quotes (")
Double quotes are for searching for a phrase instead of a single word. You must wrap whitespace-separated words in double quotes when searching in order for the phrase to be evaluated as a whole. Searches that specify a phrase for a field value are invalid without the double quotes.
Search for hosts with an HTML title
Backticks are used to escape all reserved characters occurring therein. For example, CPE-formatted software strings use many reserved characters. Instead of escaping each one, wrap the whole string in backticks.
Search for hosts running Microsoft IIS version 10.0: