Python library to interact with Joern server
Project description
Introduction
High level python library to interact with a Joern server.
pip install joern-lib
The repository includes docker compose configuration to interactively query the joern server with polynote notebooks.
Usage
Run joern server and polynote locally.
git clone https://github.com/appthreat/joern-lib.git
# Edit docker-compose.yml to set sources directory
docker compose up -d
# podman-compose up --build
Navigate to http://localhost:8192 for an interactive polynote notebook. You could open one of the sample notebooks from the contrib directory to learn about Joern server and this library.
Common steps
python -m asyncio
Execute single query
from joern_lib import client, workspace
from joern_lib.detectors import common as cpg
connection = await client.get("http://localhost:9000", "admin", "admin")
# connection = await client.get("http://localhost:9000")
res = await client.q(connection, "val a=1");
# {'response': 'a: Int = 1\n'}
Execute bulk query
res = await client.bulk_query(connection, ["val a=1", "val b=2", "val c=a+b"]);
# [{'response': 'a: Int = 1\n'}, {'response': 'b: Int = 2\n'}, {'response': 'c: Int = 3\n'}]
Workspace
List workspaces
res = await workspace.list(connection)
Get workspace path
res = await workspace.get_path(connection)
# /workspace (Response would be parsed)
Check if cpg exists
await workspace.cpg_exists(connection, "NodeGoat")
Import code for analysis
res = await workspace.import_code(connection, "/app", "NodeGoat")
# True
CPG core
List files
res = await cpg.list_files(connection)
# list of files
JavaScript specific
from joern_lib.detectors import js
List http routes
await js.list_http_routes(connection)
Name of the variable containing express()
await js.get_express_appvar(connection)
List of require statements
await js.list_requires(connection)
List of import statements
await js.list_imports(connection)
List of NoSQL DB collection names
await js.list_nosql_collections(connection)
Get HTTP sources
await js.get_http_sources(connection)
await js.get_http_sinks(connection)
AWS
Requires TypeScript project
await js.list_aws_modules(connection)
Troubleshooting
No response from server
If Joern server stops responding after a while restart docker.
docker compose down
docker compose up -d
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for joern_lib-0.6.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e33744608f016fc30a76df0dcb2ea78a2791281d263d5334f4cc3fdf648d0b29 |
|
MD5 | 2e592a7156031baf59cd6185a52f57de |
|
BLAKE2b-256 | 9d0c4be4ed0c139b7d10f86037eeda27f5b9a977697d770294b9cbaf5647b2fb |