2019-12-20 05:28:12 +00:00
|
|
|
"""Onionr - Private P2P Communication.
|
2019-12-13 18:24:29 +00:00
|
|
|
|
2019-12-20 05:28:12 +00:00
|
|
|
Processes interpreter hook events to detect security leaks
|
2019-12-13 18:24:29 +00:00
|
|
|
"""
|
|
|
|
import sys
|
2022-09-26 20:06:05 +00:00
|
|
|
import os
|
2019-12-13 18:24:29 +00:00
|
|
|
from typing import Iterable
|
|
|
|
|
2022-09-26 20:06:05 +00:00
|
|
|
import logger
|
|
|
|
|
2019-12-13 18:24:29 +00:00
|
|
|
"""
|
2022-03-18 00:56:31 +00:00
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2019-12-13 18:24:29 +00:00
|
|
|
"""
|
2022-09-26 20:06:05 +00:00
|
|
|
sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)))
|
|
|
|
import ministry
|
2019-12-13 18:24:29 +00:00
|
|
|
|
2022-09-26 20:06:05 +00:00
|
|
|
plugin_name = 'bigbrother'
|
|
|
|
PLUGIN_VERSION = '0.0.0'
|
2019-12-13 18:24:29 +00:00
|
|
|
|
|
|
|
def sys_hook_entrypoint(event, info):
|
2019-12-20 05:28:12 +00:00
|
|
|
"""Entrypoint for big brother sys auditors."""
|
2019-12-13 18:24:29 +00:00
|
|
|
if event == 'socket.connect':
|
|
|
|
ministry.ofcommunication.detect_socket_leaks(info)
|
2019-12-14 19:45:18 +00:00
|
|
|
elif event == 'exec':
|
|
|
|
# logs and block both exec and eval
|
|
|
|
ministry.ofexec.block_exec(event, info)
|
2019-12-18 09:58:47 +00:00
|
|
|
elif event == 'system':
|
|
|
|
ministry.ofexec.block_system(info)
|
2020-03-31 05:15:24 +00:00
|
|
|
elif event == 'open':
|
|
|
|
ministry.ofdisk.detect_disk_access(info)
|
2019-12-13 18:24:29 +00:00
|
|
|
|
|
|
|
|
2019-12-20 05:28:12 +00:00
|
|
|
def enable_ministries(disable_hooks: Iterable = None):
|
|
|
|
"""Enable auditors."""
|
|
|
|
disable_hooks = disable_hooks or []
|
2019-12-13 18:24:29 +00:00
|
|
|
sys.addaudithook(sys_hook_entrypoint)
|
2022-09-26 20:06:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
def on_init(api, data=None):
|
|
|
|
enable_ministries()
|
|
|
|
logger.info(
|
|
|
|
"Big brother enabled, blocking unsafe Python code.", terminal=True)
|