5 Star 20 Fork 0

wildlinux / NetSec

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
0x25_MAL_动态分析__Windows计划任务schtasks.md 6.96 KB
一键复制 编辑 原始数据 按行查看 历史
wildlinux 提交于 2020-03-15 20:32 . 202003

1. 恶意代码的概念与分类

2. 恶意代码的分析方法

2.1. 静态分析

2.2. 动态分析

3. Windows计划任务schtasks

学习内容:windows计划任务+sysmon 监控系统
学习目标:通过计划任务建立一个简单的系网络监控脚本
最后编辑:20170327 Wildlinux

3.1. 指令说明

官方文档,该指令功能等同于 控制面板-Windows计划任务。

3.2. 简单实现

一个简单的实现,每5分钟记录一下有哪些程序在连接网络。


C:\schtasks /create /TN netstat /sc MINUTE /MO 5 /TR "cmd /c netstat -bn > c:\netstatlog.txt"

任务将创建于当前登录的用户名("ICST-WINATT\Administrator")下。
请输入 ICST-WINATT\Administrator 的密码: ********

成功: 成功创建计划任务 "netstat"

参数在官方文档中都有详细说明,上一条指令中用到解释如下:
> 
> TN:Task Name,本例中是netstat
> SC: SChedule type,本例中是MINUTE,以分钟来计时
> MO: MOdifier
> TR: Task Run,要运行的指令是 netstat -bn,b表示显示可执行文件名,n表示以数字来显示IP和端口

windows计划任务图形界面可实现同样的功能。

3.3. 批处理

我们再加工一下,在C盘要目录下建一个文件c:\netstatlog.bat,内容如下:

date /t >> c:\netstatlog.txt
time /t >> c:\netstatlog.txt
netstat -bn >> c:\netstatlog.txt

可以在图形界面打开计划任务,将其中每5分钟执行的指令从"cmd /c netstat -bn > c:\netstatlog.txt"替换为“c:\netstatlog.bat”。更改完后,我们在netstatlog.txt中会看到如下的输出,多了日期与时间,这样看起来更方便。

2017-03-27 星期一 
13:05

Active Connections

  Proto  Local Address          Foreign Address        State           PID
  TCP    127.0.0.1:3018         127.0.0.1:14147        ESTABLISHED     1116
  [FileZilla Server Interface.exe]

  TCP    127.0.0.1:14147        127.0.0.1:3018         ESTABLISHED     1392
  [FileZilla Server.exe]

  TCP    127.0.0.1:5152         127.0.0.1:2312         CLOSE_WAIT      1460
  [jqs.exe]

2017-03-27 星期一 
13:10

Active Connections

  Proto  Local Address          Foreign Address        State           PID
  TCP    127.0.0.1:3018         127.0.0.1:14147        ESTABLISHED     1116
  [FileZilla Server Interface.exe]

  TCP    127.0.0.1:14147        127.0.0.1:3018         ESTABLISHED     1392
  [FileZilla Server.exe]

  TCP    127.0.0.1:5152         127.0.0.1:2312         CLOSE_WAIT      1460
  [jqs.exe]

上面生成的文件是非常基础的文件,如果抓取一天的数据,真要人工分析是很费力的。这个时候如果是我的话,我会选两种可能的处理方式:(1)把这样的日志copy到Linux,用grep,cut等文本处理工具来分析;(2)在windows里的话,最好复制到excel中,再看如何统计分析。主要是目的是为了找出哪些软件连网最多,都连接了哪些IP,把没用的重复项都去掉。

3.4. Sysmon

Sysmon是微软Sysinternals套件中的一个工具。可以监控几乎所有的重要操作。

说明可参考freebuf的一篇文档官方文档

基本操作可以描述为三步

3.4.1. 确定要监控的目标

我感兴趣的是驱动加载、网络连接、线程注入。过滤条件相当于白名单吧,多多益善,让信任的程序尽量不要记到日志里,日志多了不好分析。

