osquery


Nameosquery JSON
Version 3.1.1 PyPI version JSON
download
home_pagehttps://osquery.io
SummaryOsquery Python API
upload_time2024-07-24 04:03:30
maintainerNone
docs_urlNone
authorosquery authors
requires_pythonNone
licenseBSD
keywords security databases operating systems
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ## osquery-python

![osquery-python-logo](https://i.imgur.com/9Vy2GFx.png)

[osquery](https://github.com/facebook/osquery) exposes an operating system as a high-performance relational database. This allows you to write SQL-based queries to explore operating system data. With osquery, SQL tables represent abstract concepts such as running processes, loaded kernel modules, open network connections, browser plugins, hardware events or file hashes.

If you're interested in learning more about osquery, visit the [GitHub project](https://github.com/facebook/osquery), the [website](https://osquery.io), and the [users guide](https://osquery.readthedocs.org/).

### What is osquery-python?

[![Build Status](https://travis-ci.org/osquery/osquery-python.svg?branch=master)](https://travis-ci.org/osquery/osquery-python)

In osquery, SQL tables, configuration retrieval, log handling, etc are implemented via a simple, robust plugin and extensions API. This project contains the official Python bindings for creating osquery extensions in Python. Consider the following example:

```python
#!/usr/bin/env python

import osquery

@osquery.register_plugin
class MyTablePlugin(osquery.TablePlugin):
    def name(self):
        return "foobar"

    def columns(self):
        return [
            osquery.TableColumn(name="foo", type=osquery.STRING),
            osquery.TableColumn(name="baz", type=osquery.STRING),
        ]

    def generate(self, context):
        query_data = []

        for _ in range(2):
            row = {}
            row["foo"] = "bar"
            row["baz"] = "baz"
            query_data.append(row)

        return query_data

if __name__ == "__main__":
    osquery.start_extension(name="my_awesome_extension", version="1.0.0")
```

To test this code start an osquery shell:

```
osqueryi --nodisable_extensions
osquery> select value from osquery_flags where name = 'extensions_socket';
+-----------------------------------+
| value                             |
+-----------------------------------+
| /Users/USERNAME/.osquery/shell.em |
+-----------------------------------+
```

Then start the Python extension:

```
python ./my_table_plugin.py --socket /Users/USERNAME/.osquery/shell.em
```

Alternatively, you can also autoload your extension when starting an osquery shell:

```
osqueryi --extension path_to_my_table_plugin.py
```

This will register a table called "foobar". As you can see, the table will return two rows:

```
osquery> select * from foobar;
+-----+-----+
| foo | baz |
+-----+-----+
| bar | baz |
| bar | baz |
+-----+-----+
osquery>
```

This is obviously a contrived example, but it's easy to imagine the possibilities.

Using the instructions found on the [wiki](https://osquery.readthedocs.org/en/latest/development/osquery-sdk/), you can easily deploy your extension with an existing osquery deployment.

Extensions are the core way that you can extend and customize osquery. At Facebook, we use extensions extensively to implement many plugins that take advantage of internal APIs and tools.

### Execute queries in Python

The same Thrift bindings can be used to create a Python client for the `osqueryd` or `osqueryi`'s extension socket. There are helper classes provided that spawn an ephemeral osquery process for consecutive or long running client instances.

```python
import osquery

if __name__ == "__main__":
    # Spawn an osquery process using an ephemeral extension socket.
    instance = osquery.SpawnInstance()
    instance.open()  # This may raise an exception

    # Issues queries and call osquery Thrift APIs.
    instance.client.query("select timestamp from time")
```

### Connect to an existing socket

In the example above the `SpawnInstance()` method is used to fork and configure an osquery instance. We can use similar APIs to connect to the Thrift socket of an existing osquery instance. Remember, normal UNIX permissions apply to the Thrift socket.

Imagine if you started `osqueryd`:
```sh
$ osqueryd --ephemeral --disable_logging --disable_database \
    --extensions_socket /home/you/.osquery/osqueryd.sock &
```

Then use the Python bindings:
```python
import osquery

if __name__ == "__main__":
    # You must know the Thrift socket path
    # For an installed and running system osqueryd, this is:
    #   Linux and macOS: /var/osquery/osquery.em
    #   FreeBSD: /var/run/osquery.em
    #   Windows: \\.\pipe\osquery.em
    instance = osquery.ExtensionClient('/home/you/.osquery/osqueryd.sock')
    instance.open()  # This may raise an exception

    # Issue queries and call osquery Thrift APIs.
    client = instance.extension_client()
    client.query('select timestamp from time')
```

### Install

To install from PyPi, run the following:

```
pip install osquery
```

Alternatively, to install from this repo, run the following:

```
python setup.py build
python setup.py install
```


### Development

See [CONTRIBUTING.md](https://github.com/osquery/osquery-python/blob/master/CONTRIBUTING.md) and the [osquery wiki](https://osquery.readthedocs.org) for development information.

### How To Release

1. Pick a version number
2. Update `osquery/__init__.py` to match
3. Use the GitHub release
4. Make sure the GitHub Action ran

### Vulnerabilities

Facebook has a [bug bounty](https://www.facebook.com/whitehat/) program that includes osquery. If you find a security vulnerability in osquery, please submit it via the process outlined on that page and do not file a public issue. For more information on finding vulnerabilities in osquery, see a recent blog post about [bug-hunting osquery](https://www.facebook.com/notes/facebook-bug-bounty/bug-hunting-osquery/954850014529225).

            

Raw data

            {
    "_id": null,
    "home_page": "https://osquery.io",
    "name": "osquery",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "security databases operating systems",
    "author": "osquery authors",
    "author_email": "osquery@fb.com",
    "download_url": "https://files.pythonhosted.org/packages/02/7a/3b5060835ba7c153097ac103c5827f3fcf5add4e0c156816e6eeeb0036e4/osquery-3.1.1.tar.gz",
    "platform": null,
    "description": "## osquery-python\n\n![osquery-python-logo](https://i.imgur.com/9Vy2GFx.png)\n\n[osquery](https://github.com/facebook/osquery) exposes an operating system as a high-performance relational database. This allows you to write SQL-based queries to explore operating system data. With osquery, SQL tables represent abstract concepts such as running processes, loaded kernel modules, open network connections, browser plugins, hardware events or file hashes.\n\nIf you're interested in learning more about osquery, visit the [GitHub project](https://github.com/facebook/osquery), the [website](https://osquery.io), and the [users guide](https://osquery.readthedocs.org/).\n\n### What is osquery-python?\n\n[![Build Status](https://travis-ci.org/osquery/osquery-python.svg?branch=master)](https://travis-ci.org/osquery/osquery-python)\n\nIn osquery, SQL tables, configuration retrieval, log handling, etc are implemented via a simple, robust plugin and extensions API. This project contains the official Python bindings for creating osquery extensions in Python. Consider the following example:\n\n```python\n#!/usr/bin/env python\n\nimport osquery\n\n@osquery.register_plugin\nclass MyTablePlugin(osquery.TablePlugin):\n    def name(self):\n        return \"foobar\"\n\n    def columns(self):\n        return [\n            osquery.TableColumn(name=\"foo\", type=osquery.STRING),\n            osquery.TableColumn(name=\"baz\", type=osquery.STRING),\n        ]\n\n    def generate(self, context):\n        query_data = []\n\n        for _ in range(2):\n            row = {}\n            row[\"foo\"] = \"bar\"\n            row[\"baz\"] = \"baz\"\n            query_data.append(row)\n\n        return query_data\n\nif __name__ == \"__main__\":\n    osquery.start_extension(name=\"my_awesome_extension\", version=\"1.0.0\")\n```\n\nTo test this code start an osquery shell:\n\n```\nosqueryi --nodisable_extensions\nosquery> select value from osquery_flags where name = 'extensions_socket';\n+-----------------------------------+\n| value                             |\n+-----------------------------------+\n| /Users/USERNAME/.osquery/shell.em |\n+-----------------------------------+\n```\n\nThen start the Python extension:\n\n```\npython ./my_table_plugin.py --socket /Users/USERNAME/.osquery/shell.em\n```\n\nAlternatively, you can also autoload your extension when starting an osquery shell:\n\n```\nosqueryi --extension path_to_my_table_plugin.py\n```\n\nThis will register a table called \"foobar\". As you can see, the table will return two rows:\n\n```\nosquery> select * from foobar;\n+-----+-----+\n| foo | baz |\n+-----+-----+\n| bar | baz |\n| bar | baz |\n+-----+-----+\nosquery>\n```\n\nThis is obviously a contrived example, but it's easy to imagine the possibilities.\n\nUsing the instructions found on the [wiki](https://osquery.readthedocs.org/en/latest/development/osquery-sdk/), you can easily deploy your extension with an existing osquery deployment.\n\nExtensions are the core way that you can extend and customize osquery. At Facebook, we use extensions extensively to implement many plugins that take advantage of internal APIs and tools.\n\n### Execute queries in Python\n\nThe same Thrift bindings can be used to create a Python client for the `osqueryd` or `osqueryi`'s extension socket. There are helper classes provided that spawn an ephemeral osquery process for consecutive or long running client instances.\n\n```python\nimport osquery\n\nif __name__ == \"__main__\":\n    # Spawn an osquery process using an ephemeral extension socket.\n    instance = osquery.SpawnInstance()\n    instance.open()  # This may raise an exception\n\n    # Issues queries and call osquery Thrift APIs.\n    instance.client.query(\"select timestamp from time\")\n```\n\n### Connect to an existing socket\n\nIn the example above the `SpawnInstance()` method is used to fork and configure an osquery instance. We can use similar APIs to connect to the Thrift socket of an existing osquery instance. Remember, normal UNIX permissions apply to the Thrift socket.\n\nImagine if you started `osqueryd`:\n```sh\n$ osqueryd --ephemeral --disable_logging --disable_database \\\n    --extensions_socket /home/you/.osquery/osqueryd.sock &\n```\n\nThen use the Python bindings:\n```python\nimport osquery\n\nif __name__ == \"__main__\":\n    # You must know the Thrift socket path\n    # For an installed and running system osqueryd, this is:\n    #   Linux and macOS: /var/osquery/osquery.em\n    #   FreeBSD: /var/run/osquery.em\n    #   Windows: \\\\.\\pipe\\osquery.em\n    instance = osquery.ExtensionClient('/home/you/.osquery/osqueryd.sock')\n    instance.open()  # This may raise an exception\n\n    # Issue queries and call osquery Thrift APIs.\n    client = instance.extension_client()\n    client.query('select timestamp from time')\n```\n\n### Install\n\nTo install from PyPi, run the following:\n\n```\npip install osquery\n```\n\nAlternatively, to install from this repo, run the following:\n\n```\npython setup.py build\npython setup.py install\n```\n\n\n### Development\n\nSee [CONTRIBUTING.md](https://github.com/osquery/osquery-python/blob/master/CONTRIBUTING.md) and the [osquery wiki](https://osquery.readthedocs.org) for development information.\n\n### How To Release\n\n1. Pick a version number\n2. Update `osquery/__init__.py` to match\n3. Use the GitHub release\n4. Make sure the GitHub Action ran\n\n### Vulnerabilities\n\nFacebook has a [bug bounty](https://www.facebook.com/whitehat/) program that includes osquery. If you find a security vulnerability in osquery, please submit it via the process outlined on that page and do not file a public issue. For more information on finding vulnerabilities in osquery, see a recent blog post about [bug-hunting osquery](https://www.facebook.com/notes/facebook-bug-bounty/bug-hunting-osquery/954850014529225).\n",
    "bugtrack_url": null,
    "license": "BSD",
    "summary": "Osquery Python API",
    "version": "3.1.1",
    "project_urls": {
        "Homepage": "https://osquery.io"
    },
    "split_keywords": [
        "security",
        "databases",
        "operating",
        "systems"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9b55b0461ca9bad25a4a565f7dd25818be97d7e698af5c92cb3cd455100a0254",
                "md5": "e31f4fe9fd924b07428a79080156c357",
                "sha256": "a334a1ea867a1028b314f54669c13c6825299a6a17a88b3c2af496f8ff3d0345"
            },
            "downloads": -1,
            "filename": "osquery-3.1.1-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e31f4fe9fd924b07428a79080156c357",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 27591,
            "upload_time": "2024-07-24T04:03:29",
            "upload_time_iso_8601": "2024-07-24T04:03:29.584931Z",
            "url": "https://files.pythonhosted.org/packages/9b/55/b0461ca9bad25a4a565f7dd25818be97d7e698af5c92cb3cd455100a0254/osquery-3.1.1-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "027a3b5060835ba7c153097ac103c5827f3fcf5add4e0c156816e6eeeb0036e4",
                "md5": "7140937ce317622ae135a8bb5e23f282",
                "sha256": "8dbafbcb19d733b390e94ecf2423967f95610655c927200feef03ea7b265699d"
            },
            "downloads": -1,
            "filename": "osquery-3.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "7140937ce317622ae135a8bb5e23f282",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 24497,
            "upload_time": "2024-07-24T04:03:30",
            "upload_time_iso_8601": "2024-07-24T04:03:30.954913Z",
            "url": "https://files.pythonhosted.org/packages/02/7a/3b5060835ba7c153097ac103c5827f3fcf5add4e0c156816e6eeeb0036e4/osquery-3.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-07-24 04:03:30",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "osquery"
}
        
Elapsed time: 0.27275s