diff --git a/apps/locale/zh/LC_MESSAGES/django.mo b/apps/locale/zh/LC_MESSAGES/django.mo index 56fb9b8d2..e00cb3d92 100644 Binary files a/apps/locale/zh/LC_MESSAGES/django.mo and b/apps/locale/zh/LC_MESSAGES/django.mo differ diff --git a/apps/locale/zh/LC_MESSAGES/django.po b/apps/locale/zh/LC_MESSAGES/django.po index 57fff2e30..93d16d4bc 100644 --- a/apps/locale/zh/LC_MESSAGES/django.po +++ b/apps/locale/zh/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: JumpServer 0.3.3\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2021-01-20 16:09+0800\n" +"POT-Creation-Date: 2021-01-21 15:23+0800\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: ibuler \n" "Language-Team: JumpServer team\n" @@ -292,7 +292,7 @@ msgstr "激活" #: assets/models/asset.py:203 assets/models/cluster.py:19 #: assets/models/user.py:66 templates/_nav.html:44 -#: xpack/plugins/cloud/models.py:143 xpack/plugins/cloud/serializers.py:137 +#: xpack/plugins/cloud/models.py:143 xpack/plugins/cloud/serializers.py:113 msgid "Admin user" msgstr "管理用户" @@ -381,7 +381,7 @@ msgstr "创建者" #: assets/models/cluster.py:26 assets/models/domain.py:24 #: assets/models/gathered_user.py:19 assets/models/group.py:22 #: assets/models/label.py:25 common/db/models.py:69 common/mixins/models.py:50 -#: ops/models/adhoc.py:38 ops/models/command.py:27 orgs/models.py:25 +#: ops/models/adhoc.py:38 ops/models/command.py:29 orgs/models.py:25 #: orgs/models.py:425 perms/models/base.py:55 users/models/group.py:18 #: users/templates/users/user_group_detail.html:58 #: xpack/plugins/cloud/models.py:61 xpack/plugins/cloud/models.py:159 @@ -472,7 +472,7 @@ msgstr "命令过滤器" msgid "Regex" msgstr "正则表达式" -#: assets/models/cmd_filter.py:41 ops/models/command.py:23 +#: assets/models/cmd_filter.py:41 ops/models/command.py:25 #: terminal/backends/command/serializers.py:15 terminal/models/session.py:48 msgid "Command" msgstr "命令" @@ -602,7 +602,7 @@ msgstr "ssh私钥" #: users/templates/users/user_asset_permission.html:41 #: users/templates/users/user_asset_permission.html:73 #: users/templates/users/user_asset_permission.html:158 -#: xpack/plugins/cloud/models.py:139 xpack/plugins/cloud/serializers.py:138 +#: xpack/plugins/cloud/models.py:139 xpack/plugins/cloud/serializers.py:114 msgid "Node" msgstr "节点" @@ -992,7 +992,7 @@ msgstr "文件名" msgid "Success" msgstr "成功" -#: audits/models.py:43 ops/models/command.py:28 perms/models/base.py:52 +#: audits/models.py:43 ops/models/command.py:30 perms/models/base.py:52 #: terminal/models/session.py:51 #: tickets/serializers/ticket/meta/ticket_type/apply_application.py:43 #: tickets/serializers/ticket/meta/ticket_type/apply_application.py:74 @@ -1124,7 +1124,7 @@ msgstr "多因子认证状态(显示名称)" msgid "Is success" msgstr "是否成功" -#: audits/serializers.py:77 ops/models/command.py:24 +#: audits/serializers.py:77 ops/models/command.py:26 #: xpack/plugins/cloud/models.py:222 msgid "Result" msgstr "结果" @@ -1734,7 +1734,7 @@ msgstr "完成时间" msgid "Time" msgstr "时间" -#: ops/models/adhoc.py:246 ops/models/command.py:26 +#: ops/models/adhoc.py:246 ops/models/command.py:28 #: terminal/serializers/session.py:38 msgid "Is finished" msgstr "是否完成" @@ -1755,19 +1755,19 @@ msgstr "{} 任务开始: {}" msgid "{} Task finish" msgstr "{} 任务结束" -#: ops/models/command.py:29 +#: ops/models/command.py:31 msgid "Date finished" msgstr "结束日期" -#: ops/models/command.py:72 +#: ops/models/command.py:74 msgid "Task start" msgstr "任务开始" -#: ops/models/command.py:94 +#: ops/models/command.py:96 msgid "Command `{}` is forbidden ........" msgstr "命令 `{}` 不允许被执行 ......." -#: ops/models/command.py:101 +#: ops/models/command.py:109 msgid "Task end" msgstr "任务结束" @@ -2815,6 +2815,54 @@ msgstr "" "
\n" " " +#: terminal/utils.py:114 +#, python-format +msgid "Insecure Web Command Execution Alert: [%(name)s]" +msgstr "Web页面-> 命令执行 告警: [%(name)s]" + +#: terminal/utils.py:122 +#| msgid "" +#| "\n" +#| " Command: %(command)s\n" +#| "
\n" +#| " Asset: %(host_name)s (%(host_ip)s)\n" +#| "
\n" +#| " User: %(user)s\n" +#| "
\n" +#| " Level: %(risk_level)s\n" +#| "
\n" +#| " Session: session detail\n" +#| "
\n" +#| " " +msgid "" +"\n" +"
\n" +" Assets: %(assets)s\n" +"
\n" +" User: %(user)s\n" +"
\n" +" Level: %(risk_level)s\n" +"
\n" +"\n" +" ----------------- Commands ----------------
\n" +" %(command)s
\n" +" ----------------- Commands ----------------
\n" +" " +msgstr "" +"\n" +"
\n" +" 资产: %(assets)s\n" +"
\n" +" 用户: %(user)s\n" +"
\n" +" 等级: %(risk_level)s\n" +"
\n" +"\n" +" ----------------- 命令 ----------------
\n" +" %(command)s
\n" +" ----------------- 命令 ----------------
\n" +" " + #: tickets/const.py:8 msgid "General" msgstr "一般" @@ -3368,7 +3416,7 @@ msgstr "安全令牌验证" #: users/templates/users/_base_otp.html:14 users/templates/users/_user.html:13 #: users/templates/users/user_profile_update.html:55 -#: xpack/plugins/cloud/models.py:125 xpack/plugins/cloud/serializers.py:136 +#: xpack/plugins/cloud/models.py:125 xpack/plugins/cloud/serializers.py:112 msgid "Account" msgstr "账户" @@ -4332,7 +4380,7 @@ msgstr "实例名称" msgid "Instance name and Partial IP" msgstr "实例名称和部分IP" -#: xpack/plugins/cloud/models.py:128 xpack/plugins/cloud/serializers.py:112 +#: xpack/plugins/cloud/models.py:128 xpack/plugins/cloud/serializers.py:88 msgid "Regions" msgstr "地域" @@ -4344,7 +4392,7 @@ msgstr "实例" msgid "Hostname strategy" msgstr "主机名策略" -#: xpack/plugins/cloud/models.py:147 xpack/plugins/cloud/serializers.py:140 +#: xpack/plugins/cloud/models.py:147 xpack/plugins/cloud/serializers.py:116 msgid "Always update" msgstr "总是更新" @@ -4404,7 +4452,7 @@ msgstr "AWS (国际)" msgid "AWS (China)" msgstr "AWS (中国)" -#: xpack/plugins/cloud/providers/azure_.py:16 +#: xpack/plugins/cloud/providers/azure_.py:18 msgid "Azure (China)" msgstr "Azure (中国)" @@ -4468,23 +4516,23 @@ msgstr "拉美-圣地亚哥" msgid "Tencent Cloud" msgstr "腾讯云" -#: xpack/plugins/cloud/serializers.py:22 +#: xpack/plugins/cloud/serializers.py:25 msgid "Tenant ID" msgstr "租户ID" -#: xpack/plugins/cloud/serializers.py:26 +#: xpack/plugins/cloud/serializers.py:29 msgid "Subscription ID" msgstr "订阅ID" -#: xpack/plugins/cloud/serializers.py:110 +#: xpack/plugins/cloud/serializers.py:86 msgid "History count" msgstr "执行次数" -#: xpack/plugins/cloud/serializers.py:111 +#: xpack/plugins/cloud/serializers.py:87 msgid "Instance count" msgstr "实例个数" -#: xpack/plugins/cloud/serializers.py:139 +#: xpack/plugins/cloud/serializers.py:115 #: xpack/plugins/gathered_user/serializers.py:20 msgid "Periodic display" msgstr "定时执行" diff --git a/apps/ops/models/command.py b/apps/ops/models/command.py index 5bf808dce..80a26be70 100644 --- a/apps/ops/models/command.py +++ b/apps/ops/models/command.py @@ -9,6 +9,8 @@ from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext from django.db import models +from terminal.models import Command +from terminal.utils import send_command_execution_alert_mail from common.utils import lazyproperty from orgs.models import Organization from orgs.mixins.models import OrgModelMixin @@ -93,6 +95,12 @@ class CommandExecution(OrgModelMixin): else: msg = _("Command `{}` is forbidden ........").format(self.command) print('\033[31m' + msg + '\033[0m') + send_command_execution_alert_mail({ + 'input': self.command, + 'assets': self.hosts.all(), + 'user': str(self.user), + 'risk_level': 5, + }) self.result = {"error": msg} self.org_id = self.run_as.org_id self.is_finished = True diff --git a/apps/terminal/utils.py b/apps/terminal/utils.py index 918266b56..8ceff0166 100644 --- a/apps/terminal/utils.py +++ b/apps/terminal/utils.py @@ -110,6 +110,37 @@ def send_command_alert_mail(command): send_mail_async.delay(subject, message, recipient_list, html_message=message) +def send_command_execution_alert_mail(command): + subject = _("Insecure Web Command Execution Alert: [%(name)s]") % { + 'name': command['user'], + } + input = command['input'] + input = input.replace('\n', '
') + recipient_list = settings.SECURITY_INSECURE_COMMAND_EMAIL_RECEIVER.split(',') + + assets = ', '.join([str(asset) for asset in command['assets']]) + message = _(""" +
+ Assets: %(assets)s +
+ User: %(user)s +
+ Level: %(risk_level)s +
+ + ----------------- Commands ----------------
+ %(command)s
+ ----------------- Commands ----------------
+ """) % { + 'command': input, + 'assets': assets, + 'user': command['user'], + 'risk_level': Command.get_risk_level_str(command['risk_level']), + } + + send_mail_async.delay(subject, message, recipient_list, html_message=message) + + class ComponentsMetricsUtil(object): @staticmethod