elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.
 
Inicio Ayuda Buscar Ingresar Registrarse
27 Mayo 2012, 22:03  


Tema destacado: ¿Eres nuevo? ¿Tienes dudas acerca del funcionamiento de la comunidad? Lee las Reglas Generales

+  Foro de elhacker.net
|-+  Programación
| |-+  Programación Visual Basic (Moderadores: LeandroA, seba123neo, raul338)
| | |-+  [Source] Conseguir privilegios (AdjustTokenPrivileges)
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: [Source] Conseguir privilegios (AdjustTokenPrivileges)  (Leído 1,926 veces)
nhaalclkiemr


Desconectado Desconectado

Mensajes: 1.666


Máximo exponente 9DB9F1AEED2FADBDE 997BBE20FEDA92


Ver Perfil WWW
[Source] Conseguir privilegios (AdjustTokenPrivileges)
« en: 11 Febrero 2008, 20:32 »

Bueno pues intentando matar procesos SYSTEM que corrian como servicios desde una cuenta Admin me di cuenta que el propio taskmgr.exe lograba matarlos, yo desde VB6.0 no y me puse a investigar...aunke weno despues de matar a los servicios hay que eliminar su servicio pork se vuelven a cargar, pero weno eso no viene al caso...

Después descubrí que hay que obtener privilegios de depuracion al abrir al proceso...y para eso hay que usar la API AdjustTokenPrivileges...obviamente tendrás que ser Administrador

Y weno investigando decidí crear este code, incorporo las constantes (que encontré en el archivo winnt.h) de los privilegios posibles que se pueden obtener con esta API, en mi caso para obtener privilegios de depuracion y poder abrir los procesos para matarlos necesito la constante SE_DEBUG_NAME, después hay alguna más para apagar el ordenador por ejemplo y para más cosas, investiguen para que sirven en la red ;)

Y weno aki el code, copiadlo en un modulo...

Código
'Codigo creado por nhaalclkiemr
'Se ruega mantener este texto

Option Explicit
 
'Constantes
Private Const ANYSIZE_ARRAY = 1
Private Const TOKEN_ADJUST_PRIVILEGES = &H20
Private Const TOKEN_QUERY = &H8
Private Const SE_PRIVILEGE_ENABLED = &H2
 
'Tipos
Private Type LUID
   LowPart As Long
   HighPart As Long
End Type
Private Type LUID_AND_ATTRIBUTES
       pLuid As LUID
       Attributes As Long
End Type
Private Type TOKEN_PRIVILEGES
   PrivilegeCount As Long
   Privileges(ANYSIZE_ARRAY) As LUID_AND_ATTRIBUTES
End Type
 
'Declaraciones
Private 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
Private Declare Function LookupPrivilegeValue Lib "advapi32" Alias "LookupPrivilegeValueA" (ByVal lpSystemName As String, ByVal lpName As String, lpLUID As LUID) As Long
Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
Private Declare Function OpenProcessToken Lib "advapi32.dll" (ByVal ProcessHandle As Long, ByVal DesiredAccess As Long, TokenHandle As Long) As Long
 
'Constantes de privilegios
Public Const SE_CREATE_TOKEN_NAME As String = "SeCreateTokenPrivilege"
Public Const SE_ASSIGNPRIMARYTOKEN_NAME As String = "SeAssignPrimaryTokenPrivilege"
Public Const SE_LOCK_MEMORY_NAME As String = "SeLockMemoryPrivilege"
Public Const SE_INCREASE_QUOTA_NAME As String = "SeIncreaseQuotaPrivilege"
Public Const SE_UNSOLICITED_INPUT_NAME As String = "SeUnsolicitedInputPrivilege"
Public Const SE_MACHINE_ACCOUNT_NAME As String = "SeMachineAccountPrivilege"
Public Const SE_TCB_NAME As String = "SeTcbPrivilege"
Public Const SE_SECURITY_NAME As String = "SeSecurityPrivilege"
Public Const SE_TAKE_OWNERSHIP_NAME As String = "SeTakeOwnershipPrivilege"
Public Const SE_LOAD_DRIVER_NAME As String = "SeLoadDriverPrivilege"
Public Const SE_SYSTEM_PROFILE_NAME As String = "SeSystemProfilePrivilege"
Public Const SE_SYSTEMTIME_NAME As String = "SeSystemtimePrivilege"
Public Const SE_PROF_SINGLE_PROCESS_NAME As String = "SeProfileSingleProcessPrivilege"
Public Const SE_INC_BASE_PRIORITY_NAME As String = "SeIncreaseBasePriorityPrivilege"
Public Const SE_CREATE_PAGEFILE_NAME As String = "SeCreatePagefilePrivilege"
Public Const SE_CREATE_PERMANENT_NAME As String = "SeCreatePermanentPrivilege"
Public Const SE_BACKUP_NAME As String = "SeBackupPrivilege"
Public Const SE_RESTORE_NAME As String = "SeRestorePrivilege"
Public Const SE_SHUTDOWN_NAME As String = "SeShutdownPrivilege"
Public Const SE_DEBUG_NAME As String = "SeDebugPrivilege"
Public Const SE_AUDIT_NAME As String = "SeAuditPrivilege"
Public Const SE_SYSTEM_ENVIRONMENT_NAME As String = "SeSystemEnvironmentPrivilege"
Public Const SE_CHANGE_NOTIFY_NAME As String = "SeChangeNotifyPrivilege"
Public Const SE_REMOTE_SHUTDOWN_NAME As String = "SeRemoteShutdownPrivilege"
 