3.4.2. 写好配置文件

你想记录所有网络连接就可以简单写为<NetworkConnect>*</NetworkConnect>,不写的不记录。一般都是写成类似下面的规则,会过滤掉一些。exclude相当于白名单,不用记录。include相当于黑名单。个人觉得一般人使用白名单更安全,凡是不了解都记录。

下面是我用的配置文件C:\Sysmoncfg.txt。配置文件是xml文件,我为了简单编辑就直接命令为.txt,每次用写字本打开。

<Sysmon schemaversion="3.10">
  <!-- Capture all hashes -->
  <HashAlgorithms>*</HashAlgorithms>
  <EventFiltering>
    <!-- Log all drivers except if the signature -->
    <!-- contains Microsoft or Windows -->
    <DriverLoad onmatch="exclude">
      <Signature condition="contains">microsoft</Signature>
      <Signature condition="contains">windows</Signature>
    </DriverLoad>
    
    <NetworkConnect onmatch="exclude">
      <Image condition="end with">chrome.exe</Image>
      <Image condition="end with">iexplorer.exe</Image>
      <SourcePort condition="is">137</SourcePort>
      <SourceIp condition="is">127.0.0.1</SourceIp>
    </NetworkConnect>

    <CreateRemoteThread onmatch="include">
      <TargetImage condition="end with">explorer.exe</TargetImage>
      <TargetImage condition="end with">svchost.exe</TargetImage>
      <TargetImage condition="end with">winlogon.exe</TargetImage>
      <SourceImage condition="end with">powershell.exe</SourceImage>
    </CreateRemoteThread>
  </EventFiltering>
</Sysmon>

规则大小写敏感,开始时<SourceIp condition="is">127.0.0.1</SourceIp>误写成<SourceIP condition="is">127.0.0.1</SourceIP>,导致不认配置文件,其中P应该小写。

3.4.3. 启动sysmon

安装sysmon:sysmon.exe -i config_file_name.

因为我安装过了,所以先停止服务,再安装一次。

Microsoft Windows [版本 6.1.7600]
版权所有 (c) 2009 Microsoft Corporation。保留所有权利。

Z:\SysinternalsSuite201608>Sysmon.exe -u

System Monitor v4.12 - System activity monitor
Copyright (C) 2014-2016 Mark Russinovich and Thomas Garnier
Sysinternals - www.sysinternals.com

Stopping Sysmon..
Sysmon stopped.
Sysmon removed.
Stopping SysmonDrv.
SysmonDrv stopped.
SysmonDrv removed.
Removing service files

Z:\SysinternalsSuite201608>Sysmon.exe -i C:\Sysmoncfg.txt


System Monitor v4.12 - System activity monitor
Copyright (C) 2014-2016 Mark Russinovich and Thomas Garnier
Sysinternals - www.sysinternals.com

Loading configuration file with schema version 3.10
Configuration file successfully applied.
Sysmon installed.
SysmonDrv installed.
Starting SysmonDrv.
SysmonDrv started.
Starting Sysmon..
Sysmon started.

配置文件可以随时修改,修改完需要用如下指令更新一下sysmon.exe -c config_file_name

Z:\SysinternalsSuite201608>Sysmon.exe -c C:\Sysmoncfg.txt


System Monitor v4.12 - System activity monitor
Copyright (C) 2014-2016 Mark Russinovich and Thomas Garnier
Sysinternals - www.sysinternals.com

Loading configuration file with schema version 3.10
Configuration file successfully applied.
Configuration updated.

3.4.4. 然后就可以在 事件查看器 里找到日志了

图懒得抓了。日志在事件日志的“Applications and Services Logs/Microsoft/Windows/Sysmon/Operational”下,如果你的系统是中文,那就找对应的翻译。

Win7实测可用。

1
https://gitee.com/wildlinux/NetSec.git
git@gitee.com:wildlinux/NetSec.git
wildlinux
NetSec
NetSec
master

搜索帮助