Censys Query Language

Use Censys Query Language (CenQL) to write queries and search across data in the Censys Platform.

There are two primary ways to search across host, web property, and certificate data: full-text queries and field-value queries. You can also use the Query Assistant in the Platform web UI to generate valid CenQL queries using natural language input.

📘

Note

You can directly look up a host or certificate by entering its IP address or SHA-256 hash, respectively, in the Platform search bar.

Full-text queries

A full-text search searches across the entire record for a value, such as "example.com". It matches any record that contains the search term in any field.

Full-text queries only target the cert.names, cert.parsed.issuer_dn, and cert.parsed.subject_dn fields for certificate records.

Field-value queries

CenQL queries can target field-value pairs, like host.location.city="Ann Arbor". A complete list of data fields available for host, web property, and certificate records in the Platform is available in the in-app data definitions.

  • Field queries target a specific field on a record and can specify the comparison behavior. The syntax for targeting a field-value pair is <field name> <operator> <value>.
  • The table below outlines the field-value pair operators that are supported.

Field-value pairs and full-text searches can be combined with logical operators like and, or, and not. You can use comparison operators to target ranges of values.

Field-value pair operators

The following operators are supported for field queries:

OperatorDescriptionExample queryHitMiss
:A case-insensitive search that uses tokenization (see below). Records that contain the indicated value or values will be matched by the query.field: "hello"Hello WorldHi World
=

Matches if the field is exactly equal to the value.

For string fields, this performs a case-sensitive exact match.

field= "hello"helloanything else
=~

Matches if the field’s value matches against the given regex.

Regex matches against any part of the field that matches the regex input. You may include your own ^ and $ characters at the beginning and end of a regex, respectively, but using ^ or $ elsewhere will cause the query to fail.

Learn more here.

field=~`^Hello\s\w{5}$`

Hello WorldWorld Hello
<, >, <=, >=

Matches by comparing the field’s value to the specified value.

Range operators work for string, numbers, dates, and IP addresses.

field > 10209
:*Matches if the field contains any non-zero valuefield: *hello""

Tokenization

The : operator in CenQL uses tokenization to split text into searchable "chunks." Instead of scanning the entire data field as one large block of text, the Platform breaks it into smaller tokens.

Tokenization examples

The two examples below describe how tokenization works for hosts and web properties in the Censys Platform.

  • If you run the query web.endpoints.http.body: "click save", the Platform locates all services running HTTP and scans the body. It tokenizes "click" and "save" separately and ensures that they are in close proximity to each other in the body. Optimized tokenization allows Censys to handle large amounts of data, including HTML bodies, titles, and metadata, without slowing down performance.
  • Similarly, when a user searches for web.endpoints.http.body: "access=denied, the query undergoes the same tokenization process, converting access=denied into access denied and will match on that phrase. When the Platform checks a document, it verifies that the query's tokens appear in the correct order.

Tokenization and certificate data

Tokenization via the : operator works differently for certificate data in the Platform.

All *.common_name and cert.names fields utilize a subdomain analyzer. This method would extract the tokens abcdefg-1234567.example.domain.com,example.domain.com, and domain.com from cert.parsed.subject.common_name: "abcdefg-1234567.example.domain.com".

The only way to search for matches based on a component of a string that would be tokenized when using : is to use regex. For example, you could run:

cert.parsed.subject.common_name=~`^abcdefg-1234567`

This would return any certificates with common names that begin with abcdefg-1234567.

Aliased fields

Some fields are grouped into aliases to make it easier to search across multiple fields at once. Aliases can be used in the Platform web UI or API.

The table below lists aliases and their fields.

AliasFields included
bannerhost.services.banner

host.services.endpoints.banner

web.endpoints.banner
cpehost.hardware.cpe

host.hardware.components.cpe

host.services.hardware.components.cpe

host.services.hardware.cpe

host.services.software.components.cpe

host.services.software.cpe

host.operating_system.components.cpe

host.operating_system.cpe

host.services.operating_systems.components.cpe

host.services.operating_systems.cpe

web.operating_systems.components.cpe

web.operating_systems.cpe

web.hardware.cpe

web.hardware.components.cpe

web.software.cpe

web.software.components.cpe
sha256web.endpoints.banner_hash_sha256

web.endpoints.http.body_hash_sha256

web.endpoints.http.favicons.hash_sha256

