MCPcopy Create free account
hub / github.com/aaPanel/BaoTa / crontab

Method crontab

class/btdockerModel/securityModel.py:1238–1311  ·  view source on GitHub ↗

@name crontab后门检测

()

Source from the content-addressed store, hash-verified

1236 pass
1237
1238 def crontab():
1239 """
1240 @name crontab后门检测
1241 """
1242 cron_list = [
1243 "/etc/crontab", "/etc/cron.hourly", "/etc/cron.daily",
1244 "/etc/cron.weekly", "/etc/cron.monthly", "/etc/cron.d"
1245 ]
1246 environment_regex = '''[a-zA-Z90-9]+\s*=\s*[^\s]+$'''
1247 cron_regex = '''((\d{1,2}|\*)\s+){5}[a-zA-Z0-9]+\s+(.*)'''
1248 backdoor_regex_list = [
1249 # download
1250 r'''^(wget|curl)\b'''
1251 # mrig
1252 r'''^([\w0-9]*mrig[\w0-9]*)\b'''
1253 ]
1254
1255 def detect_crontab_content(cron_f):
1256 """
1257 @name 检查crontab内容
1258 """
1259 result_dict = {}
1260 for line in cron_f.readlines():
1261 # preprocess
1262 line = line.strip()
1263 line = line.replace("\n", "")
1264 # environment
1265 if re.match(environment_regex, line): continue
1266 m = re.match(cron_regex, line)
1267 if m:
1268 if len(m.groups()) == 3:
1269 cmdline1 = m.group(3)
1270 # for backdoor_regex in backdoor_regex_list:
1271 # if re.search(backdoor_regex, cmdline1):
1272 # result_dict[backdoor_regex] = cmdline1
1273 for backdoor_regex in backdoor_regex_list1:
1274 if re.search(backdoor_regex, cmdline1):
1275 self.send_image_ws(
1276 get,
1277 msg="发现cron后门{}".format(filepath),
1278 detail="发现镜像存在cron后门【{}】,恶意代码内容:<br/>{}".format(filepath,
1279 self.short_string(
1280 cmdline1)),
1281 repair="1.进入使用该镜像部署的容器删除文件下的恶意代码<br/>2.排查容器是否已被入侵,更新容器内业务的访问令牌或账号密码<br/>3.建议更换官方镜像或其他可信的镜像部署容器",
1282 status=3
1283 )
1284 result_dict[backdoor_regex] = cmdline1
1285 else:
1286 continue
1287 return result_dict
1288
1289 for cron in cron_list:
1290 try:
1291 # filetype
1292 cron_stat = image.stat(cron)
1293 if S_ISDIR(cron_stat.st_mode):
1294 for root, dirs, files in image.walk(cron):
1295 for file in files:

Callers 15

del_cron_taskFunction · 0.80
execute_startup_servicesFunction · 0.80
_add_cron_taskMethod · 0.80
add_crontabMethod · 0.80
start_taskMethod · 0.80
modify_crontab_statusMethod · 0.80
remove_crontabMethod · 0.80
get_crontab_logMethod · 0.80
clearn_logsMethod · 0.80
set_cron_status_allMethod · 0.80
del_crontabMethod · 0.80

Calls 4

statMethod · 0.80
walkMethod · 0.45
joinMethod · 0.45
openMethod · 0.45

Tested by

no test coverage detected