audit_hook_example.py
· 314 B · Python
Исходник
import sys
def audit_hook(event, args):
print(f"Audit event: {event}, Arguments: {args}")
# 註冊審計鉤子
sys.addaudithook(audit_hook)
# 觸發一些事件
open("test.txt", "w").write("Hello") # 檔案寫入事件
import os # 模組導入事件
os.system("echo Security Check") # 執行命令事件
| 1 | import sys |
| 2 | |
| 3 | def audit_hook(event, args): |
| 4 | print(f"Audit event: {event}, Arguments: {args}") |
| 5 | |
| 6 | # 註冊審計鉤子 |
| 7 | sys.addaudithook(audit_hook) |
| 8 | |
| 9 | # 觸發一些事件 |
| 10 | open("test.txt", "w").write("Hello") # 檔案寫入事件 |
| 11 | import os # 模組導入事件 |
| 12 | os.system("echo Security Check") # 執行命令事件 |
| 13 |