host.services.endpoints.http.body_hash_sha256

host.services.endpoints.http.favicons.hash_sha256

host.services.endpoints.banner_hash_sha256

host.services.banner_hash_sha256

cert.fingerprint_sha256

host.services.cert.fingerprint_sha256

web.cert.fingerprint_sha256
labelshost.labels.value

host.services.labels.value

web.labels.value

cert.labels
producthost.hardware.components.product

host.hardware.product

host.services.hardware.components.product

host.services.hardware.product

host.services.software.components.product

host.services.software.product

host.operating_system.components.product

host.operating_system.product

host.services.operating_systems.components.product

host.services.operating_systems.product

web.operating_systems.components.product

web.operating_systems.product

web.hardware.product

web.hardware.components.product

web.software.components.product

web.software.product
vendorhost.hardware.components.vendor

host.hardware.vendor

host.services.hardware.components.vendor

host.services.hardware.vendor

host.services.software.components.vendor

host.services.software.vendor

host.operating_system.components.vendor

host.operating_system.vendor

host.services.operating_systems.vendor

host.services.operating_systems.components.vendor

web.hardware.components.vendor

web.hardware.vendor

web.software.vendor

web.software.components.vendor

web.operating_systems.vendor

web.operating_systems.components.vendor
vulnshost.services.vulns.id

web.vulns.id
vuln_scoreweb.vulns.metrics.cvss_v31.score

web.vulns.metrics.cvss_v40.score

web.vulns.metrics.cvss_v30.score

host.services.vulns.metrics.cvss_v30.score

host.services.vulns.metrics.cvss_v31.score

host.services.vulns.metrics.cvss_v40.score
threatshost.services.threats.name
web.threats.name
screenshotshost.services.screenshots.handle
sha1host.services.redis.git_sha1
host.services.cert.fingerprint_sha1
host.services.endpoints.http.body_hash_sha1
cert.fingerprint_sha1
web.cert.fingerprint_sha1
web.endpoints.http.body_hash_sha1
orghost.whois.organization.name
host.autonomous_system.organization
host.services.cert.parsed.subject.organization
host.services.cert.parsed.issuer.organization
web.cert.parsed.subject.organization
web.cert.parsed.issuer.organization
cert.parsed.subject.organization
cert.parsed.issuer.organization

Alias nuances

Aliases cannot be used in queries that target nested fields. For example, host.services: (protocol: SSH and product: "OpenSSH") is invalid.

Only fields that your account has access to are included in an alias search. If you search across the product alias on a Censys Free account, then *.components fields will not be included.

You cannot create a report broken down by an alias.

twist function

Use the twist function to find field values that are similar to a specified value. This is similar to the functionality provided by dnstwist, but has a more limited scope. When targeting domains, the twist function in CenQL will run fewer permutations than dnstwist does.

Additionally, the function is less successful at finding related values to domains that are limited to two or three characters (for example, ab.com or abc.com).

The twist function is available to all users.

You can build queries that incorporate the twist function using the following structure:

twist([fieldname], `[value]`)

You can use the twist function to find typosquatted domains or domains attempting to impersonate a valid domain by omitting known domains from your query. For example, the following query will find web properties that use names similar to censys.io but will omit results that include censys.io.

twist(web.hostname, `censys.io`) and not web.hostname:`censys.io`

You can use a query similar to the one provided above in a collection to find existing and new suspicious domains.

Boolean operators and parentheses

You can combine and modify search criteria using and, or, not, and parentheses. Boolean operators are case-insensitive.

and

Use and to specify multiple criteria that an entire record must match in order to be considered a hit. The query host.services.port=8880 and host.services.protocol=HTTP will return hosts that have port 8880 open (with any service running on it) and an HTTP service running on any port.

Query description and linkQuery syntax
Hosts that have port 8880 open (with any service running on it) and an HTTP service running on any porthost.services.port=8880 and host.services.protocol=HTTP

Note that the query syntax provided in the table above does not require that returned matches are on the same service, just that a host has both of the queried field values present anywhere on the record. The query syntax above could return host records that use port 8880 and are not HTTP. To require that multiple search criteria are present in a single nested object, you need to use nested fields.

or

The or operator can be used to provide multiple criteria that a record can match in order to be considered a hit.

Query description and linkQuery syntax
Hosts that have either port 21 open (with any service running on it) or an FTP service running on any porthost.services.port=21 or host.services.protocol=FTP

