This repository has been archived by the owner on Jul 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 299
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
169 changed files
with
12,586 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
#!/usr/bin/python3 | ||
# coding: utf-8 | ||
# author: 9ian1i https://github.com/Qianlitp | ||
|
||
""" | ||
install 安装ES索引模板,初始化LDAP配置 | ||
check 检查各个数据库连接状态、消息队列状态 | ||
start 加载动态配置信息、创建计划任务、启动检测引擎 | ||
restart 重新加载动态配置信息、删除计划任务、重启检测引擎 | ||
stop 停止引擎 (删除现有消息队列,防止数据量过大造成积压) | ||
status 查看当前引擎状态 | ||
""" | ||
|
||
|
||
from io import StringIO | ||
import optparse | ||
import sys | ||
from _project_dir import project_dir | ||
import subprocess | ||
from tools.common.Logger import logger | ||
from scripts.init_settings import init_es_template, check_es_template, check_mongo_connection, check_mq_connection, \ | ||
init_ldap_settings, init_default_settings, get_all_dc_names, set_learning_end_time_setting, init_sensitive_groups, \ | ||
set_crontab_tasks | ||
|
||
|
||
def install(domain, server, user, password): | ||
logger.info("Install the WatchAD ...") | ||
# 初始化ES索引模板 | ||
init_es_template() | ||
# 初始化LDAP配置信息 | ||
init_ldap_settings(domain, server, user, password) | ||
# 获取域控计算机名保存入库 | ||
get_all_dc_names(domain) | ||
# 初始化其余配置信息 | ||
init_default_settings(domain) | ||
# 初始化填入敏感用户组 | ||
init_sensitive_groups(domain) | ||
# 根据当前安装时间,设置数据统计结束时间 | ||
set_learning_end_time_setting() | ||
# 设置计划任务 | ||
set_crontab_tasks() | ||
|
||
|
||
def check() -> bool: | ||
logger.info("Checking the WatchAD environment ...") | ||
# 检查ES模板安装状态 | ||
if not check_es_template(): | ||
return False | ||
# 检查数据库连接 | ||
if not check_mongo_connection(): | ||
return False | ||
# 检查消息队列连接 | ||
if not check_mq_connection(): | ||
return False | ||
logger.info("OK!") | ||
logger.info("Check the WatchAD environment successfully!") | ||
return True | ||
|
||
|
||
def start(): | ||
if not check(): | ||
sys.exit(-1) | ||
logger.info("Starting the WatchAD detect engine ...") | ||
|
||
rsp = subprocess.call("supervisord -c {root_dir}/supervisor.conf".format(root_dir=project_dir), | ||
shell=True, | ||
env={"WATCHAD_ENGINE_DIR": project_dir, "ENV_WATCHAD_ENGINE_NUM": 5}) | ||
if rsp == 0: | ||
logger.info("Started!") | ||
else: | ||
logger.error("Start failed.") | ||
|
||
|
||
def stop(): | ||
logger.info("Stopping the WatchAD detect engine ...") | ||
|
||
rsp = subprocess.call("supervisorctl -c {root_dir}/supervisor.conf shutdown".format(root_dir=project_dir), | ||
shell=True, | ||
env={"WATCHAD_ENGINE_DIR": project_dir, "ENV_WATCHAD_ENGINE_NUM": 5}) | ||
|
||
if rsp == 0: | ||
logger.info("Stopped!") | ||
else: | ||
logger.error("Stop failed.") | ||
|
||
|
||
def restart(): | ||
stop() | ||
start() | ||
|
||
|
||
def status(): | ||
subprocess.call("supervisorctl -c {root_dir}/supervisor.conf status".format(root_dir=project_dir), | ||
shell=True, | ||
env={"WATCHAD_ENGINE_DIR": project_dir}) | ||
|
||
|
||
def usage(): | ||
s = StringIO() | ||
s.write("Usage: WatchAD.py <options> [settings]") | ||
s.seek(0) | ||
return s.read() | ||
|
||
|
||
def parse_option(): | ||
parser = optparse.OptionParser(usage=usage()) | ||
parser.add_option("--install", action="store_true", dest="install", help="执行WatchAD初始化安装,在次之前请确保已完整环境安装和配置。") | ||
parser.add_option("-d", "--domain", action="store", dest="domain", help="A FQDN domain name of detection.") | ||
parser.add_option("-s", "--ldap-server", action="store", dest="server", | ||
help="Server address for LDAP search. e.g: dc01.corp.com") | ||
parser.add_option("-u", "--domain-user", action="store", dest="username", | ||
help="Username for LDAP search. e.g: CORP\\peter") | ||
parser.add_option("-p", "--domain-passwd", action="store", dest="password", | ||
help="Password for LDAP search.") | ||
parser.add_option("--check", action="store_true", dest="check", help="检查各个数据库连接状态、消息队列状态") | ||
parser.add_option("--start", action="store_true", dest="start", help="启动检测引擎") | ||
parser.add_option("--restart", action="store_true", dest="restart", help="重新加载动态配置信息、删除计划任务、重启检测引擎") | ||
parser.add_option("--stop", action="store_true", dest="stop", help="停止引擎 (删除现有消息队列,防止数据量过大造成积压)") | ||
parser.add_option("--status", action="store_true", dest="status", help="查看当前引擎状态") | ||
return parser | ||
|
||
|
||
def main(): | ||
parser = parse_option() | ||
if len(sys.argv) < 2: | ||
logger.error("WatchAD must run with an action.") | ||
parser.print_help() | ||
sys.exit(1) | ||
options, args = parser.parse_args() | ||
|
||
if options.install: | ||
if not options.domain or not options.server or not options.username or not options.password: | ||
logger.error("WatchAD install action must provide domain, server, user and password params.") | ||
sys.exit(1) | ||
install(domain=options.domain, server=options.server, user=options.username, password=options.password) | ||
elif options.check: | ||
check() | ||
elif options.start: | ||
start() | ||
elif options.restart: | ||
restart() | ||
elif options.stop: | ||
stop() | ||
elif options.status: | ||
status() | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/usr/bin/python3 | ||
# coding: utf-8 | ||
# author: 9ian1i https://github.com/Qianlitp | ||
|
||
import os | ||
|
||
project_dir = os.path.dirname(os.path.abspath(__file__)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
version: '3' | ||
services: | ||
watchad_rabbitmq: | ||
image: rabbitmq:management | ||
ports: | ||
- "15672:15672" | ||
- "5672:5672" | ||
environment: | ||
RABBITMQ_IO_THREAD_POOL_SIZE: 100 | ||
RABBITMQ_HIPE_COMPILE: "true" | ||
RABBITMQ_DEFAULT_USER: WatchAD | ||
RABBITMQ_DEFAULT_PASS: WatchAD-by-0KEE | ||
restart: always | ||
|
||
watchad_logstash: | ||
image: logstash:6.4.1 | ||
ports: | ||
- "5044:5044" | ||
environment: | ||
XPACK_MONITORING_ENABLED: "false" | ||
pipeline.batch.size: 10 | ||
volumes: | ||
- ./settings/logstash/:/usr/share/logstash/pipeline/ | ||
links: | ||
- watchad_elasticsearch | ||
restart: always | ||
|
||
watchad_elasticsearch: | ||
image: elasticsearch:5.2.1 | ||
environment: | ||
http.host: 0.0.0.0 | ||
transport.host: 127.0.0.1 | ||
cluster.name: docker-cluster | ||
bootstrap.memory_lock: "true" | ||
ES_JAVA_OPTS: "-Xms512m -Xmx512m" | ||
thread_pool.bulk.size: 9 | ||
thread_pool.bulk.queue_size: 1000 | ||
ulimits: | ||
memlock: | ||
soft: -1 | ||
hard: -1 | ||
nofile: | ||
soft: 65536 | ||
hard: 65536 | ||
ports: | ||
- "9200:9200" | ||
restart: always | ||
|
||
watchad_redis: | ||
image: redis:latest | ||
ports: | ||
- "6379:6379" | ||
restart: always | ||
|
||
watchad_mongo: | ||
image: mongo:latest | ||
ports: | ||
- "27017:27017" | ||
environment: | ||
MONGO_INITDB_ROOT_USERNAME: WatchAD | ||
MONGO_INITDB_ROOT_PASSWORD: WatchAD-by-0KEE |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
class ARC4Cipher(object): | ||
def __init__(self, key): | ||
self.key = key | ||
|
||
def encrypt(self, data): | ||
S = range(256) | ||
j = 0 | ||
out = [] | ||
for i in range(256): | ||
j = (j + S[i] + ord( self.key[i % len(self.key)] )) % 256 | ||
S[i] , S[j] = S[j] , S[i] | ||
i = j = 0 | ||
for char in data: | ||
i = ( i + 1 ) % 256 | ||
j = ( j + S[i] ) % 256 | ||
S[i] , S[j] = S[j] , S[i] | ||
out.append(chr(ord(char) ^ S[(S[i] + S[j]) % 256])) | ||
return ''.join(out) | ||
|
||
def decrypt(self, data): | ||
return self.encrypt(data) | ||
|
||
def new(key): | ||
return ARC4Cipher(key) |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import hashlib | ||
|
||
def new(*args): | ||
return hashlib.new('md4', *args) |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import hashlib | ||
|
||
def new(*args): | ||
return hashlib.md5(*args) |
Binary file not shown.
Empty file.
Binary file not shown.
Oops, something went wrong.