ninjasignal 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ninjasignal-0.1.0/.gitignore +28 -0
- ninjasignal-0.1.0/CHANGELOG.md +12 -0
- ninjasignal-0.1.0/LICENSE +201 -0
- ninjasignal-0.1.0/NOTICE +29 -0
- ninjasignal-0.1.0/PKG-INFO +109 -0
- ninjasignal-0.1.0/README.md +83 -0
- ninjasignal-0.1.0/SECURITY.md +21 -0
- ninjasignal-0.1.0/examples/quickstart.py +27 -0
- ninjasignal-0.1.0/ninjasignal/__init__.py +72 -0
- ninjasignal-0.1.0/ninjasignal/cli.py +88 -0
- ninjasignal-0.1.0/ninjasignal/client.py +162 -0
- ninjasignal-0.1.0/pyproject.toml +40 -0
- ninjasignal-0.1.0/tests/test_client.py +82 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*.egg-info/
|
|
5
|
+
.eggs/
|
|
6
|
+
build/
|
|
7
|
+
dist/
|
|
8
|
+
.pytest_cache/
|
|
9
|
+
.ruff_cache/
|
|
10
|
+
.mypy_cache/
|
|
11
|
+
|
|
12
|
+
# envs
|
|
13
|
+
.venv/
|
|
14
|
+
venv/
|
|
15
|
+
env/
|
|
16
|
+
|
|
17
|
+
# secrets — never commit
|
|
18
|
+
.env
|
|
19
|
+
*.pem
|
|
20
|
+
*.key
|
|
21
|
+
*.token
|
|
22
|
+
secrets*.json
|
|
23
|
+
|
|
24
|
+
# editor / OS
|
|
25
|
+
.vscode/
|
|
26
|
+
.idea/
|
|
27
|
+
.DS_Store
|
|
28
|
+
Thumbs.db
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.0 — 2026-10-07
|
|
4
|
+
|
|
5
|
+
Initial release.
|
|
6
|
+
|
|
7
|
+
- `Client` + module-level helpers over the public Ninja Labz feeds:
|
|
8
|
+
`groups`, `group`, `recent`, `monthly`, `predictions`, `surging`, `predict`, `risk`.
|
|
9
|
+
- `ninja` / `ninjasignal` CLI with table or `--json` output.
|
|
10
|
+
- Zero runtime dependencies; optional pandas via `frame()`.
|
|
11
|
+
- Non-JSON responses are rejected (a stale CDN entry or error page can never be
|
|
12
|
+
parsed into bad data).
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or Derivative
|
|
95
|
+
Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Scott Gardner / Ninja Labz
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
ninjasignal-0.1.0/NOTICE
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
ninjasignal
|
|
2
|
+
Copyright 2026 Scott Gardner / Ninja Labz (ninja.ing)
|
|
3
|
+
|
|
4
|
+
This product is licensed under the Apache License, Version 2.0 (see LICENSE).
|
|
5
|
+
|
|
6
|
+
Intellectual-property boundary
|
|
7
|
+
------------------------------
|
|
8
|
+
This open-source client library contains NO Ninja Labs predictive-intelligence
|
|
9
|
+
methods, models, correlation/inference algorithms, scoring, or systems. It only
|
|
10
|
+
reads already-published outputs from the public Ninja Labs data feeds.
|
|
11
|
+
|
|
12
|
+
The predictive-intelligence methods and systems that produce those outputs are
|
|
13
|
+
proprietary to Ninja Labs and are patent-pending and/or patented. Nothing in this
|
|
14
|
+
repository — neither the Apache-2.0 code license nor the CC-BY data license —
|
|
15
|
+
grants any right, express or implied, to those methods, models, or systems, by
|
|
16
|
+
license, estoppel, or otherwise.
|
|
17
|
+
|
|
18
|
+
Licensing summary
|
|
19
|
+
-----------------
|
|
20
|
+
- This client CODE: Apache License 2.0 (patent grant limited to what this code
|
|
21
|
+
itself embodies — which is none of the proprietary methods).
|
|
22
|
+
- The DATA served by the feeds: Creative Commons Attribution 4.0 (CC BY 4.0).
|
|
23
|
+
Attribute "Ninja Labs — ninjalabz.io".
|
|
24
|
+
- The predictive METHODS/MODELS behind the data: proprietary, patent-pending.
|
|
25
|
+
NOT licensed by this repository.
|
|
26
|
+
|
|
27
|
+
"Ninja Labs", "Ninja Signal", "ninja.ing" and associated marks are trademarks of
|
|
28
|
+
their owner. This License does not grant permission to use those marks except as
|
|
29
|
+
required for reasonable and customary use in describing the origin of the work.
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: ninjasignal
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python client for Ninja Labz predictive threat intelligence — live ransomware groups, victims, and what the lab predicts next.
|
|
5
|
+
Project-URL: Homepage, https://ninjalabz.io
|
|
6
|
+
Project-URL: Predictive Intel Report, https://ninjalabz.io/intel-report/
|
|
7
|
+
Project-URL: Data Feeds, https://ninjalabz.io/feeds/
|
|
8
|
+
Project-URL: Source, https://github.com/scottgardner777/ninjasignal
|
|
9
|
+
Author-email: Scott Gardner <the_v01d@ninja.ing>
|
|
10
|
+
License: Apache-2.0
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
License-File: NOTICE
|
|
13
|
+
Keywords: cti,ninja-labz,ninjasignal,osint,predictive-intelligence,ransomware,security,threat-intelligence
|
|
14
|
+
Classifier: Development Status :: 4 - Beta
|
|
15
|
+
Classifier: Intended Audience :: Information Technology
|
|
16
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
17
|
+
Classifier: Operating System :: OS Independent
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Classifier: Topic :: Security
|
|
20
|
+
Requires-Python: >=3.9
|
|
21
|
+
Provides-Extra: dev
|
|
22
|
+
Requires-Dist: pytest>=7; extra == 'dev'
|
|
23
|
+
Provides-Extra: pandas
|
|
24
|
+
Requires-Dist: pandas>=1.3; extra == 'pandas'
|
|
25
|
+
Description-Content-Type: text/markdown
|
|
26
|
+
|
|
27
|
+
# ninjasignal
|
|
28
|
+
|
|
29
|
+
**The Python client for [Ninja Labz](https://ninjalabz.io) predictive threat intelligence.**
|
|
30
|
+
|
|
31
|
+
Ninja Labz tracks the ransomware ecosystem on live data and publishes *what it predicts next* — surging groups, new entrants, sectors in the crosshairs, and calibrated forward calls. `ninjasignal` puts that in three lines of Python.
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
pip install ninjasignal
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
import ninjasignal as ns
|
|
39
|
+
|
|
40
|
+
ns.surging() # groups accelerating right now
|
|
41
|
+
ns.predict("qilin") # what the lab predicts for a group
|
|
42
|
+
ns.groups() # active groups + victim counts, top sector/country, origin
|
|
43
|
+
ns.recent(limit=20) # latest claimed victims (date, group, sector, country)
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Zero runtime dependencies. Talks only to the public feeds over HTTPS. Pandas is an optional convenience, never required.
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
## Why
|
|
51
|
+
|
|
52
|
+
Ransomware intel is everywhere; *predictive* ransomware intel, published openly, is not. Ninja Labz runs an AI-native lab that scans dated victim activity, scores the ecosystem, and calls what's next — then publishes it. This library is how you consume it from a notebook, a pipeline, or a terminal.
|
|
53
|
+
|
|
54
|
+
## CLI
|
|
55
|
+
|
|
56
|
+
Installs `ninja` (and `ninjasignal`):
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
ninja surging # groups accelerating now
|
|
60
|
+
ninja predict qilin # the lab's calls for a group
|
|
61
|
+
ninja groups # active groups
|
|
62
|
+
ninja recent --limit 20 --sector Healthcare
|
|
63
|
+
ninja report # latest monthly stats
|
|
64
|
+
ninja risk --sector Healthcare # exposure concentration (descriptive)
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Add `--json` to any command for raw output, `--base URL` to point at a mirror.
|
|
68
|
+
|
|
69
|
+
## API
|
|
70
|
+
|
|
71
|
+
| Call | Returns |
|
|
72
|
+
|------|---------|
|
|
73
|
+
| `ns.groups()` | active ransomware groups: `name, victims, top_sector, top_country, origin, sanctioned` |
|
|
74
|
+
| `ns.group(slug)` | one group's full dossier data (sectors, countries, recent, aliases) |
|
|
75
|
+
| `ns.recent(limit=, group=, sector=, country=)` | recent claimed victims, newest first |
|
|
76
|
+
| `ns.monthly()` | per-month totals + top groups (the trend series) |
|
|
77
|
+
| `ns.predictions(kind=)` | the lab's predictions: `type, subject, statement, confidence, basis` |
|
|
78
|
+
| `ns.surging()` | predictions of type `rising_group` |
|
|
79
|
+
| `ns.predict(group)` | predictions matching a group |
|
|
80
|
+
| `ns.risk(sector=, country=)` | a transparent exposure-concentration score (see note) |
|
|
81
|
+
|
|
82
|
+
Use a `Client` directly to set caching / host:
|
|
83
|
+
|
|
84
|
+
```python
|
|
85
|
+
from ninjasignal import Client
|
|
86
|
+
nl = Client(cache_ttl=600)
|
|
87
|
+
nl.frame(nl.groups()) # a pandas DataFrame if pandas is installed, else a list
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
> **Note on `risk()`** — this is a simple, transparent *descriptive* measure (a sector's share of recent claims, scaled 0–100). It is **not** a probabilistic forecast and **not** the lab's model. For the model's forward calls, use `predictions()`.
|
|
91
|
+
|
|
92
|
+
## Data & provenance
|
|
93
|
+
|
|
94
|
+
All data comes from the public feeds under `https://ninjalabz.io/feeds/`, documented at **<https://ninjalabz.io/feeds/>**. The monthly **Predictive Intel Report** lives at **<https://ninjalabz.io/intel-report/>**.
|
|
95
|
+
|
|
96
|
+
- **Data license:** Creative Commons Attribution 4.0 (CC BY 4.0). Attribute *"Ninja Labz — ninjalabz.io"*.
|
|
97
|
+
- **This client's code:** Apache License 2.0.
|
|
98
|
+
|
|
99
|
+
## Intellectual property
|
|
100
|
+
|
|
101
|
+
This client library **embodies none of Ninja Labz's predictive methods** — it only reads already-published outputs. The models, correlation/inference algorithms, and systems that produce those outputs are **proprietary to Ninja Labz and patent-pending**. Neither the Apache-2.0 code license nor the CC-BY data license grants any right to those methods. See [`NOTICE`](NOTICE).
|
|
102
|
+
|
|
103
|
+
## Contributing & security
|
|
104
|
+
|
|
105
|
+
Issues and PRs welcome for the client itself. Please report security concerns privately via GitHub Security Advisories — see [`SECURITY.md`](SECURITY.md).
|
|
106
|
+
|
|
107
|
+
---
|
|
108
|
+
|
|
109
|
+
*Built by [Ninja Labz](https://ninjalabz.io) — the name in predictive threat intelligence.*
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# ninjasignal
|
|
2
|
+
|
|
3
|
+
**The Python client for [Ninja Labz](https://ninjalabz.io) predictive threat intelligence.**
|
|
4
|
+
|
|
5
|
+
Ninja Labz tracks the ransomware ecosystem on live data and publishes *what it predicts next* — surging groups, new entrants, sectors in the crosshairs, and calibrated forward calls. `ninjasignal` puts that in three lines of Python.
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install ninjasignal
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
```python
|
|
12
|
+
import ninjasignal as ns
|
|
13
|
+
|
|
14
|
+
ns.surging() # groups accelerating right now
|
|
15
|
+
ns.predict("qilin") # what the lab predicts for a group
|
|
16
|
+
ns.groups() # active groups + victim counts, top sector/country, origin
|
|
17
|
+
ns.recent(limit=20) # latest claimed victims (date, group, sector, country)
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Zero runtime dependencies. Talks only to the public feeds over HTTPS. Pandas is an optional convenience, never required.
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## Why
|
|
25
|
+
|
|
26
|
+
Ransomware intel is everywhere; *predictive* ransomware intel, published openly, is not. Ninja Labz runs an AI-native lab that scans dated victim activity, scores the ecosystem, and calls what's next — then publishes it. This library is how you consume it from a notebook, a pipeline, or a terminal.
|
|
27
|
+
|
|
28
|
+
## CLI
|
|
29
|
+
|
|
30
|
+
Installs `ninja` (and `ninjasignal`):
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
ninja surging # groups accelerating now
|
|
34
|
+
ninja predict qilin # the lab's calls for a group
|
|
35
|
+
ninja groups # active groups
|
|
36
|
+
ninja recent --limit 20 --sector Healthcare
|
|
37
|
+
ninja report # latest monthly stats
|
|
38
|
+
ninja risk --sector Healthcare # exposure concentration (descriptive)
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Add `--json` to any command for raw output, `--base URL` to point at a mirror.
|
|
42
|
+
|
|
43
|
+
## API
|
|
44
|
+
|
|
45
|
+
| Call | Returns |
|
|
46
|
+
|------|---------|
|
|
47
|
+
| `ns.groups()` | active ransomware groups: `name, victims, top_sector, top_country, origin, sanctioned` |
|
|
48
|
+
| `ns.group(slug)` | one group's full dossier data (sectors, countries, recent, aliases) |
|
|
49
|
+
| `ns.recent(limit=, group=, sector=, country=)` | recent claimed victims, newest first |
|
|
50
|
+
| `ns.monthly()` | per-month totals + top groups (the trend series) |
|
|
51
|
+
| `ns.predictions(kind=)` | the lab's predictions: `type, subject, statement, confidence, basis` |
|
|
52
|
+
| `ns.surging()` | predictions of type `rising_group` |
|
|
53
|
+
| `ns.predict(group)` | predictions matching a group |
|
|
54
|
+
| `ns.risk(sector=, country=)` | a transparent exposure-concentration score (see note) |
|
|
55
|
+
|
|
56
|
+
Use a `Client` directly to set caching / host:
|
|
57
|
+
|
|
58
|
+
```python
|
|
59
|
+
from ninjasignal import Client
|
|
60
|
+
nl = Client(cache_ttl=600)
|
|
61
|
+
nl.frame(nl.groups()) # a pandas DataFrame if pandas is installed, else a list
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
> **Note on `risk()`** — this is a simple, transparent *descriptive* measure (a sector's share of recent claims, scaled 0–100). It is **not** a probabilistic forecast and **not** the lab's model. For the model's forward calls, use `predictions()`.
|
|
65
|
+
|
|
66
|
+
## Data & provenance
|
|
67
|
+
|
|
68
|
+
All data comes from the public feeds under `https://ninjalabz.io/feeds/`, documented at **<https://ninjalabz.io/feeds/>**. The monthly **Predictive Intel Report** lives at **<https://ninjalabz.io/intel-report/>**.
|
|
69
|
+
|
|
70
|
+
- **Data license:** Creative Commons Attribution 4.0 (CC BY 4.0). Attribute *"Ninja Labz — ninjalabz.io"*.
|
|
71
|
+
- **This client's code:** Apache License 2.0.
|
|
72
|
+
|
|
73
|
+
## Intellectual property
|
|
74
|
+
|
|
75
|
+
This client library **embodies none of Ninja Labz's predictive methods** — it only reads already-published outputs. The models, correlation/inference algorithms, and systems that produce those outputs are **proprietary to Ninja Labz and patent-pending**. Neither the Apache-2.0 code license nor the CC-BY data license grants any right to those methods. See [`NOTICE`](NOTICE).
|
|
76
|
+
|
|
77
|
+
## Contributing & security
|
|
78
|
+
|
|
79
|
+
Issues and PRs welcome for the client itself. Please report security concerns privately via GitHub Security Advisories — see [`SECURITY.md`](SECURITY.md).
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
*Built by [Ninja Labz](https://ninjalabz.io) — the name in predictive threat intelligence.*
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Security Policy
|
|
2
|
+
|
|
3
|
+
## Scope
|
|
4
|
+
|
|
5
|
+
`ninjasignal` is a read-only client for public, open data feeds. It uses no
|
|
6
|
+
credentials, writes nothing, and contacts only its configured host (default
|
|
7
|
+
`https://ninjalabz.io`) over HTTPS. It ships with no runtime dependencies.
|
|
8
|
+
|
|
9
|
+
## Reporting a vulnerability
|
|
10
|
+
|
|
11
|
+
Please report security issues **privately** via GitHub Security Advisories
|
|
12
|
+
("Report a vulnerability" on the repository's **Security** tab) rather than a
|
|
13
|
+
public issue. We aim to acknowledge within a few days.
|
|
14
|
+
|
|
15
|
+
Helpful to include: the version, a minimal reproduction, and the impact you see.
|
|
16
|
+
|
|
17
|
+
## Out of scope
|
|
18
|
+
|
|
19
|
+
- The Ninja Labz backend, feeds infrastructure, or data content (report those
|
|
20
|
+
through the Ninja Labz site, not this repo).
|
|
21
|
+
- The proprietary predictive methods behind the feeds — not part of this package.
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"""Quickstart — live against the public Ninja Labz feeds.
|
|
2
|
+
|
|
3
|
+
python examples/quickstart.py
|
|
4
|
+
"""
|
|
5
|
+
import ninjasignal as ns
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def main():
|
|
9
|
+
print("== Surging now ==")
|
|
10
|
+
for p in ns.surging()[:5]:
|
|
11
|
+
print(f" {p['subject']:<16} conf {p['confidence']:<4} {p['statement'][:80]}")
|
|
12
|
+
|
|
13
|
+
print("\n== Most-tracked groups ==")
|
|
14
|
+
for g in sorted(ns.groups(), key=lambda g: g.get("victims", 0), reverse=True)[:5]:
|
|
15
|
+
flag = " [SANCTIONED]" if g.get("sanctioned") else ""
|
|
16
|
+
print(f" {g['name']:<16} {g.get('victims', 0):>5} victims top: {g.get('top_sector')}{flag}")
|
|
17
|
+
|
|
18
|
+
print("\n== Latest recent victims ==")
|
|
19
|
+
for v in ns.recent(limit=5):
|
|
20
|
+
print(f" {v['date']} {v['group']:<14} {v.get('sector', '?'):<16} {v.get('country', '?')}")
|
|
21
|
+
|
|
22
|
+
print("\n== Healthcare exposure (descriptive) ==")
|
|
23
|
+
print(" ", ns.risk(sector="Healthcare"))
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
if __name__ == "__main__":
|
|
27
|
+
main()
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"""ninjasignal — the Python client for Ninja Labz predictive threat intelligence.
|
|
2
|
+
|
|
3
|
+
Ninja Labz tracks the ransomware ecosystem on live data and publishes what it
|
|
4
|
+
predicts next. This library is a thin, dependency-free reader over the public
|
|
5
|
+
feeds — it talks only to https://ninjalabz.io and reads open CC-BY data.
|
|
6
|
+
|
|
7
|
+
import ninjasignal as ns
|
|
8
|
+
ns.surging() # groups accelerating right now
|
|
9
|
+
ns.predict("qilin") # what the lab predicts for a group
|
|
10
|
+
ns.groups() # active groups + victim counts
|
|
11
|
+
ns.recent(limit=20) # latest claimed victims
|
|
12
|
+
|
|
13
|
+
IP boundary: this client embodies NONE of Ninja Labz's predictive methods. It
|
|
14
|
+
only consumes already-published outputs. The models and systems behind those
|
|
15
|
+
outputs are proprietary and patent-pending, and nothing here licenses them.
|
|
16
|
+
"""
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
19
|
+
from .client import Client, NinjaSignalError, DEFAULT_BASE
|
|
20
|
+
|
|
21
|
+
__all__ = ["Client", "NinjaSignalError", "DEFAULT_BASE", "__version__",
|
|
22
|
+
"groups", "group", "recent", "monthly", "predictions", "surging",
|
|
23
|
+
"predict", "risk", "latest_month"]
|
|
24
|
+
|
|
25
|
+
__version__ = "0.1.0"
|
|
26
|
+
|
|
27
|
+
_default: Client | None = None
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _client() -> Client:
|
|
31
|
+
global _default
|
|
32
|
+
if _default is None:
|
|
33
|
+
_default = Client()
|
|
34
|
+
return _default
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
# Module-level convenience wrappers over a shared default Client.
|
|
38
|
+
def groups():
|
|
39
|
+
return _client().groups()
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def group(slug: str):
|
|
43
|
+
return _client().group(slug)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def recent(limit: int | None = None, group: str | None = None,
|
|
47
|
+
sector: str | None = None, country: str | None = None):
|
|
48
|
+
return _client().recent(limit=limit, group=group, sector=sector, country=country)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def monthly():
|
|
52
|
+
return _client().monthly()
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def predictions(kind: str | None = None):
|
|
56
|
+
return _client().predictions(kind=kind)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def surging():
|
|
60
|
+
return _client().surging()
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def predict(group: str):
|
|
64
|
+
return _client().predict(group)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def risk(sector: str | None = None, country: str | None = None):
|
|
68
|
+
return _client().risk(sector=sector, country=country)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def latest_month():
|
|
72
|
+
return _client().latest_month()
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"""Command-line interface: `ninja` / `ninjasignal`.
|
|
2
|
+
|
|
3
|
+
ninja surging
|
|
4
|
+
ninja predict qilin
|
|
5
|
+
ninja groups
|
|
6
|
+
ninja recent --limit 20 --sector Healthcare
|
|
7
|
+
ninja report
|
|
8
|
+
ninja risk --sector Healthcare
|
|
9
|
+
|
|
10
|
+
Every command takes --json for raw output and --base to point at a mirror.
|
|
11
|
+
"""
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
import argparse
|
|
15
|
+
import json
|
|
16
|
+
import sys
|
|
17
|
+
|
|
18
|
+
from . import __version__
|
|
19
|
+
from .client import Client, NinjaSignalError
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def _table(rows: list[dict], cols: list[str]) -> str:
|
|
23
|
+
if not rows:
|
|
24
|
+
return "(no results)"
|
|
25
|
+
cols = [c for c in cols if any(c in r for r in rows)]
|
|
26
|
+
widths = {c: max(len(c), *(len(str(r.get(c, ""))) for r in rows)) for c in cols}
|
|
27
|
+
line = " ".join(c.upper().ljust(widths[c]) for c in cols)
|
|
28
|
+
out = [line, " ".join("-" * widths[c] for c in cols)]
|
|
29
|
+
for r in rows:
|
|
30
|
+
out.append(" ".join(str(r.get(c, "")).ljust(widths[c]) for c in cols))
|
|
31
|
+
return "\n".join(out)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def _emit(data, as_json: bool, cols: list[str] | None = None):
|
|
35
|
+
if as_json:
|
|
36
|
+
print(json.dumps(data, indent=2, ensure_ascii=False))
|
|
37
|
+
elif isinstance(data, list) and cols:
|
|
38
|
+
print(_table(data, cols))
|
|
39
|
+
else:
|
|
40
|
+
print(json.dumps(data, indent=2, ensure_ascii=False))
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def main(argv: list[str] | None = None) -> int:
|
|
44
|
+
p = argparse.ArgumentParser(
|
|
45
|
+
prog="ninja", description="Ninja Labz predictive threat-intel client.")
|
|
46
|
+
p.add_argument("--version", action="version", version=f"ninjasignal {__version__}")
|
|
47
|
+
p.add_argument("--base", help="feed host (default https://ninjalabz.io)")
|
|
48
|
+
p.add_argument("--json", action="store_true", help="raw JSON output")
|
|
49
|
+
sub = p.add_subparsers(dest="cmd", required=True)
|
|
50
|
+
|
|
51
|
+
sub.add_parser("groups", help="active ransomware groups")
|
|
52
|
+
sub.add_parser("surging", help="groups accelerating right now")
|
|
53
|
+
sub.add_parser("report", help="latest monthly stats")
|
|
54
|
+
sp = sub.add_parser("predict", help="predictions for a group")
|
|
55
|
+
sp.add_argument("group")
|
|
56
|
+
sr = sub.add_parser("recent", help="recent claimed victims")
|
|
57
|
+
sr.add_argument("--limit", type=int, default=25)
|
|
58
|
+
sr.add_argument("--group"); sr.add_argument("--sector"); sr.add_argument("--country")
|
|
59
|
+
sk = sub.add_parser("risk", help="exposure concentration (descriptive, not a forecast)")
|
|
60
|
+
sk.add_argument("--sector"); sk.add_argument("--country")
|
|
61
|
+
|
|
62
|
+
a = p.parse_args(argv)
|
|
63
|
+
nl = Client(base=a.base) if a.base else Client()
|
|
64
|
+
try:
|
|
65
|
+
if a.cmd == "groups":
|
|
66
|
+
_emit(nl.groups(), a.json, ["name", "victims", "top_sector", "top_country", "origin", "sanctioned"])
|
|
67
|
+
elif a.cmd == "surging":
|
|
68
|
+
_emit(nl.surging(), a.json, ["subject", "confidence", "statement"])
|
|
69
|
+
elif a.cmd == "report":
|
|
70
|
+
_emit(nl.latest_month(), a.json)
|
|
71
|
+
elif a.cmd == "predict":
|
|
72
|
+
preds = nl.predict(a.group)
|
|
73
|
+
_emit(preds or [{"note": f"no current prediction for {a.group!r}"}], a.json,
|
|
74
|
+
["type", "subject", "confidence", "statement"])
|
|
75
|
+
elif a.cmd == "recent":
|
|
76
|
+
_emit(nl.recent(limit=a.limit, group=a.group, sector=a.sector, country=a.country),
|
|
77
|
+
a.json, ["date", "group", "victim", "sector", "country"])
|
|
78
|
+
elif a.cmd == "risk":
|
|
79
|
+
_emit(nl.risk(sector=a.sector, country=a.country), a.json,
|
|
80
|
+
None if (a.sector or a.country) else None)
|
|
81
|
+
except NinjaSignalError as e:
|
|
82
|
+
print(f"error: {e}", file=sys.stderr)
|
|
83
|
+
return 2
|
|
84
|
+
return 0
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
if __name__ == "__main__":
|
|
88
|
+
raise SystemExit(main())
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
"""The Ninja Signal client — a thin, dependency-free reader over the public
|
|
2
|
+
Ninja Labz predictive threat-intelligence feeds.
|
|
3
|
+
|
|
4
|
+
Everything here talks to ONE public host (https://ninjalabz.io) over HTTPS and
|
|
5
|
+
reads only the open, CC-BY data feeds under /feeds/ransomware/. There are no
|
|
6
|
+
credentials, no private endpoints, and nothing internal — point it somewhere else
|
|
7
|
+
with `Client(base=...)` if you mirror the feeds yourself.
|
|
8
|
+
"""
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import json
|
|
12
|
+
import time
|
|
13
|
+
import urllib.error
|
|
14
|
+
import urllib.request
|
|
15
|
+
|
|
16
|
+
__all__ = ["Client", "NinjaSignalError"]
|
|
17
|
+
|
|
18
|
+
DEFAULT_BASE = "https://ninjalabz.io"
|
|
19
|
+
_FEED = "/feeds/ransomware"
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class NinjaSignalError(RuntimeError):
|
|
23
|
+
"""Raised when a feed can't be fetched or isn't valid JSON."""
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class Client:
|
|
27
|
+
"""Reader for the Ninja Labz predictive-intel feeds.
|
|
28
|
+
|
|
29
|
+
>>> from ninjasignal import Client
|
|
30
|
+
>>> nl = Client()
|
|
31
|
+
>>> [g["name"] for g in nl.groups()][:3]
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
def __init__(self, base: str = DEFAULT_BASE, timeout: float = 15.0,
|
|
35
|
+
cache_ttl: float = 300.0, user_agent: str | None = None):
|
|
36
|
+
self.base = base.rstrip("/")
|
|
37
|
+
self.timeout = timeout
|
|
38
|
+
self.cache_ttl = cache_ttl
|
|
39
|
+
self.user_agent = user_agent or "ninjasignal-python"
|
|
40
|
+
self._cache: dict[str, tuple[float, dict]] = {}
|
|
41
|
+
|
|
42
|
+
# ── transport ────────────────────────────────────────────────────────────
|
|
43
|
+
def _get(self, path: str) -> dict:
|
|
44
|
+
now = time.time()
|
|
45
|
+
hit = self._cache.get(path)
|
|
46
|
+
if hit and (now - hit[0]) < self.cache_ttl:
|
|
47
|
+
return hit[1]
|
|
48
|
+
url = self.base + path
|
|
49
|
+
req = urllib.request.Request(url, headers={"User-Agent": self.user_agent,
|
|
50
|
+
"Accept": "application/json"})
|
|
51
|
+
try:
|
|
52
|
+
with urllib.request.urlopen(req, timeout=self.timeout) as r:
|
|
53
|
+
raw = r.read().decode("utf-8", "replace")
|
|
54
|
+
except urllib.error.HTTPError as e:
|
|
55
|
+
raise NinjaSignalError(f"{url} returned HTTP {e.code}") from e
|
|
56
|
+
except urllib.error.URLError as e:
|
|
57
|
+
raise NinjaSignalError(f"could not reach {url}: {e.reason}") from e
|
|
58
|
+
stripped = raw.lstrip()
|
|
59
|
+
if not stripped or stripped[0] not in "{[":
|
|
60
|
+
# a feed is always JSON; anything else (an error page, a stale CDN
|
|
61
|
+
# entry) is rejected rather than parsed into nonsense.
|
|
62
|
+
raise NinjaSignalError(f"{url} did not return JSON (got {stripped[:40]!r}…)")
|
|
63
|
+
try:
|
|
64
|
+
data = json.loads(raw)
|
|
65
|
+
except json.JSONDecodeError as e:
|
|
66
|
+
raise NinjaSignalError(f"{url} returned invalid JSON: {e}") from e
|
|
67
|
+
self._cache[path] = (now, data)
|
|
68
|
+
return data
|
|
69
|
+
|
|
70
|
+
def _feed(self, name: str) -> dict:
|
|
71
|
+
return self._get(f"{_FEED}/{name}.js")
|
|
72
|
+
|
|
73
|
+
# ── data feeds ───────────────────────────────────────────────────────────
|
|
74
|
+
def groups(self) -> list[dict]:
|
|
75
|
+
"""Active ransomware groups: victim counts, top sector/country, origin."""
|
|
76
|
+
return self._feed("groups").get("groups", [])
|
|
77
|
+
|
|
78
|
+
def group(self, slug: str) -> dict:
|
|
79
|
+
"""Full dossier data for one group (victims, sectors, countries, recent)."""
|
|
80
|
+
slug = slug.strip().lower().replace(" ", "")
|
|
81
|
+
return self._feed(f"group-{slug}")
|
|
82
|
+
|
|
83
|
+
def recent(self, limit: int | None = None, group: str | None = None,
|
|
84
|
+
sector: str | None = None, country: str | None = None) -> list[dict]:
|
|
85
|
+
"""Recent claimed victims (date, group, victim, sector, country), newest first,
|
|
86
|
+
optionally filtered."""
|
|
87
|
+
vics = self._feed("victims-recent").get("victims", [])
|
|
88
|
+
|
|
89
|
+
def keep(v: dict) -> bool:
|
|
90
|
+
if group and (v.get("group") or "").lower() != group.lower():
|
|
91
|
+
return False
|
|
92
|
+
if sector and (v.get("sector") or "").lower() != sector.lower():
|
|
93
|
+
return False
|
|
94
|
+
if country and (v.get("country") or "").lower() != country.lower():
|
|
95
|
+
return False
|
|
96
|
+
return True
|
|
97
|
+
|
|
98
|
+
out = [v for v in vics if keep(v)]
|
|
99
|
+
return out[:limit] if limit else out
|
|
100
|
+
|
|
101
|
+
def monthly(self) -> list[dict]:
|
|
102
|
+
"""Per-month totals + top groups (the time series behind the trends)."""
|
|
103
|
+
return self._feed("stats-monthly").get("months", [])
|
|
104
|
+
|
|
105
|
+
# ── predictions (the differentiator) ─────────────────────────────────────
|
|
106
|
+
def predictions(self, kind: str | None = None) -> list[dict]:
|
|
107
|
+
"""The lab's live predictions: {type, subject, statement, confidence, basis}.
|
|
108
|
+
`kind` filters by type (rising_group | likely_target | momentum | watch)."""
|
|
109
|
+
preds = self._feed("predictions").get("predictions", [])
|
|
110
|
+
return [p for p in preds if (not kind or p.get("type") == kind)]
|
|
111
|
+
|
|
112
|
+
def surging(self) -> list[dict]:
|
|
113
|
+
"""Groups the lab flags as accelerating right now (type=rising_group)."""
|
|
114
|
+
return self.predictions(kind="rising_group")
|
|
115
|
+
|
|
116
|
+
def predict(self, group: str) -> list[dict]:
|
|
117
|
+
"""Predictions whose subject matches a group (case-insensitive)."""
|
|
118
|
+
g = group.strip().lower()
|
|
119
|
+
return [p for p in self.predictions() if g in (p.get("subject") or "").lower()]
|
|
120
|
+
|
|
121
|
+
# ── a small derived signal: exposure/risk ────────────────────────────────
|
|
122
|
+
def risk(self, sector: str | None = None, country: str | None = None) -> dict:
|
|
123
|
+
"""A simple, transparent exposure score from the recent-victim mix.
|
|
124
|
+
|
|
125
|
+
Score = this sector's (or country's) share of recent claims, scaled to the
|
|
126
|
+
busiest sector/country = 100. It's a descriptive concentration measure, not a
|
|
127
|
+
probabilistic forecast — see `predictions()` for the model's forward calls.
|
|
128
|
+
"""
|
|
129
|
+
vics = self.recent()
|
|
130
|
+
if not vics:
|
|
131
|
+
return {"score": 0, "basis": "no recent data"}
|
|
132
|
+
field = "sector" if sector else "country" if country else "sector"
|
|
133
|
+
target = (sector or country or "").lower()
|
|
134
|
+
counts: dict[str, int] = {}
|
|
135
|
+
for v in vics:
|
|
136
|
+
key = (v.get(field) or "unknown")
|
|
137
|
+
counts[key] = counts.get(key, 0) + 1
|
|
138
|
+
ranked = sorted(counts.items(), key=lambda kv: kv[1], reverse=True)
|
|
139
|
+
top = ranked[0][1] if ranked else 1
|
|
140
|
+
if not target:
|
|
141
|
+
return {"field": field, "ranking": [{field: k, "recent_claims": n,
|
|
142
|
+
"score": round(100 * n / top)} for k, n in ranked[:15]],
|
|
143
|
+
"window_claims": len(vics)}
|
|
144
|
+
n = next((c for k, c in counts.items() if k.lower() == target), 0)
|
|
145
|
+
rank = next((i + 1 for i, (k, _) in enumerate(ranked) if k.lower() == target), None)
|
|
146
|
+
return {field: sector or country, "recent_claims": n,
|
|
147
|
+
"score": round(100 * n / top), "rank": rank,
|
|
148
|
+
"of": len(ranked), "window_claims": len(vics)}
|
|
149
|
+
|
|
150
|
+
# ── convenience ──────────────────────────────────────────────────────────
|
|
151
|
+
def latest_month(self) -> dict:
|
|
152
|
+
months = self.monthly()
|
|
153
|
+
return months[0] if months else {}
|
|
154
|
+
|
|
155
|
+
def frame(self, rows: list[dict]):
|
|
156
|
+
"""Return rows as a pandas DataFrame if pandas is installed, else the list.
|
|
157
|
+
Keeps pandas an optional convenience, never a hard dependency."""
|
|
158
|
+
try:
|
|
159
|
+
import pandas as pd # noqa: PLC0415
|
|
160
|
+
except ImportError:
|
|
161
|
+
return rows
|
|
162
|
+
return pd.DataFrame(rows)
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "ninjasignal"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Python client for Ninja Labz predictive threat intelligence — live ransomware groups, victims, and what the lab predicts next."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
license = { text = "Apache-2.0" }
|
|
12
|
+
authors = [{ name = "Scott Gardner", email = "the_v01d@ninja.ing" }]
|
|
13
|
+
keywords = ["threat-intelligence", "ransomware", "predictive-intelligence", "cti",
|
|
14
|
+
"security", "osint", "ninja-labz", "ninjasignal"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 4 - Beta",
|
|
17
|
+
"Intended Audience :: Information Technology",
|
|
18
|
+
"Topic :: Security",
|
|
19
|
+
"License :: OSI Approved :: Apache Software License",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Operating System :: OS Independent",
|
|
22
|
+
]
|
|
23
|
+
dependencies = [] # stdlib only — no runtime dependencies
|
|
24
|
+
|
|
25
|
+
[project.optional-dependencies]
|
|
26
|
+
pandas = ["pandas>=1.3"]
|
|
27
|
+
dev = ["pytest>=7"]
|
|
28
|
+
|
|
29
|
+
[project.urls]
|
|
30
|
+
Homepage = "https://ninjalabz.io"
|
|
31
|
+
"Predictive Intel Report" = "https://ninjalabz.io/intel-report/"
|
|
32
|
+
"Data Feeds" = "https://ninjalabz.io/feeds/"
|
|
33
|
+
Source = "https://github.com/scottgardner777/ninjasignal"
|
|
34
|
+
|
|
35
|
+
[project.scripts]
|
|
36
|
+
ninja = "ninjasignal.cli:main"
|
|
37
|
+
ninjasignal = "ninjasignal.cli:main"
|
|
38
|
+
|
|
39
|
+
[tool.hatch.build.targets.wheel]
|
|
40
|
+
packages = ["ninjasignal"]
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"""Offline tests: feed access is monkeypatched so the suite never hits the network."""
|
|
2
|
+
import pytest
|
|
3
|
+
|
|
4
|
+
from ninjasignal import Client, NinjaSignalError
|
|
5
|
+
|
|
6
|
+
FEEDS = {
|
|
7
|
+
"/feeds/ransomware/groups.js": {"groups": [
|
|
8
|
+
{"slug": "lockbit", "name": "LockBit", "victims": 3315, "top_sector": "Manufacturing",
|
|
9
|
+
"top_country": "US", "origin": "Russia", "sanctioned": True, "apt": False},
|
|
10
|
+
{"slug": "qilin", "name": "Qilin", "victims": 700, "top_sector": "Healthcare",
|
|
11
|
+
"top_country": "US", "origin": "Russia", "sanctioned": False, "apt": False}]},
|
|
12
|
+
"/feeds/ransomware/victims-recent.js": {"victims": [
|
|
13
|
+
{"date": "2026-10-07", "group": "Qilin", "victim": "Acme Health", "sector": "Healthcare", "country": "US"},
|
|
14
|
+
{"date": "2026-10-06", "group": "LockBit", "victim": "Widgets Inc", "sector": "Manufacturing", "country": "DE"},
|
|
15
|
+
{"date": "2026-10-06", "group": "Qilin", "victim": "Clinic Co", "sector": "Healthcare", "country": "GB"}]},
|
|
16
|
+
"/feeds/ransomware/stats-monthly.js": {"months": [
|
|
17
|
+
{"month": "2026-10", "total": 173, "top_groups": [{"name": "Qilin", "victims": 19}]}]},
|
|
18
|
+
"/feeds/ransomware/predictions.js": {"month": "2026-10", "predictions": [
|
|
19
|
+
{"type": "rising_group", "subject": "Qilin", "statement": "expanding in healthcare",
|
|
20
|
+
"confidence": 0.9, "basis": "surge 3x"},
|
|
21
|
+
{"type": "watch", "subject": "LockBit", "statement": "sanctioned, steady", "confidence": 0.7, "basis": ""}]},
|
|
22
|
+
"/feeds/ransomware/group-qilin.js": {"slug": "qilin", "name": "Qilin", "victims": 700,
|
|
23
|
+
"sectors": [["Healthcare", 120]], "recent": []},
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
@pytest.fixture
|
|
28
|
+
def nl(monkeypatch):
|
|
29
|
+
c = Client(cache_ttl=0)
|
|
30
|
+
monkeypatch.setattr(c, "_get", lambda path: FEEDS[path])
|
|
31
|
+
return c
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def test_groups(nl):
|
|
35
|
+
g = nl.groups()
|
|
36
|
+
assert len(g) == 2 and g[0]["name"] == "LockBit"
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def test_recent_filters(nl):
|
|
40
|
+
assert len(nl.recent(sector="Healthcare")) == 2
|
|
41
|
+
assert len(nl.recent(group="LockBit")) == 1
|
|
42
|
+
assert len(nl.recent(limit=1)) == 1
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def test_predictions_and_surging(nl):
|
|
46
|
+
assert len(nl.predictions()) == 2
|
|
47
|
+
s = nl.surging()
|
|
48
|
+
assert len(s) == 1 and s[0]["subject"] == "Qilin"
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def test_predict(nl):
|
|
52
|
+
assert nl.predict("qilin")[0]["type"] == "rising_group"
|
|
53
|
+
assert nl.predict("nonexistent") == []
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def test_risk(nl):
|
|
57
|
+
r = nl.risk(sector="Healthcare")
|
|
58
|
+
assert r["recent_claims"] == 2 and r["score"] == 100 and r["rank"] == 1
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def test_group(nl):
|
|
62
|
+
assert nl.group("Qilin")["name"] == "Qilin"
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def test_non_json_rejected():
|
|
66
|
+
"""A stale CDN entry / error page must never be parsed as data."""
|
|
67
|
+
c = Client()
|
|
68
|
+
|
|
69
|
+
class FakeResp:
|
|
70
|
+
def read(self): return b"<!doctype html><html>nope</html>"
|
|
71
|
+
def __enter__(self): return self
|
|
72
|
+
def __exit__(self, *a): return False
|
|
73
|
+
|
|
74
|
+
import urllib.request
|
|
75
|
+
import pytest as _p
|
|
76
|
+
orig = urllib.request.urlopen
|
|
77
|
+
urllib.request.urlopen = lambda *a, **k: FakeResp()
|
|
78
|
+
try:
|
|
79
|
+
with _p.raises(NinjaSignalError):
|
|
80
|
+
c._get("/feeds/ransomware/groups.js")
|
|
81
|
+
finally:
|
|
82
|
+
urllib.request.urlopen = orig
|