wafaHell 0.1.1__py3-none-any.whl

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.
wafaHell/__init__.py ADDED
@@ -0,0 +1,3 @@
1
+ from .middleware import WafaHell
2
+
3
+ # agora a classe está disponível diretamente ao importar o pacote
wafaHell/middleware.py ADDED
@@ -0,0 +1,65 @@
1
+ import re
2
+ from flask import request, abort
3
+ from urllib.parse import unquote
4
+
5
+ class WafaHell:
6
+ def __init__(self, app=None, block_code=403, log_func=None, monitor_mode=False):
7
+ self.app = app
8
+ self.block_code = block_code
9
+ self.log_func = log_func or (lambda msg: print(f"[WAF] {msg}"))
10
+ self.monitor_mode = monitor_mode
11
+ # Regras básicas
12
+ self.rules = [
13
+ r"(\bUNION\b|\bSELECT\b|\bINSERT\b|\bDROP\b)",
14
+ r"' OR '1'='1",
15
+ r"<script.*?>.*?</script>",
16
+ r"javascript:",
17
+ ]
18
+
19
+ if app is not None:
20
+ self.init_app(app)
21
+
22
+ def init_app(self, app):
23
+ @app.before_request
24
+ def waf_check():
25
+ if self.is_malicious(request):
26
+ self.log_attack(request)
27
+ if not self.monitor_mode:
28
+ abort(self.block_code)
29
+
30
+ def detect_attack(self, data: str) -> bool:
31
+ for pattern in self.rules:
32
+ if re.search(pattern, data, re.IGNORECASE):
33
+ return True
34
+ return False
35
+
36
+ def is_malicious(self, req) -> bool:
37
+ # URL + Query Params
38
+ if self.detect_attack(req.url) or any(self.detect_attack(v) for v in req.args.values()):
39
+ return True
40
+
41
+ # Headers
42
+ for _, value in req.headers.items():
43
+ if self.detect_attack(value):
44
+ return True
45
+
46
+ # Body
47
+ if req.data and self.detect_attack(req.data.decode(errors="ignore")):
48
+ return True
49
+
50
+ return False
51
+
52
+ def log_attack(self, req):
53
+ ip = req.remote_addr
54
+ user_agent = req.headers.get("User-Agent", "unknown")
55
+ path = req.path
56
+ query = req.query_string.decode(errors="ignore") if req.query_string else ""
57
+
58
+ msg = (
59
+ f"Ataque detectado\n",
60
+ f"IP: {ip}\n"
61
+ f"User-Agent: {user_agent}\n"
62
+ f"Rota: {path}\n"
63
+ f"Query: {unquote(query)}\n"
64
+ )
65
+ self.log_func(msg)
@@ -0,0 +1,55 @@
1
+ Metadata-Version: 2.4
2
+ Name: wafaHell
3
+ Version: 0.1.1
4
+ Summary: Middleware WAF to Flask
5
+ Author-email: Yago Martins <yagomartins30@gmail.com>
6
+ License: MIT License
7
+
8
+ Copyright (c) 2025 Seu Nome
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+
28
+ Classifier: Programming Language :: Python :: 3
29
+ Classifier: Framework :: Flask
30
+ Classifier: License :: OSI Approved :: MIT License
31
+ Classifier: Operating System :: OS Independent
32
+ Requires-Python: >=3.9
33
+ Description-Content-Type: text/markdown
34
+ License-File: LICENSE
35
+ Requires-Dist: Flask>=2.0
36
+ Dynamic: license-file
37
+
38
+ # WafHell
39
+
40
+ Middleware WAF for Flask, to detect SQLi and XSS.
41
+
42
+ ## Instalation
43
+
44
+ ```bash
45
+ pip install wafaHell
46
+ ```
47
+
48
+ ## Usage
49
+ ```python
50
+ from flask import Flask
51
+ from flask_waf import FlaskWAF
52
+
53
+ app = Flask(__name__)
54
+ waf = FlaskWAF(app)
55
+ ```
@@ -0,0 +1,7 @@
1
+ wafaHell/__init__.py,sha256=enTIAbStl7o_cDo93-s8nq86BsN3OEGYu9AbtESQVXQ,105
2
+ wafaHell/middleware.py,sha256=UQ5TPcuz6UDyy5FjyUNXSAZqv2IjnOoc3ze2M8He7Tw,2151
3
+ wafahell-0.1.1.dist-info/licenses/LICENSE,sha256=6bv9v4HamenV3rqm3mhaGOecwGFrgxtVTW7JPfFDmeY,1086
4
+ wafahell-0.1.1.dist-info/METADATA,sha256=DKx0AS6ZJ82ATAkBJetN_AG8doVO00xxMI7PwBdcBzQ,1980
5
+ wafahell-0.1.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
6
+ wafahell-0.1.1.dist-info/top_level.txt,sha256=VGBo2g3pOeTH2qIXfZDJCSblJgijemMHUHmI0bBgrls,9
7
+ wafahell-0.1.1.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.9.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Seu Nome
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ wafaHell