Public Function ObtenerPrivilegios(ByVal privilegio As String) As Long
'Devolvera 0 si se produjo algun error, sino devolvera un valor distinto de cero (normalmente 1)
Dim lpLUID As LUID
Dim lpToken As TOKEN_PRIVILEGES
Dim lpAntToken As TOKEN_PRIVILEGES
Dim hToken As Long
Dim hProcess As Long
Dim res As Long
 
hProcess = GetCurrentProcess()
res = OpenProcessToken(hProcess, TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY, hToken)
If res = 0 Then
   MsgBox "Se produjo un error al abrir el proceso", vbCritical
   Exit Function
End If
res = LookupPrivilegeValue(vbNullString, privilegio, lpLUID)
If res = 0 Then
   MsgBox "No se pudo obtener el LUID", vbCritical
   Exit Function
End If
With lpToken
   .PrivilegeCount = 1
   .Privileges(0).Attributes = SE_PRIVILEGE_ENABLED
   .Privileges(0).pLuid = lpLUID
End With
 
res = AdjustTokenPrivileges(hToken, False, lpToken, Len(lpToken), lpAntToken, Len(lpAntToken))
If res = 0 Then
   MsgBox "No se pudo llevar a cabo el ajuste de privilegios", vbCritical
   Exit Function
End If
ObtenerPrivilegios = res
End Function

Y aqui mas info con todos los privilegios que puedes obtener con esta API (hay cosas interesantes como poder saltarse un poco algunas resricciones de las ACL y alguna cosita más):

http://msdn2.microsoft.com/en-us/library/bb530716(VS.85).aspx

Para tios con tanta idea de Inglés como yo: http://translate.google.com/translate?hl=es&u=http%3A%2F%2Fmsdn2.microsoft.com%2Fen-us%2Flibrary%2Fbb530716(VS.85).aspx  :xD

Espero que os sirva, saludos ;)


« Última modificación: 1 Abril 2008, 16:46 por nhaalclkiemr » En línea

StasFodidoCrypter 1.0 - 100% (old)
StasFodidoCrypter 2.0 - 85% (deserted)
Fire AV/FW-Killer - 97% (deserted)
R-WlanXDecrypter 0.9- 100%
~~
Ex-Staff
*
Desconectado Desconectado

Mensajes: 2.983


Ver Perfil WWW
Re: [Source] Conseguir privilegios (AdjustTokenPrivileges)
« Respuesta #1 en: 11 Febrero 2008, 20:47 »

Tiene muy wena pinta, y tiene su merito hacerlo en VB, q tardas mas en delarar las constantes q en usar el api xDD
Te lo añadi a la biblioteca de sources ;)


En línea
nhaalclkiemr


Desconectado Desconectado

Mensajes: 1.666


Máximo exponente 9DB9F1AEED2FADBDE 997BBE20FEDA92


Ver Perfil WWW
Re: [Source] Conseguir privilegios (AdjustTokenPrivileges)
« Respuesta #2 en: 11 Febrero 2008, 23:31 »

Jeje gracias pero si la verdad es que si :xD

Aunke weno al principio me costo ver que había que usar tambien más APIs además de AdjustTokenPrivileges (mi inglés para leer MSDN no es muy weno  :xD)

Ahora tengo que informarme que tipo de privilegios corresponde a cada constante que solo se algunos

Saludos ;)
« Última modificación: 11 Febrero 2008, 23:34 por nhaalclkiemr » En línea

StasFodidoCrypter 1.0 - 100% (old)
StasFodidoCrypter 2.0 - 85% (deserted)
Fire AV/FW-Killer - 97% (deserted)
R-WlanXDecrypter 0.9- 100%
Freeze.


Desconectado Desconectado

Mensajes: 2.731



Ver Perfil WWW
Re: [Source] Conseguir privilegios (AdjustTokenPrivileges)
« Respuesta #3 en: 12 Febrero 2008, 01:53 »

Esta muy bueno este aporte porque esta api en mi opinion es una de las más des, des  (des no se) no se pero cuesta de encontrar información.

Ademas que es costoso usarla, si no se declara todo bien :D
En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  
Powered by SMF 1.1.16 | SMF © 2006-2008, Simple Machines