关于AWD线下攻防的经验
- # -*- coding: utf-8 -*-
- #use: python file_check.py ./
- import os
- import hashlib
- import shutil
- import ntpath
- import time
- CWD = os.getcwd()
- FILE_MD5_DICT = {} # 文件MD5字典
- ORIGIN_FILE_LIST = []
- # 特殊文件路径字符串
- Special_path_str = 'drops_JWI96TY7ZKNMQPDRUOSG0FLH41A3C5EXVB82'
- bakstring = 'bak_EAR1IBM0JT9HZ75WU4Y3Q8KLPCX26NDFOGVS'
- logstring = 'log_WMY4RVTLAJFB28960SC3KZX7EUP1IHOQN5GD'
- webshellstring = 'webshell_WMY4RVTLAJFB28960SC3KZX7EUP1IHOQN5GD'
- difffile = 'diff_UMTGPJO17F82K35Z0LEDA6QB9WH4IYRXVSCN'
- Special_string = 'drops_log' # 免死金牌
- UNICODE_ENCODING = "utf-8"
- INVALID_UNICODE_CHAR_FORMAT = r"?%02x"
- # 文件路径字典
- spec_base_path = os.path.realpath(os.path.join(CWD, Special_path_str))
- Special_path = {
- 'bak' : os.path.realpath(os.path.join(spec_base_path, bakstring)),
- 'log' : os.path.realpath(os.path.join(spec_base_path, logstring)),
- 'webshell' : os.path.realpath(os.path.join(spec_base_path, webshellstring)),
- 'difffile' : os.path.realpath(os.path.join(spec_base_path, difffile)),
- }
- def isListLike(value):
- return isinstance(value, (list, tuple, set))
- # 获取Unicode编码
- def getUnicode(value, encoding=None, noneToNull=False):
- if noneToNull and value is None:
- return NULL
- if isListLike(value):
- value = list(getUnicode(_, encoding, noneToNull) for _ in value)
- return value
- if isinstance(value, unicode):
- return value
- elif isinstance(value, basestring):
- while True:
- try:
- return unicode(value, encoding or UNICODE_ENCODING)
- except UnicodeDecodeError, ex:
- try:
- return unicode(value, UNICODE_ENCODING)
- except:
- value = value[:ex.start] + "".join(INVALID_UNICODE_CHAR_FORMAT % ord(_) for _ in value[ex.start:ex.end]) + value[ex.end:]
- else:
- try:
- return unicode(value)
- except UnicodeDecodeError:
- return unicode(str(value), errors="ignore")
- # 目录创建
- def mkdir_p(path):
- import errno
- try:
- os.makedirs(path)
- except OSError as exc:
- if exc.errno == errno.EEXIST and os.path.isdir(path):
- pass
- else: raise
- # 获取当前所有文件路径
- def getfilelist(cwd):
- filelist = []
- for root,subdirs, files in os.walk(cwd):
- for filepath in files:
- originalfile = os.path.join(root, filepath)
- if Special_path_str not in originalfile:
- #排除权限不足的文件,一般flag,还有后缀.sh的动不了
- if "flag" not in originalfile and ".sh" not in originalfile:
- filelist.append(originalfile)
- return filelist
- # 计算机文件MD5值
- def calcMD5(filepath):
- try:
- with open(filepath,'rb') as f:
- md5obj = hashlib.md5()
- md5obj.update(f.read())
- hash = md5obj.hexdigest()
- return hash
- except Exception, e:
- print u'[!] getmd5_error : ' + getUnicode(filepath)
- print getUnicode(e)
- try:
- ORIGIN_FILE_LIST.remove(filepath)
- FILE_MD5_DICT.pop(filepath, None)
- except KeyError, e:
- pass
- # 获取所有文件MD5
- def getfilemd5dict(filelist = []):
- filemd5dict = {}
- for ori_file in filelist:
- if Special_path_str not in ori_file:
- md5 = calcMD5(os.path.realpath(ori_file))
- if md5:
- filemd5dict[ori_file] = md5
- return filemd5dict
- # 备份所有文件
- def backup_file(filelist=[]):
- # if len(os.listdir(Special_path['bak'])) == 0:
- for filepath in filelist:
- if Special_path_str not in filepath:
- shutil.copy2(filepath, Special_path['bak'])
- if __name__ == '__main__':
- print u'---------start------------'
- for value in Special_path:
- mkdir_p(Special_path[value])
- # 获取所有文件路径,并获取所有文件的MD5,同时备份所有文件
- ORIGIN_FILE_LIST = getfilelist(CWD)
- FILE_MD5_DICT = getfilemd5dict(ORIGIN_FILE_LIST)
- backup_file(ORIGIN_FILE_LIST) # TODO 备份文件可能会产生重名BUG
- print u'[*] pre work end!'
- while True:
- file_list = getfilelist(CWD)
- # 移除新上传文件
- diff_file_list = list(set(file_list) ^ set(ORIGIN_FILE_LIST))
- if len(diff_file_list) != 0:
- # import pdb;pdb.set_trace()
- for filepath in diff_file_list:
- try:
- f = open(filepath, 'r').read()
- except Exception, e:
- break
- if Special_string not in f:
- try:
- print u'[*] webshell find : ' + getUnicode(filepath)
- shutil.move(filepath, os.path.join(Special_path['webshell'], ntpath.basename(filepath) + '.txt'))
- except Exception as e:
- print u'[!] move webshell error, "%s" maybe is webshell.'%getUnicode(filepath)
- try:
- f = open(os.path.join(Special_path['log'], 'log.txt'), 'a')
- f.write('newfile: ' + getUnicode(filepath) + ' : ' + str(time.ctime()) + 'n')
- f.close()
- except Exception as e:
- print u'[-] log error : file move error: ' + getUnicode(e)
- # 防止任意文件被修改,还原被修改文件
- md5_dict = getfilemd5dict(ORIGIN_FILE_LIST)
- for filekey in md5_dict:
- if md5_dict[filekey] != FILE_MD5_DICT[filekey]:
- try:
- f = open(filekey, 'r').read()
- except Exception, e:
- break
- if Special_string not in f:
- try:
- print u'[*] file had be change : ' + getUnicode(filekey)
- shutil.move(filekey, os.path.join(Special_path['difffile'], ntpath.basename(filekey) + '.txt'))
- shutil.move(os.path.join(Special_path['bak'], ntpath.basename(filekey)), filekey)
- except Exception as e:
- print u'[!] move webshell error, "%s" maybe is webshell.'%getUnicode(filekey)
- try:
- f = open(os.path.join(Special_path['log'], 'log.txt'), 'a')
- f.write('diff_file: ' + getUnicode(filekey) + ' : ' + getUnicode(time.ctime()) + 'n')
- f.close()
- except Exception as e:
- print u'[-] log error : done_diff: ' + getUnicode(filekey)
- pass
- time.sleep(2)
- # print '[*] ' + getUnicode(time.ctime())
关于AWD线下攻防的经验的更多相关文章
- CTF线下攻防赛
SSH登陆 两三个人进行分工,一个粗略的看下web,有登陆口的话,就需要修改密码,将情况反馈给队友,让登陆ssh的小伙伴进行密码的修改,改成炒鸡复杂.然后将Web目录下载下来,上WAF.文件监控.端口 ...
- CTF线下awd攻防文件监控脚本
CTF线下awd攻防赛中常用一个文件监控脚本来保护文件,但是就博主对于该脚本的审计分析 发现如下的问题: 1.记录文件的路径未修改导致log暴露原文件备份文件夹:drops_JWI96TY7ZKNMQ ...
- 线下AWD平台搭建以及一些相关问题解决
线下AWD平台搭建以及一些相关问题解决 一.前言 文章首发于tools,因为发现了一些新问题但是没法改,所以在博客进行补充. 因为很多人可能没有机会参加线下的AWD比赛,导致缺乏这方面经验,比如我参加 ...
- CTF线下赛AWD套路小结
近打了2场CTF线下赛,把AWD模式中的一些小套路做一些总结,本人web狗,二进制部分就不班门弄斧了. 一. AWD模式简介 AWD:Attack With Defence,比赛中每个队伍维护多台服务 ...
- CTF线下赛AWD模式下的生存技巧
作者:Veneno@Nu1L 稿费:200RMB 投稿方式:发送邮件至linwei#360.cn,或登陆网页版在线投稿 原文:https://www.anquanke.com/post/id/8467 ...
- YY一下微信线下支付的场景
在上一篇文章里面提到了 <跨行清算的实现原理>,这次来分析一下线下支付的场景和流程. 今天看到一篇文章:http://www.huxiu.com/article/23248/1.html? ...
- ABP(现代ASP.NET样板开发框架)主题线下交流会(上海)开始报名了!
点这里进入ABP系列文章总目录 ABP主题线下交流会(上海)开始报名了 ABP是“ASP.NET Boilerplate Project (ASP.NET样板项目)”的简称.它是采用最佳实践和流行技术 ...
- MongoDB深圳用户组线下活动召集
MongoDB线下用户组是由全世界MongoDB爱好者发起的不定期线下交流活动.目前全球有100多个MongoDB用户组,3万5千多爱好者参与.用户组活动的形式通常会有一到两个MongoDB相关的技术 ...
- .NET Core 成都线下面基会拉开序幕
2017年07月29日下午,由 .NET China Foundation 成都小组组织的 .NET Core 成都地区线下技术交流会在成都成华区某茶楼成功举行,这也是成都地区 .NET Core 非 ...
随机推荐
- iPython的安装过程
http://blog.csdn.net/u012587561/article/details/50900781 python2.7.10 amd64 win10 x64 1. 安装setuptool ...
- supersocket Silverlight 策略服务器
<?xml version="1.0"?> <configuration> <configSections> <section name= ...
- [转]Android Studio实现代码混淆
1,在build.grandle添加,其中规则写在proguard-rules.pro中,也可以自定义一个文件,将其代替,比如eclipse常用的 proguard-project.txt: bui ...
- Python--day69--单表查询之神奇的双下划线
单表查询之神奇的双下划线: 单表查询之神奇的双下划线 models.Tb1.objects.filter(id__lt=10, id__gt=1) # 获取id大于1 且 小于10的值 models. ...
- Scrap简介
原文:https://blog.csdn.net/ssw_1990/article/details/51254227 提到Python与网络爬虫,可能会想到urllib,urllib2,Beautif ...
- CSS 实现单行及多行文字省略
单行文字省略 很多时候不确定字数限制,但换行可能影响整体设计,这个时候常用就是文字省略加全文字提示了 .dom{ text-overflow: ellipsis; overflow: hidden; ...
- jquery自己写的幻灯片插件,好用不解释
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- dotnet 通过 WMI 获取设备厂商
本文告诉大家如何通过 WMI 获取设备厂商 通过 Win32_ComputerSystem 可以获取电脑系统信息 通过下面代码可以获取 机器型号 和 制造厂商 var mc = "Win32 ...
- js算法(1)
数组排序 arr.sort(function compare(a,b){return b.value-a.value}); json 排序 $.getJSON('URl',function(data) ...
- 为什么我们要使用DTO
基础结构解释 UI-表现层-与控制器打交道(UI向Controller 传递数据时使用DTO(数据传输对象)) Service-应用服务层 Domain 领域对象 DTO 数据传输对象,一般只包含基础 ...