 |
ActiveDelphi .: O site do programador Delphi! :.
|
| Exibir mensagem anterior :: Exibir próxima mensagem |
| Autor |
Mensagem |
samuelrizzo2 Novato

Registrado: Segunda-Feira, 17 de Fevereiro de 2014 Mensagens: 14
|
Enviada: Seg Fev 17, 2014 1:39 pm Assunto: Ajuda Converter C++ to Delphi 7 |
|
|
aaaa
Editado pela última vez por samuelrizzo2 em Dom Fev 23, 2014 11:54 am, num total de 1 vez |
|
| Voltar ao Topo |
|
 |
cobaiaoo Colaborador

Registrado: Domingo, 1 de Abril de 2012 Mensagens: 1283
|
Enviada: Seg Fev 17, 2014 3:11 pm Assunto: Re: Ajuda Converter C++ to Delphi 7 |
|
|
ok, vc precisa de q e o q essas rotinas fazem? _________________ I João 4:8 - "Aquele que não ama não conhece a Deus; porque Deus é amor." |
|
| Voltar ao Topo |
|
 |
samuelrizzo2 Novato

Registrado: Segunda-Feira, 17 de Fevereiro de 2014 Mensagens: 14
|
Enviada: Ter Fev 18, 2014 10:17 am Assunto: |
|
|
| me ajuda a fazer um bloqueio de DLL |
|
| Voltar ao Topo |
|
 |
cobaiaoo Colaborador

Registrado: Domingo, 1 de Abril de 2012 Mensagens: 1283
|
Enviada: Ter Fev 18, 2014 11:55 am Assunto: |
|
|
n entendi bloqueio de dll??? pra q isso? _________________ I João 4:8 - "Aquele que não ama não conhece a Deus; porque Deus é amor." |
|
| Voltar ao Topo |
|
 |
samuelrizzo2 Novato

Registrado: Segunda-Feira, 17 de Fevereiro de 2014 Mensagens: 14
|
Enviada: Ter Fev 18, 2014 12:05 pm Assunto: |
|
|
| cara, isso seve pra bloquear a injeção de dll |
|
| Voltar ao Topo |
|
 |
cobaiaoo Colaborador

Registrado: Domingo, 1 de Abril de 2012 Mensagens: 1283
|
|
| Voltar ao Topo |
|
 |
samuelrizzo2 Novato

Registrado: Segunda-Feira, 17 de Fevereiro de 2014 Mensagens: 14
|
Enviada: Ter Fev 18, 2014 3:58 pm Assunto: |
|
|
| n funciona, facilmente burlado |
|
| Voltar ao Topo |
|
 |
strak2012 Colaborador


