Skip to content

Commit

Permalink
code_update
Browse files Browse the repository at this point in the history
  • Loading branch information
grayddq authored and grayddq committed May 20, 2019
1 parent bf6717b commit 286fbc0
Show file tree
Hide file tree
Showing 11 changed files with 483 additions and 141 deletions.
5 changes: 3 additions & 2 deletions GScan.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@


if __name__ == '__main__':
version = 'v0.1'
progam = u'''
_______ _______. ______ ___ .__ __.
/ _____| / | / | / \ | \ | | {version:v0.1}
/ _____| / | / | / \ | \ | | {version:%s}
| | __ | (----`| ,----' / ^ \ | \| |
| | |_ | \ \ | | / /_\ \ | . ` | {author:咚咚呛}
| |__| | .----) | | `----. / _____ \ | |\ |
\______| |_______/ \______|/__/ \__\ |__| \__| http://grayddq.top
'''
''' % version
print(progam)

main(os.path.dirname(os.path.abspath(__file__)))
73 changes: 48 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
1、主机信息获取
2、系统初始化alias检查
3、文件类安全扫描
3.1、系统可执行文件安全扫描
3.2、临时目录文件安全扫描
3.3、用户目录文件扫描
3.4、可疑隐藏文件扫描
3.1、系统重要文件完整行扫描
3.2、系统可执行文件安全扫描
3.3、临时目录文件安全扫描
3.4、用户目录文件扫描
3.5、可疑隐藏文件扫描
4、各用户历史操作类
4.1、境外ip操作类
4.2、反弹shell类
Expand Down Expand Up @@ -91,30 +92,53 @@
参数参考

> root# python GScan.py -h
> sh-3.2# python GScan.py -h
>
> _______ _______. ______ ___ .__ __.
> / _____| / | / | / \ | \ | | {version:v0.1}
> | | __ | (----`| ,----' / ^ \ | \| |
> | | |_ | \ \ | | / /_\ \ | . ` | {author:咚咚呛}
> | |__| | .----) | | `----. / _____ \ | |\ |
> \______| |_______/ \______|/__/ \__\ |__| \__| http://grayddq.top
>
> Usage: GScan.py [options]
>
> Usage: GScan.py [options]
>
> Options:
>
> -h, --help show this help message and exit
>
> --overseas 境外模式,此参数将不进行境外ip的匹配
>
> --full 完全扫描,此参数将启用完全扫描
>
> --debug 调试模式,进行程序的调试数据输出
>
> -l LOGDIR, --log=LOGDIR 打包当前系统的所有安全日志,demo: -l /var/log/
执行参考:
>
> -h, --help show this help message and exit
> --version 当前程序版本
>
> Mode:
> GScan running mode options
>
> --overseas 境外模式,此参数将不进行境外ip的匹配
> --full 完全模式,此参数将启用完全扫描
> --debug 调试模式,进行程序的调试数据输出
> --dif 差异模式,比对上一次的结果,输出差异结果信息。
> --sug 排查建议,用于对异常点的手工排查建议
> --pro 处理方案,根据异常风险生成初步的处理方案
>
> Optimization:
> Optimization options
>
> --time=TIME 搜索指定时间内主机改动过的所有文件,demo: --time='2019-05-07
> 00:00:00~2019-05-07 23:00:00'
> --job 添加定时任务,用于定时执行程序
> --log 打包当前系统的所有安全日志(暂不支持)

执行命令参考:

>root# <kbd>python GScan.py</kbd>
>
>或者使用nohup后台执行,一段时间后直接查看输出结果./GScan/log/gscan.log
>root# <kbd>python GScan.py --sug --pro</kbd>
>
>root# <kbd>nohup python GScan.py &</kbd>
>进行定时任务设置,异常日志将按行输出到./GScan/log/log.log,可通过syslog等服务同步日志信息。
>
>root# <kbd>python GScan.py --job</kbd> #每天零点执行一次
>
>root# <kbd>python GScan.py --job --hour=2</kbd> #每2小时执行一次
## 程序脚本说明 ##

Expand Down Expand Up @@ -152,9 +176,7 @@
>
>2、程序包括10W+的恶意特征信息,用于恶意文件的比对和查杀。
>
>3、WebShell的检测采用目前比较流行的Yara库进行查杀。
>
>4、结果自动化分析,进行黑客攻击溯源
>3、结果自动化分析,进行黑客攻击溯源


Expand All @@ -174,7 +196,7 @@
|:-------------|:---------: |:------: |:------: |:---------: |
| 对比版本 | v0.1 | v0.53 | v1.4.6 | v2.7.1 |
| 【检测前检查项】文件alias检查 ||| | |
| 【检测前检查项】系统重要文件完整性检测 | || | |
| 【检测前检查项】系统重要文件完整性检测 | || | |
| 【主机文件检测】系统重要文件权限检测 | ||| |
| 【主机文件检测】文件恶意特征扫描 || | | |
| 【主机文件检测】文件境外IP特征扫描 || | | |
Expand Down Expand Up @@ -206,6 +228,7 @@
| 【常规后门检测】Cron后门检测(/etc/cron.hourly/) || | | |
| 【常规后门检测】Cron后门检测(/etc/cron.monthly/) || | | |
| 【常规后门检测】alias后门检测 || || |
| 【常规后门检测】其他环境变量未知后门检测 || | | |
| 【常规后门检测】SSH后门检测 || | | |
| 【常规后门检测】SSH Wrapper后门检测 || | | |
| 【常规后门检测】inetd.conf后门检测 || || |
Expand Down
Binary file added db/.DS_Store
Binary file not shown.
58 changes: 50 additions & 8 deletions lib/core/common.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# coding:utf-8
from __future__ import print_function
import os, sys, json, re, time, pwd
import os, sys, json, re, time, pwd, logging
from imp import reload
from lib.core.ip.ip import *
from lib.core.globalvar import *
Expand Down Expand Up @@ -212,13 +212,17 @@ def gci(filepath):
def mkfile():
SYS_PATH = get_value('SYS_PATH')
LOG_PATH = get_value('LOG_PATH')
if os.path.exists(LOG_PATH):
f = open(LOG_PATH, "r+")
f.truncate()
f.close()
else:
if not os.path.exists(SYS_PATH + '/log/'): os.mkdir(SYS_PATH + '/log/')
f = open(LOG_PATH, "w")
DB_PATH = get_value('DB_PATH')
# 判断日志目录是否存在,不存在则创建日志目录
if not os.path.exists(SYS_PATH + '/log/'): os.mkdir(SYS_PATH + '/log/')
if not os.path.exists(SYS_PATH + '/db/'): os.mkdir(SYS_PATH + '/db/')
# 判断日志文件是否存在,不存在则创建,存在则情况
f = open(LOG_PATH, "w")
f.truncate()
f.close()
# 判断本地数据文件是否存在,不存在则创建
if not os.path.exists(DB_PATH):
f = open(DB_PATH, "w")
f.truncate()
f.close()

Expand Down Expand Up @@ -380,3 +384,41 @@ def analysis_file(file, mode='fast'):
return ""
except:
return ""


# 写定时任务信息
def cron_write(hour='0'):
SYS_PATH = get_value('SYS_PATH')
if not os.path.exists('/var/spool/cron/'): return False
if os.path.exists('/var/spool/cron/root'):
f = open('/var/spool/cron/root', 'a+')
# 每N小时执行一次
if hour != '0':
f.write('* */' + hour + ' * * * python ' + SYS_PATH + '/GScan.py --dif\n')
else:
f.write('0 0 * * * python ' + SYS_PATH + '/GScan.py --dif\n')
f.close()
else:
f = open('/var/spool/cron/root', 'w')
# 每N小时执行一次
if hour != '0':
f.write('* */' + hour + ' * * * python ' + SYS_PATH + '/GScan.py --dif\n')
else:
f.write('0 0 * * * python ' + SYS_PATH + '/GScan.py --dif\n')
f.close()
return True


# 日志输出到指定文件,用于syslog打印
def loging():
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger('GScan')
SYS_PATH = get_value('SYS_PATH')
logfile = SYS_PATH + '/log/log.log'
fh = logging.FileHandler(logfile)
fh.setLevel(logging.INFO)
formatter = logging.Formatter('%(asctime)s - %(message)s')
fh.setFormatter(formatter)
logger.addHandler(fh)
logger.propagate = False
return logger
Loading

0 comments on commit 286fbc0

Please sign in to comment.