not

The not operator is used to provide criteria that a host must not match in order to be considered a hit.

Query description and linkQuery syntax
Host that are not located in the United Statesnot host.location.country="United States"

Parentheses and brackets

Use parentheses to include multiple field value pairs or nested fields in a single search query. Brackets can be used to target specific values.

Query description and linkQuery syntax
Hosts that are not located in the United States or Indianot (host.location.country="United States" or host.location.country="India")
Another version of the query above, but using brackets to exclude a range of valuesnot (host.location.country: {"United States", "India"})
Hosts with services running on only ports 80 and 443host.services.port: 80 and host.services.port: 443 and not host.services:(not port:{80, 443})

Ranges

Ranges for values like numbers and dates can be defined using the comparison operators >, <, >=, and <=. Integer and date values must be wrapped in quotes or backticks.

You can also use relative time variables with comparison operators.

Query description and linkQuery syntax
Certificates added to Censys between October 20 and October 30, 2024, including October 20 and 30cert.added_at>="2024-10-20" and cert.added_at<="2024-10-30"
Hosts with services scanned in the last 24 hourshost.services.scan_time > "now-1d"
Web endpoints with status codes between 200 and 204, including 200 and 204web.endpoints: (http.status_code >= "200" and http.status_code <= "204")

Nested fields

Use nested fields to apply multiple search criteria to a single object within a list of like objects instead of to the entity as a whole.

To apply all of the search criteria to a single object within an array, use parentheses to group those nested fields after the colon separating the nested field name.

Query description and linkQuery syntax
Hosts running SSH on port 22host.services: (port = "22" and protocol = "SSH")
Hosts running version 2.4.62 of HTTPD (Apache HTTP Server)host.services.software: (product = "httpd" and version = "2.4.62")
Hosts running services with an nginx server headerhost.services.endpoints.http.headers: (key = "Server" and value = "nginx")
Hosts running nginx with "Welcome to nginx!" in the HTML titlehost.services: (software.product = "nginx" and endpoints.http.html_title = "Welcome to nginx!")

Unicode escape sequences

The following sequences will be interpreted as unicode escape sequences to allow users to search for these special characters where they are commonly found, such as service banners and HTTP bodies.

Escape sequenceCharacter represented
\aAlert
\bBackspace
\eEscape character
\fFormfeed / page break
\nNewline
\rCarriage return
\tHorizontal tab
\vVertical tab

Regular expression (regex)

CenQL supports using regular expression (regex) in advanced queries. Documentation for using regex in CenQL is available here.

Quick search across CIDR blocks

To quickly search for a CIDR block in the Platform web UI, you can input a range of IPs in CIDR notation in the search bar without specifying a field to target.

To combine a CIDR block search with other fields, use host.ip and the format host.ip: "cidrblock".

Field types

When you target certain data fields with CenQL queries, they must include valid values for that field type. The following table provides examples of data field types and values in the Censys datasets.

TypeDescriptionExamples
booleanTrue or false values.True

False
ipIP addresses. When searching host.ip with a CIDR block, wrap it in quotes or backticks.1.1.1.1
ip_rangeA range of ip values.125.8.0.0/13
String

Quoted strings may contain white-space, keywords, escapes, and certain special characters.

Quoted strings may use single ' or double " quotes. A string that is quoted in backticks do not need to escape any character except a backtick.

Unquoted strings are limited to those that match the regex [a-zA-Z][a-zA-Z0-9._-]*

"hello world"

hello.world

hello-world

hello_world
date

An RFC 3339 formatted timestamp.

Date values can also be input into queries in epoch millisecond format.

2024-10-25T00:00:00-04:00

2024-10-25

1746618176700
unsigned_longA numeric value that represents an unsigned 64-bit integer with a minimum value of 0 and a maximum value of 218446744073709551615. Examples include fields with human-readable numbers like host.services.port and version numbers for some named service and protocol data fields, like host.services.tacacs_plus.version.22

3389
textFull-text content. Examples include banner content (host.services.banner, host.services.endpoints.banner, web.endpoints.banner, and so on) and their hashes. Popular fields like host.services.software.product, host.services.software.version, and host.services.software.cpe use this type.HTTP/1.1 404 Not Found\r\nContent-Length: 0\r\n

1.16.1