首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 數據庫知識 >  >> SQL Server 資料庫 >> 關於SqlServer

掌握 SQL Server 內建擴展預存程序:xp_cmdshell、xp_dirtree 等 DLL 對應關係與恢復技巧

     編輯:關於SqlServer

SQL Server 將擴展預存程序 (Extended Stored Procedures, ESP) 封裝於 DLL 中。本文透過 eXeScope 反編譯 xplog70.dll、xpstar.dll、odsole70.dll 等核心 DLL,列出其導出的 ESP 清單,並說明刪除後如何透過 sp_addextendedproc 恢復,以及為何某些 ESP (如 xp_dirtree) 需對應特定 DLL (xpstar.dll)。

核心 DLL 與 ESP 對應表

DLL主要 ESP (部分列舉)
xplog70.dllxp_cmdshell, xp_enumerrorlogs, xp_readerrorlog, xp_sqlmaint, xp_terminate_process 等
xpstar.dllxp_dirtree, xp_subdirs, xp_fileexist, xp_fixeddrives, xp_regread/write/delete/enum*, xp_servicecontrol, xp_sqlagent_*, xp_availablemedia, xp_getnetname, xp_msver 等 100+
odsole70.dllsp_OACreate, sp_OADestroy, sp_OAGetProperty, sp_OASetProperty, sp_OAMethod, sp_OAGetErrorInfo, sp_OAStop
sqlmap70.dllxp_sendmail, xp_readmail, xp_startmail, xp_stopmail, xp_findnextmsg, xp_deletemail 等
xpqueue.dllxp_createprivatequeue, xp_deleteprivatequeue, xp_peekqueue, xp_readpkfromqueue, xp_resetqueue 等
xprepl.dllxp_repl_encrypt, xp_showcolv, xp_showlineage, xp_mergelineages, xp_varbintohexstr 等
xpsqlbot.dllxp_qv
xpweb70.dllxp_makewebtask, xp_dropwebtask, xp_readwebtask, xp_runwebtask, xp_convertwebtask, xp_cleanupwebtask, xp_enumcodepages

刪除與恢復實例

-- 刪除 (安全強化常見操作)
EXEC sp_dropextendedproc 'xp_cmdshell';

-- 恢復 (必須指定正確 DLL)
EXEC sp_addextendedproc 'xp_cmdshell', @dllname = 'xplog70.dll';
-- xp_dirtree 屬於 xpstar.dll
EXEC sp_addextendedproc 'xp_dirtree', @dllname = 'xpstar.dll';

安全性建議

  • 生產環境建議刪除高風險 ESP:xp_cmdshell (OS 命令執行)、xp_regwrite (登錄表寫入)、xp_servicecontrol (服務控制)、xp_terminate_process (進程終止)。
  • 若業務需求需用,改用 CLR 整合 (SQL 2005+) 實現沙箱隔離、代碼存取安全 (CAS) 權限控制。
  • 定期審核 sys.extended_procedures 確認無未授權 ESP。

工具提示

使用 eXeScope 或 Dependency Walker 開啟 MSSQL\Binn\*.dll 可視覺化導出函數,快速確認 ESP 所屬 DLL。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved