Subversion Repositories php-qbpwcf

Rev

Rev 350 | Rev 371 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 350 Rev 368
Line 23128... Line 23128...
23128
			#回傳結果
23128
			#回傳結果
23129
			return $result;
23129
			return $result;
23130
 
23130
 
23131
			}#if end
23131
			}#if end
23132
 
23132
 
23133
		#取得 http 存取記錄的 log
-
 
23134
		#函式說明:
-
 
23135
		#檢查指令的輸出是否含有關鍵字
-
 
23136
		#回傳結果:
-
 
23137
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
23138
		#$result["error"],錯誤訊息.
-
 
23139
		#$result["function"],當前執行的函式名稱.
-
 
23140
		#$result["argu"],使用的參數.
-
 
23141
		#$result["grepCmd"],截取關鍵字的指令.
-
 
23142
		#$result["founded"],是否找到關鍵字,"true"代表有,"false"代表沒有.
-
 
23143
		#$result["content"],關鍵字所在列的輸出.
-
 
23144
		#$result["count"],輸出的列數.
-
 
23145
		#必填參數:
-
 
23146
		#$conf["cmd"],字串,要執行的指令.
-
 
23147
		$conf["cmd::searchOutPut"]["cmd"]="cat";
-
 
23148
		#$conf["keyWord"],字串,要檢查是否有關鍵字.
-
 
23149
		$conf["cmd::searchOutPut"]["keyWord"]=" 404 ";
-
 
23150
		#$conf["fileArgu"],字串,變數__FILE__的內容.
-
 
23151
		$conf["cmd::searchOutPut"]["fileArgu"]=$conf["fileArgu"];
-
 
23152
		#可省略參數:
-
 
23153
		#$conf["binPath"],字串,應用程式的路徑,預設為"/usr/bin".
-
 
23154
		#$conf["binPath"]="";
-
 
23155
		#$conf["argu"],陣列字串,指令搭配的參數,預設不使用.
-
 
23156
		$conf["cmd::searchOutPut"]["argu"]=array($conf["logPath"]."/access_log");
-
 
23157
		#$conf["excludeGrep"],字串,"true"代表排除含有 " | grep ".$conf["keyWord"] 字樣的輸出;預設為"false",不排除.
-
 
23158
		#$conf["excludeGrep"]="false";
-
 
23159
 
-
 
23160
		#如果有設置 username
-
 
23161
		if(isset($conf["username"])){
-
 
23162
 
-
 
23163
			#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
-
 
23164
			$conf["cmd::searchOutPut"]["username"]=$conf["username"];
-
 
23165
 
-
 
23166
			}#if end
-
 
23167
 
-
 
23168
		#如果有設置 password
-
 
23169
		if(isset($conf["password"])){
-
 
23170
 
-
 
23171
			#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
-
 
23172
			$conf["cmd::searchOutPut"]["password"]=$conf["password"];
-
 
23173
 
-
 
23174
			}#if end
-
 
23175
 
-
 
23176
		$searchOutPut=cmd::searchOutPut($conf["cmd::searchOutPut"]);
-
 
23177
		unset($conf["cmd::searchOutPut"]);
-
 
23178
 
-
 
23179
		#如果執行失敗
-
 
23180
		if($searchOutPut["status"]==="false"){
-
 
23181
 
-
 
23182
			#設置執行失敗
-
 
23183
			$result["status"]="false";
-
 
23184
 
-
 
23185
			#設置錯誤訊息
-
 
23186
			$result["error"]=$searchOutPut;
-
 
23187
 
-
 
23188
			#回傳結果
-
 
23189
			return $result;
-
 
23190
 
-
 
23191
			}#if end
-
 
23192
 
-
 
23193
		#過濾掉對於含有 ".css" ".js" "favicon.ico" ".jpg" ".png" 關鍵字串的結果.
-
 
23194
		#函式說明:
-
 
23195
		#檢查多個字串中的每個字串是否有多個關鍵字
-
 
23196
		#回傳的結果:
-
 
23197
		#$result["status"],整體來說,執行是否成功,"true"代表執行成功,"false"代表執行失敗。
-
 
23198
		#$result["function"],當前執行的函式名稱.
-
 
23199
		#$result["error"],錯誤訊息.
-
 
23200
		#$result["argu"],使用的參數.
-
 
23201
		#$result["foundedTrueKey"],結果為"true"的被搜尋元素key陣列.
-
 
23202
		#$result["foundedKeyWords"].找到的關鍵字.
-
 
23203
		#$result["foundedFalseKey"],結果為"false"的被搜尋元素key陣列.
-
 
23204
		#$result["foundedTrueKeyWords"],二維陣列,各個字串有找到的關鍵字陣列.
-
 
23205
		#$result["foundedAll"],是否每個關鍵字都有找到,"true"代表每個都有找到,"false"代表沒有每個都找到.
-
 
23206
		#必填參數:
-
 
23207
		$conf["search::findManyKeyWordsFromManyString"]["keyWords"]=array(".css",".js","favicon.ico",".jpg",".png");#想要搜尋的關鍵字
-
 
23208
		$conf["search::findManyKeyWordsFromManyString"]["stringArray"]=$searchOutPut["content"];#要被搜尋的字串內容陣列
-
 
23209
		#可省略參數:
-
 
23210
		#$conf["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為"false"不需要完全符合.
-
 
23211
		$findManyKeyWordsFromManyString=search::findManyKeyWordsFromManyString($conf["search::findManyKeyWordsFromManyString"]);
-
 
23212
		unset($conf["search::findManyKeyWordsFromManyString"]);
-
 
23213
 
-
 
23214
		#如果執行出錯
-
 
23215
		if($findManyKeyWordsFromManyString["status"]==="false"){
-
 
23216
 
-
 
23217
			#設置執行失敗
-
 
23218
			$result["status"]="false";
-
 
23219
 
-
 
23220
			#設置錯誤訊息
-
 
23221
			$result["error"]=$findManyKeyWordsFromManyString;
-
 
23222
 
-
 
23223
			#回傳結果
-
 
23224
			return $result;
-
 
23225
 
-
 
23226
			}#if end
-
 
23227
 
-
 
23228
		#取得不含有 ".css" ".js" "favicon.ico" ".jpg" ".png" 關鍵字串的結果.
-
 
23229
		$searchOutPut["content"]=$findManyKeyWordsFromManyString["foundedFalseKey"];
-
 
23230
 
-
 
23231
		#更新計數
-
 
23232
		$searchOutPut["count"]=count($searchOutPut["content"]);
-
 
23233
 
-
 
23234
		#用空格分割字串
-
 
23235
		#函式說明:
-
 
23236
		#將多個固定格式的字串分開,並回傳分開的結果
-
 
23237
		#回傳的參數:
-
 
23238
		#$result["status"],執行成功與否,若爲"true",代表執行成功,若爲"false"代表執失敗。
-
 
23239
		#$result["error"],錯誤訊息陣列.
-
 
23240
		#$result["function"],當前執行的函式名稱.
-
 
23241
		#$result["spiltString"][$i]["oriStr"],爲第i個字串的原始內容
-
 
23242
		#$result["spiltString"][$i]["dataArray"],爲第($i+1)個字串分割後的字串陣列
-
 
23243
		#$result["spiltString"][$i]["dataArray"][$j],爲第($i+1)的分割好的字串的第($j+1)段內容
-
 
23244
		#$result["spiltString"][$i]["dataCounts"],爲第($i+1)個字串分割後總共分成幾段
-
 
23245
		#必填參數:
-
 
23246
		#$conf["stringIn"],字串陣列,要處理的字串陣列.
-
 
23247
		$conf["stringProcess::spiltMutiString"]["stringIn"]=$searchOutPut["content"];
-
 
23248
		#$conf["spiltSymbol"],字串,爲要以哪個符號作爲分割.
-
 
23249
		$conf["stringProcess::spiltMutiString"]["spiltSymbol"]=" ";
-
 
23250
		$spiltMutiString=stringProcess::spiltMutiString($conf["stringProcess::spiltMutiString"]);
-
 
23251
		unset($conf["stringProcess::spiltMutiString"]);
-
 
23252
 
-
 
23253
		#如果分割失敗
-
 
23254
		if($spiltMutiString["status"]==="false"){
-
 
23255
 
-
 
23256
			#設置執行失敗
-
 
23257
			$result["status"]="false";
-
 
23258
 
-
 
23259
			#設置錯誤訊息
-
 
23260
			$result["error"]=$spiltMutiString;
-
 
23261
 
-
 
23262
			#回傳結果
-
 
23263
			return $result;
-
 
23264
 
-
 
23265
			}#if end
-
 
23266
 
-
 
23267
		#初始化儲存有問題IP的陣列
23133
		#初始化要檢查的服務清單
23268
		$ips=array();
-
 
23269
 
-
 
23270
		#初始化儲存可能有問題的IP陣列
-
 
23271
		$ips_byIp=array();
23134
		$service2check=array();
23272
 
-
 
23273
		#針對每行內容
-
 
23274
		for($i=0;$i<$searchOutPut["count"];$i++){
-
 
23275
 
-
 
23276
			#如果沒有分割出來的內容
-
 
23277
			if($spiltMutiString["spiltString"][$i]["dataCounts"]===0){
-
 
23278
 
-
 
23279
				#換下一個
-
 
23280
				continue;
-
 
23281
 
-
 
23282
				}#if end
-
 
23283
 
-
 
23284
			#有問題的資訊
-
 
23285
			$info=array();
-
 
23286
 
-
 
23287
			#設置問題對應的log行內容
-
 
23288
			$info["log"]=$spiltMutiString["spiltString"][$i]["oriStr"];
-
 
23289
 
-
 
23290
			#設置問題時間點
-
 
23291
			$info["time"]=$spiltMutiString["spiltString"][$i]["dataArray"][3];
-
 
23292
 
-
 
23293
			#記錄有問題的ip
-
 
23294
			$info["ip"]=$spiltMutiString["spiltString"][$i]["dataArray"][0];
-
 
23295
 
-
 
23296
			#取得可能有問題的IP位置資訊
-
 
23297
			$ips_byIp[$spiltMutiString["spiltString"][$i]["dataArray"][0]][]=$info;
-
 
23298
 
-
 
23299
			}#for end
-
 
23300
 
-
 
23301
		#針對每個可能有問題的IP
-
 