Registrado: Segunda-Feira, 13 de Janeiro de 2014 Mensagens: 1518 Localização: Maceió - AL
|
Enviada: Ter Fev 18, 2014 4:34 pm Assunto: |
|
|
Em delphi 7 ficaria assim:
| Código: |
function Bloquear(pid: integer; libName: string; apiName: string): boolean;
var
pRet: pointer; // 195 = 0xc3 = the asm 'RET' instruction
hLib: HMODULE;
pAddr: pointer;
bRet: boolean;
dwRet: SIZE_T;
hProcess: integer;
begin
{ 195 = 0xc3 = the asm 'RET' instruction }
pRet := pointer($C3);
hLib := 0;
pAddr := 0;
bRet := false;
dwRet := 0;
result := pid <> 0;
if not result then
exit;
{ 0x28 is process_vm_write/operation access }
hProcess := OpenProcess($28, false, pid);
result := hProcess <> 0;
if not result then
exit;
try
hLib := LoadLibrary(libName);
result := hLib <> 0;
if not result then
exit;
try
pAddr := GetProcAddress(hLib, pchar(apiName));
if (pAddr <> nil) then
if (WriteProcessMemory(hProcess, pAddr, pRet, 1, dwRet)) then
bRet := dwRet <> 0;
finally
FreeLibrary(hLib);
result := bRet;
end;
finally
CloseHandle(hProcess);
end;
end;
procedure Anti;
var
hProc: THANDLE;
begin
{ Gets a WINDOW handle }
hProc := FindWindow(0, 'Gunz');
while (TRUE) do
begin
{ Needs a PROCESS handle }
Bloquear(hProc, 'NTDLL.DLL', 'LdrLoadDll');
Sleep(100);
end;
end;
function BloquearA(hProcess: THANDLE; libName: string; apiName: string)
: boolean;
var
pRet: pointer; // 195 = 0xc3 = the asm 'RET' instruction
hLib: integer;
pAddr: pointer;
bRet: boolean;
dwRet: SIZE_T;
begin
hLib := LoadLibrary(libName);
if hLib <> 0 then
begin
pAddr := GetProcAddress(hLib, pchar(apiName));
if pAddr <> nil then
begin
{ Needs a PROCESS HANDLE.Plus access. }
if (WriteProcessMemory(hProcess, LPVOID(pAddr), LPVOID(pRet),
sizeof(pRet), dwRet)) then
begin
if dwRet <> 0 then
bRet := TRUE;
end;
end;
FreeLibrary(hLib);
end;
result := bRet;
end;
|
Em delphi xe2 ficara assim
| Código: |
function Bloquear(pid: integer; libName: string; apiName: string): boolean;
var
pRet: pointer; // 195 = 0xc3 = the asm 'RET' instruction
hLib: HMODULE;
pAddr: pointer;
bRet: boolean;
dwRet: SIZE_T;
hProcess: integer;
begin
{ 195 = 0xc3 = the asm 'RET' instruction }
pRet := pointer($C3);
hLib := 0;
pAddr := 0;
bRet := false;
dwRet := 0;
result := pid <> 0;
if not result then
exit;
{ 0x28 is process_vm_write/operation access }
hProcess := OpenProcess($28, false, pid);
result := hProcess <> 0;
if not result then
exit;
try
hLib := LoadLibrary(pwidechar(libName));
result := hLib <> 0;
if not result then
exit;
try
pAddr := GetProcAddress(hLib, pansichar(ansistring(apiName)));
if (pAddr <> nil) then
if (WriteProcessMemory(hProcess, pAddr, pRet, 1, dwRet)) then
bRet := dwRet <> 0;
finally
FreeLibrary(hLib);
result := bRet;
end;
finally
CloseHandle(hProcess);
end;
end;
procedure Anti;
var
hProc: THANDLE;
begin
{ Gets a WINDOW handle }
hProc := FindWindow(0, 'Gunz');
while (TRUE) do
begin
{ Needs a PROCESS handle }
Bloquear(hProc, 'NTDLL.DLL', 'LdrLoadDll');
Sleep(100);
end;
end;
function BloquearA(hProcess: THANDLE; libName: string; apiName: string)
: boolean;
var
pRet: pointer; // 195 = 0xc3 = the asm 'RET' instruction
hLib: HMODULE;
pAddr: pointer;
bRet: boolean;
dwRet: SIZE_T;
begin
hLib := LoadLibrary(pwidechar(libName));
if hLib <> 0 then
begin
pAddr := GetProcAddress(hLib, pansichar(ansistring(apiName)));
if pAddr <> nil then
begin
{ Needs a PROCESS HANDLE.Plus access. }
if (WriteProcessMemory(hProcess, LPVOID(pAddr), LPVOID(pRet),
sizeof(pRet), dwRet)) then
begin
if dwRet <> 0 then
bRet := TRUE;
end;
end;
FreeLibrary(hLib);
end;
result := bRet;
end;
|
|
|
| Voltar ao Topo |
|
 |
samuelrizzo2 Novato

Registrado: Segunda-Feira, 17 de Fevereiro de 2014 Mensagens: 14
|
Enviada: Ter Fev 18, 2014 4:59 pm Assunto: |
|
|
| Código: |
#include <windows>
#include <stdio>
#include <wininet>
DWORD HookFunction(LPCSTR lpModule, LPCSTR lpFuncName, LPVOID lpFunction, unsigned char *lpBackup);
int newHttpSendRequestW(HINTERNET hRequest, LPCTSTR lpszHeaders, DWORD dwHeadersLength, LPVOID lpOptional, DWORD dwOptionalLength);
BYTE hook[6];
int main()
{
void WinMainCRTStartup()
{
HookFunction("wininet.dll","HttpSendRequestW",newHttpSendRequestW,hook);
if dwOptionalLength > 0
{
MessageBox(0,lpOptional,"",MB_OK);
}
}
DWORD HookFunction(LPCSTR lpModule, LPCSTR lpFuncName, LPVOID lpFunction, unsigned char *lpBackup)
{
DWORD dwAddr = (DWORD)GetProcAddress(GetModuleHandle(lpModule),lpFuncName);
BYTE jmp[6] = { 0xe9,//jmp
0x00, 0x00, 0x00, 0x00,//address
0xc3
};
ReadProcessMemory(GetCurrentPRocess(),(LPVOID)dwAddr,lpBackup,6,0);
DWORD dwCalc = ((DWORD)lpFunction - dwAddr - 5);
&jmp[1], &dwCalc, 4);//build the jmp
WriteProcessMemory(GetCurrentProcess(), (LPVOID)dwAddr, jmp, 6, 0);
return dwAddr;
}
}
|
esse vc consegue? |
|
| Voltar ao Topo |
|
 |
strak2012 Colaborador


Registrado: Segunda-Feira, 13 de Janeiro de 2014 Mensagens: 1518 Localização: Maceió - AL
|
Enviada: Ter Fev 18, 2014 5:24 pm Assunto: |
|
|
existe um erro na linha
&jmp[1], &dwCalc, 4);//build the jmp
falta algo nesta linha esta linha não estar completa. |
|
| Voltar ao Topo |
|
 |
samuelrizzo2 Novato

