Skip to content

Commit fb376f1

Browse files
grayddqgrayddq
authored andcommitted
add_setuid_check
1 parent f676996 commit fb376f1

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
6.10、SSH wrapper 后门检测
4545
6.11、inetd.conf 后门检测
4646
6.12、xinetd.conf 后门检测
47+
6.13、setUID 后门检测
4748
6.13、8种系统启动项后门检测
4849
7、账户类安全排查
4950
7.1、root权限账户检测
@@ -177,6 +178,9 @@
177178
| 【常规后门检测】SSH Wrapper后门检测 || | | |
178179
| 【常规后门检测】inetd.conf后门检测 || || |
179180
| 【常规后门检测】xinetd.conf后门检测 || || |
181+
| 【常规后门检测】setUID后门检测 || | | |
182+
| 【常规后门检测】setGID后门检测 | | | | |
183+
| 【常规后门检测】fstab后门检测 | | | | |
180184
| 【常规后门检测】系统启动项(/etc/init.d/)后门检测 || || |
181185
| 【常规后门检测】系统启动项(/etc/rc.d/)后门检测 || || |
182186
| 【常规后门检测】系统启动项(/etc/rc.local)后门检测 || || |

lib/Backdoor_Analysis.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import os, time, sys, json, re
44
from lib.common import *
55
from lib.ip.ip import *
6+
from subprocess import Popen, PIPE
67

78

89
# 作者:咚咚呛
@@ -19,6 +20,8 @@
1920
# 10、SSH Server wrapper 后门,替换/user/sbin/sshd 为脚本文件
2021
# 11、/etc/inetd.conf 后门
2122
# 12、/etc/xinetd.conf/后门
23+
# 13、setuid类后门
24+
# 14、/etc/fstab类后门(待写)
2225
# 13、系统启动项后门检测
2326

2427

@@ -206,6 +209,25 @@ def check_xinetd(self):
206209
except:
207210
return suspicious, malice
208211

212+
# 分析setuid后门后
213+
def check_setuid(self):
214+
suspicious, malice = False, False
215+
try:
216+
p1 = Popen("find / -type f -perm -4000 -not -path '/proc/*' -not -path '/run/*'", stdout=PIPE, shell=True)
217+
p2 = Popen(
218+
"grep -vE 'pam_timestamp_check|unix_chkpwd|ping|mount|su|pt_chown|ssh-keysign|at|passwd|chsh|crontab|chfn|usernetctl|staprun|newgrp|chage|dhcp|helper|pkexec'",
219+
stdin=p1.stdout, stdout=PIPE, shell=True)
220+
file_infos = p2.stdout.splitlines()
221+
if info in file_infos:
222+
self.backdoor.append(
223+
{u'异常类型': u'setuid后门', u'异常信息': u'文件被设置setuid属性', u'文件': info,
224+
u'手工确认': u"[1]ls -l %s [2]判断是否存在setuid设置" % info,
225+
u'风险说明': u'通常此类被设置权限的文件执行后会给予普通用户root权限,通常利用会使用ld-linux类或者自己编写程序类'})
226+
suspicious = True
227+
return suspicious, malice
228+
except:
229+
return suspicious, malice
230+
209231
# 系统启动项检测
210232
def check_startup(self):
211233
suspicious, malice = False, False
@@ -312,7 +334,11 @@ def run(self):
312334
suspicious, malice = self.check_xinetd()
313335
result_output_tag(suspicious, malice)
314336

315-
string_output(u' [13]系统启动项后门检测')
337+
string_output(u' [13]setuid 后门检测')
338+
suspicious, malice = self.check_setuid()
339+
result_output_tag(suspicious, malice)
340+
341+
string_output(u' [14]系统启动项后门检测')
316342
suspicious, malice = self.check_startup()
317343
result_output_tag(suspicious, malice)
318344

lib/File_Analysis.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def check_hide(self):
9393
suspicious, malice = False, False
9494
try:
9595
infos = os.popen(
96-
'find / -type f -name " *" -o -name ". *" -o -name "..." -o -name ".." -o -name "." -o -name " " -print | grep -v "No such" |grep -v "Permission denied"').read().splitlines()
96+
'find / -type f -name ". *" -o -name "...*" -o -name "..*" -not -path "/proc/*" -not -path "/run/*" -not -path "/private/*"').read().splitlines()
9797
for file in infos:
9898
self.file_malware.append(
9999
{u'异常类型': u'文件异常隐藏', u'文件路径': file, u'手工确认': u'[1]ls -l %s [2]strings %s' % (file, file)})

0 commit comments

Comments
 (0)