23302
		foreach($ips_byIp as $ip => $infos){
-
 
23303
 
-
 
23304
			#計數 ip 於同時間前來的計數
-
 
23305
			$ipSameTimeCount=0;
-
 
23306
 
-
 
23307
			#用來存放來存取的同一時間
-
 
23308
			$ipSameTime="";
-
 
23309
 
-
 
23310
			#看來拜訪的時間點
-
 
23311
			foreach($infos as $info){
-
 
23312
 
-
 
23313
				#如果是初次
-
 
23314
				if($ipSameTime===""){
-
 
23315
 
-
 
23316
					#記錄時間點
-
 
23317
					$ipSameTime=$info["time"];
-
 
23318
 
-
 
23319
					#同時間點計數加1
-
 
23320
					$ipSameTimeCount++;
-
 
23321
 
-
 
23322
					}#if end
-
 
23323
 
-
 
23324
				#反之如果時間點相同
-
 
23325
				else if($ipSameTime===$info["time"]){
-
 
23326
 
23135
 
23327
					#同時間點計數加1
23136
		#新增 http 服務
23328
					$ipSameTimeCount++;
23137
		$service2check[]="http";
23329
 
23138
		
23330
					}#if end
23139
		#新增 https 服務
-
 
23140
		$service2check[]="https";
23331
 
23141
		
23332
				#反之時間點不相同
23142
		#新增 postfix 服務
23333
				else{
23143
		$service2check[]="postfix";
23334
 
23144
		
23335
					#記錄時間點
23145
		#新增 named 服務
23336
					$ipSameTime=$info["time"];
23146
		$service2check[]="named";
23337
 
23147
		
23338
					#同時間點計數重設為1
23148
		#新增 docevot 服務
23339
					$ipSameTimeCount=1;
23149
		$service2check[]="dovecot";
23340
 
23150
		
23341
					}#else end
23151
		#新增 ssh 服務
-
 
23152
		$service2check[]="ssh";
23342
 
23153
 
23343
				#如果同時間的計數達到3
23154
		#針對每個要檢查的服務
23344
				if($ipSameTimeCount===3){
23155
		foreach($service2check as $index => $serviceName){
23345
 
23156
		
23346
					#初始化暫存的陣列
23157
			#判斷服務的名稱
-
 
23158
			switch($serviceName){
-
 
23159
			
-
 
23160
				#如果是 http 服務
23347
					$tmp=array();
23161
				case "http":
23348
					
23162
				
23349
					#儲存資訊
23163
					#函式說明:
-
 
23164
					#檢查 apache http(s) log 中疑似攻擊的記錄.
-
 
23165
					#回傳結果:
-
 
23166
					#$result["status"],字串,執行是否正常,"true"代表正常,"false"代表不正常.
-
 
23167
					#$result["error"],錯誤訊息陣列.
-
 
23168
					#$result["function"],字串,當前執行的函式名稱.
-
 
23169
					#$result["content"],陣列,攻擊記錄資訊,每個元素為陣列key為"ip"者為攻擊者的ip;key為info者為其資訊陣列,其key為"log"者代表log的行內容;key為"time"者代表時間點;key為ip者代表ip.
-
 
23170
					#必填參數:
-
 
23171
					#無.
-
 
23172
					#可省略參數:
-
 
23173
					#$conf["logPath"],http log的路徑,預設為"/var/log/httpd".
-
 
23174
					$conf["cmd::checkHttpAttackLog"]["logPath"]=$conf["logPath"];
-
 
23175
					#$conf["https"],字串,是否為要查https的log,預設為"false",代表為http.
23350
					$tmp["info"]=$infos;
23176
					#$conf["https"]="false";
-
 
23177
					#參考資料:
-
 
23178
					#無.
-
 
23179
					#備註:
-
 
23180
					#目前僅支援 apache 提供的 http 服務.
-
 
23181
					#攻擊者的定義為http回應的code為4開頭,且時間間隔不超過1秒鐘,次數達到3次.
-
 
23182
					$checkHttpAttackLog=security::checkHttpAttackLog($conf["cmd::checkHttpAttackLog"]);
-
 
23183
					unset($conf["cmd::checkHttpAttackLog"]);
23351
					
23184
					
23352
					#儲存ip
-
 
23353
					$tmp["ip"]=$info["ip"];
-
 
23354
 
-
 
23355
					#取得有問題的IP
-
 
23356
					$ips[]=$tmp;
-
 
23357
 
-
 
23358
					#換檢查下一個IP
-
 
23359
					continue 2;
-
 
23360
 
-
 
23361
					}#if end
-
 
23362
 
-
 
23363
				}#foreach end
-
 
23364
 
-
 
23365
			}#foreach end
-
 
23366
 
-
 
23367
		#取得 https 存取記錄的 log
-
 
23368
		#函式說明:
-
 
23369
		#檢查指令的輸出是否含有關鍵字
-
 
23370
		#回傳結果:
-
 
23371
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
23372
		#$result["error"],錯誤訊息.
-
 
23373
		#$result["function"],當前執行的函式名稱.
-
 
23374
		#$result["argu"],使用的參數.
-
 
23375
		#$result["grepCmd"],截取關鍵字的指令.
-
 
23376
		#$result["founded"],是否找到關鍵字,"true"代表有,"false"代表沒有.
-
 
23377
		#$result["content"],關鍵字所在列的輸出.
-
 
23378
		#$result["count"],輸出的列數.
-
 
23379
		#必填參數:
-
 
23380
		#$conf["cmd"],字串,要執行的指令.
-
 
23381
		$conf["cmd::searchOutPut"]["cmd"]="cat";
-
 
23382
		#$conf["keyWord"],字串,要檢查是否有關鍵字.
-
 
23383
		$conf["cmd::searchOutPut"]["keyWord"]=" 404 ";
-
 
23384
		#$conf["fileArgu"],字串,變數__FILE__的內容.
-
 
23385
		$conf["cmd::searchOutPut"]["fileArgu"]=$conf["fileArgu"];
-
 
23386
		#可省略參數:
-
 
23387
		#$conf["binPath"],字串,應用程式的路徑,預設為"/usr/bin".
-
 
23388
		#$conf["binPath"]="";
-
 
23389
		#$conf["argu"],陣列字串,指令搭配的參數,預設不使用.
-
 
23390
		$conf["cmd::searchOutPut"]["argu"]=array($conf["logPath"]."/ssl_access_log");
-
 
23391
		#$conf["excludeGrep"],字串,"true"代表排除含有 " | grep ".$conf["keyWord"] 字樣的輸出;預設為"false",不排除.
-
 
23392
		#$conf["excludeGrep"]="false";
-
 
23393
 
-
 
23394
		#如果有設置 username
-
 
23395
		if(isset($conf["username"])){
-
 
23396
 
-
 
23397
			#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
-
 
23398
			$conf["cmd::searchOutPut"]["username"]=$conf["username"];
-
 
23399
 
-
 
23400
			}#if end
-
 
23401
 
-
 
23402
		#如果有設置 password
-
 
23403
		if(isset($conf["password"])){
-
 
23404
 
-
 
23405
			#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
-
 
23406
			$conf["cmd::searchOutPut"]["password"]=$conf["password"];
-
 
23407
 
-
 
23408
			}#if end
-
 
23409
 
-
 
23410
		$searchOutPut=cmd::searchOutPut($conf["cmd::searchOutPut"]);
-
 
23411
		unset($conf["cmd::searchOutPut"]);
-
 
23412
 
-
 
23413
		#如果執行失敗
-
 
23414
		if($searchOutPut["status"]==="false"){
-
 
23415
 
-
 
23416
			#設置執行失敗
-
 
23417
			$result["status"]="false";
-
 
23418
 
-
 
23419
			#設置錯誤訊息
-
 
23420
			$result["error"]=$searchOutPut;
-
 
23421
 
-
 
23422
			#回傳結果
-
 
23423
			return $result;
-
 
23424
 
-
 
23425
			}#if end
-
 
23426
 
-
 
23427
		#過濾掉對於含有 ".css",".js","favicon.ico",".jpg",".png" 關鍵字串的結果.
-
 
23428
		#函式說明:
-
 
23429
		#檢查多個字串中的每個字串是否有多個關鍵字
-
 
23430
		#回傳的結果:
-
 
23431
		#$result["status"],整體來說,執行是否成功,"true"代表執行成功,"false"代表執行失敗。
-
 
23432
		#$result["function"],當前執行的函式名稱.
-
 
23433
		#$result["error"],錯誤訊息.
-
 
23434
		#$result["argu"],使用的參數.
-
 
23435
		#$result["foundedTrueKey"],結果為"true"的被搜尋元素key陣列.
-
 
23436
		#$result["foundedKeyWords"].找到的關鍵字.
-
 
23437
		#$result["foundedFalseKey"],結果為"false"的被搜尋元素key陣列.
-
 
23438
		#$result["foundedTrueKeyWords"],二維陣列,各個字串有找到的關鍵字陣列.
-
 
23439
		#$result["foundedAll"],是否每個關鍵字都有找到,"true"代表每個都有找到,"false"代表沒有每個都找到.
-
 
23440
		#必填參數:
-
 
23441
		$conf["search::findManyKeyWordsFromManyString"]["keyWords"]=array(".css",".js","favicon.ico",".jpg",".png");#想要搜尋的關鍵字
-
 
23442
		$conf["search::findManyKeyWordsFromManyString"]["stringArray"]=$searchOutPut["content"];#要被搜尋的字串內容陣列
-
 
23443
		#可省略參數:
-
 
23444
		#$conf["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為"false"不需要完全符合.
-
 
23445
		$findManyKeyWordsFromManyString=search::findManyKeyWordsFromManyString($conf["search::findManyKeyWordsFromManyString"]);
-
 
23446
		unset($conf["search::findManyKeyWordsFromManyString"]);
-
 
23447
 
-
 
23448
		#如果執行出錯
23185
					#如果執行異常
23449
		if($findManyKeyWordsFromManyString["status"]==="false"){
-
 
23450
 
-
 
23451
			#設置執行失敗
-
 
23452
			$result["status"]="false";
-
 
23453
 
-
 
23454
			#設置錯誤訊息
-
 
23455
			$result["error"]=$findManyKeyWordsFromManyString;
-
 
23456
 
-
 
23457
			#回傳結果
-
 
23458
			return $result;
-
 
23459
 
-
 
23460
			}#if end
-
 
23461
 
-
 
23462
		#取得不含有 ".css",".js","favicon.ico",".jpg",".png" 關鍵字串的結果.
-
 
23463
		$searchOutPut["content"]=$findManyKeyWordsFromManyString["foundedFalseKey"];
-
 
23464
 
-
 
23465
		#更新計數
-
 
23466
		$searchOutPut["count"]=count($searchOutPut["content"]);
-
 
23467
 
-
 
23468
		#用空格分割字串
-
 
23469
		#函式說明:
-
 
23470
		#將多個固定格式的字串分開,並回傳分開的結果
-
 
23471
		#回傳的參數:
-
 
23472
		#$result["status"],執行成功與否,若爲"true",代表執行成功,若爲"false"代表執失敗。
-
 
23473
		#$result["error"],錯誤訊息陣列.
-
 
23474
		#$result["function"],當前執行的函式名稱.
-
 
23475
		#$result["spiltString"][$i]["oriStr"],爲第i個字串的原始內容
-
 
23476
		#$result["spiltString"][$i]["dataArray"],爲第($i+1)個字串分割後的字串陣列
-
 
23477
		#$result["spiltString"][$i]["dataArray"][$j],爲第($i+1)的分割好的字串的第($j+1)段內容
-
 
23478
		#$result["spiltString"][$i]["dataCounts"],爲第($i+1)個字串分割後總共分成幾段
-
 
23479
		#必填參數:
-
 
23480
		#$conf["stringIn"],字串陣列,要處理的字串陣列.
-
 
23481
		$conf["stringProcess::spiltMutiString"]["stringIn"]=$searchOutPut["content"];
-
 
23482
		#$conf["spiltSymbol"],字串,爲要以哪個符號作爲分割.
-
 
23483
		$conf["stringProcess::spiltMutiString"]["spiltSymbol"]=" ";
-
 
23484
		$spiltMutiString=stringProcess::spiltMutiString($conf["stringProcess::spiltMutiString"]);
-
 
23485
		unset($conf["stringProcess::spiltMutiString"]);
-
 
23486
 
-
 
23487
		#如果分割失敗
-
 
23488
		if($spiltMutiString["status"]==="false"){
23186
					if($checkHttpAttackLog["status"]==="false"){
23489
 
-
 
23490
			#設置執行失敗
-
 
23491
			$result["status"]="false";
-
 
23492
 
-
 
23493
			#設置錯誤訊息
-
 
23494
			$result["error"]=$spiltMutiString;
-
 
23495
 
-
 
23496
			#回傳結果
-
 
23497
			return $result;
-
 
23498
 
-
 
23499
			}#if end
-
 
23500
 
-
 
23501
		#初始化儲存有問題IP的陣列
-
 
23502
		$ips_https=array();
-
 
23503
 
-
 
23504
		#初始化儲存可能有問題的IP陣列
-
 
23505
		$ips_byIp_https=array();
-
 
23506
 
-
 
23507
		#針對每行內容
-
 
23508
		for($i=0;$i<$searchOutPut["count"];$i++){
-
 
23509
 
-
 
23510
			#如果沒有分割出來的內容
-
 
23511
			if($spiltMutiString["spiltString"][$i]["dataCounts"]===0){
-
 
23512
 
-
 
23513
				#換下一個
-
 
23514
				continue;
-
 
23515
 
-
 
23516
				}#if end
-
 
23517
 
-
 
23518
			#有問題的資訊
-
 
23519
			$info=array();
-
 
23520
 
-
 
23521
			#設置問題對應的log行內容
-
 
23522
			$info["log"]=$spiltMutiString["spiltString"][$i]["oriStr"];
-
 
23523
 
-
 
23524
			#設置問題時間點
-
 
23525
			$info["time"]=$spiltMutiString["spiltString"][$i]["dataArray"][3];
-
 
23526
 
-
 
23527
			#記錄有問題的ip
-
 
23528
			$info["ip"]=$spiltMutiString["spiltString"][$i]["dataArray"][0];
-
 
23529
 
-
 
23530
			#取得可能有問題的IP位置,key為[ip][int]
-
 
23531
			$ips_byIp_https[$spiltMutiString["spiltString"][$i]["dataArray"][0]][]=$info;
-
 
23532
 
-
 
23533
			}#for end
-
 
23534
 
-
 
23535
		#debug
-
 
23536
		#var_dump(__LINE__,"http待整理的可能有問題IP清單",$ips_byIp_https);
-
 
23537
 
-
 
23538
		#針對每個可能有問題的IP
-
 
23539
		foreach($ips_byIp_https as $infos){
-
 
23540
 
-
 
23541
			#計數 ip 於同時間前來的計數
-
 
23542
			$ipSameTimeCount=0;
-
 
23543
 
-
 
23544
			#用來存放來存取的同一時間
-
 
23545
			$ipSameTime="";
-
 
23546
 
23187
 
23547
			#看來拜訪的時間點
-
 
23548
			foreach($infos as $info){
-
 
23549
 
-
 
23550
				#如果是初次
-
 
23551
				if($ipSameTime===""){
-
 
23552
 
-
 
23553
					#記錄時間點
23188
						#設置執行失敗
23554
					$ipSameTime=$info["time"];
-
 
23555
 
-
 
23556
					#同時間點計數加1
-
 
23557
					$ipSameTimeCount++;
-
 
23558
 
-
 
23559
					}#if end
-
 
23560
 
-
 
23561
				#反之如果時間點相同
-
 
23562
				else if($ipSameTime===$info["time"]){
-
 
23563
 
-
 
23564
					#同時間點計數加1
-
 
23565
					$ipSameTimeCount++;
-
 
23566
 
-
 
23567
					}#if end
-
 
23568
 
-
 
23569
				#反之時間點不相同
-
 
23570
				else{
-
 
23571
 
-
 
23572
					#記錄時間點
-
 
23573
					$ipSameTime=$info["time"];
23189
						$result["status"]="false";
23574
 
-
 
23575
					#同時間點計數重設為1
-
 
23576
					$ipSameTimeCount=1;
-
 
23577
 
-
 
23578
					}#else end
-
 
23579
 
23190
 
23580
				#如果同時間的計數達到3
23191
						#設置錯誤訊息
23581
				if($ipSameTimeCount===3){
23192
						$result["error"]=$checkHttpAttackLog;
23582
 
23193
 
23583
					#初始化暫存的陣列
23194
						#回傳結果
23584
					$tmp=array();
23195
						return $result;
23585
 
23196
 
23586
					#取得事件資訊
-
 
23587
					$tmp["info"]=$infos;
23197
						}#if end
23588
					
23198
					
23589
					#取得ip
-
 
23590
					$tmp["ip"]=$info["ip"];
-
 
23591
 
-
 
23592
					#取得有問題的IP資訊
23199
					#取得有問題的 http log 記錄
23593
					$ips_https[]=$tmp;
-
 
23594
 
-
 
23595
					#換檢查下一個IP
-
 
23596
					continue 2;
-
 
23597
 
-
 
23598
					}#if end
-
 
23599
 
-
 
23600
				}#foreach end
-
 
23601
 
-
 
23602
			}#foreach end
-
 
23603
 
-
 
23604
		#debug
-
 
23605
		#var_dump(__LINE__,"http有問題IP清單",$ips_https);
-
 
23606
 
-
 
23607
		#透過 journalctl -a -e -f --unit=postfix.service | grep "authentication failed" 來取得認證失敗的 ip
-
 
23608
		#函式說明:
-
 
23609
		#呼叫shell執行系統命令,並取得回傳的內容.
-
 
23610
		#回傳的結果:
-
 
23611
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
23612
		#$result["error"],錯誤訊息陣列.
-
 
23613
		#$result["function"],當前執行的函式名稱.
-
 
23614
		#$result["argu"],使用的參數.
-
 
23615
		#$result["cmd"],執行的指令內容.
-
 
23616
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
-
 
23617
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
-
 
23618
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
-
 
23619
		#$result["running"],是否還在執行.
-
 
23620
		#$result["pid"],pid.
-
 
23621
		#$result["statusCode"],執行結束後的代碼.
-
 
23622
		#必填參數:
-
 
23623
		#$conf["command"],字串,要執行的指令與.
-
 
23624
		$conf["external::callShell"]["command"]="journalctl";
-
 
23625
		#$conf["fileArgu"],字串,變數__FILE__的內容.
-
 
23626
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
-
 
23627
		#可省略參數:
-
 
23628
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
-
 
23629
		$conf["external::callShell"]["argu"]=array("-a","-e","--unit=postfix.service","|","grep","authentication failed");
-
 
23630
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
-
 
23631
		#$conf["arguIsAddr"]=array();
-
 
23632
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
-
 
23633
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
-
 
23634
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
-
 
23635
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
-
 
23636
		#$conf["enablePrintDescription"]="true";
-
 
23637
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
-
 
23638
		#$conf["printDescription"]="";
-
 
23639
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
-
 
23640
		$conf["external::callShell"]["escapeshellarg"]="true";
-
 
23641
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
-
 
23642
		#$conf["username"]="";
-
 
23643
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
-
 
23644
		#$conf["password"]="";
-
 
23645
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
-
 
23646
		#$conf["useScript"]="";
-
 
23647
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
-
 
23648
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
-
 
23649
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
-
 
23650
		#$conf["inBackGround"]="";
-
 
23651
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
-
 
23652
		#$conf["getErr"]="false";
-
 
23653
		#備註:
-
 
23654
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
-
 
23655
		#參考資料:
-
 
23656
		#exec=>http://php.net/manual/en/function.exec.php
23200
					$ips_http=$checkHttpAttackLog["content"];
23657
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
-
 
23658
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
-
 
23659
		$callShell=external::callShell($conf["external::callShell"]);
-
 
23660
		unset($conf["external::callShell"]);
-
 
23661
 
-
 
23662
		#如果執行失敗
-
 
23663
		if($callShell["status"]==="false" && ( $callShell["statusCode"]!==0 && $callShell["statusCode"]!==1 ) ){
-
 
23664
 
-
 
23665
			#設置執行失敗
-
 
23666
			$result["status"]="false";
-
 
23667
 
-
 
23668
			#設置錯誤訊息
-
 
23669
			$result["error"]=$callShell;
-
 
23670
 
-
 
23671
			#回傳結果
-
 
23672
			return $result;
-
 
23673
 
-
 
23674
			}#if end
-
 
23675
 
-
 
23676
		#儲存有問題的smtp IP
-
 
23677
		$ips_smtp=array();
-
 
23678
 
-
 
23679
		#狀態碼不為1才執行
-
 
23680
		if($callShell["statusCode"]!==1){
-
 
23681
 
-
 
23682
			#初始化記錄每行log的時間點
-
 
23683
			$occurTime=array();
-
 
23684
 
-
 
23685
			#初始化儲存log行資訊的變數
-
 
23686
			$oriLog=array();
-
 
23687
 
-
 
23688
			#根據每筆記錄
-
 
23689
			foreach($callShell["output"] as $index => $line){
-
 
23690
 
-
 
23691
				#截取出的格式
-
 
23692
				#Sep 28 07:54:16 qbpwcf.org postfix/smtpd[2766456]: warning: unknown[158.94.208.72]: SASL LOGIN authentication failed: (reason unavailable), sasl_username=1q2w
-
 
23693
				#Sep 28 07:57:15 qbpwcf.org postfix/smtpd[2768441]: warning: unknown[213.209.157.249]: SASL LOGIN authentication failed: (reason unavailable), sasl_username=sybase
-
 
23694
				#Sep 28 08:01:09 qbpwcf.org postfix/smtpd[2771112]: warning: unknown[213.209.157.165]: SASL LOGIN authentication failed: (reason unavailable), sasl_username=spam
-
 
23695
				#Sep 28 08:01:51 qbpwcf.org postfix/smtpd[2771112]: warning: unknown[103.109.20.174]: SASL LOGIN authentication failed: (reason unavailable), sasl_username=print@qbpwcf.org
-
 
23696
				#Sep 28 08:03:14 qbpwcf.org postfix/smtpd[2771112]: warning: unknown[62.60.130.148]: SASL LOGIN authentication failed: (reason unavailable), sasl_username=admin2
-
 
23697
				#Sep 28 08:16:06 qbpwcf.org postfix/smtpd[2781279]: warning: unknown[103.109.20.174]: SASL LOGIN authentication failed: (reason unavailable), sasl_username=user@qbpwcf.org
-
 
23698
				#Sep 28 08:16:44 qbpwcf.org postfix/smtpd[2781279]: warning: unknown[178.16.53.142]: SASL LOGIN authentication failed: (reason unavailable), sasl_username=hualing@qbpwcf.org
-
 
23699
				#Sep 28 08:16:53 qbpwcf.org postfix/smtpd[2781279]: warning: unknown[178.16.53.142]: SASL LOGIN authentication failed: (reason unavailable), sasl_username=hualing@qbpwcf.org
-
 
23700
				#Sep 28 08:17:06 qbpwcf.org postfix/smtpd[2781279]: warning: unknown[178.16.53.142]: SASL LOGIN authentication failed: (reason unavailable), sasl_username=hualing@qbpwcf.org
-
 
23701
				#Sep 28 08:17:16 qbpwcf.org postfix/smtpd[2781279]: warning: unknown[178.16.53.142]: SASL LOGIN authentication failed: Connection lost to authentication server, sasl_username=hualing@qbpwcf.org
-
 
23702
				#Sep 28 08:20:28 qbpwcf.org postfix/smtpd[2784204]: warning: unknown[158.94.208.72]: SASL LOGIN authentication failed: (reason unavailable), sasl_username=1q2w1q2w
-
 
23703
				#Sep 28 08:23:09 qbpwcf.org postfix/smtpd[2785986]: warning: unknown[213.209.157.249]: SASL LOGIN authentication failed: (reason unavailable), sasl_username=informix
-
 
23704
				#Sep 28 08:23:39 qbpwcf.org postfix/smtpd[2785986]: warning: unknown[62.60.130.148]: SASL LOGIN authentication failed: (reason unavailable), sasl_username=admin3
-
 
23705
				#May 22 12:58:54 qbpwcf.org postfix/smtpd[2059124]: warning: unknown[80.94.95.242]: SASL LOGIN authentication failed: Invalid authentication mechanism: 'LOGIN', sasl_username=(unavailable)
-
 
23706
				#May 22 12:58:59 qbpwcf.org postfix/smtpd[2059124]: warning: unknown[80.94.95.242]: SASL PLAIN authentication failed: (reason unavailable), sasl_username=nonexistent_user_26@qbpwcf.org
-
 
23707
				#May 22 12:59:07 qbpwcf.org postfix/smtpd[2059124]: warning: unknown[80.94.95.242]: SASL PLAIN authentication failed: (reason unavailable), sasl_username=finance@qbpwcf.org#"${doNotNeed} postfix/smtpd[${pid}]${doNotNeed}[${ip}]"
-
 
23708
				
23201
				
23709
				#用 " " 分割 以取得 月日時分秒
-
 
23710
				#函式說明:
-
 
23711
				#將固定格式的字串分開,並回傳分開的結果.
-
 
23712
				#回傳結果:
-
 
23713
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
23714
				#$result["error"],錯誤訊息陣列
-
 
23715
				#$result["function"],當前執行的函數名稱.
-
 
23716
				#$result["argu"],使用的參數.
-
 
23717
				#$result["oriStr"],要分割的原始字串內容
-
 
23718
				#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
-
 
23719
				#$result["dataCounts"],爲總共分成幾段
-
 
23720
				#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
-
 
23721
				#必填參數:
-
 
23722
				#$conf["stringIn"],字串,要處理的字串.
-
 
23723
				$conf["stringProcess::spiltString"]["stringIn"]=$line;
-
 
23724
				#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
-
 
23725
				$conf["stringProcess::spiltString"]["spiltSymbol"]=" ";
-
 
23726
				#可省略參數:
-
 
23727
				#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
-
 
23728
				#$conf["allowEmptyStr"]="false";
-
 
23729
				#參考資料:
-
 
23730
				#無.
-
 
23731
				#備註:
-
 
23732
				#無.
-
 
23733
				$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
-
 
23734
				unset($conf["stringProcess::spiltString"]);
-
 
23735
 
-
 
23736
				#如果分割失敗
-
 
23737
				if($spiltString["status"]==="false"){
-
 
23738
 
-
 
23739
					#設置執行失敗
-
 
23740
					$result["status"]="false";
-
 
23741
 
-
 
23742
					#設置錯誤訊息
-
 
23743
					$result["error"]=$spiltString;
-
 
23744
 
-
 
23745
					#回傳結果
-
 
23746
					return $result;
-
 
23747
 
-
 
23748
					}#if end
-
 
23749
 
-
 
23750
				#如果分割失敗
-
 
23751
				if($spiltString["dataCounts"]<3){
-
 
23752
 
-
 
23753
					#設置執行失敗
-
 
23754
					$result["status"]="false";
-
 
23755
 
-
 
23756
					#設置錯誤訊息
-
 
23757
					$result["error"]=$spiltString;
-
 
23758
 
-
 
23759
					#回傳結果
-
 
23760
					return $result;
-
 
23761
 
-
 
23762
					}#if end
-
 
23763
 
-
 
23764
				#儲存時間
-
 
23765
				$occurTime[$index]=strtotime($spiltString["dataArray"][0]." ".$spiltString["dataArray"][1]." ".$spiltString["dataArray"][2]);
-
 
23766
 
-
 
23767
				#取得 ip
-
 
23768
				#函式說明:
-
 
23769
				#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
-
 
23770
				#回傳結果:
-
 
23771
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
23772
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
-
 
23773
				#$result["function"],當前執行的函式名稱.
-
 
23774
				#$result["argu"],所使用的參數.
-
 
23775
				#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
-
 
23776
				#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
-
 
23777
				#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
-
 
23778
				#必填參數:
-
 
23779
				#$conf["input"],字串,要檢查的字串.
-
 
23780
				$conf["search::findSpecifyStrFormat"]["input"]=$line;
-
 
23781
				#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
-
 
23782
				$conf["search::findSpecifyStrFormat"]["format"]="\${doNotNeed} postfix/smtpd[\${pid}]\${doNotNeed}[\${ip}]:[\${reason}]";
-
 
23783
				#可省略參數:
-
 
23784
				#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
-
 
23785
				#$conf["search::findSpecifyStrFormat"]["varEqual"]=array(null,"found");
-
 
23786
				#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
23202
					#結束 switch
23787
				#$conf["varCon"]=array("no_tail"=>" not");
-
 
23788
				#參考資料:
-
 
23789
				#無.
23203
					break;
23790
				#備註:
-
 
23791
				#無.
23204
					
23792
				$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
-
 
23793
				unset($conf["search::findSpecifyStrFormat"]);
-
 
23794
 
-
 
23795
				#如果分割失敗
-
 
23796
				if($findSpecifyStrFormat["status"]==="false"){
-
 
23797
 
-
 
23798
					#設置執行失敗
-
 
23799
					$result["status"]="false";
-
 
23800
 
-
 
23801
					#設置錯誤訊息
-
 
23802
					$result["error"]=$findSpecifyStrFormat;
-
 
23803
 
-
 
23804
					#回傳結果
-
 
23805
					return $result;
-
 
23806
 
-
 
23807
					}#if end
-
 
23808
 
-
 
23809
				#如果沒有符合格式
23205
				#如果是 https 服務
23810
				if($findSpecifyStrFormat["found"]==="false"){
-
 
23811
 
-
 
23812
					#剔除時間點 記錄
-
 
23813
					array_pop($occurTime);
-
 
23814
 
-
 
23815
					#跳過該行
-
 
23816
					continue;
-
 
23817
 
-
 
23818
					}#if end
-
 
23819
 
-
 
23820
				#取得解析好的ip
-
 
23821
				$ip=$findSpecifyStrFormat["parsedVar"]["ip"];
-
 
23822
 
-
 
23823
				#儲存原始的log行內容
-
 
23824
				$oriLog[$index]=$spiltMutiString["spiltString"][$index ]["oriStr"];
-
 
23825
 
-
 
23826
				#初始化暫存的陣列
-
 
23827
				$tmp=array();
23206
				case "https":
23828
 
-
 
23829
				#設置log、time
-
 
23830
				$tmp["info"][]=array("log"=>$oriLog[$index],"time"=>$occurTime[$index]);
-
 
23831
 
-
 
23832
				#設置問題ip
-
 
23833
				$tmp["ip"]=$ip;
-
 
23834
				
23207
				
23835
				#取得所需的有問題的IP
-
 
23836
				$ips_smtp[]=$tmp;
-
 
23837
 
-
 
23838
				}#foreach end
-
 
23839
 
-
 
23840
			}#if end
-
 
23841
 
-
 
23842
		#透過 journalctl -a -e -f --unit=named.service | grep ' query ' 來取得 IP
-
 
23843
		#函式說明:
23208
					#函式說明:
23844
		#呼叫shell執行系統命令,並取得回傳的內容.
23209
					#檢查 apache http log 中疑似攻擊的記錄.
23845
		#回傳的結果:
23210
					#回傳結果:
23846
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
23211
					#$result["status"],字串,執行是否正常,"true"代表正常,"false"代表不正常.
23847
		#$result["error"],錯誤訊息陣列.
23212
					#$result["error"],錯誤訊息陣列.
23848
		#$result["function"],當前執行的函式名稱.
23213
					#$result["function"],字串,當前執行的函式名稱.
23849
		#$result["argu"],使用的參數.
-
 
23850
		#$result["cmd"],執行的指令內容.
-
 
23851
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
-
 
23852
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
-
 
23853
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
-
 
23854
		#$result["running"],是否還在執行.
-
 
23855
		#$result["pid"],pid.
-
 
23856
		#$result["statusCode"],執行結束後的代碼.
-
 
23857
		#必填參數:
-
 
23858
		#$conf["command"],字串,要執行的指令與.
-
 
23859
		$conf["external::callShell"]["command"]="journalctl";
-
 
23860
		#$conf["fileArgu"],字串,變數__FILE__的內容.
-
 
23861
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
-
 
23862
		#可省略參數:
-
 
23863
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
-
 
23864
		$conf["external::callShell"]["argu"]=array("-a","-e","--unit=named.service","|","grep"," query ");
-
 
23865
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
23214
					#$result["content"],陣列,攻擊記錄資訊,每個元素為陣列key為"ip"者為攻擊者的ip;key為info者為其資訊陣列,其key為"log"者代表log的行內容;key為"time"者代表時間點;key為ip者代表ip.
23866
		#$conf["arguIsAddr"]=array();
-
 
23867
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
-
 
23868
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
-
 
23869
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
-
 
23870
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
-
 
23871
		#$conf["enablePrintDescription"]="true";
-
 
23872
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
-
 
23873
		#$conf["printDescription"]="";
-
 
23874
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
-
 
23875
		$conf["external::callShell"]["escapeshellarg"]="true";
-
 
23876
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
-
 
23877
		#$conf["username"]="";
-
 
23878
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
-
 
23879
		#$conf["password"]="";
-
 
23880
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
-
 
23881
		#$conf["useScript"]="";
-
 
23882
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
-
 
23883
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
-
 
23884
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
-
 
23885
		#$conf["inBackGround"]="";
-
 
23886
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
-
 
23887
		#$conf["getErr"]="false";
-
 
23888
		#備註:
-
 
23889
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
-
 
23890
		#參考資料:
-
 
23891
		#exec=>http://php.net/manual/en/function.exec.php
-
 
23892
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
-
 
23893
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
-
 
23894
		$callShell=external::callShell($conf["external::callShell"]);
-
 
23895
		unset($conf["external::callShell"]);
-
 
23896
 
-
 
23897
		#如果執行失敗
-
 
23898
		if($callShell["status"]==="false" && ( $callShell["statusCode"]!==0 && $callShell["statusCode"]!==1 ) ){
-
 
23899
 
-
 
23900
			#設置執行失敗
-
 
23901
			$result["status"]="false";
-
 
23902
 
-
 
23903
			#設置錯誤訊息
-
 
23904
			$result["error"]=$callShell;
-
 
23905
 
-
 
23906
			#回傳結果
-
 
23907
			return $result;
-
 
23908
 
-
 
23909
			}#if end
-
 
23910
 
-
 
23911
		#記錄攻擊者的IP
-
 
23912
		$attacker_ips_namd=array();
-
 
23913
 
-
 
23914
		#狀態碼不為1才執行
-
 
23915
		if($callShell["statusCode"]!==1){
-
 
23916
 
-
 
23917
			#截取出的格式
-
 
23918
			#Nov 24 20:55:15 localhost.localdomain named[99512]: client @0x7f7714041d10 191.7.219.100#6238 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied
-
 
23919
			#Nov 24 20:55:15 localhost.localdomain named[99512]: client @0x7f77180297c0 191.7.219.100#6238 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied
-
 
23920
			#Nov 24 20:55:15 localhost.localdomain named[99512]: client @0x7f7714041d10 191.7.219.100#6238 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied
-
 
23921
			#Nov 24 20:55:15 localhost.localdomain named[99512]: client @0x7f77180297c0 191.7.219.100#6238 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied
-
 
23922
			#Nov 24 20:55:15 localhost.localdomain named[99512]: client @0x7f7714041d10 191.7.219.100#6238 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied
-
 
23923
			#Nov 24 20:55:17 localhost.localdomain named[99512]: client @0x7f7714041d10 34.80.86.198#31220 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied
-
 
23924
			#Nov 24 20:55:17 localhost.localdomain named[99512]: client @0x7f7714041d10 34.80.86.198#31220 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied
-
 
23925
			#Nov 24 20:55:17 localhost.localdomain named[99512]: client @0x7f7714041d10 34.80.86.198#31220 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied
-
 
23926
			#Nov 24 20:55:17 localhost.localdomain named[99512]: client @0x7f77180297c0 34.80.86.198#31220 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied
-
 
23927
			#Nov 24 20:55:17 localhost.localdomain named[99512]: client @0x7f770c077bf0 34.80.86.198#31220 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied
-
 
23928
			#Nov 24 20:55:17 localhost.localdomain named[99512]: client @0x7f770c077bf0 191.7.219.100#8794 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied
-
 
23929
			#Nov 24 20:55:17 localhost.localdomain named[99512]: client @0x7f77180297c0 191.7.219.100#8794 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied
-
 
23930
			#Nov 24 20:55:17 localhost.localdomain named[99512]: client @0x7f770c077bf0 191.7.219.100#8794 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied
-
 
23931
			#Nov 24 20:55:17 localhost.localdomain named[99512]: client @0x7f7714041d10 191.7.219.100#8794 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied
-
 
23932
			#Nov 24 20:55:18 localhost.localdomain named[99512]: client @0x7f770c077bf0 5.29.224.190#10027 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied
-
 
23933
			#Nov 24 20:55:18 localhost.localdomain named[99512]: client @0x7f770c077bf0 5.29.224.190#10027 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied
-
 
23934
			#Nov 24 20:55:18 localhost.localdomain named[99512]: client @0x7f7714041d10 5.29.224.190#10027 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied
-
 
23935
			#Nov 24 20:55:18 localhost.localdomain named[99512]: client @0x7f77180297c0 5.29.224.190#10027 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied
-
 
23936
			#Nov 24 20:55:18 localhost.localdomain named[99512]: client @0x7f7714041d10 5.29.224.190#10027 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied
-
 
23937
			#Nov 24 20:55:18 localhost.localdomain named[99512]: client @0x7f77180297c0 5.29.224.190#10027 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied
-
 
23938
			#Nov 24 20:55:18 localhost.localdomain named[99512]: client @0x7f7714041d10 5.29.224.190#10027 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied
-
 
23939
			#Nov 24 20:55:22 localhost.localdomain named[99512]: client @0x7f7714041d10 123.253.64.16#54404 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied
-
 
23940
			#Nov 24 20:55:22 localhost.localdomain named[99512]: client @0x7f7714041d10 123.253.64.16#54404 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied
-
 
23941
			#Nov 24 20:55:22 localhost.localdomain named[99512]: client @0x7f7714041d10 123.253.64.16#54404 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied
-
 
23942
			#Dec 14 18:51:45 localhost.localdomain named[1159]: client @0x7f3dc801bc80 61.220.11.198#40052 (dns.qbpwcf.org): query 'dns.qbpwcf.org/AAAA/IN' denied
-
 
23943
			#Dec 14 18:51:45 localhost.localdomain named[1159]: client @0x7f3dc8003700 61.220.11.198#48628 (aesopower-cms-sock-latest.qbpwcf.org): query 'aesopower-cms-sock-latest.qbpwcf.org/A/IN' denied
-
 
23944
			#Dec 14 18:51:45 localhost.localdomain named[1159]: client @0x7f3dc8003700 61.220.11.198#52460 (dns.qbpwcf.org): query 'dns.qbpwcf.org/AAAA/IN' denied
-
 
23945
			#Dec 14 18:51:45 localhost.localdomain named[1159]: client @0x7f3dc801bc80 61.220.11.198#60457 (aesopower-cms-sock-latest.qbpwcf.org): query 'aesopower-cms-sock-latest.qbpwcf.org/A/IN' denied
-
 
23946
			#Dec 14 18:51:45 localhost.localdomain named[1159]: client @0x7f3dc801bc80 61.220.11.198#10213 (dns.qbpwcf.org): query 'dns.qbpwcf.org/AAAA/IN' denied
-
 
23947
			#Dec 14 18:51:45 localhost.localdomain named[1159]: client @0x7f3dc801bc80 61.220.11.198#44377 (aesopower-cms-sock-latest.qbpwcf.org): query 'aesopower-cms-sock-latest.qbpwcf.org/A/IN' denied
-
 
23948
			#Dec 14 18:51:45 localhost.localdomain named[1159]: client @0x7f3dc8003700 61.220.11.198#4481 (dns.qbpwcf.org): query 'dns.qbpwcf.org/AAAA/IN' denied
-
 
23949
			#Dec 14 18:51:45 localhost.localdomain named[1159]: client @0x7f3dc8003700 61.220.11.198#53061 (aesopower-cms-sock-latest.qbpwcf.org): query 'aesopower-cms-sock-latest.qbpwcf.org/A/IN' denied
-
 
23950
			#Dec 14 18:51:45 localhost.localdomain named[1159]: client @0x7f3dc8003700 61.220.11.198#31654 (dns.qbpwcf.org): query 'dns.qbpwcf.org/AAAA/IN' denied
-
 
23951
			#Dec 14 18:51:45 localhost.localdomain named[1159]: client @0x7f3dc802a410 61.220.11.198#57701 (aesopower-cms-sock-latest.qbpwcf.org): query 'aesopower-cms-sock-latest.qbpwcf.org/A/IN' denied
-
 
23952
			#Sep 29 03:37:20 dns.qbpwcf.org named[94]: client @0x7f60e00734e8 61.166.210.84#49954 (twitter.com): query failed (REFUSED) for twitter.com/IN/AAAA at ../../../lib/ns/query.c:5691
-
 
23953
			#Sep 29 03:37:20 dns.qbpwcf.org named[94]: client @0x7f60e006f428 61.166.210.84#49954 (twitter.com): query failed (REFUSED) for twitter.com/IN/A at ../../../lib/ns/query.c:5691
-
 
23954
			#Sep 29 03:37:21 dns.qbpwcf.org named[94]: client @0x7f60e80889a8 61.166.210.84#50057 (astrill4u.com): query failed (REFUSED) for astrill4u.com/IN/AAAA at ../../../lib/ns/query.c:5691
-
 
23955
			#Sep 29 03:37:21 dns.qbpwcf.org named[94]: client @0x7f60e805ed08 61.166.210.84#50057 (astrill4u.com): query failed (REFUSED) for astrill4u.com/IN/A at ../../../lib/ns/query.c:5691
-
 
23956
			#Sep 29 03:46:33 dns.qbpwcf.org named[94]: client @0x7f60d402b618 165.22.223.147#16200 (tool.lu): query failed (REFUSED) for tool.lu/IN/A at ../../../lib/ns/query.c:5691
-
 
23957
			#Sep 29 03:49:16 dns.qbpwcf.org named[94]: client @0x7f60e0060a28 76.20.229.207#80 (sl): query failed (REFUSED) for sl/IN/ANY at ../../../lib/ns/query.c:5691
-
 
23958
			#Sep 29 04:19:10 dns.qbpwcf.org named[94]: client @0x7f60e0060a28 76.20.229.207#80 (sl): query failed (REFUSED) for sl/IN/ANY at ../../../lib/ns/query.c:5691
-
 
23959
			#Sep 29 04:20:28 dns.qbpwcf.org named[94]: client @0x7f60e0060a28 76.20.229.207#80 (sl): query failed (REFUSED) for sl/IN/ANY at ../../../lib/ns/query.c:5691
-
 
23960
			#Sep 29 04:24:20 dns.qbpwcf.org named[94]: client @0x7f60e0060a28 76.20.229.207#80 (sl): query failed (REFUSED) for sl/IN/ANY at ../../../lib/ns/query.c:5691
-
 
23961
			#Sep 29 04:24:59 dns.qbpwcf.org named[94]: client @0x7f60e0060a28 76.20.229.207#80 (sl): query failed (REFUSED) for sl/IN/ANY at ../../../lib/ns/query.c:5691
-
 
23962
			#Sep 29 04:40:48 dns.qbpwcf.org named[94]: client @0x7f60f9377888 174.96.56.126#80 (sl): query failed (REFUSED) for sl/IN/ANY at ../../../lib/ns/query.c:5691
-
 
23963
			#${month} ${day} ${hour}:${min}:${sec} ${doNotNeed} client ${doNotNeed} ${ip}#${remoteRevPort} (${$queryTarget}): ${doNotNeed}
-
 
23964
 
-
 
23965
			#函式說明:
-
 
23966
			#檢查多個字串中的每個字串是否有多個關鍵字
-
 
23967
			#回傳結果:
-
 
23968
			#$result["status"],整體來說,執行是否成功,"true"代表執行成功,"false"代表執行失敗。
-
 
23969
			#$result["function"],當前執行的函數名稱.
-
 
23970
			#$result["error"],錯誤訊息.
-
 
23971
			#$result["argu"],使用的參數.
-
 
23972
			#$result["foundedTrueKey"],結果為"true"的被搜尋元素key陣列,與其數值內容.
-
 
23973
			#$result["foundedKeyWords"],找到的關鍵字陣列.
-
 
23974
			#$result["foundedFalseKey"],結果為"false"的被搜尋元素key陣列,與其數值內容.
-
 
23975
			#$result["foundedTrueKeyWords"],二維陣列,各個字串有找到的關鍵字陣列.
-
 
23976
			#$result["foundedAll"],是否每個關鍵字都有找到,"true"代表每個都有找到,"false"代表沒有每個都找到.
-
 
23977
			#$result["keyWordsIncludeStr"],陣列,儲存有找到關鍵字的來源的索引(sourceIndex)與其內容(sourceVal)跟找到的關鍵字項目陣列(KeyWords).
-
 
23978
			#必填參數:
23215
					#必填參數:
23979
			#$conf["keyWords"],字串陣列,想要搜尋的關鍵字.
-
 
23980
			$conf["search::findManyKeyWordsFromManyString"]["keyWords"]=array("(REFUSED)"," denied");
-
 
23981
			#$conf["stringArray"],字串陣列,要被搜尋的字串內容陣列.
-
 
23982
			$conf["search::findManyKeyWordsFromManyString"]["stringArray"]=$callShell["output"];
-
 
23983
			#可省略參數:
-
 
23984
			#$conf["completeEqual"],字串,是否內容要完全符合,不能多出任何不符合的內容,預設為"false"不需要完全符合.
-
 
23985
			#$conf["completeEqual"]="true";
-
 
23986
			#參考資料:
-
 
23987
			#無.
-
 
23988
			#備註:
-
 
23989
			#無.
23216
					#無.
23990
			$findManyKeyWordsFromManyString=search::findManyKeyWordsFromManyString($conf["search::findManyKeyWordsFromManyString"]);
-
 
23991
			unset($conf["search::findManyKeyWordsFromManyString"]);
-
 
23992
 
-
 
23993
			#如果執行失敗
-
 
23994
			if($findManyKeyWordsFromManyString["status"]==="false"){
-
 
23995
 
-
 
23996
				#設置執行失敗
-
 
23997
				$result["status"]="false";
-
 
23998
 
-
 
23999
				#設置錯誤訊息
-
 
24000
				$result["error"]=$findManyKeyWordsFromManyString;
-
 
24001
 
-
 
24002
				#回傳結果
-
 
24003
				return $result;
-
 
24004
 
-
 
24005
				}#if end
-
 
24006
 
-
 
24007
			#初始化儲存原始log行內容
-
 
24008
			#$oriLog=array();
-
 
24009
 
-
 
24010
			#儲存疑似有問題的IP
-
 
24011
			$ips_named=array();
-
 
24012
 
-
 
24013
			#初始化儲存確定有問題的ip
-
 
24014
			$attacker_ips_namd=array();
-
 
24015
 
-
 
24016
			#針對每個符合的行
-
 
24017
			foreach($findManyKeyWordsFromManyString["foundedTrueKey"] as $oriLog){
-
 
24018
 
-
 
24019
				#初始化儲存資訊的暫存陣列
-
 
24020
				$info=array();
-
 
24021
 
-
 
24022
				#解析時間與來源ip
-
 
24023
				#函式說明:
-
 
24024
				#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
-
 
24025
				#回傳結果:
-
 
24026
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
24027
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
-
 
24028
				#$result["function"],當前執行的函式名稱.
-
 
24029
				#$result["argu"],所使用的參數.
-
 
24030
				#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
-
 
24031
				#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
-
 
24032
				#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
-
 
24033
				#必填參數:
-
 
24034
				#$conf["input"],字串,要檢查的字串.
-
 
24035
				$conf["search::findSpecifyStrFormat"]["input"]=$oriLog;
-
 
24036
				#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
-
 
24037
				$conf["search::findSpecifyStrFormat"]["format"]="\${month} \${day} \${hour}:\${min}:\${sec} \${doNotNeed} client \${doNotNeed} \${ip}#\${remoteRevPort} (\${queryTarget}): \${doNotNeed}";
-
 
24038
				#可省略參數:
23217
					#可省略參數:
24039
				#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
23218
					#$conf["logPath"],http log的路徑,預設為"/var/log/httpd".
24040
				#$conf["search::findSpecifyStrFormat"]["varEqual"]=array(null,"found");
23219
					#$conf["logPath"]="/var/log/httpd";
24041
				#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
23220
					#$conf["https"],字串,是否為要查https的log,預設為"false",代表為http.
24042
				#$conf["varCon"]=array("no_tail"=>" not");
23221
					$conf["security::checkHttpAttackLog"]["https"]="true";
24043
				#參考資料:
23222
					#參考資料:
24044
				#無.
23223
					#無.
24045
				#備註:
23224
					#備註:
24046
				#無.
-
 
24047
				$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
-
 
24048
				unset($conf["search::findSpecifyStrFormat"]);
23225
					#目前僅支援 apache 提供的 http 服務.
24049
 
-
 
24050
				#如果分割失敗
-
 
24051
				if($findSpecifyStrFormat["status"]==="false"){
-
 
24052
 
-
 
24053
					#設置執行失敗
-
 
24054
					$result["status"]="false";
-
 
24055
 
-
 
24056
					#設置錯誤訊息
-
 
24057
					$result["error"]=$findSpecifyStrFormat;
-
 
24058
 
-
 
24059
					#回傳結果
-
 
24060
					return $result;
-
 
24061
 
-
 
24062
					}#if end
-
 
24063
 
-
 
24064
				#如果沒有符合格式
-
 
24065
				if($findSpecifyStrFormat["found"]==="false"){
-
 
24066
 
-
 
24067
					#跳過該行
-
 
24068
					continue;
-
 
24069
 
-
 
24070
					}#if end
-
 
24071
 
-
 
24072
				#儲存時間點
-
 
24073
				$info["time"]=$findSpecifyStrFormat["parsedVar"]["month"][0]." ".$findSpecifyStrFormat["parsedVar"]["day"][0]." ".$findSpecifyStrFormat["parsedVar"]["hour"][0].":".$findSpecifyStrFormat["parsedVar"]["min"][0].":".$findSpecifyStrFormat["parsedVar"]["sec"][0];
23226
					#攻擊者的定義為http回應的code為4開頭,且時間間隔不超過1秒鐘,次數達到3次.
24074
 
-
 
24075
				#儲存ip
-
 
24076
				$info["ip"]=$findSpecifyStrFormat["parsedVar"]["ip"][0];
-
 
24077
 
-
 
24078
				#儲存log
-
 
24079
				$info["log"]=$oriLog;
-
 
24080
 
-
 
24081
				#儲存查詢的目標
-
 
24082
				$info["queryTarget"]=$findSpecifyStrFormat["parsedVar"]["queryTarget"][0];
23227
					$checkHttpsAttackLog=security::checkHttpAttackLog($conf["security::checkHttpAttackLog"]);
24083
 
-
 
24084
				#儲存疑似有問題的ip
-
 
24085
				$ips_named[$info["ip"]][]=$info;
-
 
24086
 
-
 
24087
				}#foreach end
-
 
24088
 
-
 
24089
			#針對每個可能有問題ip的每個log行
-
 
24090
			foreach($ips_named as $ip => $infos){
-
 
24091
 
-
 
24092
				#初始化記錄ip來訪不大於1分鐘的計數
-
 
24093
				$count=0;
-
 
24094
 
-
 
24095
				#初始化記錄歷史log跟time
-
 
24096
				$history=array();
-
 
24097
 
-
 
24098
				#針對每個log行資訊
-
 
24099
				foreach($infos as $index => $info){
23228
					unset($conf["security::checkHttpAttackLog"]);
24100
 
-
 
24101
					#unixtime
23229
					
24102
					$time=strtotime($info["time"]);
-
 
24103
 
-
 
24104
					#如果沒有下筆記錄
23230
					#如果執行異常
24105
					if(!isset($infos[$index+1])){
23231
					if($checkHttpsAttackLog["status"]==="false"){
24106
 
-
 
24107
						#結束 foreach
-
 
24108
						break;
-
 
24109
 
-
 
24110
						}#if end
-
 
24111
 
23232
 
24112
					#取得unixtime
23233
						#設置執行失敗
24113
					$next_time=strtotime($infos[$index+1]["time"]);
23234
						$result["status"]="false";
24114
 
23235
 
24115
					#如果時間間隔大於60秒
23236
						#設置錯誤訊息
24116
					if($next_time-$time>60){
23237
						$result["error"]=$checkHttpsAttackLog;
24117
 
23238
 
24118
						#跳過,看下筆記錄
23239
						#回傳結果
24119
						continue;
23240
						return $result;
24120
 
23241
 
24121
						}#if end
23242
						}#if end
24122
 
-
 
24123
					#計數+1
-
 
24124
					$count++;
-
 
24125
					
23243
					
24126
					#記錄歷史資訊
-
 
24127
					$history[]=array("time"=>$time,"log"=>$info["log"]);
-
 
24128
 
-
 
24129
					}#foreach end
-
 
24130
 
-
 
24131
				#如果有達到3次
-
 
24132
				if($count>=3){
-
 
24133
 
-
 
24134
					#初始化暫存的陣列
-
 
24135
					$tmp=array();
-
 
24136
					
-
 
24137
					#設置ip
-
 
24138
					$tmp["ip"]=$ip;
-
 
24139
					
-
 
24140
					#設置info
-
 
24141
					$tmp["info"]=$history;
-
 
24142
 
-
 
24143
					#記錄攻擊者的IP
-
 
24144
					$attacker_ips_namd[]=$tmp;
-
 
24145
 
-
 
24146
					}#if end
-
 
24147
 
-
 
24148
				}#foreach end
-
 
24149
 
-
 
24150
			}#if end
-
 
24151
 
-
 
24152
		#透過 journalctl -a -e --unit=dovecot.service 來取得 IP
-
 
24153
		#函式說明:
-
 
24154
		#呼叫shell執行系統命令,並取得回傳的內容.
-
 
24155
		#回傳的結果:
-
 
24156
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
24157
		#$result["error"],錯誤訊息陣列.
-
 
24158
		#$result["function"],當前執行的函式名稱.
-
 
24159
		#$result["argu"],使用的參數.
-
 
24160
		#$result["cmd"],執行的指令內容.
-
 
24161
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
-
 
24162
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
-
 
24163
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
-
 
24164
		#$result["running"],是否還在執行.
-
 
24165
		#$result["pid"],pid.
-
 
24166
		#$result["statusCode"],執行結束後的代碼.
-
 
24167
		#必填參數:
-
 
24168
		#$conf["command"],字串,要執行的指令與.
-
 
24169
		$conf["external::callShell"]["command"]="journalctl";
-
 
24170
		#$conf["fileArgu"],字串,變數__FILE__的內容.
-
 
24171
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
-
 
24172
		#可省略參數:
-
 
24173
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
-
 
24174
		$conf["external::callShell"]["argu"]=array("-a","-e","--unit=dovecot.service");
-
 
24175
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
-
 
24176
		#$conf["arguIsAddr"]=array();
-
 
24177
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
-
 
24178
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
-
 
24179
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
-
 
24180
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
-
 
24181
		#$conf["enablePrintDescription"]="true";
-
 
24182
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
-
 
24183
		#$conf["printDescription"]="";
-
 
24184
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
-
 
24185
		$conf["external::callShell"]["escapeshellarg"]="true";
-
 
24186
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
-
 
24187
		#$conf["username"]="";
-
 
24188
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
-
 
24189
		#$conf["password"]="";
-
 
24190
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
-
 
24191
		#$conf["useScript"]="";
-
 
24192
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
-
 
24193
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
-
 
24194
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
-
 
24195
		#$conf["inBackGround"]="";
-
 
24196
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
-
 
24197
		#$conf["getErr"]="false";
-
 
24198
		#備註:
-
 
24199
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
-
 
24200
		#參考資料:
-
 
24201
		#exec=>http://php.net/manual/en/function.exec.php
-
 
24202
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
-
 
24203
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
-
 
24204
		$callShell=external::callShell($conf["external::callShell"]);
-
 
24205
		unset($conf["external::callShell"]);
-
 
24206
 
-
 
24207
		#如果執行失敗
-
 
24208
		if($callShell["status"]==="false"){
-
 
24209
 
-
 
24210
			#設置執行失敗
-
 
24211
			$result["status"]="false";
-
 
24212
 
-
 
24213
			#設置錯誤訊息
-
 
24214
			$result["error"]=$callShell;
-
 
24215
 
-
 
24216
			#回傳結果
-
 
24217
			return $result;
-
 
24218
 
-
 
24219
			}#if end
-
 
24220
 
-
 
24221
		#記錄攻擊者的IP
-
 
24222
		$attacker_ips_imap=array();
-
 
24223
 
-
 
24224
		/* $callShell["output"] 範例截取結果
-
 
24225
		Feb 23 00:24:58 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<MxQuPu+73xpliNc9>
-
 
24226
		Feb 23 00:24:58 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<hH8xPu+7dBtliNc9>
-
 
24227
		Feb 23 00:24:58 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<nmI0Pu+7zhtliNc9>
23244
					#取得有問題的 https log 記錄
24228
		Feb 23 00:24:58 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<1GU2Pu+7NBhliNc9>
23245
					$ips_https=$checkHttpsAttackLog["content"];
24229
		Feb 23 00:24:59 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 1 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<0Io5Pu+7sRhliNc9>
23246
				
24230
		Feb 23 00:24:59 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<zbQ+Pu+7rhlliNc9>
23247
					#結束 switch
24231
		Feb 23 00:24:59 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<0P5APu+7/BlliNc9>
23248
					break;
24232
		Feb 23 00:24:59 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<gKRDPu+7XhpliNc9>
23249
				
24233
		Feb 23 00:24:59 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<4hNHPu+77hpliNc9>
23250
				#如果是 postfix
24234
		Feb 23 00:25:00 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<belIPu+7bBtliNc9>
-
 
24235
		Feb 23 00:25:00 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<VhRLPu+7xBtliNc9>
-
 
24236
		Feb 23 00:46:19 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<loiMiu+7cxhliNc9>
-
 
24237
		Feb 23 00:46:19 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<RNCQiu+7/xhliNc9>
-
 
24238
		Feb 23 00:46:20 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 1 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<NWCTiu+7PBlliNc9>
-
 
24239
		Feb 23 00:46:20 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<2tiViu+7hBlliNc9>
-
 
24240
		Feb 23 00:46:20 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<w6Sbiu+7/xlliNc9>
-
 
24241
		Feb 23 00:46:21 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<SkWkiu+7gBtliNc9>
-
 
24242
		Feb 23 00:46:21 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<bGCmiu+7qBtliNc9>
-
 
24243
		Feb 23 00:46:21 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<0E+oiu+76RtliNc9>
-
 
24244
		Feb 23 00:46:21 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<FBGriu+7UhhliNc9>
-
 
24245
		Feb 23 00:46:21 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<AeSsiu+7iBhliNc9>
-
 
24246
		Feb 23 00:46:21 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<gpSuiu+70hhliNc9>
-
 
24247
		Feb 23 01:40:38 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<zYfITPC7RBlliNc9>
-
 
24248
		Feb 23 01:40:38 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<GULMTPC7zhlliNc9>
-
 
24249
		Feb 23 01:40:38 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<3jjOTPC7CBpliNc9>
-
 
24250
		Feb 23 01:40:38 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<vhHQTPC7UBpliNc9>
-
 
24251
		Feb 23 01:40:38 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<vArTTPC7rxpliNc9>
-
 
24252
		Feb 23 01:40:39 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<hDTXTPC7GhtliNc9>
-
 
24253
		Feb 23 01:40:39 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<c6vZTPC7SRtliNc9>
-
 
24254
		Feb 23 01:40:39 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<rQzcTPC7jBtliNc9>
-
 
24255
		Feb 23 01:40:39 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<LSffTPC78htliNc9>
-
 
24256
		Feb 23 01:40:39 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<XLThTPC7KBhliNc9>
-
 
24257
		Feb 23 01:40:40 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<tZfjTPC7dxhliNc9>
-
 
24258
		Feb 23 03:27:10 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<i3bIyfG7AxtliNc9>
-
 
24259
		Feb 23 03:27:11 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<0sLVyfG7uxtliNc9>
-
 
24260
		Feb 23 03:27:11 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<BJXZyfG7BhhliNc9>
-
 
24261
		Feb 23 03:27:11 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<xK3cyfG7SxhliNc9>
-
 
24262
		Feb 23 03:27:12 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 1 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<q43gyfG7aRhliNc9>
-
 
24263
		Feb 23 03:27:12 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<Oj3syfG7FBlliNc9>
-
 
24264
		Feb 23 03:27:12 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<SF7uyfG7RhlliNc9>
-
 
24265
		Feb 23 03:27:13 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 1 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<IM/wyfG7ZRlliNc9>
-
 
24266
		Feb 23 03:27:13 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<pXv1yfG7vBlliNc9>
-
 
24267
		Feb 23 03:27:13 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<8ub4yfG7/xlliNc9>
-
 
24268
		Feb 23 03:27:13 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<H0j7yfG7NRpliNc9>
-
 
24269
		Feb 23 06:10:07 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 1 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<Zw6FEPS7WxhliNc9>
-
 
24270
		Feb 23 06:10:08 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 1 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<vmKTEPS7cRpliNc9>
-
 
24271
		Feb 23 06:10:08 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<SkOXEPS7BxtliNc9>
-
 
24272
		Feb 23 06:10:08 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<H42bEPS7WRtliNc9>
-
 
24273
		Feb 23 06:10:09 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<jFqoEPS7SRhliNc9>
-
 
24274
		Feb 23 06:10:10 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<TNy4EPS7DhpliNc9>
-
 
24275
		Feb 23 06:10:10 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<JYW7EPS7mBpliNc9>
-
 
24276
		Feb 23 06:10:10 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=</Ve+EPS76hpliNc9>
-
 
24277
		Feb 23 06:10:11 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<StLGEPS7qhtliNc9>
-
 
24278
		Feb 23 06:10:11 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<7RnLEPS7DBhliNc9>
-
 
24279
		Feb 23 06:10:11 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<6xTOEPS7eBhliNc9>
-
 
24280
		Feb 23 06:29:27 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<YHy0VfS7uBhliNc9>
-
 
24281
		Feb 23 06:29:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<WLW4VfS7fxlliNc9>
-
 
24282
		Feb 23 06:29:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<lM66VfS73BlliNc9>
-
 
24283
		Feb 23 06:29:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<Q4K9VfS7NxpliNc9>
-
 
24284
		Feb 23 06:29:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<JiLBVfS7rRpliNc9>
-
 
24285
		Feb 23 06:29:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<DETIVfS7qxtliNc9>
-
 
24286
		Feb 23 06:29:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<UlLLVfS7GhhliNc9>
-
 
24287
		Feb 23 06:29:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<safNVfS7txhliNc9>
-
 
24288
		Feb 23 06:29:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<M/DQVfS7LxlliNc9>
-
 
24289
		Feb 23 06:29:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<+zPTVfS7eRlliNc9>
-
 
24290
		Feb 23 06:29:30 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 1 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<dxXWVfS72hlliNc9>
-
 
24291
		Feb 23 06:44:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 1 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<S0pci/S7SxhliNc9>
-
 
24292
		Feb 23 06:44:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<zThji/S78RhliNc9>
-
 
24293
		Feb 23 06:44:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<8PJoi/S7ixlliNc9>
-
 
24294
		Feb 23 06:44:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<Qkhui/S7PBpliNc9>
-
 
24295
		Feb 23 06:44:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<SXVzi/S7hhtliNc9>
-
 
24296
		Feb 23 06:44:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=</X55i/S7uhhliNc9>
-
 
24297
		Feb 23 06:44:30 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<MHJ9i/S74hlliNc9>
-
 
24298
		Feb 23 06:44:30 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<RBWBi/S7pRpliNc9>
-
 
24299
		Feb 23 06:44:30 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<NJeGi/S7yhtliNc9>
-
 
24300
		Feb 23 06:44:31 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<QsaMi/S7rxhliNc9>
-
 
24301
		Feb 23 06:44:31 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<8fiPi/S7uBlliNc9>
-
 
24302
		Feb 23 07:01:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 1 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<dt04yPS7KBlliNc9>
-
 
24303
		Feb 23 07:01:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<ZMI9yPS7WxpliNc9>
-
 
24304
		Feb 23 07:01:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<nTVAyPS7ARtliNc9>
-
 
24305
		Feb 23 07:01:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<wj1CyPS7lxtliNc9>
-
 
24306
		Feb 23 07:01:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<u7RFyPS7YRhliNc9>
-
 
24307
		Feb 23 07:01:30 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<tpBLyPS7ZhlliNc9>
-
 
24308
		Feb 23 07:01:30 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<CRdOyPS7wxlliNc9>
-
 
24309
		Feb 23 07:01:30 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<v9NQyPS7JxpliNc9>
-
 
24310
		Feb 23 07:01:30 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<81lUyPS73hpliNc9>
-
 
24311
		Feb 23 07:01:31 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<PCZXyPS7TRtliNc9>
-
 
24312
		Feb 23 07:01:31 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<VnNZyPS7qxtliNc9>
-
 
24313
		Feb 23 07:14:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 1 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<op+l9vS7ZxhliNc9>
-
 
24314
		Feb 23 07:14:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<aBCr9vS7CBlliNc9>
-
 
24315
		Feb 23 07:14:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<0sOt9vS7dRlliNc9>
-
 
24316
		Feb 23 07:14:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<NFaw9vS7xhlliNc9>
-
 
24317
		Feb 23 07:14:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<QS609vS7SRpliNc9>
-
 
24318
		Feb 23 07:14:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<4FW79vS76htliNc9>
-
 
24319
		Feb 23 07:14:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<Fxu+9vS7gBhliNc9>
-
 
24320
		Feb 23 07:14:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<3djA9vS75RhliNc9>
-
 
24321
		Feb 23 07:14:30 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 1 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<hgzE9vS7mxlliNc9>
-
 
24322
		Feb 23 07:14:30 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<J8TG9vS7GBpliNc9>
-
 
24323
		Feb 23 07:14:30 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<t87I9vS7mBpliNc9>
-
 
24324
		Feb 23 07:29:27 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<1xBILPW7MRtliNc9>
-
 
24325
		Feb 23 07:29:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<IXZNLPW79htliNc9>
-
 
24326
		Feb 23 07:29:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<6OdPLPW7chhliNc9>
-
 
24327
		Feb 23 07:29:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<M5BSLPW78hhliNc9>
-
 
24328
		Feb 23 07:29:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<Nv9VLPW7UxlliNc9>
-
 
24329
		Feb 23 07:29:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<foJbLPW7KRpliNc9>
-
 
24330
		Feb 23 07:29:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<EoVeLPW7nxpliNc9>
-
 
24331
		Feb 23 07:29:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<DwNhLPW7JRtliNc9>
-
 
24332
		Feb 23 07:29:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<mKhkLPW7ohtliNc9>
-
 
24333
		Feb 23 07:29:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<3nhnLPW7/htliNc9>
-
 
24334
		Feb 23 07:29:30 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 1 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<e+lpLPW7XRhliNc9>
-
 
24335
		Feb 23 07:44:27 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<KtTtYfW7dBhliNc9>
-
 
24336
		Feb 23 07:44:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<MLTxYfW77BhliNc9>
-
 
24337
		Feb 23 07:44:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<9GL0YfW7KBlliNc9>
-
 
24338
		Feb 23 07:44:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<JNT2YfW7fRlliNc9>
-
 
24339
		Feb 23 07:44:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<8Zv5YfW72RlliNc9>
-
 
24340
		Feb 23 07:44:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<lbv/YfW73BpliNc9>
-
 
24341
		Feb 23 07:44:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<5zsCYvW7EBtliNc9>
-
 
24342
		Feb 23 07:44:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<aE8EYvW7bRtliNc9>
-
 
24343
		Feb 23 07:44:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<LEIHYvW75RtliNc9>
-
 
24344
		Feb 23 07:44:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<rLsJYvW7MRhliNc9>
-
 
24345
		Feb 23 07:44:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<9oMMYvW7ihhliNc9>
-
 
24346
		Feb 23 07:59:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 1 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<x7SUl/W7mBpliNc9>
-
 
24347
		Feb 23 07:59:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<k1KZl/W73xtliNc9>
-
 
24348
		Feb 23 07:59:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<Veabl/W7PxhliNc9>
-
 
24349
		Feb 23 07:59:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<Yamel/W7sxhliNc9>
-
 
24350
		Feb 23 07:59:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<wpGil/W7OBlliNc9>
-
 
24351
		Feb 23 07:59:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<+VCol/W7aBpliNc9>
-
 
24352
		Feb 23 07:59:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<TMaql/W7zhpliNc9>
-
 
24353
		Feb 23 07:59:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<KnKtl/W7GBtliNc9>
23251
				case "postfix":
24354
		Feb 23 07:59:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<Lkixl/W7ixtliNc9>
23252
				
24355
		Feb 23 07:59:30 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 1 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<8bWzl/W7ARhliNc9>
23253
					#函式說明:
24356
		Feb 23 07:59:30 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<70q2l/W7PBhliNc9>
23254
					#檢查 postfixv log 中疑似攻擊的記錄.
24357
		Sep 29 06:53:42 qbpwcf.org dovecot[98]: imap-login: Disconnected: Connection closed (no auth attempts in 0 secs): user=<>, rip=3.231.151.171, lip=169.254.2.1, TLS, session=<MaKQGOs/wIMD55er>
-
 
24358
		Sep 29 07:42:58 qbpwcf.org auth[3737748]: pam_unix(dovecot:auth): check pass; user unknown
-
 
24359
		Sep 29 07:42:58 qbpwcf.org auth[3737748]: pam_unix(dovecot:auth): authentication failure; logname=liveuser uid=0 euid=0 tty=dovecot ruser=account@qbpwcf.org rhost=62.60.131.29
-
 
24360
		Sep 29 08:10:02 qbpwcf.org dovecot[98]: imap(liveuser)<3755807><SvyIKew/xLpyIuFn>: Disconnected: Connection closed (UID SEARCH finished 0.039 secs ago) in=119 out=1504 deleted=0 expunged=0 trashed=0 hdr_count=0 hdr_bytes=0 body_count=0 body_bytes=0
-
 
24361
		Sep 29 08:12:02 qbpwcf.org dovecot[98]: imap-login: Login: user=<liveuser>, method=PLAIN, rip=149.102.158.38, lip=169.254.2.1, mpid=3757116, TLS, session=<B2O9MOw/TrmVZp4m>
-
 
24362
		Sep 29 08:12:04 qbpwcf.org dovecot[98]: imap(liveuser)<3757116><B2O9MOw/TrmVZp4m>: Disconnected: Logged out in=240 out=21891 deleted=0 expunged=0 trashed=0 hdr_count=0 hdr_bytes=0 body_count=0 body_bytes=0
-
 
24363
		Sep 29 08:12:06 qbpwcf.org dovecot[98]: imap-login: Login: user=<liveuser>, method=PLAIN, rip=149.102.158.38, lip=169.254.2.1, mpid=3757144, TLS, session=<S0rwMOw/XLmVZp4m>
-
 
24364
		Sep 29 08:12:09 qbpwcf.org dovecot[98]: imap(liveuser)<3757144><S0rwMOw/XLmVZp4m>: Disconnected: Logged out in=885 out=25454 deleted=0 expunged=0 trashed=0 hdr_count=2 hdr_bytes=21658 body_count=0 body_bytes=0
-
 
24365
		Sep 29 08:28:48 qbpwcf.org dovecot[98]: imap-login: Login: user=<liveuser>, method=PLAIN, rip=114.34.225.103, lip=169.254.2.1, mpid=3768144, TLS, session=<Gk6ybOw/nNpyIuFn>
-
 
24366
		Sep 29 08:28:51 qbpwcf.org dovecot[98]: imap(liveuser)<3768144><Gk6ybOw/nNpyIuFn>: Disconnected: Connection closed (LIST finished 1.939 secs ago) in=50 out=17609 deleted=0 expunged=0 trashed=0 hdr_count=0 hdr_bytes=0 body_count=0 body_bytes=0
-
 
24367
		Sep 29 08:28:51 qbpwcf.org dovecot[98]: imap-login: Login: user=<liveuser>, method=PLAIN, rip=114.34.225.103, lip=169.254.2.1, mpid=3768149, TLS, session=<ct7bbOw/qtpyIuFn>
-
 
24368
		Sep 29 08:28:52 qbpwcf.org dovecot[98]: imap(liveuser)<3768149><ct7bbOw/qtpyIuFn>: Disconnected: Connection closed (UID FETCH finished 0.045 secs ago) in=196 out=2381 deleted=0 expunged=0 trashed=0 hdr_count=0 hdr_bytes=0 body_count=0 body_bytes=0
-
 
24369
		Sep 29 08:28:53 qbpwcf.org dovecot[98]: imap-login: Login: user=<liveuser>, method=PLAIN, rip=114.34.225.103, lip=169.254.2.1, mpid=3768155, TLS, session=<DvP1bOw/tNpyIuFn>
-
 
24370
		Sep 29 08:28:55 qbpwcf.org dovecot[98]: imap(liveuser)<3768155><DvP1bOw/tNpyIuFn>: Disconnected: Connection closed (UID SEARCH finished 0.180 secs ago) in=119 out=1504 deleted=0 expunged=0 trashed=0 hdr_count=0 hdr_bytes=0 body_count=0 body_bytes=0
-
 
24371
		Sep 29 08:39:24 qbpwcf.org auth[3775219]: pam_unix(dovecot:auth): check pass; user unknown
-
 
24372
		Sep 29 08:39:24 qbpwcf.org auth[3775219]: pam_unix(dovecot:auth): authentication failure; logname=liveuser uid=0 euid=0 tty=dovecot ruser=test rhost=196.251.92.78
-
 
24373
		Sep 29 08:40:44 qbpwcf.org auth[3776113]: pam_unix(dovecot:auth): check pass; user unknown
-
 
24374
		Sep 29 08:40:44 qbpwcf.org auth[3776113]: pam_unix(dovecot:auth): authentication failure; logname=liveuser uid=0 euid=0 tty=dovecot ruser=1q2w3e4r5t4567 rhost=158.94.208.72
-
 
24375
		Sep 29 08:41:18 qbpwcf.org auth[3776113]: pam_unix(dovecot:auth): check pass; user unknown
-
 
24376
		Sep 29 08:41:18 qbpwcf.org auth[3776113]: pam_unix(dovecot:auth): authentication failure; logname=liveuser uid=0 euid=0 tty=dovecot ruser=spam rhost=62.60.130.148
-
 
24377
		*/
-
 
24378
 
-
 
24379
		#認證失敗的關鍵字
-
 
24380
		$keyWordAF="authentication failure";
-
 
24381
 
-
 
24382
		#未認證或SSL錯誤
-
 
24383
		$keyWordNAA="no auth attempts";
-
 
24384
 
-
 
24385
		#搜尋符合關鍵字的log行
-
 
24386
		#函式說明:
-
 
24387
		#檢查多個字串中的每個字串是否有多個關鍵字
-
 
24388
		#回傳結果:
-
 
24389
		#$result["status"],整體來說,執行是否成功,"true"代表執行成功,"false"代表執行失敗。
-
 
24390
		#$result["function"],當前執行的函數名稱.
-
 
24391
		#$result["error"],錯誤訊息.
-
 
24392
		#$result["argu"],使用的參數.
-
 
24393
		#$result["foundedTrueKey"],結果為"true"的被搜尋元素key陣列,與其數值內容.
-
 
24394
		#$result["foundedKeyWords"],找到的關鍵字陣列.
-
 
24395
		#$result["foundedFalseKey"],結果為"false"的被搜尋元素key陣列,與其數值內容.
-
 
24396
		#$result["foundedTrueKeyWords"],二維陣列,各個字串有找到的關鍵字陣列.
-
 
24397
		#$result["foundedAll"],是否每個關鍵字都有找到,"true"代表每個都有找到,"false"代表沒有每個都找到.
-
 
24398
		#$result["keyWordsIncludeStr"],陣列,儲存有找到關鍵字的來源的索引(sourceIndex)與其內容(sourceVal)跟找到的關鍵字項目陣列(KeyWords).
-
 
24399
		#必填參數:
-
 
24400
		#$conf["keyWords"],字串陣列,想要搜尋的關鍵字.
-
 
24401
		$conf["search::findManyKeyWordsFromManyString"]["keyWords"]=array($keyWordAF,$keyWordNAA);
-
 
24402
		#$conf["stringArray"],字串陣列,要被搜尋的字串內容陣列.
-
 
24403
		$conf["search::findManyKeyWordsFromManyString"]["stringArray"]=$callShell["output"];
-
 
24404
		#可省略參數:
-
 
24405
		#$conf["completeEqual"],字串,是否內容要完全符合,不能多出任何不符合的內容,預設為"false"不需要完全符合.
-
 
24406
		#$conf["completeEqual"]="true";
-
 
24407
		#參考資料:
-
 
24408
		#無.
-
 
24409
		#備註:
-
 
24410
		#無.
-
 
24411
		$findManyKeyWordsFromManyString=search::findManyKeyWordsFromManyString($conf["search::findManyKeyWordsFromManyString"]);
-
 
24412
		unset($conf["search::findManyKeyWordsFromManyString"]);
-
 
24413
 
-
 
24414
		#如果執行失敗
-
 
24415
		if($findManyKeyWordsFromManyString["status"]==="false"){
-
 
24416
 
-
 
24417
			#設置執行失敗
-
 
24418
			$result["status"]="false";
-
 
24419
 
-
 
24420
			#設置錯誤訊息
-
 
24421
			$result["error"]=$findManyKeyWordsFromManyString;
-
 
24422
 
-
 
24423
			#回傳結果
-
 
24424
			return $result;
-
 
24425
 
-
 
24426
			}#if end
-
 
24427
 
-
 
24428
		#初始化儲存可能有問題的存取Dovecot服務遠端ip
-
 
24429
		$rickyIpsOfDocecot=array();
-
 
24430
 
-
 
24431
		#針對每個符合的log行
-
 
24432
		foreach($findManyKeyWordsFromManyString["foundedTrueKey"] as $index => $oriLog){
-
 
24433
 
-
 
24434
			#找到的關鍵字
-
 
24435
			$foundKeyWord=$findManyKeyWordsFromManyString["foundedTrueKeyWords"][$index][0];
-
 
24436
 
-
 
24437
			#依照符合的關鍵字
-
 
24438
			switch($foundKeyWord){
-
 
24439
 
-
 
24440
				#如果是認證失敗
-
 
24441
				case $keyWordAF:
-
 
24442
 
-
 
24443
					#範例
-
 
24444
					#Sep 29 08:41:18 qbpwcf.org auth[3776113]: pam_unix(dovecot:auth): authentication failure; logname=liveuser uid=0 euid=0 tty=dovecot ruser=spam rhost=62.60.130.148
-
 
24445
					#${month} ${day} ${hour}:${min}:${sec} ${doNotNeed} : authentication failure; logname=${account} ${doNotNeed} rhost=${ip}
-
 
24446
 
-
 
24447
					#取得時間點跟遠端IP
-
 
24448
					#函式說明:
-
 
24449
					#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
-
 
24450
					#回傳結果:
23255
					#回傳結果:
24451
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
23256
					#$result["status"],字串,執行是否正常,"true"代表正常,"false"代表不正常.
24452
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
23257
					#$result["error"],錯誤訊息陣列.
24453
					#$result["function"],當前執行的函式名稱.
23258
					#$result["function"],字串,當前執行的函式名稱.
24454
					#$result["argu"],所使用的參數.
-
 
24455
					#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
23259
					#$result["content"],陣列,攻擊記錄資訊,每個元素為陣列key為"ip"者為攻擊者的ip;key為info者為其資訊陣列,其key為"log"者代表log的行內容;key為"time"者代表時間點;key為ip者代表ip.
24456
					#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
-
 
24457
					#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
-
 
24458
					#必填參數:
23260
					#必填參數:
24459
					#$conf["input"],字串,要檢查的字串.
23261
					#無.
24460
					$conf["search::findSpecifyStrFormat"]["input"]=$oriLog;
-
 
24461
					#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
-
 
24462
					$conf["search::findSpecifyStrFormat"]["format"]="\${month} \${day} \${hour}:\${min}:\${sec} \${doNotNeed} : authentication failure; logname=\${account} \${doNotNeed} rhost=\${ip}";
-
 
24463
					#可省略參數:
23262
					#可省略參數:
24464
					#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
-
 
24465
					#$conf["search::findSpecifyStrFormat"]["varEqual"]=array(null,"found");
-
 
24466
					#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
23263
					#無
24467
					#$conf["varCon"]=array("no_tail"=>" not");
-
 
24468
					#參考資料:
23264
					#參考資料:
24469
					#無.
23265
					#無.
24470
					#備註:
23266
					#備註:
24471
					#無.
23267
					#無.
24472
					$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
-
 
24473
					unset($conf["search::findSpecifyStrFormat"]);
23268
					$checkPostfixAttackLog=security::checkPostfixAttackLog();
24474
 
23269
					
24475
					#如果分割失敗
23270
					#如果執行異常
24476
					if($findSpecifyStrFormat["status"]==="false"){
23271
					if($checkPostfixAttackLog["status"]==="false"){
24477
 
23272
 
24478
						#設置執行失敗
23273
						#設置執行失敗
24479
						$result["status"]="false";
23274
						$result["status"]="false";
24480
 
23275
 
24481
						#設置錯誤訊息
23276
						#設置錯誤訊息
24482
						$result["error"]=$findSpecifyStrFormat;
23277
						$result["error"]=$checkPostfixAttackLog;
24483
 
23278
 
24484
						#回傳結果
23279
						#回傳結果
24485
						return $result;
23280
						return $result;
24486
 
23281
 
24487
						}#if end
23282
						}#if end
24488
 
-
 
24489
					#如果沒有符合格式
-
 
24490
					if($findSpecifyStrFormat["found"]==="false"){
-
 
24491
 
-
 
24492
						#跳過該行
-
 
24493
						continue 2;
-
 
24494
 
-
 
24495
						}#if end
23283
					
24496
 
-
 
24497
					#取得時間點
23284
					#取得有問題的 postfix log 記錄
24498
					$time=$findSpecifyStrFormat["parsedVar"]["month"][0]." ".$findSpecifyStrFormat["parsedVar"]["day"][0]." ".$findSpecifyStrFormat["parsedVar"]["hour"][0].":".$findSpecifyStrFormat["parsedVar"]["min"][0].":".$findSpecifyStrFormat["parsedVar"]["sec"][0];
23285
					$ips_smtp=$checkPostfixAttackLog["content"];
24499
 
-
 
24500
					#取得ip
23286
					
24501
					$ip=$findSpecifyStrFormat["parsedVar"]["ip"][0];
-
 
24502
 
-
 
24503
					#儲存其資訊
-
 
24504
					$rickyIpsOfDocecot[$ip][]=array("time"=>$time,"ip"=>$ip,"log"=>$oriLog);
-
 
24505
 
-
 
24506
					#跳出  switch
23287
					#跳出 switch
24507
					break;
23288
					break;
24508
 
23289
					
24509
				#如果是未認證或SSL錯誤
23290
				#如果是 "named"
24510
				case $keyWordNAA:
23291
				case "named":
24511
 
-
 
24512
					#範例
-
 
24513
					#Feb 23 07:59:30 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<70q2l/W7PBhliNc9>
23292
				
24514
					#Sep 29 06:53:42 qbpwcf.org dovecot[98]: imap-login: Disconnected: Connection closed (no auth attempts in 0 secs): user=<>, rip=3.231.151.171, lip=169.254.2.1, TLS, session=<MaKQGOs/wIMD55er>
-
 
24515
					#${month} ${day} ${hour}:${min}:${sec} ${doNotNeed} ( no auth attempts in ${doNotNeed} user=<${account}>, rip=${ip}, ${doNotNeed}
-
 
24516
 
-
 
24517
					#取得時間點跟遠端IP
-
 
24518
					#函式說明:
23293
					#函式說明:
24519
					#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
23294
					#檢查 named log 中疑似攻擊的記錄.
24520
					#回傳結果:
23295
					#回傳結果:
24521
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
23296
					#$result["status"],字串,執行是否正常,"true"代表正常,"false"代表不正常.
24522
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
23297
					#$result["error"],錯誤訊息陣列.
24523
					#$result["function"],當前執行的函式名稱.
23298
					#$result["function"],字串,當前執行的函式名稱.
24524
					#$result["argu"],所使用的參數.
-
 
24525
					#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
23299
					#$result["content"],陣列,攻擊記錄資訊,每個元素為陣列key為"ip"者為攻擊者的ip;key為info者為其資訊陣列,其key為"log"者代表log的行內容;key為"time"者代表時間點;key為ip者代表ip.
24526
					#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
-
 
24527
					#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
-
 
24528
					#必填參數:
23300
					#必填參數:
24529
					#$conf["input"],字串,要檢查的字串.
23301
					#無.
24530
					$conf["search::findSpecifyStrFormat"]["input"]=$oriLog;
-
 
24531
					#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
-
 
24532
					$conf["search::findSpecifyStrFormat"]["format"]="\${month} \${day} \${hour}:\${min}:\${sec} \${doNotNeed} ( no auth attempts in \${doNotNeed} user=<\${account}>, rip=\${ip}, \${doNotNeed}";
-
 
24533
					#可省略參數:
23302
					#可省略參數:
24534
					#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
-
 
24535
					#$conf["search::findSpecifyStrFormat"]["varEqual"]=array(null,"found");
-
 
24536
					#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
23303
					#無
24537
					#$conf["varCon"]=array("no_tail"=>" not");
-
 
24538
					#參考資料:
23304
					#參考資料:
24539
					#無.
23305
					#無.
24540
					#備註:
23306
					#備註:
24541
					#無.
23307
					#無.
24542
					$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
-
 
24543
					unset($conf["search::findSpecifyStrFormat"]);
23308
					$checkNamedAttackLog=security::checkNamedAttackLog();
24544
 
23309
					
24545
					#如果分割失敗
23310
					#如果執行異常
24546
					if($findSpecifyStrFormat["status"]==="false"){
23311
					if($checkNamedAttackLog["status"]==="false"){
24547
 
23312
 
24548
						#設置執行失敗
23313
						#設置執行失敗
24549
						$result["status"]="false";
23314
						$result["status"]="false";
24550
 
23315
 
24551
						#設置錯誤訊息
23316
						#設置錯誤訊息
24552
						$result["error"]=$findSpecifyStrFormat;
23317
						$result["error"]=$checkNamedAttackLog;
24553
 
23318
 
24554
						#回傳結果
23319
						#回傳結果
24555
						return $result;
23320
						return $result;
24556
 
23321
 
24557
						}#if end
23322
						}#if end
24558
 
-
 
24559
					#如果沒有符合格式
-
 
24560
					if($findSpecifyStrFormat["found"]==="false"){
-
 
24561
 
-
 
24562
						#跳過該行
-
 
24563
						continue 2;
-
 
24564
 
-
 
24565
						}#if end
23323
					
24566
 
-
 
24567
					#取得時間點
23324
					#取得有問題的 dns log 記錄
24568
					$time=$findSpecifyStrFormat["parsedVar"]["month"][0]." ".$findSpecifyStrFormat["parsedVar"]["day"][0]." ".$findSpecifyStrFormat["parsedVar"]["hour"][0].":".$findSpecifyStrFormat["parsedVar"]["min"][0].":".$findSpecifyStrFormat["parsedVar"]["sec"][0];
23325
					$attacker_ips_namd=$checkNamedAttackLog["content"];
24569
 
-
 
24570
					#取得ip
23326
				
24571
					$ip=$findSpecifyStrFormat["parsedVar"]["ip"][0];
-
 
24572
 
-
 
24573
					#儲存其資訊
-
 
24574
					$rickyIpsOfDocecot[$ip][]=array("time"=>$time,"ip"=>$ip,"log"=>$oriLog);
-
 
24575
 
-
 
24576
					#跳出  switch
23327
					#跳出 switch
24577
					break;
-
 
24578
 
-
 
24579
				#不應該執行到這邊
-
 
24580
				default:
-
 
24581
 
-
 
24582
					#設置執行失敗
-
 
24583
					$result["status"]="false";
-
 
24584
 
-
 
24585
					#設置錯誤訊息
-
 
24586
					$result["error"][]="unexpected error";
-
 
24587
 
-
 
24588
					#設置錯誤訊息
-
 
24589
					$result["error"][]=$findManyKeyWordsFromManyString;
-
 
24590
 
-
 
24591
					#回傳結果
-
 
24592
					return $result;
-
 
24593
 
-
 
24594
				}#switch end
-
 
24595
 
-
 
24596
			}#foreach end
-
 
24597
 
-
 
24598
		#初始化儲存可能有問題的ip資訊
-
 
24599
		$risky_ips=array();
-
 
24600
 
-
 
24601
		#針對每個ip
-
 
24602
		foreach($rickyIpsOfDocecot as $ip => $info){
-
 
24603
 
-
 
24604
			#如果同樣ip不到3次
-
 
24605
			if(count($rickyIpsOfDocecot[$ip])<3){
-
 
24606
 
-
 
24607
				#換看下個ip
-
 
24608
				continue;
-
 
24609
 
-
 
24610
				}#if end
-
 
24611
 
-
 
24612
			#儲存可能有問題的ip資訊
-
 
24613
			$risky_ips[]=$rickyIpsOfDocecot[$ip];
-
 
24614
 
-
 
24615
			}#foreach end
-
 
24616
 
-
 
24617
		#針對每個可能有問題ip的每個log行
-
 
24618
		foreach($risky_ips as $ip => $infos){
-
 
24619
 
-
 
24620
			#初始化暫存歷史資訊的陣列
-
 
24621
			$history=array();
-
 
24622
 
-
 
24623
			#初始化記錄ip來訪不大於1分鐘的計數
-
 
24624
			$count=0;
-
 
24625
 
-
 
24626
			#針對每個log行資訊
-
 
24627
			foreach($infos as $index => $info){
-
 
24628
 
-
 
24629
				#unixtime
-
 
24630
				$time=strtotime($info["time"]);
-
 
24631
 
-
 
24632
				#如果沒有下筆記錄
-
 
24633
				if(!isset($infos[$index+1])){
-
 
24634
 
-
 
24635
					#結束 foreach
-
 
24636
					break;
23328
					break;
24637
 
-
 
24638
					}#if end
23329
					
24639
 
-
 
24640
				#取得unixtime
-
 
24641
				$next_time=strtotime($infos[$index+1]["time"]);
-
 
24642
 
-
 
24643
				#如果時間間隔大於60秒
-
 
24644
				if($next_time-$time>60){
-
 
24645
 
-
 
24646
					#跳過,看下筆記錄
-
 
24647
					continue;
-
 
24648
 
-
 
24649
					}#if end
-
 
24650
 
-
 
24651
				#計數+1
-
 
24652
				$count++;
-
 
24653
 
-
 
24654
				#記錄該次事件資訊
-
 
24655
				$history[]=array("time"=>$time,"log"=>$info["log"]);
-
 
24656
 
-
 
24657
				}#foreach end
-
 
24658
 
-
 
24659
			#如果有達到3次
23330
				#如果是 "dovecot"
24660
			if($count>=3){
-
 
24661
 
-
 
24662
				#初始化陣列
-
 
24663
				$tmp=array();
-
 
24664
 
-
 
24665
				#記錄ip
-
 
24666
				$tmp["ip"]=$ip;
23331
				case "dovecot":
24667
 
-
 
24668
				#記錄歷史資訊
-
 
24669
				$tmp["info"]=$history;
-
 
24670
 
-
 
24671
				#記錄攻擊者的IP
-
 
24672
				$attacker_ips_imap[]=$ip;
-
 
24673
 
-
 
24674
				}#if end
-
 
24675
 
-
 
24676
			}#foreach end
-
 
24677
 
-
 
24678
		#記錄ssh攻擊者的IP
-
 
24679
		$attacker_ips_ssh=array();
-
 
24680
 
-
 
24681
		#透過 journalctl -a -e --unit=sshd.service來取得 ssh 攻擊者的 IP
-
 
24682
		#函式說明:
-
 
24683
		#呼叫shell執行系統命令,並取得回傳的內容.
-
 
24684
		#回傳的結果:
-
 
24685
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
24686
		#$result["error"],錯誤訊息陣列.
-
 
24687
		#$result["function"],當前執行的函式名稱.
-
 
24688
		#$result["argu"],使用的參數.
-
 
24689
		#$result["cmd"],執行的指令內容.
-
 
24690
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
-
 
24691
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
-
 
24692
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
-
 
24693
		#$result["running"],是否還在執行.
-
 
24694
		#$result["pid"],pid.
-
 
24695
		#$result["statusCode"],執行結束後的代碼.
-
 
24696
		#必填參數:
-
 
24697
		#$conf["command"],字串,要執行的指令與.
-
 
24698
		$conf["external::callShell"]["command"]="journalctl";
-
 
24699
		#$conf["fileArgu"],字串,變數__FILE__的內容.
-
 
24700
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
-
 
24701
		#可省略參數:
-
 
24702
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
-
 
24703
		$conf["external::callShell"]["argu"]=array("-a","-e","--unit=sshd.service");
-
 
24704
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
-
 
24705
		#$conf["arguIsAddr"]=array();
-
 
24706
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
-
 
24707
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
-
 
24708
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
-
 
24709
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
-
 
24710
		#$conf["enablePrintDescription"]="true";
-
 
24711
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
-
 
24712
		#$conf["printDescription"]="";
-
 
24713
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
-
 
24714
		$conf["external::callShell"]["escapeshellarg"]="true";
-
 
24715
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
-
 
24716
		#$conf["username"]="";
-
 
24717
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
-
 
24718
		#$conf["password"]="";
-
 
24719
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
-
 
24720
		#$conf["useScript"]="";
-
 
24721
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
-
 
24722
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
-
 
24723
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
-
 
24724
		#$conf["inBackGround"]="";
-
 
24725
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
-
 
24726
		#$conf["getErr"]="false";
-
 
24727
		#備註:
-
 
24728
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
-
 
24729
		#參考資料:
-
 
24730
		#exec=>http://php.net/manual/en/function.exec.php
-
 
24731
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
-
 
24732
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
-
 
24733
		$callShell=external::callShell($conf["external::callShell"]);
-
 
24734
		unset($conf["external::callShell"]);
-
 
24735
 
-
 
24736
		#如果執行失敗
-
 
24737
		if($callShell["status"]==="false"){
-
 
24738
 
-
 
24739
			#設置執行失敗
-
 
24740
			$result["status"]="false";
-
 
24741
 
-
 
24742
			#設置錯誤訊息
-
 
24743
			$result["error"]=$callShell;
-
 
24744
 
-
 
24745
			#回傳結果
-
 
24746
			return $result;
-
 
24747
 
-
 
24748
			}#if end
-
 
24749
 
-
 
24750
		/*
-
 
24751
		得到的範例輸出
-
 
24752
		Sep 30 00:36:36 silverblue-guest.qbpwcf.org sshd-session[1607010]: Invalid user lizepeng from 60.213.10.69 port 39156
-
 
24753
		Sep 30 00:36:36 silverblue-guest.qbpwcf.org sshd-session[1607010]: pam_unix(sshd:auth): check pass; user unknown
-
 
24754
		Sep 30 00:36:36 silverblue-guest.qbpwcf.org sshd-session[1607010]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=60.213.10.69
-
 
24755
		Sep 30 00:36:38 silverblue-guest.qbpwcf.org sshd-session[1607010]: Failed password for invalid user lizepeng from 60.213.10.69 port 39156 ssh2
-
 
24756
		Sep 30 00:36:40 silverblue-guest.qbpwcf.org sshd-session[1607010]: Connection closed by invalid user lizepeng 60.213.10.69 port 39156 [preauth]
-
 
24757
		Sep 30 05:54:01 silverblue-guest.qbpwcf.org sshd-session[2346022]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=60.213.10.81  user=root
-
 
24758
		Sep 30 05:54:03 silverblue-guest.qbpwcf.org sshd-session[2346022]: Failed password for root from 60.213.10.81 port 41644 ssh2
-
 
24759
		Sep 30 05:54:04 silverblue-guest.qbpwcf.org sshd-session[2346022]: Connection closed by authenticating user root 60.213.10.81 port 41644 [preauth]
-
 
24760
		Sep 30 05:54:20 silverblue-guest.qbpwcf.org sshd-session[2346860]: Invalid user qy from 60.213.10.81 port 42960
-
 
24761
		Sep 30 05:54:21 silverblue-guest.qbpwcf.org sshd-session[2346860]: pam_unix(sshd:auth): check pass; user unknown
-
 
24762
		Sep 30 05:54:21 silverblue-guest.qbpwcf.org sshd-session[2346860]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=60.213.10.81
-
 
24763
		Sep 30 05:54:22 silverblue-guest.qbpwcf.org sshd-session[2346860]: Failed password for invalid user qy from 60.213.10.81 port 42960 ssh2
-
 
24764
		Sep 30 05:54:23 silverblue-guest.qbpwcf.org sshd-session[2346860]: Connection closed by invalid user qy 60.213.10.81 port 42960 [preauth]
-
 
24765
		Sep 30 06:08:06 silverblue-guest.qbpwcf.org sshd-session[2378295]: Connection closed by 167.94.145.105 port 55712 [preauth]
-
 
24766
		Sep 30 08:09:51 silverblue-guest.qbpwcf.org sshd-session[2662907]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=183.13.207.69  user=root
-
 
24767
		Sep 30 08:09:54 silverblue-guest.qbpwcf.org sshd-session[2662907]: Failed password for root from 183.13.207.69 port 18258 ssh2
-
 
24768
		Sep 30 08:09:54 silverblue-guest.qbpwcf.org sshd-session[2662907]: Connection closed by authenticating user root 183.13.207.69 port 18258 [preauth]
-
 
24769
		Sep 30 08:10:11 silverblue-guest.qbpwcf.org sshd-session[2663658]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=183.13.207.69  user=root
-
 
24770
		Sep 30 08:10:13 silverblue-guest.qbpwcf.org sshd-session[2663658]: Failed password for root from 183.13.207.69 port 17293 ssh2
-
 
24771
		Sep 30 08:10:13 silverblue-guest.qbpwcf.org sshd-session[2663658]: Connection closed by authenticating user root 183.13.207.69 port 17293 [preauth]
-
 
24772
		*/
23332
				
24773
 
-
 
24774
		#認證失敗的關鍵字
-
 
24775
		$keyWordFP=" Failed password ";
-
 
24776
 
-
 
24777
		#不存在使用者的關鍵字
-
 
24778
		$keyWordIU=" Invalid user ";
-
 
24779
 
-
 
24780
		#搜尋符合關鍵字的log行
-
 
24781
		#函式說明:
23333
					#函式說明:
24782
		#檢查多個字串中的每個字串是否有多個關鍵字
23334
					#檢查 dovecot log 中疑似攻擊的記錄.
24783
		#回傳結果:
-
 
24784
		#$result["status"],整體來說,執行是否成功,"true"代表執行成功,"false"代表執行失敗。
-
 
24785
		#$result["function"],當前執行的函數名稱.
-
 
24786
		#$result["error"],錯誤訊息.
-
 
24787
		#$result["argu"],使用的參數.
-
 
24788
		#$result["foundedTrueKey"],結果為"true"的被搜尋元素key陣列,與其數值內容.
-
 
24789
		#$result["foundedKeyWords"],找到的關鍵字陣列.
-
 
24790
		#$result["foundedFalseKey"],結果為"false"的被搜尋元素key陣列,與其數值內容.
-
 
24791
		#$result["foundedTrueKeyWords"],二維陣列,各個字串有找到的關鍵字陣列.
-
 
24792
		#$result["foundedAll"],是否每個關鍵字都有找到,"true"代表每個都有找到,"false"代表沒有每個都找到.
-
 
24793
		#$result["keyWordsIncludeStr"],陣列,儲存有找到關鍵字的來源的索引(sourceIndex)與其內容(sourceVal)跟找到的關鍵字項目陣列(KeyWords).
-
 
24794
		#必填參數:
-
 
24795
		#$conf["keyWords"],字串陣列,想要搜尋的關鍵字.
-
 
24796
		$conf["search::findManyKeyWordsFromManyString"]["keyWords"]=array($keyWordFP,$keyWordIU);
-
 
24797
		#$conf["stringArray"],字串陣列,要被搜尋的字串內容陣列.
-
 
24798
		$conf["search::findManyKeyWordsFromManyString"]["stringArray"]=$callShell["output"];
-
 
24799
		#可省略參數:
-
 
24800
		#$conf["completeEqual"],字串,是否內容要完全符合,不能多出任何不符合的內容,預設為"false"不需要完全符合.
-
 
24801
		#$conf["completeEqual"]="true";
-
 
24802
		#參考資料:
-
 
24803
		#無.
-
 
24804
		#備註:
-
 
24805
		#無.
-
 
24806
		$findManyKeyWordsFromManyString=search::findManyKeyWordsFromManyString($conf["search::findManyKeyWordsFromManyString"]);
-
 
24807
		unset($conf["search::findManyKeyWordsFromManyString"]);
-
 
24808
 
-
 
24809
		#如果執行失敗
-
 
24810
		if($findManyKeyWordsFromManyString["status"]==="false"){
-
 
24811
 
-
 
24812
			#設置執行失敗
-
 
24813
			$result["status"]="false";
-
 
24814
 
-
 
24815
			#設置錯誤訊息
-
 
24816
			$result["error"]=$findManyKeyWordsFromManyString;
-
 
24817
 
-
 
24818
			#回傳結果
-
 
24819
			return $result;
-
 
24820
 
-
 
24821
			}#if end
-
 
24822
 
-
 
24823
		#初始化儲存可能有問題的存取ssh服務遠端ip
-
 
24824
		$risky_ips=array();
-
 
24825
 
-
 
24826
		#針對每個符合的log行
-
 
24827
		foreach($findManyKeyWordsFromManyString["foundedTrueKey"] as $index => $oriLog){
-
 
24828
 
-
 
24829
			#找到的關鍵字
-
 
24830
			$foundKeyWord=$findManyKeyWordsFromManyString["foundedTrueKeyWords"][$index][0];
-
 
24831
 
-
 
24832
			#依照符合的關鍵字
-
 
24833
			switch($foundKeyWord){
-
 
24834
 
-
 
24835
				#如果是秘密碼錯誤
-
 
24836
				case $keyWordFP:
-
 
24837
 
-
 
24838
					#範例
-
 
24839
					#Sep 30 08:10:13 silverblue-guest.qbpwcf.org sshd-session[2663658]: Failed password for root from 183.13.207.69 port 17293 ssh2
-
 
24840
					#${month} ${day} ${hour}:${min}:${sec} ${doNotNeed} Failed password for ${account} from ${ip} ${doNotNeed}
-
 
24841
 
-
 
24842
					#取得時間點跟遠端IP
-
 
24843
					#函式說明:
-
 
24844
					#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
-
 
24845
					#回傳結果:
23335
					#回傳結果:
24846
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
23336
					#$result["status"],字串,執行是否正常,"true"代表正常,"false"代表不正常.
24847
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
23337
					#$result["error"],錯誤訊息陣列.
24848
					#$result["function"],當前執行的函式名稱.
23338
					#$result["function"],字串,當前執行的函式名稱.
24849
					#$result["argu"],所使用的參數.
-
 
24850
					#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
23339
					#$result["content"],陣列,攻擊記錄資訊,每個元素為陣列key為"ip"者為攻擊者的ip;key為info者為其資訊陣列,其key為"log"者代表log的行內容;key為"time"者代表時間點;key為ip者代表ip.
24851
					#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
-
 
24852
					#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
-
 
24853
					#必填參數:
23340
					#必填參數:
24854
					#$conf["input"],字串,要檢查的字串.
23341
					#無.
24855
					$conf["search::findSpecifyStrFormat"]["input"]=$oriLog;
-
 
24856
					#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
-
 
24857
					$conf["search::findSpecifyStrFormat"]["format"]="\${month} \${day} \${hour}:\${min}:\${sec} \${doNotNeed} Failed password for \${account} from \${ip} \${doNotNeed}";
-
 
24858
					#可省略參數:
23342
					#可省略參數:
24859
					#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
-
 
24860
					#$conf["search::findSpecifyStrFormat"]["varEqual"]=array(null,"found");
-
 
24861
					#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
23343
					#無
24862
					#$conf["varCon"]=array("no_tail"=>" not");
-
 
24863
					#參考資料:
23344
					#參考資料:
24864
					#無.
23345
					#無.
24865
					#備註:
23346
					#備註:
24866
					#無.
23347
					#無.
24867
					$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
-
 
24868
					unset($conf["search::findSpecifyStrFormat"]);
23348
					$checkDovecotAttackLog=security::checkDovecotAttackLog();
24869
 
23349
					
24870
					#如果分割失敗
23350
					#如果執行異常
24871
					if($findSpecifyStrFormat["status"]==="false"){
23351
					if($checkDovecotAttackLog["status"]==="false"){
24872
 
23352
 
24873
						#設置執行失敗
23353
						#設置執行失敗
24874
						$result["status"]="false";
23354
						$result["status"]="false";
24875
 
23355
 
24876
						#設置錯誤訊息
23356
						#設置錯誤訊息
24877
						$result["error"]=$findSpecifyStrFormat;
23357
						$result["error"]=$checkDovecotAttackLog;
24878
 
23358
 
24879
						#回傳結果
23359
						#回傳結果
24880
						return $result;
23360
						return $result;
24881
 
23361
 
24882
						}#if end
23362
						}#if end
24883
 
-
 
24884
					#如果沒有符合格式
-
 
24885
					if($findSpecifyStrFormat["found"]==="false"){
-
 
24886
 
-
 
24887
						#跳過該行
-
 
24888
						continue 2;
-
 
24889
 
-
 
24890
						}#if end
23363
					
24891
 
-
 
24892
					#取得時間點
23364
					#取得有問題的 dovecot log 記錄
24893
					$time=$findSpecifyStrFormat["parsedVar"]["month"][0]." ".$findSpecifyStrFormat["parsedVar"]["day"][0]." ".$findSpecifyStrFormat["parsedVar"]["hour"][0].":".$findSpecifyStrFormat["parsedVar"]["min"][0].":".$findSpecifyStrFormat["parsedVar"]["sec"][0];
23365
					$attacker_ips_imap=$checkDovecotAttackLog["content"];
24894
 
-
 
24895
					#取得ip
23366
				
24896
					$ip=$findSpecifyStrFormat["parsedVar"]["ip"][0];
-
 
24897
 
-
 
24898
					#儲存其資訊
-
 
24899
					$risky_ips[$ip][]=array("time"=>$time,"ip"=>$ip,"log"=>$oriLog);
-
 
24900
 
-
 
24901
					#跳出  switch
23367
					#跳出 switch
24902
					break;
23368
					break;
24903
 
23369
					
24904
				#如果是不存在的使用者
23370
				#如果是 "ssh"
24905
				case $keyWordIU:
23371
				case "ssh":
24906
 
-
 
24907
					#範例
23372
				
24908
					#Sep 30 00:36:36 silverblue-guest.qbpwcf.org sshd-session[1607010]: Invalid user lizepeng from 60.213.10.69 port 39156
-
 
24909
					#${month} ${day} ${hour}:${min}:${sec} ${doNotNeed} Invalid user ${account} from ${ip} port ${doNotNeed}
-
 
24910
 
-
 
24911
					#取得時間點跟遠端IP
-
 
24912
					#函式說明:
23373
					#函式說明:
24913
					#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
23374
					#檢查 ssh log 中疑似攻擊的記錄.
24914
					#回傳結果:
23375
					#回傳結果:
24915
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
23376
					#$result["status"],字串,執行是否正常,"true"代表正常,"false"代表不正常.
24916
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
23377
					#$result["error"],錯誤訊息陣列.
24917
					#$result["function"],當前執行的函式名稱.
23378
					#$result["function"],字串,當前執行的函式名稱.
24918
					#$result["argu"],所使用的參數.
-
 
24919
					#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
23379
					#$result["content"],陣列,攻擊記錄資訊,每個元素為陣列key為"ip"者為攻擊者的ip;key為info者為其資訊陣列,其key為"log"者代表log的行內容;key為"time"者代表時間點;key為ip者代表ip.
24920
					#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
-
 
24921
					#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
-
 
24922
					#必填參數:
23380
					#必填參數:
24923
					#$conf["input"],字串,要檢查的字串.
23381
					#無.
24924
					$conf["search::findSpecifyStrFormat"]["input"]=$oriLog;
-
 
24925
					#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
-
 
24926
					$conf["search::findSpecifyStrFormat"]["format"]="\${month} \${day} \${hour}:\${min}:\${sec} \${doNotNeed} Invalid user \${account} from \${ip} port \${doNotNeed}";
-
 
24927
					#可省略參數:
23382
					#可省略參數:
24928
					#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
-
 
24929
					#$conf["search::findSpecifyStrFormat"]["varEqual"]=array(null,"found");
-
 
24930
					#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
23383
					#無
24931
					#$conf["varCon"]=array("no_tail"=>" not");
-
 
24932
					#參考資料:
23384
					#參考資料:
24933
					#無.
23385
					#無.
24934
					#備註:
23386
					#備註:
24935
					#無.
23387
					#無.
24936
					$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
-
 
24937
					unset($conf["search::findSpecifyStrFormat"]);
23388
					$checkSshAttackLog=security::checkSshAttackLog();
24938
 
23389
					
24939
					#如果分割失敗
23390
					#如果執行異常
24940
					if($findSpecifyStrFormat["status"]==="false"){
23391
					if($checkSshAttackLog["status"]==="false"){
24941
 
23392
 
24942
						#設置執行失敗
23393
						#設置執行失敗
24943
						$result["status"]="false";
23394
						$result["status"]="false";
24944
 
23395
 
24945
						#設置錯誤訊息
23396
						#設置錯誤訊息
24946
						$result["error"]=$findSpecifyStrFormat;
23397
						$result["error"]=$checkSshAttackLog;
24947
 
23398
 
24948
						#回傳結果
23399
						#回傳結果
24949
						return $result;
23400
						return $result;
24950
 
23401
 
24951
						}#if end
23402
						}#if end
24952
 
-
 
24953
					#如果沒有符合格式
-
 
24954
					if($findSpecifyStrFormat["found"]==="false"){
-
 
24955
 
-
 
24956
						#跳過該行
-
 
24957
						continue 2;
-
 
24958
 
-
 
24959
						}#if end
23403
					
24960
 
-
 
24961
					#取得時間點
23404
					#取得有問題的 ssh log 記錄
24962
					$time=$findSpecifyStrFormat["parsedVar"]["month"][0]." ".$findSpecifyStrFormat["parsedVar"]["day"][0]." ".$findSpecifyStrFormat["parsedVar"]["hour"][0].":".$findSpecifyStrFormat["parsedVar"]["min"][0].":".$findSpecifyStrFormat["parsedVar"]["sec"][0];
23405
					$attacker_ips_ssh=$checkSshAttackLog["content"];
24963
 
-
 
24964
					#取得ip
23406
				
24965
					$ip=$findSpecifyStrFormat["parsedVar"]["ip"][0];
-
 
24966
 
-
 
24967
					#儲存其資訊
-
 
24968
					$risky_ips[$ip][]=array("time"=>$time,"ip"=>$ip,"log"=>$oriLog);
-
 
24969
 
-
 
24970
					#跳出  switch
23407
					#跳出 switch
24971
					break;
23408
					break;
24972
 
23409
					
24973
				#不應該執行到這邊
23410
				#其他不支援的服務
24974
				default:
23411
				default:
24975
 
23412
				
24976
					#設置執行失敗
23413
					#設置執行失敗
24977
					$result["status"]="false";
23414
					$result["status"]="false";
24978
 
23415
 
24979
					#設置錯誤訊息
23416
					#設置錯誤訊息
24980
					$result["error"][]="unexpected error";
23417
					$result["error"][]="unsupported service:".$serviceName;
24981
 
-
 
24982
					#設置錯誤訊息
-
 
24983
					$result["error"][]=$findManyKeyWordsFromManyString;
-
 
24984
 
23418
 
24985
					#回傳結果
23419
					#回傳結果
24986
					return $result;
23420
					return $result;
24987
 
23421
			
24988
				}#switch end
23422
				}#switch end
24989
 
-
 
24990
			}#foreach end
-
 
24991
 
-
 
24992
		#針對每個可能有問題ip的每個log行
-
 
24993
		foreach($risky_ips as $ip => $infos){
-
 
24994
 
-
 
24995
			#初始化暫存歷史記錄的陣列
-
 
24996
			$history=array();
-
 
24997
 
-
 
24998
			#初始化記錄ip來訪不大於1分鐘的計數
-
 
24999
			$count=0;
-
 
25000
 
-
 
25001
			#針對每個log行資訊
-
 
25002
			foreach($infos as $index => $info){
-
 
25003
 
-
 
25004
				#unixtime
-
 
25005
				$time=strtotime($info["time"]);
-
 
25006
 
-
 
25007
				#如果沒有下筆記錄
-
 
25008
				if(!isset($infos[$index+1])){
-
 
25009
 
-
 
25010
					#結束 foreach
-
 
25011
					break;
-
 
25012
 
-
 
25013
					}#if end
-
 
25014
 
-
 
25015
				#取得unixtime
-
 
25016
				$next_time=strtotime($infos[$index+1]["time"]);
-
 
25017
 
-
 
25018
				#如果下筆時間記錄與當前這筆間隔大於60秒
-
 
25019
				if($next_time-$time>60){
-
 
25020
 
-
 
25021
					#跳過,看下筆記錄
-
 
25022
					continue;
-
 
25023
 
-
 
25024
					}#if end
-
 
25025
 
-
 
25026
				#計數+1
-
 
25027
				$count++;
-
 
25028
				
-
 
25029
				#記錄該次記錄
-
 
25030
				$history[]=array("time"=>$time,"log"=>$info["log"]);
-
 
25031
 
-
 
25032
				}#foreach end
-
 
25033
 
-
 
25034
			#如果有達到3次
-
 
25035
			if($count>=3){
-
 
25036
 
-
 
25037
				#初始化暫存的陣列
-
 
25038
				$tmp=array();
-
 
25039
				
-
 
25040
				#取得資訊
-
 
25041
				$tmp["info"]=$history;
-
 
25042
				
23423
			
25043
				#取得問題ip
-
 
25044
				$tmp["ip"]=$ip;
-
 
25045
 
-
 
25046
				#記錄攻擊者的IP
-
 
25047
				$attacker_ips_ssh[]=$tmp;
-
 
25048
 
-
 
25049
				}#if end
-
 
25050
 
-
 
25051
			}#foreach end
23424
			}#foreach end
