def saveLogBtnClick(self): # 로그 기록 텍스트 파일로 저장 logDB = mongoDB.DBConn("shutdown").log logData = logDB.find({}, {'_id': 0}) logDBCount = logDB.count() for item in logData: inputData = str(item).replace("{", "").replace("}", "") f = open("log.txt", 'w') for i in range(1, logDBCount + 1): data = "NUMBER{} --> {}\n".format(i, inputData) f.write(data) f.close()
def delBtnClick(self): filePath = self.ui.page2_filepathLabel.text( ) + self.ui.page2_filenameLabel.text() os.remove(filePath) # 버튼 비활성화 self.ui.delFileBtn.setEnabled(True) self.ui.delFileBtn.setStyleSheet( "background-color: #0F75BD;color: white;border:nono;") # 로그디비에 삭제기록 업데이트 fileHash = getFileHash.getFileHash(filePath) logDB = mongoDB.DBConn("shutdown").log logDB.update({"hash": fileHash}, {"state": "REMOVED"})
def delFileBtnClick(self): # 로그 테이블에서 기록 선택 후 파일 삭제 try: selectedRow = self.ui.logTable.currentRow() filePath = self.ui.logTable.item(selectedRow, 1).text() filePath = str(filePath).strip() # 로그디비에 삭제 logDB = mongoDB.DBConn("shutdown").log logDB.remove({"filename": filePath}) os.remove(filePath) except: pass Form.selectLog(self) self.ui.logTable.repaint()
def checkHashInDB(md5Hash): checkCount = 0 try: opcode_data = mongoDB.DBConn("shutdown").opcode_data selectDB = opcode_data.find({}, {'_id': 0, 'hash': 1, 'kind': 1}) for i in selectDB: i = str(i).split(",") kind = i[0].replace("{'kind': '", "").replace("'", "") hash = i[1].replace(" 'hash': '", "").replace("'}", "") if hash == md5Hash: if kind == "MALWARE": checkCount = 1 return "YES", "M" elif kind == "NORMAL": checkCount = 0 return "YES", "N" if checkCount == 0: return "NO", "?" else: return "YES" except: pass
def startFileDetectionBtnClick(self): QGuiApplication.setOverrideCursor(Qt.WaitCursor) self.ui.loadingImg.show() Form.loadingAnimation(self) print(fname) # tab1에 내용 세팅 todayTime = datetime.today().strftime("%Y-%m-%d %H:%M:%S") self.ui.page2_dateLabel.setText(todayTime) fileBaseName = os.path.basename(fname) self.ui.page2_filenameLabel.setText(fileBaseName) fileDirName = os.path.dirname(fname) self.ui.page2_filepathLabel.setText(fileDirName) fileHash = getFileHash.getFileHash(fname) self.ui.page2_md5Label.setText(fileHash) # 입력받은 파일의 해시값을 데이터베이스와 비교 self.ui.numberCountLabel.setPixmap(QPixmap("Proc02Hash.jpg")) md5Check = getFileHash.checkHashInDB(fname) if md5Check[0] == "YES": if md5Check[1] == "M": self.ui.MD5HashLabel.setText("악성파일") self.ui.page2_similarLabel.setText("악성파일") elif md5Check[1] == "N": self.ui.MD5HashLabel.setText("정상파일") self.ui.page2_similarLabel.setText("정상파일") elif md5Check[0] == "NO": self.ui.numberCountLabel.setPixmap(QPixmap("Proc03VTotal.jpg")) self.ui.MD5HashLabel.setText("해시값 미등록 파일") # 바이러스 토탈 돌리기 dic = vt.get_mal_kind(fname) try: if dic[0] > 4: self.ui.VTResultLabel.setText(dic[0] + "밴더 탐지") self.ui.numberCountLabel.setPixmap( QPixmap("Proc04Machine.jpg")) # 머신러닝 machineRslt = fileMachine.getFIleMachine(fname) if machineRslt == "NORMAL": self.ui.page2_similarLabel.setText("정상파일") self.ui.machineResultLabel.setText("정상파일") else: self.ui.page2_similarLabel.setText("악성파일") self.ui.machineResultLabel.setText("악성파일") else: self.ui.VTResultLabel.setText("정상파일") self.ui.page2_similarLabel.setText("정상파일") except: self.ui.VTResultLabel.setText("ERROR") self.ui.page2_similarLabel.setText("ERROR") else: self.ui.VTResultLabel.setText("ERROR") self.ui.page2_similarLabel.setText("ERROR") # 파일삭제버튼 활성화/비활성화 if self.ui.page2_similarLabel.text() == "악성파일": self.ui.delFileBtn.setEnabled(True) self.ui.delFileBtn.setStyleSheet( "background-color: #0F75BD;color: white;border:nono;") else: self.ui.delFileBtn.setEnabled(False) self.ui.delFileBtn.setStyleSheet( "background-color:lightgray;color: white;border:nono;") # 검사시작 버튼 클릭시 tab3에 보여줄 로그 데이터베이스에 INSERT logDB = mongoDB.DBConn("shutdown").log if logDB.count() == 10: logDB.remove() insertLogData = {} insertLogData.update({ "date": todayTime, "hash": getFileHash.getFileHash(fname), "filename": fname, "result": "normal", "state": "finished" }) logDB.insert(insertLogData) Form.selectLog(self) self.tabWidget.setTabEnabled(1, True) self.tabWidget.setCurrentIndex(1) self.ui.loadingImg.hide() self.ui.loadingImg.repaint() QGuiApplication.restoreOverrideCursor()
def delLogBtnClick(self): # 로그 전체기록 삭제하기 logDB = mongoDB.DBConn("shutdown").log logDB.remove() Form.selectLog(self) self.ui.logTable.repaint()