defendking 1.0.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.
- defendking-1.0.0/PKG-INFO +97 -0
- defendking-1.0.0/README.md +75 -0
- defendking-1.0.0/defendking/__init__.py +135 -0
- defendking-1.0.0/defendking/handler.py +1249 -0
- defendking-1.0.0/defendking.egg-info/PKG-INFO +97 -0
- defendking-1.0.0/defendking.egg-info/SOURCES.txt +10 -0
- defendking-1.0.0/defendking.egg-info/dependency_links.txt +1 -0
- defendking-1.0.0/defendking.egg-info/requires.txt +8 -0
- defendking-1.0.0/defendking.egg-info/top_level.txt +1 -0
- defendking-1.0.0/pyproject.toml +40 -0
- defendking-1.0.0/setup.cfg +4 -0
- defendking-1.0.0/test/test_defendking.py +380 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: defendking
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: A defensive-only Python security toolkit: passwords, phishing/URL checks, brute-force protection, file hygiene, web-app security, network checks, crypto helpers, and monitoring/reporting.
|
|
5
|
+
Author: Barman
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Repository, https://github.com/Barman-Zarei/defendking.git
|
|
8
|
+
Keywords: security,defensive-security,password,phishing,xss,sql-injection,hardening
|
|
9
|
+
Classifier: Development Status :: 4 - Beta
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Topic :: Security
|
|
14
|
+
Requires-Python: >=3.9
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
Provides-Extra: full
|
|
17
|
+
Requires-Dist: requests>=2.31; extra == "full"
|
|
18
|
+
Requires-Dist: cryptography>=42.0; extra == "full"
|
|
19
|
+
Requires-Dist: pyjwt>=2.8; extra == "full"
|
|
20
|
+
Provides-Extra: dev
|
|
21
|
+
Requires-Dist: pytest>=8.0; extra == "dev"
|
|
22
|
+
|
|
23
|
+
# DefendKing
|
|
24
|
+
|
|
25
|
+
A defensive-only Python security toolkit (~60 functions) covering:
|
|
26
|
+
|
|
27
|
+
1. Passwords & authentication
|
|
28
|
+
2. Phishing & URL/email safety
|
|
29
|
+
3. Brute-force / abuse protection
|
|
30
|
+
4. File / malware hygiene
|
|
31
|
+
5. Web application security (XSS, CSRF, SQLi heuristics, headers)
|
|
32
|
+
6. Network-level defense (TLS, firewall rules, ARP/DNS checks)
|
|
33
|
+
7. Cryptography & secrets management
|
|
34
|
+
8. Monitoring, risk scoring & reporting
|
|
35
|
+
|
|
36
|
+
Every function protects, detects, or reports — none of them attack, exploit,
|
|
37
|
+
or access systems you don't own/manage.
|
|
38
|
+
|
|
39
|
+
**Author:** Barman
|
|
40
|
+
**License:** MIT
|
|
41
|
+
|
|
42
|
+
## Structure
|
|
43
|
+
|
|
44
|
+
```
|
|
45
|
+
defendking/
|
|
46
|
+
├── pyproject.toml
|
|
47
|
+
├── README.md
|
|
48
|
+
├── tests/
|
|
49
|
+
│ └── test_defendking.py
|
|
50
|
+
└── defendking/ ← the actual package
|
|
51
|
+
├── __init__.py ← re-exports everything from handler.py
|
|
52
|
+
└── handler.py ← all ~60 functions live here
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Install
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
pip install -e . # core package, no third-party deps required
|
|
59
|
+
pip install -e ".[full]" # adds requests / cryptography / pyjwt for the
|
|
60
|
+
# functions that call external APIs or do AES/JWT
|
|
61
|
+
pip install -e ".[dev]" # adds pytest for running the test suite
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
```python
|
|
65
|
+
import defendking
|
|
66
|
+
defendking.check_password_strength("...")
|
|
67
|
+
|
|
68
|
+
# or
|
|
69
|
+
from defendking import check_password_strength
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Run the tests
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
python -m pytest tests/ -v
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Known limitations
|
|
79
|
+
|
|
80
|
+
- **Heuristic detection isn't a real classifier.** `detect_xss_patterns`,
|
|
81
|
+
`validate_input_against_sql_injection`, and `check_suspicious_url` are
|
|
82
|
+
regex-based signals, not a guarantee of safety. Always pair them with the
|
|
83
|
+
real defenses: parameterized queries/ORM for SQL, contextual output
|
|
84
|
+
encoding + a strict CSP for XSS, and a reputation/block-list service for
|
|
85
|
+
URLs.
|
|
86
|
+
- **The local common-password list is a small sample**, not a real breach
|
|
87
|
+
corpus. `check_password_breached` queries the Have I Been Pwned API by
|
|
88
|
+
default — the local list is only an offline fallback.
|
|
89
|
+
- **`detect_anomalous_login_location`** gives an accurate result only when
|
|
90
|
+
you pass real `previous_coords` / `new_coords` (it then uses haversine
|
|
91
|
+
distance via `distance_km_between`). Without coordinates it falls back to
|
|
92
|
+
a conservative fixed-distance estimate, which is a rough approximation.
|
|
93
|
+
|
|
94
|
+
## Versioning
|
|
95
|
+
|
|
96
|
+
Following semantic-ish convention: first digit = structural changes, second
|
|
97
|
+
= new features, third = bug fixes.
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# DefendKing
|
|
2
|
+
|
|
3
|
+
A defensive-only Python security toolkit (~60 functions) covering:
|
|
4
|
+
|
|
5
|
+
1. Passwords & authentication
|
|
6
|
+
2. Phishing & URL/email safety
|
|
7
|
+
3. Brute-force / abuse protection
|
|
8
|
+
4. File / malware hygiene
|
|
9
|
+
5. Web application security (XSS, CSRF, SQLi heuristics, headers)
|
|
10
|
+
6. Network-level defense (TLS, firewall rules, ARP/DNS checks)
|
|
11
|
+
7. Cryptography & secrets management
|
|
12
|
+
8. Monitoring, risk scoring & reporting
|
|
13
|
+
|
|
14
|
+
Every function protects, detects, or reports — none of them attack, exploit,
|
|
15
|
+
or access systems you don't own/manage.
|
|
16
|
+
|
|
17
|
+
**Author:** Barman
|
|
18
|
+
**License:** MIT
|
|
19
|
+
|
|
20
|
+
## Structure
|
|
21
|
+
|
|
22
|
+
```
|
|
23
|
+
defendking/
|
|
24
|
+
├── pyproject.toml
|
|
25
|
+
├── README.md
|
|
26
|
+
├── tests/
|
|
27
|
+
│ └── test_defendking.py
|
|
28
|
+
└── defendking/ ← the actual package
|
|
29
|
+
├── __init__.py ← re-exports everything from handler.py
|
|
30
|
+
└── handler.py ← all ~60 functions live here
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Install
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
pip install -e . # core package, no third-party deps required
|
|
37
|
+
pip install -e ".[full]" # adds requests / cryptography / pyjwt for the
|
|
38
|
+
# functions that call external APIs or do AES/JWT
|
|
39
|
+
pip install -e ".[dev]" # adds pytest for running the test suite
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
```python
|
|
43
|
+
import defendking
|
|
44
|
+
defendking.check_password_strength("...")
|
|
45
|
+
|
|
46
|
+
# or
|
|
47
|
+
from defendking import check_password_strength
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Run the tests
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
python -m pytest tests/ -v
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Known limitations
|
|
57
|
+
|
|
58
|
+
- **Heuristic detection isn't a real classifier.** `detect_xss_patterns`,
|
|
59
|
+
`validate_input_against_sql_injection`, and `check_suspicious_url` are
|
|
60
|
+
regex-based signals, not a guarantee of safety. Always pair them with the
|
|
61
|
+
real defenses: parameterized queries/ORM for SQL, contextual output
|
|
62
|
+
encoding + a strict CSP for XSS, and a reputation/block-list service for
|
|
63
|
+
URLs.
|
|
64
|
+
- **The local common-password list is a small sample**, not a real breach
|
|
65
|
+
corpus. `check_password_breached` queries the Have I Been Pwned API by
|
|
66
|
+
default — the local list is only an offline fallback.
|
|
67
|
+
- **`detect_anomalous_login_location`** gives an accurate result only when
|
|
68
|
+
you pass real `previous_coords` / `new_coords` (it then uses haversine
|
|
69
|
+
distance via `distance_km_between`). Without coordinates it falls back to
|
|
70
|
+
a conservative fixed-distance estimate, which is a rough approximation.
|
|
71
|
+
|
|
72
|
+
## Versioning
|
|
73
|
+
|
|
74
|
+
Following semantic-ish convention: first digit = structural changes, second
|
|
75
|
+
= new features, third = bug fixes.
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"""
|
|
2
|
+
DefendKing - Defensive Security Toolkit
|
|
3
|
+
=========================================
|
|
4
|
+
|
|
5
|
+
This package keeps all logic in a single module (`handler.py`) for
|
|
6
|
+
simplicity, and re-exports everything here so consumers can just do:
|
|
7
|
+
|
|
8
|
+
import defendking
|
|
9
|
+
defendking.check_password_strength("...")
|
|
10
|
+
|
|
11
|
+
or:
|
|
12
|
+
|
|
13
|
+
from defendking import check_password_strength
|
|
14
|
+
|
|
15
|
+
Author: Barman
|
|
16
|
+
License: MIT
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
from .handler import (
|
|
20
|
+
# Section 1 - Passwords & authentication
|
|
21
|
+
check_password_strength,
|
|
22
|
+
check_password_breached,
|
|
23
|
+
generate_strong_password,
|
|
24
|
+
hash_password,
|
|
25
|
+
verify_password,
|
|
26
|
+
detect_common_password_patterns,
|
|
27
|
+
check_two_factor_status,
|
|
28
|
+
check_password_expiry,
|
|
29
|
+
validate_password_policy_compliance,
|
|
30
|
+
check_default_credentials,
|
|
31
|
+
|
|
32
|
+
# Section 2 - Phishing & URL / email safety
|
|
33
|
+
check_suspicious_url,
|
|
34
|
+
check_domain_similarity,
|
|
35
|
+
check_ssl_certificate,
|
|
36
|
+
scan_email_for_phishing_signs,
|
|
37
|
+
extract_and_check_links,
|
|
38
|
+
validate_email_format_and_mx,
|
|
39
|
+
|
|
40
|
+
# Section 3 - Brute-force / abuse protection
|
|
41
|
+
RateLimiter,
|
|
42
|
+
rate_limiter,
|
|
43
|
+
detect_brute_force_attempt,
|
|
44
|
+
IPBlocklist,
|
|
45
|
+
block_ip_temporarily,
|
|
46
|
+
implement_captcha_trigger,
|
|
47
|
+
log_failed_login_attempt,
|
|
48
|
+
distance_km_between,
|
|
49
|
+
detect_anomalous_login_location,
|
|
50
|
+
detect_privilege_escalation_attempt,
|
|
51
|
+
|
|
52
|
+
# Section 4 - File / malware hygiene
|
|
53
|
+
compute_file_hash,
|
|
54
|
+
scan_file_hash_virustotal,
|
|
55
|
+
detect_suspicious_file_extension,
|
|
56
|
+
check_file_integrity,
|
|
57
|
+
scan_directory_for_malware_signatures,
|
|
58
|
+
quarantine_suspicious_file,
|
|
59
|
+
verify_backup_integrity,
|
|
60
|
+
|
|
61
|
+
# Section 5 - Web application security
|
|
62
|
+
sanitize_user_input,
|
|
63
|
+
generate_csrf_token,
|
|
64
|
+
check_csrf_token_validity,
|
|
65
|
+
validate_cors_policy,
|
|
66
|
+
detect_xss_patterns,
|
|
67
|
+
check_secure_cookie_flags,
|
|
68
|
+
validate_input_against_sql_injection,
|
|
69
|
+
check_security_headers,
|
|
70
|
+
verify_csp_header,
|
|
71
|
+
|
|
72
|
+
# Section 6 - Network-level defense
|
|
73
|
+
check_tls_version_support,
|
|
74
|
+
check_firewall_rules_status,
|
|
75
|
+
detect_arp_spoofing,
|
|
76
|
+
validate_dns_response,
|
|
77
|
+
check_vpn_connection_security,
|
|
78
|
+
audit_server_config,
|
|
79
|
+
|
|
80
|
+
# Section 7 - Cryptography & secrets management
|
|
81
|
+
generate_secure_token,
|
|
82
|
+
ApiKeyRecord,
|
|
83
|
+
rotate_api_key,
|
|
84
|
+
mask_sensitive_data_in_logs,
|
|
85
|
+
encrypt_sensitive_data,
|
|
86
|
+
decrypt_sensitive_data,
|
|
87
|
+
validate_jwt_token,
|
|
88
|
+
check_secrets_in_codebase,
|
|
89
|
+
|
|
90
|
+
# Section 8 - Monitoring, risk scoring & reporting
|
|
91
|
+
SecurityFinding,
|
|
92
|
+
calculate_risk_score,
|
|
93
|
+
generate_security_report,
|
|
94
|
+
export_findings_to_json,
|
|
95
|
+
generate_incident_response_report,
|
|
96
|
+
audit_user_permissions,
|
|
97
|
+
notify_admin_dashboard,
|
|
98
|
+
send_security_alert,
|
|
99
|
+
schedule_periodic_scan,
|
|
100
|
+
generate_security_checklist,
|
|
101
|
+
|
|
102
|
+
# module logger, in case a consumer wants to attach their own handler
|
|
103
|
+
logger,
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
__all__ = [
|
|
107
|
+
"check_password_strength", "check_password_breached", "generate_strong_password",
|
|
108
|
+
"hash_password", "verify_password", "detect_common_password_patterns",
|
|
109
|
+
"check_two_factor_status", "check_password_expiry", "validate_password_policy_compliance",
|
|
110
|
+
"check_default_credentials",
|
|
111
|
+
"check_suspicious_url", "check_domain_similarity", "check_ssl_certificate",
|
|
112
|
+
"scan_email_for_phishing_signs", "extract_and_check_links", "validate_email_format_and_mx",
|
|
113
|
+
"RateLimiter", "rate_limiter", "detect_brute_force_attempt", "IPBlocklist",
|
|
114
|
+
"block_ip_temporarily", "implement_captcha_trigger", "log_failed_login_attempt",
|
|
115
|
+
"distance_km_between", "detect_anomalous_login_location", "detect_privilege_escalation_attempt",
|
|
116
|
+
"compute_file_hash", "scan_file_hash_virustotal", "detect_suspicious_file_extension",
|
|
117
|
+
"check_file_integrity", "scan_directory_for_malware_signatures", "quarantine_suspicious_file",
|
|
118
|
+
"verify_backup_integrity",
|
|
119
|
+
"sanitize_user_input", "generate_csrf_token", "check_csrf_token_validity",
|
|
120
|
+
"validate_cors_policy", "detect_xss_patterns", "check_secure_cookie_flags",
|
|
121
|
+
"validate_input_against_sql_injection", "check_security_headers", "verify_csp_header",
|
|
122
|
+
"check_tls_version_support", "check_firewall_rules_status", "detect_arp_spoofing",
|
|
123
|
+
"validate_dns_response", "check_vpn_connection_security", "audit_server_config",
|
|
124
|
+
"generate_secure_token", "ApiKeyRecord", "rotate_api_key", "mask_sensitive_data_in_logs",
|
|
125
|
+
"encrypt_sensitive_data", "decrypt_sensitive_data", "validate_jwt_token",
|
|
126
|
+
"check_secrets_in_codebase",
|
|
127
|
+
"SecurityFinding", "calculate_risk_score", "generate_security_report",
|
|
128
|
+
"export_findings_to_json", "generate_incident_response_report", "audit_user_permissions",
|
|
129
|
+
"notify_admin_dashboard", "send_security_alert", "schedule_periodic_scan",
|
|
130
|
+
"generate_security_checklist",
|
|
131
|
+
"logger",
|
|
132
|
+
]
|
|
133
|
+
|
|
134
|
+
__version__ = "1.0.0"
|
|
135
|
+
__author__ = "Barman"
|