25052
 
23425
 
25053
		#合併取得的有問題IP集合
23426
		#合併取得的有問題IP集合
25054
		#$ips,$ips_https,$ips_smtp,$attacker_ips_imap,$attacker_ips_namd,$attacker_ips_ssh
23427
		#$ips,$ips_https,$ips_smtp,$attacker_ips_imap,$attacker_ips_namd,$attacker_ips_ssh
25055
 
23428
 
Line 25060... Line 23433...
25060
		#$result["error"],錯誤訊息陣列.
23433
		#$result["error"],錯誤訊息陣列.
25061
		#$result["function"],當前執行的函式.
23434
		#$result["function"],當前執行的函式.
25062
		#$result["content"],合併好的一維陣列.
23435
		#$result["content"],合併好的一維陣列.
25063
		#必填參數:
23436
		#必填參數:
25064
		#$conf["inputArray"],陣列,要合併的一維陣列變數,例如:=array($array1,$array2);
23437
		#$conf["inputArray"],陣列,要合併的一維陣列變數,例如:=array($array1,$array2);
25065
		$conf["arrays::mergeArray"]["inputArray"]=array($ips,$ips_https,$ips_smtp,$attacker_ips_namd,$attacker_ips_imap,$attacker_ips_ssh);
23438
		$conf["arrays::mergeArray"]["inputArray"]=array($ips_http,$ips_https,$ips_smtp,$attacker_ips_namd,$attacker_ips_imap,$attacker_ips_ssh);
25066
		#可省略參數:
23439
		#可省略參數:
25067
		#$conf["allowRepeat"],字串,預設為"true",允許重複的結果;若為"false"則不會出現重複的元素內容.
23440
		#$conf["allowRepeat"],字串,預設為"true",允許重複的結果;若為"false"則不會出現重複的元素內容.
25068
		$conf["arrays::mergeArray"]["allowRepeat"]="false";
23441
		$conf["arrays::mergeArray"]["allowRepeat"]="false";
25069
		$mergeArray=arrays::mergeArray($conf["arrays::mergeArray"]);
23442
		$mergeArray=arrays::mergeArray($conf["arrays::mergeArray"]);
25070
		unset($conf["arrays::mergeArray"]);
23443
		unset($conf["arrays::mergeArray"]);