def _check_debugger(self):
if sys.gettrace() is not None:
self._exit_program("检测到调试器")
if ctypes.windll.kernel32.IsDebuggerPresent():
self._exit_program("检测到系统调试器") 2. 时间检测
检测代码执行时间异常(反单步调试)
使用连续失败计数器避免误报
首次检查跳过机制
def _check_timing(self):
if time_diff > self._timing_threshold:
self._consecutive_timing_fails += 1
if self._consecutive_timing_fails >= 5:
self._exit_program("执行时间异常") 3. 虚拟机检测
检测常见虚拟机环境特征
累积多次检测才触发退出
def _check_vm(self):
vm_signs = ['VMware', 'VBox', 'Virtual', 'QEMU', 'Xen']
if any(sign.lower() in system_info.lower() for sign in vm_signs):
self._traces.append("VM") 4. 进程检测
def _security_monitor(self):
while True:
time.sleep(random.uniform(1.0, 1.5))
self.anti_debug.check_security() 8. 密码验证保护
动态盐值加密
多重验证逻辑
装饰器安全检查
@security_check
def _verify_password(self):
salt = b"8dj3n9" + os.urandom(4)
verification = all([
input_password == correct_password,
len(input_password) == len(correct_password),
sum(ord(c) for c in input_password) == sum(ord(c) for c in correct_password)
]) 9. 检查频率控制
使用不同的检查间隔
基于质数的检查频率
def check_security(self):
if self._check_count % 2 == 0: # 调试器检测
if self._check_count % 5 == 0: # 时间检测
if self._check_count % 10 == 0: # VM检测
if self._check_count % 15 == 0: # 进程检测
if self._check_count % 20 == 0: # 内存检测
if self._check_count % 25 == 0: # 环境检测