| 1 |
CLI Usage |
| 2 |
========= |
| 3 |
|
| 4 |
.. raw:: html |
| 5 |
:file: cli.html |
| 6 |
|
| 7 |
Before continuing please ensure you have successfully configured your credentials. |
| 8 |
|
| 9 |
.. prompt:: bash |
| 10 |
|
| 11 |
censys config |
| 12 |
|
| 13 |
The configuration file by default is written to ``~/.config/censys/censys.cfg``, but you can change this by setting the ``CENSYS_CONFIG_PATH`` environment variable. |
| 14 |
|
| 15 |
.. prompt:: bash |
| 16 |
|
| 17 |
export CENSYS_CONFIG_PATH=/path/to/config/file |
| 18 |
|
| 19 |
Optionally, you can enable tab completion for the CLI by adding this line to your `~/.bashrc`, `~/.zshrc`, or equivalent. |
| 20 |
|
| 21 |
.. prompt:: bash |
| 22 |
|
| 23 |
eval "$(register-python-argcomplete censys)" |
| 24 |
|
| 25 |
.. note:: |
| 26 |
|
| 27 |
Please note that autocomplete is supported for field names in the `search` command. |
| 28 |
|
| 29 |
|
| 30 |
``search`` |
| 31 |
---------- |
| 32 |
|
| 33 |
Below we show an example of searching hosts from the CLI. |
| 34 |
|
| 35 |
.. prompt:: bash |
| 36 |
|
| 37 |
censys search 'services.http.response.html_title: "Dashboard"' |
| 38 |
|
| 39 |
By combining the ``search`` command with ``jq`` we can easily manipulate the output to get the desired fields. |
| 40 |
|
| 41 |
.. prompt:: bash |
| 42 |
|
| 43 |
censys search 'services.service_name: ELASTICSEARCH' | jq -c '.[] | {ip: .ip}' |
| 44 |
|
| 45 |
By setting the ``--pages`` flag to ``-1`` we can get all pages of results. |
| 46 |
|
| 47 |
.. prompt:: bash |
| 48 |
|
| 49 |
censys search 'ip: 8.8.8.0/16' --pages -1 | jq -c '[.[] | .ip]' |
| 50 |
|
| 51 |
By settings the ``--index-type`` flag we can search other indexes such as ``certificates``. |
| 52 |
|
| 53 |
.. prompt:: bash |
| 54 |
|
| 55 |
censys search 'parsed.subject_dn: "censys.io"' --index-type certificates |
| 56 |
|
| 57 |
For the ``certificates`` index we can also add the ``--fields`` flag to specify which fields we want returned. |
| 58 |
|
| 59 |
.. prompt:: bash |
| 60 |
|
| 61 |
censys search 'parsed.subject.country: AU' --index-type certificates --fields parsed.issuer.organization |
| 62 |
|
| 63 |
``view`` |
| 64 |
-------- |
| 65 |
|
| 66 |
Below we show an example of viewing a host from the CLI. |
| 67 |
|
| 68 |
.. prompt:: bash |
| 69 |
|
| 70 |
censys view 8.8.8.8 |
| 71 |
|
| 72 |
Below we show an example of viewing a certificate from the CLI. |
| 73 |
|
| 74 |
.. prompt:: bash |
| 75 |
|
| 76 |
censys view 9b267decc8d23586dc4c56dd0789574cab0f28581ef354ff2fcec8ca6d992fc2 --index-type certificates |
| 77 |
|
| 78 |
You can save results to a file using the ``-o`` argument. |
| 79 |
|
| 80 |
.. prompt:: bash |
| 81 |
|
| 82 |
censys view 8.8.8.8 -o google.json |
| 83 |
|
| 84 |
We can then parse this json with something like ``jq``. |
| 85 |
|
| 86 |
.. prompt:: bash |
| 87 |
|
| 88 |
cat google.json | jq '[.services[] | {port: .port, protocol: .service_name}]' |
| 89 |
|
| 90 |
If you have access to historical ``hosts`` data you can view the data at a specific point in time using the ``--at-time`` argument. |
| 91 |
|
| 92 |
.. prompt:: bash |
| 93 |
|
| 94 |
censys view 1.1.1.1 --at-time 2023-01-01 |
| 95 |
|
| 96 |
.. note:: |
| 97 |
|
| 98 |
The ``--at-time`` argument is only available for the ``hosts`` index. |
| 99 |
|
| 100 |
``subdomains`` |
| 101 |
-------------- |
| 102 |
|
| 103 |
Below we show an example of subdomain enumeration from the CLI. |
| 104 |
|
| 105 |
.. prompt:: bash |
| 106 |
|
| 107 |
censys subdomains censys.io |
| 108 |
|
| 109 |
You can limit the number of results by setting the ``--max-records`` flag. |
| 110 |
|
| 111 |
.. prompt:: bash |
| 112 |
|
| 113 |
censys subdomains censys.io --max-records 10 |
| 114 |
|
| 115 |
We can then output the results in JSON format using the ``--json`` flag. |
| 116 |
|
| 117 |
.. prompt:: bash |
| 118 |
|
| 119 |
censys subdomains censys.io --json |
| 120 |
|
| 121 |
``account`` |
| 122 |
----------- |
| 123 |
|
| 124 |
Below we show an example of viewing your account information from the CLI. |
| 125 |
|
| 126 |
.. prompt:: bash |
| 127 |
|
| 128 |
censys account |
| 129 |
|
| 130 |
You can also request the JSON version of your account information. |
| 131 |
|
| 132 |
.. prompt:: bash |
| 133 |
|
| 134 |
censys account --json |
| 135 |
|
| 136 |
``asm`` |
| 137 |
------- |
| 138 |
|
| 139 |
``add-seeds`` |
| 140 |
^^^^^^^^^^^^^ |
| 141 |
|
| 142 |
See CLI command :ref:`asm add-seeds<cli:censys asm add-seeds>` for detail documentation of parameters. |
| 143 |
|
| 144 |
Below we show an example of adding seeds from the CLI. |
| 145 |
|
| 146 |
.. prompt:: bash |
| 147 |
|
| 148 |
censys asm add-seeds -j '["1.1.1.1"]' |
| 149 |
|
| 150 |
You can add seeds from JSON or CSV files. JSON is assumed unless ``--csv`` is specified. |
| 151 |
The CSV file option is shown here. |
| 152 |
|
| 153 |
.. prompt:: bash |
| 154 |
|
| 155 |
censys asm add-seeds --csv -i 'good_seeds.csv' |
| 156 |
|
| 157 |
.. list-table:: CSV File Format |
| 158 |
:header-rows: 1 |
| 159 |
|
| 160 |
* - type |
| 161 |
- value |
| 162 |
- label |
| 163 |
* - IP_ADDRESS |
| 164 |
- 1.1.1.1 |
| 165 |
- Example Label |
| 166 |
* - DOMAIN_NAME |
| 167 |
- one.one.one.one |
| 168 |
- Example Label |
| 169 |
|
| 170 |
You can also add seeds from STDIN using the ``-i -`` argument. |
| 171 |
In the example below we are adding IPs from a Censys Search. |
| 172 |
|
| 173 |
.. prompt:: bash |
| 174 |
|
| 175 |
censys search 'services.tls.certificates.leaf_data.issuer.common_name: "Roomba CA"' | jq '[.[] | .ip]' | censys asm add-seeds -i - |
| 176 |
|
| 177 |
You can also add seeds from an nmap XML file using the ``--nmap-xml`` argument. |
| 178 |
In the example below we are adding IPs from a nmap scan on ``censys.io``. |
| 179 |
|
| 180 |
.. prompt:: bash |
| 181 |
|
| 182 |
nmap censys.io -oX censys.xml |
| 183 |
censys asm add-seeds --nmap-xml censys.xml |
| 184 |
|
| 185 |
``delete-seeds`` |
| 186 |
^^^^^^^^^^^^^^^^ |
| 187 |
|
| 188 |
See CLI command :ref:`asm delete-seeds<cli:censys asm delete-seeds>` for detail documentation of parameters. |
| 189 |
|
| 190 |
Below we show an example of deleting seeds from the CLI. |
| 191 |
|
| 192 |
.. prompt:: bash |
| 193 |
|
| 194 |
censys asm delete-seeds -j '["1.1.1.1"]' |
| 195 |
|
| 196 |
You can delete seeds using file input as well, including CSV files. |
| 197 |
|
| 198 |
.. prompt:: bash |
| 199 |
|
| 200 |
censys asm delete-seeds --csv -i 'bad_seeds.csv' |
| 201 |
|
| 202 |
.. list-table:: CSV File Format |
| 203 |
:header-rows: 1 |
| 204 |
|
| 205 |
* - id |
| 206 |
- type |
| 207 |
- value |
| 208 |
- label |
| 209 |
* - 1 |
| 210 |
- IP_ADDRESS |
| 211 |
- 1.1.1.1 |
| 212 |
- Example Label |
| 213 |
* - 2 |
| 214 |
- DOMAIN_NAME |
| 215 |
- one.one.one.one |
| 216 |
- Example Label |
| 217 |
|
| 218 |
``delete-all-seeds`` |
| 219 |
^^^^^^^^^^^^^^^^^^^^ |
| 220 |
|
| 221 |
See CLI command :ref:`asm delete-all-seeds<cli:censys asm delete-all-seeds>` for detail documentation of parameters. |
| 222 |
|
| 223 |
Below we show an example of deleting all seeds from the CLI. You will be prompted to confirm. |
| 224 |
|
| 225 |
.. prompt:: bash |
| 226 |
|
| 227 |
censys asm delete-all-seeds |
| 228 |
|
| 229 |
If you want to delete all seeds without a prompt, you can use the ``--force`` parameter. |
| 230 |
|
| 231 |
.. prompt:: bash |
| 232 |
|
| 233 |
censys asm delete-all-seeds --force |
| 234 |
|
| 235 |
|
| 236 |
``delete-labeled-seeds`` |
| 237 |
^^^^^^^^^^^^^^^^^^^^^^^^ |
| 238 |
|
| 239 |
See CLI command :ref:`asm delete-labeled-seeds<cli:censys asm delete-labeled-seeds>` for detail documentation of parameters. |
| 240 |
|
| 241 |
Below we show an example of deleting all seeds with a given label from the CLI. |
| 242 |
|
| 243 |
.. prompt:: bash |
| 244 |
|
| 245 |
censys asm delete-labeled-seeds -l "Some Label" |
| 246 |
|
| 247 |
``replace-labeled-seeds`` |
| 248 |
^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 249 |
|
| 250 |
See CLI command :ref:`asm replace-labeled-seeds<cli:censys asm replace-labeled-seeds>` for detail documentation of parameters. |
| 251 |
|
| 252 |
Below we show an example of replacing labeled seeds from the CLI, which will replace all existing seeds that have |
| 253 |
the specified label with the provided seeds, which will also have that label applied. |
| 254 |
|
| 255 |
.. prompt:: bash |
| 256 |
|
| 257 |
censys asm replace-labeled-seeds -l "Some Label" -j '["1.1.1.1"]' |
| 258 |
|
| 259 |
You can also use a variety of methods to specific the new seeds, including providing them in a CSV file. |
| 260 |
|
| 261 |
.. prompt:: bash |
| 262 |
|
| 263 |
censys asm replace-labeled-seeds -l "Some Label" --csv -i 'new_seeds.csv' |
| 264 |
|
| 265 |
``list-seeds`` |
| 266 |
^^^^^^^^^^^^^^ |
| 267 |
|
| 268 |
See CLI command :ref:`asm list-seeds<cli:censys asm list-seeds>` for detail documentation of parameters. |
| 269 |
|
| 270 |
Below we show an example of listing all seeds in CSV file format and appending it to a file. |
| 271 |
|
| 272 |
.. prompt:: bash |
| 273 |
|
| 274 |
censys asm list-seeds --csv >> seeds.csv |
| 275 |
|
| 276 |
You can also filter the seeds by type (``-t``) and/or label (``-l``). |
| 277 |
|
| 278 |
.. prompt:: bash |
| 279 |
|
| 280 |
censys asm list-seeds -t 'IP_ADDRESS' -l 'Some Label' >> filtered_seeds.json |
| 281 |
|
| 282 |
|
| 283 |
``list-saved-queries`` |
| 284 |
^^^^^^^^^^^^^^^^^^^^^^ |
| 285 |
|
| 286 |
See CLI command :ref:`asm list-saved-queries<cli:censys asm list-saved-queries>` for detail documentation of parameters. |
| 287 |
|
| 288 |
Below we show an example of listing all saved queries in CSV file format and appending it to a file. |
| 289 |
|
| 290 |
.. prompt:: bash |
| 291 |
|
| 292 |
censys asm list-saved-queries --csv >> saved_queries.csv |
| 293 |
|
| 294 |
You can also filter the saved queries by query name prefix (``--query-name-prefix``) and/or filter term (``--filter-term``). |
| 295 |
|
| 296 |
.. prompt:: bash |
| 297 |
|
| 298 |
censys asm list-saved-queries --query-name-prefix 'Some Prefix' --filter-term 'Some Term' >> filtered_saved_queries.json |
| 299 |
|
| 300 |
|
| 301 |
``add-saved-query`` |
| 302 |
^^^^^^^^^^^^^^^^^^^ |
| 303 |
|
| 304 |
See CLI command :ref:`asm add-saved-query<cli:censys asm add-saved-query>` for detail documentation of parameters. |
| 305 |
|
| 306 |
Below we show an example of adding a saved query from the CLI. |
| 307 |
|
| 308 |
.. prompt:: bash |
| 309 |
|
| 310 |
censys asm add-saved-query --query-name 'Some Query' --query 'services.http.response.html_title: "Dashboard"' |
| 311 |
|
| 312 |
``get-saved-query-by-id`` |
| 313 |
^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 314 |
|
| 315 |
See CLI command :ref:`asm get-saved-query-by-id<cli:censys asm get-saved-query-by-id>` for detail documentation of parameters. |
| 316 |
|
| 317 |
Below we show an example of getting a saved query by ID from the CLI. |
| 318 |
|
| 319 |
.. prompt:: bash |
| 320 |
|
| 321 |
censys asm get-saved-query-by-id --query-id 'Some ID' |
| 322 |
|
| 323 |
``edit-saved-query-by-id`` |
| 324 |
^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 325 |
|
| 326 |
See CLI command :ref:`asm edit-saved-query-by-id<cli:censys asm edit-saved-query-by-id>` for detail documentation of parameters. |
| 327 |
|
| 328 |
Below we show an example of editing a saved query by ID from the CLI. |
| 329 |
|
| 330 |
.. prompt:: bash |
| 331 |
|
| 332 |
censys asm edit-saved-query-by-id --query-id 'Some ID' --query-name 'Some Query' --query 'services.http.response.html_title: "Dashboard"' |
| 333 |
|
| 334 |
``delete-saved-query-by-id`` |
| 335 |
^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 336 |
|
| 337 |
See CLI command :ref:`asm delete-saved-query-by-id<cli:censys asm delete-saved-query-by-id>` for detail documentation of parameters. |
| 338 |
|
| 339 |
Below we show an example of deleting a saved query by ID from the CLI. |
| 340 |
|
| 341 |
.. prompt:: bash |
| 342 |
|
| 343 |
censys asm delete-saved-query-by-id --query-id 'Some ID' |
| 344 |
|
| 345 |
``execute-saved-query-by-name`` |
| 346 |
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 347 |
|
| 348 |
See CLI command :ref:`asm execute-saved-query-by-name<cli:censys asm execute-saved-query-by-name>` for detail documentation of parameters. |
| 349 |
|
| 350 |
Below we show an example of executing a saved query by name from the CLI. |
| 351 |
|
| 352 |
.. prompt:: bash |
| 353 |
|
| 354 |
censys asm execute-saved-query-by-name --query-name 'Some query name' |
| 355 |
|
| 356 |
``execute-saved-query-by-id`` |
| 357 |
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 358 |
|
| 359 |
See CLI command :ref:`asm execute-saved-query-by-id<cli:censys asm execute-saved-query-by-id>` for detail documentation of parameters. |
| 360 |
|
| 361 |
Below we show an example of executing a saved query by ID from the CLI. |
| 362 |
|
| 363 |
.. prompt:: bash |
| 364 |
|
| 365 |
censys asm execute-saved-query-by-id --query-id 'Some query ID' |
| 366 |
|
| 367 |
``search`` |
| 368 |
^^^^^^^^^^ |
| 369 |
|
| 370 |
See CLI command :ref:`asm search<cli:censys asm search>` for detail documentation of parameters. |
| 371 |
|
| 372 |
Below we show an example of executing an inventory search query from the CLI. |
| 373 |
|
| 374 |
.. prompt:: bash |
| 375 |
|
| 376 |
censys asm search --query 'Some query' |