Çalışan işlemi üzerinde SeDebugPrivilege ayrıcalığı ayarlayarak, çalışan her uygulamanın işlem tanıtıcı elde edebilirsiniz. Tanıtıcı bir işlem edinirken, arama, normalde değil yapabilirsiniz, işlem tanıtıcısı üzerinde çeşitli Win32 Apı'ların sağlayacak PROCESS_ALL_ACCESS bayrağı sonra belirtebilirsiniz. Başarılı olarak adlandırılabilir Win32 Apı'lerinin bazıları şunlardır:
TerminateProcess
CreateRemoteThread
Bu makalede, nasıl ayarlayabilir SeDebugPrivilege uygulama işlemi belirtecinizi ve, başka bir uygulama sona erdirmek için kullanmak hakkında ayrıntılı örnek içerir. Bu gelişmiş bir konu ve güçlü bir bilgi işlem güvenlik önemle önerilir.
Bu makalenin kapsamı içinde hangi işlemi Access işlem simgeleri ve Token ayrıcalıklarını kapsadığı tartışma. Bu makalede, okuyucu zaten bu gelişmiş konular anladığı varsayar.
Bu örnek, üç ayrı bir Visual Basic uygulamalarını oluşturma içerir. Her uygulama bir kerede oluşturulan ve birlikte SeDebugPrivilege işlem ayrıcalığı gücünü göstermek için kullanılır.
Yeni bir proje standart exe DOSYASı, Visual Basic 5.0 ile oluşturun.
Proje için Term01 değiştirin.
Form1 frmTerm01 için yeniden adlandırın.
Bir komut düğmesi için frmTerm01 ekleyin.
Resim yazısı için "Sonlandırma Notepad" Command1 ayarlayın
FrmTerm01 için aşağıdaki kodu ekleyin:
Option Explicit
Private Sub Command1_Click()
' This is a simple application that attempts
' to shut down any process that is passed in through
' the command line.
Call TerminateProcess(CLng(Command$), 0)
End Sub
Proje için bir standart modül ekleme ve MdlApi01 için dosyayı yeniden adlandırın.
MdlApi01 için aşağıdaki kodu ekleyin:
Option Explicit
Declare Function TerminateProcess Lib "kernel32" _
(ByVal hProcess As Long, _
ByVal uExitCode As Long) As Long
Yeni bir standart exe DOSYASı, Visual Basic 5.0 ile oluşturun.
Proje için Term02 değiştirin.
Form1 frmTerm02 için yeniden adlandırın.
Bir komut düğmesi için frmTerm02 ekleyin.
Resim yazısı için "Sonlandırma Notepad" Command1 ayarlayın
Bir liste kutusu için frmTerm02 ekleyin.
ListBox1 genişliğini 3735 için ayarlayın.
FrmTerm02 için aşağıdaki kodu ekleyin:
Private Sub Command1_Click()
' The PID of the application you want to kill will be received
' through the command line. Convert it to a long so it can be
' used with the various API calls.
SeDebugSample CLng(Command$)
End Sub
Proje için bir standart modül ekleme ve mdlAPI02 için dosyayı yeniden adlandırın.
Modül mdlApi02 için aşağıdaki kodu ekleyin:
Option Explicit
' Constants used for various API calls. Refer to MSDN for detailed
' information about what these constants mean.
Public Const TOKEN_ADJUST_PRIVILEGES = &H20
Public Const TOKEN_QUERY = &H8
Public Const ANYSIZE_ARRAY = 1
Public Const PROCESS_ALL_ACCESS = &H1F0FFF
Public Const SE_DEBUG_NAME = "SeDebugPrivilege"
Public Const SE_PRIVILEGE_ENABLED = &H2
' Structures used with various API calls.
' Refer to MSDN for detailed information
' about what these structures are, and how they are used.
Type LARGE_INTEGER
lowpart As Long
highpart As Long
End Type
Type Luid
lowpart As Long
highpart As Long
End Type
Type LUID_AND_ATTRIBUTES
pLuid As Luid
Attributes As Long
End Type
Type TOKEN_PRIVILEGES
PrivilegeCount As Long
Privileges(ANYSIZE_ARRAY) As LUID_AND_ATTRIBUTES
End Type
' Refer to the MSDN for detailed information on
' all of these API calls.
Declare Function CloseHandle Lib "kernel32" _
(ByVal hObject As Long)As Long
Declare Function GetCurrentProcess Lib "kernel32" () As Long
Declare Function OpenProcessToken Lib "advapi32.dll" _
(ByVal ProcessHandle As Long, ByVal DesiredAccess As Long, _
TokenHandle As Long) As Long
Declare Function LookupPrivilegeValue Lib "advapi32.dll" Alias _
"LookupPrivilegeValueA" (ByVal lpSystemName As String, _
ByVal lpName As String, lpLuid As Luid) As Long
Declare Function AdjustTokenPrivileges Lib "advapi32.dll" _
(ByVal TokenHandle As Long, ByVal DisableAllPrivileges As Long, _
NewState As TOKEN_PRIVILEGES, ByVal BufferLength As Long, _
PreviousState As TOKEN_PRIVILEGES, ReturnLength As Long) As Long
Declare Function OpenProcess Lib "kernel32" _
(ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, _
ByVal dwProcessId As Long) As Long
Declare Function TerminateProcess Lib "kernel32" _
(ByVal hProcess As Long, ByVal uExitCode As Long) As Long
' SeDebugSample shows how to grab the Process Handle of any running
' Application, and then use the SeDebug privilege to shut it down.
Public Sub SeDebugSample(ApplicationPID As Long)
Dim hProcessID As Long ' Handle to your sample
' process you are going to
' terminate.
Dim hProcess As Long ' Handle to your current process
' (Term02.exe).
Dim hToken As Long ' Handle to your process token.
Dim lPrivilege As Long ' Privilege to enable/disable
Dim iPrivilegeflag As Boolean ' Flag whether to enable/disable
' the privilege of concern.
Dim lResult As Long ' Result call of various APIs.
' clear the list box first
frmTerm02.List1.Clear
frmTerm02.List1.AddItem "Start SeDebug Sample"
' set the incoming PID to our internal variable
hProcessID = ApplicationPID
' get our current process handle
hProcess = GetCurrentProcess
' show our handle just for fun
frmTerm02.List1.AddItem "Current (Pseudo) Process Handle : " & _
Hex(hProcess)
' open the tokens for this process (Term02.exe)
lResult = OpenProcessToken(hProcess, TOKEN_ADJUST_PRIVILEGES Or _
TOKEN_QUERY, hToken)
' if OpenProcessToken fails, the return result is zero, test for
' success here
If (lResult = 0) Then
frmTerm02.List1.AddItem "Error: _
Unable To Open Process Token : " _
& Err.LastDllError
CloseHandle (hToken)
Exit Sub
Else
' show success
frmTerm02.List1.AddItem "Opened Process Token : " & hToken
End If
' Now that you have the token for this process, you want to set
' the SE_DEBUG_NAME privilege.
lResult = SetPrivilege(hToken, SE_DEBUG_NAME, True)
' Make sure you could set the privilege on this token.
If (lResult = False) Then
frmTerm02.List1.AddItem _
"Error : Could Not Set SeDebug Privilege on Token Handle"
CloseHandle (hToken)
Exit Sub
Else
frmTerm02.List1.AddItem "Set SeDebug Privilege On Token Handle"
End If
' Now that you have changed the privileges on the token,
' have some fun. You can now get a process handle to the
' process ID that you passed into this program, and
' demand whatever access you want on it!
hProcess = OpenProcess(PROCESS_ALL_ACCESS, 0, hProcessID)
' Make sure you opened the process so you can do stuff with it
If (hProcess = Null) Then
frmTerm02.List1.AddItem _
"Error : Unable To Open Process : " & Err.LastDllError
CloseHandle (hToken)
Exit Sub
Else
frmTerm02.List1.AddItem "Opened Process : " & hProcess
End If
' Now turn the SE_DEBUG_PRIV back off,
lResult = SetPrivilege(hToken, SE_DEBUG_NAME, False)
' Make sure you succeeded in reversing the privilege!
If (lResult = False) Then
frmTerm02.List1.AddItem _
"Error : Unable To Disable SeDebug Privilege On Token Handle"
CloseHandle (hProcess)
CloseHandle (hToken)
Exit Sub
Else
frmTerm02.List1.AddItem _
"Disabled SeDebug Privilege On Token Handle"
End If
' Now you want to kill the application, which you can do since
' your process handle to the application includes full access to
' romp and roam - you got the process handle when you had the
' SE_DEBUG_NAME privilege enabled!
lResult = TerminateProcess(hProcess, 0)
' Let's see the result, and go from there.
If (lResult = 0) Then
frmTerm02.List1.AddItem _
"Error : Unable To Terminate Application : " & Err.LastDllError
CloseHandle (hProcess)
CloseHandle (hToken)
Exit Sub
Else
frmTerm02.List1.AddItem "Terminated Application"
End If
' Close our handles and get out of here.
CloseHandle (hProcess)
CloseHandle (hToken)
' Finally, let the user know that you have completed the
' SeDebug Sample.
frmTerm02.List1.AddItem "SeDebug Sample Completed"
End Sub
' The SetPrivilege function will accept a handle to a token, a
' privilege, and a flag to either enable/disable that privilege. The
' function will attempt to perform the desired action upon the token
' returning TRUE if it succeeded, or FALSE if it failed.
Private Function SetPrivilege(hToken As Long, Privilege As String, _
bSetFlag As Boolean) As Boolean
Dim TP As TOKEN_PRIVILEGES ' Used in getting the current
' token privileges
Dim TPPrevious As TOKEN_PRIVILEGES ' Used in setting the new
' token privileges
Dim Luid As Luid ' Stores the Local Unique
' Identifier - refer to MSDN
Dim cbPrevious As Long ' Previous size of the
' TOKEN_PRIVILEGES structure
Dim lResult As Long ' Result of various API calls
' Grab the size of the TOKEN_PRIVILEGES structure,
' used in making the API calls.
cbPrevious = Len(TP)
' Grab the LUID for the request privilege.
lResult = LookupPrivilegeValue("", Privilege, Luid)
' If LoopupPrivilegeValue fails, the return result will be zero.
' Test to make sure that the call succeeded.
If (lResult = 0) Then
SetPrivilege = False
End If
' Set up basic information for a call.
' You want to retrieve the current privileges
' of the token under concern before you can modify them.
TP.PrivilegeCount = 1
TP.Privileges(0).pLuid = Luid
TP.Privileges(0).Attributes = 0
SetPrivilege = lResult
' You need to acquire the current privileges first
lResult = AdjustTokenPrivileges(hToken, -1, TP, Len(TP), _
TPPrevious, cbPrevious)
' If AdjustTokenPrivileges fails, the return result is zero,
' test for success.
If (lResult = 0) Then
SetPrivilege = False
End If
' Now you can set the token privilege information
' to what the user is requesting.
TPPrevious.PrivilegeCount = 1
TPPrevious.Privileges(0).pLuid = Luid
' either enable or disable the privilege,
' depending on what the user wants.
Select Case bSetFlag
Case True: TPPrevious.Privileges(0).Attributes = _
TPPrevious.Privileges(0).Attributes Or _
(SE_PRIVILEGE_ENABLED)
Case False: TPPrevious.Privileges(0).Attributes = _
TPPrevious.Privileges(0).Attributes Xor _
(SE_PRIVILEGE_ENABLED And _
TPPrevious.Privileges(0).Attributes)
End Select
' Call adjust the token privilege information.
lResult = AdjustTokenPrivileges(hToken, -1, TPPrevious, _
cbPrevious, TP, cbPrevious)
' Determine your final result of this function.
If (lResult = 0) Then
' You were not able to set the privilege on this token.
SetPrivilege = False
Else
' You managed to modify the token privilege
SetPrivilege = True
End If
End Function
Projeyi Term01 proje olarak aynı dizine kaydedin ve .exe dosyasını (Term02.exe).
Yeni bir Standart EXE projesi, Visual Basic 5.0 ile oluşturun.
Proje için MainTest yeniden adlandırın.
Form1 için frmTest yeniden adlandırın.
Üç komut düğmeleri forma ekleyin.
Resim yazısı Command1 "Start Notepad" için ayarlamak
Resim yazısı Command2 "Başlat Term01" için ayarlamak
Resim yazısı Command3 "Başlat Term02" için ayarlamak
FrmTest için aşağıdaki kodu ekleyin:
Option Explicit
' You want to keep the process ID of the NotePad instance
' that you create
Private iAppPID As Long
Private Sub Command1_Click()
' Create an instance of the NotePad.exe application.
iAppPID = Shell("Notepad.exe", vbNormalFocus)
End Sub
Private Sub Command2_Click()
' You will try to terminate the NotePad application by another
' application, which is running in its own process space.
' This will FAIL.
Call Shell(App.Path & "\Term01.Exe " & iAppPID, vbNormalFocus)
End Sub
Private Sub Command3_Click()
' You will try to terminate the NotePad application by another
' application, which is running in its own process space.
' However, this application is going to use the SeDebugPrivilege,
' and will be able to terminate the application without a fuss.
Call Shell(App.Path & "\Term02.Exe " & iAppPID, vbNormalFocus)
End Sub
Projeyi Term01 proje olarak aynı dizine kaydedin ve .exe dosyasını (MainTest.exe).
Yerleşik ve üç uygulama derlenmiş sürüyor gösteri görebilirsiniz. Ikinci uygulamada (Term02.exe) kodunu Not Defteri'nde (Notepad.exe) uygulama yolu içinde bulunan varsayar.
MainTest.exe programını çalıştırın. Bu bizim "denetim paneli" gösteri için olacaktır.
Not Defteri'nde, Başlat düğmesini tıklatın. Bu, Not Defteri'ni başlatacak.
Term01 Başlat düğmesini tıklatın. Bu, Term01 başlatacak uygulama.
Sonlandır Not Defteri'ni düğmesini Term01 uygulama Ek Yardım düğmesini tıklatın. Not Defteri'ni kapatmaya amaçlanmıştır, ancak başarılı olmaz.
Term02 uygulamasında Not Defteri'ni Sonlandır düğmesini tıklatın. Bu işlem sonlandırıldı Not Defteri'nde neden olur SeDebugPrivilege gösteri başlayacaktır. Liste kutusu, işlemde giderek için görsel geri besleme sağlar.
ÖNEMLİ: Bu makale, bir kişi tarafından çevrilmek yerine, Microsoft makine-çevirisi yazılımı ile çevrilmiştir. Microsoft size hem kişiler tarafından çevrilmiş, hem de makine-çevrisi ile çevrilmiş makaleler sunar. Böylelikle, bilgi bankamızdaki tüm makalelere, kendi dilinizde ulaşmış olursunuz. Bununla birlikte, makine tarafından çevrilmiş makaleler mükemmel değildir. Bir yabancının sizin dilinizde konuşurken yapabileceği hatalar gibi, makale; kelime dağarcığı, söz dizim kuralları veya dil bilgisi açısından yanlışlar içerebilir. Microsoft, içeriğin yanlış çevrimi veya onun müşteri tarafından kullanımından doğan; kusur, hata veya zarardan sorumlu değildir. Microsoft ayrıca makine çevirisi yazılımını sıkça güncellemektedir.
Makalenin İngilizcesi aşağıdaki gibidir:185215
(http://support.microsoft.com/kb/185215/en-us/
)
Bu makale, Microsoft'un artık destek sağlamadığı ürünler ile ilgili olarak yazılmıştır. Bu nedenle, bu makale "olduğu gibi" sağlanmıştır ve bundan sonra güncelleştirilmeyecektir.
Bu makaleyi kullanmak için ne kadar kişisel çaba harcadınız?
Çok az
Az
Orta
Fazla
Çok fazla
Bu bilgiyi geliştirmemiz için nedenleri ve bu konuda neler yapabileceğimizi paylaşın
Teşekkürler! Görüşleriniz, destek içeriğimizi geliştirmemize yardımcı olmak için kullanılmaktadır. Diğer yardım seçenekleri için, lütfen Yardım ve Destek Giriş Sayfasını ziyaret edin.