Registrado: Segunda-Feira, 17 de Fevereiro de 2014 Mensagens: 14
|
Enviada: Qui Fev 20, 2014 3:27 pm Assunto: |
|
|
| Código: | #include
DWORD g_dwLoadLibraryAJMP;
/* HOOK FUNCTION */
DWORD WINAPI jumphook( DWORD AddressToPerformJump, DWORD AddressOfMyFunction, DWORD LenghOfTheAreaToPerformTheJump )
{
if( LenghOfTheAreaToPerformTheJump < 5 )
return 0;
DWORD RelativeJump,
NextInstructionAddress,
Flag;
if ( ! VirtualProtect((LPVOID)AddressToPerformJump, LenghOfTheAreaToPerformTheJump, PAGE_EXECUTE_READWRITE, &Flag) )
return 0;
NextInstructionAddress = AddressToPerformJump + LenghOfTheAreaToPerformTheJump;
*(BYTE*)AddressToPerformJump = 0xE9;
for( DWORD i = 5; i < LenghOfTheAreaToPerformTheJump; i++)
*(BYTE*)(AddressToPerformJump+i) = 0x90;
RelativeJump = AddressOfMyFunction - AddressToPerformJump - 0x5;
*(DWORD*)(AddressToPerformJump + 0x1) = RelativeJump;
VirtualProtect((LPVOID)AddressToPerformJump, LenghOfTheAreaToPerformTheJump, Flag, &Flag);
return NextInstructionAddress;
}
/* END HOOK FUNCTION */
HMODULE WINAPI hLoadLibraryA( LPCSTR lpLibFileName )
{
__asm
{
mov eax, dword ptr ss:[esp + 0x18]
cmp dword ptr ds:[eax-0x12], 0x8B55FF8B
je erro
}
if( lpLibFileName )
{
if( !strcmp( lpLibFileName, "twain_32.dll" ) )
__asm jmp g_dwLoadLibraryAJMP
}
return LoadLibraryExA( lpLibFileName, 0, 0 );
erro:
/* dll injetada */
ExitProcess( 0 );
return 0;
}
void ZPerformHooks()
{
g_dwLoadLibraryAJMP = (DWORD)GetModuleHandle( "kernel32" ) + 0x6E2A1;
jumphook( (DWORD)LoadLibraryA, (DWORD)&hLoadLibraryA, 57 );
}
|
consegue? |
|
| Voltar ao Topo |
|
 |
strak2012 Colaborador


Registrado: Segunda-Feira, 13 de Janeiro de 2014 Mensagens: 1518 Localização: Maceió - AL
|
Enviada: Qui Fev 20, 2014 4:04 pm Assunto: |
|
|
seria algo do tipo
| Código: |
// #include
var
g_dwLoadLibraryAJMP: DWORD;
(* HOOK FUNCTION *)
function jumphook(AddressToPerformJump: DWORD; AddressOfMyFunction: DWORD;
LenghOfTheAreaToPerformTheJump: DWORD): DWORD;
var
RelativeJump, NextInstructionAddress, Flag, Addr: DWORD;
i: DWORD;
begin
if LenghOfTheAreaToPerformTheJump < 5 then
begin
result := 0;
exit;
end;
if not VirtualProtect(LPVOID(AddressToPerformJump),
LenghOfTheAreaToPerformTheJump, PAGE_EXECUTE_READWRITE, Flag) then
begin
result := 0;
exit;
end;
NextInstructionAddress := AddressToPerformJump +
LenghOfTheAreaToPerformTheJump;
pbyte(AddressToPerformJump) := pbyte($E9); // 0xE9;
for i := 5 to LenghOfTheAreaToPerformTheJump do
begin
Addr := AddressToPerformJump + i;
pbyte(Addr) := pbyte($90); // 0x90;
end;
RelativeJump := AddressOfMyFunction - AddressToPerformJump - $5; // 0x5;
Addr := AddressToPerformJump + $1; // 0x1
Pword(Addr) := Pword(RelativeJump);
VirtualProtect(LPVOID(AddressToPerformJump), LenghOfTheAreaToPerformTheJump,
Flag, Flag);
result := NextInstructionAddress;
end;
(* END HOOK FUNCTION *)
function hLoadLibraryA(lpLibFileName: LPCSTR): HMODULE;
label erro;
begin
asm
mov eax, dword ptr ss:[esp + 0x18]
cmp dword ptr ds:[eax-0x12], 0x8B55FF8B
je erro
end;
if lpLibFileName <> nil then
begin
if lpLibFileName <> 'twain_32.dll' then
asm
jmp g_dwLoadLibraryAJMP
end;
end;
result := LoadLibraryExA(lpLibFileName, 0, 0);
erro:
(* dll injetada *)
ExitProcess(0);
result := 0;
end;
procedure ZPerformHooks;
begin
g_dwLoadLibraryAJMP := DWORD(GetModuleHandle('kernel32')) + $6E2A1; // 0x6E2A1;
jumphook(DWORD(@LoadLibraryA), DWORD(@hLoadLibraryA), 57);
end;
|
precisa ser revisada a parte do assembler, esta parte não entendo muito bem. |
|
| Voltar ao Topo |
|
 |
|
|
Enviar Mensagens Novas: Proibido. Responder Tópicos Proibido Editar Mensagens: Proibido. Excluir Mensagens: Proibido. Votar em Enquetes: Proibido.
|
|