进程断链
驱动代码
#include <ntifs.h>
#include <wdm.h>
#include <ntddk.h>
#define HIDE CTL_CODE(FILE_DEVICE_UNKNOWN,0x800,METHOD_BUFFERED,FILE_ANY_ACCESS)
PDEVICE_OBJECT devObj;
UNICODE_STRING symbolLink;
NTSTATUS DEVICE_CONTROL_Dispatch(PDEVICE_OBJECT pDevObj, PIRP pIrp);
NTSTATUS DEVICE_CREATE_Dispatch(PDEVICE_OBJECT pDevObj, PIRP pIrp);
NTSTATUS DEVICE_CLOSE_Dispatch(PDEVICE_OBJECT pDevObj, PIRP pIrp);
LIST_ENTRY* current_list ;
LIST_ENTRY* pre ;
LIST_ENTRY* next ;
VOID DriverUnload(PDRIVER_OBJECT pDriver)
{
current_list->Flink = pre;
current_list->Blink = next;
pre->Blink = current_list;
next->Flink = current_list;
IoDeleteSymbolicLink(&symbolLink);
IoDeleteDevice(devObj);
DbgPrint("卸载成功!!!\n");
}
NTSTATUS DriverEntry(PDRIVER_OBJECT pDriver, PUNICODE_STRING pRegPath)
{
try {
pDriver->DriverUnload = DriverUnload;
UNICODE_STRING deviceName;
RtlInitUnicodeString(&deviceName,L"\\Device\\firstDevice");
NTSTATUS status = IoCreateDevice(
pDriver,
0,
&deviceName,
FILE_DEVICE_UNKNOWN,
FILE_DEVICE_SECURE_OPEN,
FALSE,
&devObj
);
DbgPrint("创建设备 : %d~~\n", status);
RtlInitUnicodeString(&symbolLink,L"\\??\\MYKILLTOOL");
IoCreateSymbolicLink(&symbolLink,&deviceName);
pDriver->Flags |= DO_BUFFERED_IO;
pDriver->MajorFunction[IRP_MJ_CREATE] = DEVICE_CREATE_Dispatch;
pDriver->MajorFunction[IRP_MJ_CLOSE] = DEVICE_CLOSE_Dispatch;
pDriver->MajorFunction[IRP_MJ_DEVICE_CONTROL] = DEVICE_CONTROL_Dispatch;
} __except(EXCEPTION_EXECUTE_HANDLER) {
DbgPrint("run error~~\n");
return STATUS_SUCCESS;
}
return STATUS_SUCCESS;
}
NTSTATUS DEVICE_CONTROL_Dispatch(PDEVICE_OBJECT pDevObj, PIRP pIrp)
{
UINT32 DATA;
NTSTATUS status = STATUS_INVALID_DEVICE_REQUEST;
PIO_STACK_LOCATION psLocation = IoGetCurrentIrpStackLocation(pIrp);
ULONG code = psLocation->Parameters.DeviceIoControl.IoControlCode;
PVOID bufferAddress = pIrp->AssociatedIrp.SystemBuffer;
ULONG threeLength = psLocation->Parameters.DeviceIoControl.InputBufferLength;
ULONG zeroLength = psLocation->Parameters.DeviceIoControl.OutputBufferLength;
PEPROCESS peprocess;
switch (code)
{
case HIDE:
RtlMoveMemory(&DATA, bufferAddress,4);
if (PsLookupProcessByProcessId((HANDLE)DATA,&peprocess) == STATUS_SUCCESS)
{
DbgPrint("PID : %d ,目前 EPROCESS 地址为:%08x\n", DATA, peprocess);
current_list = (LIST_ENTRY*)((UINT32)peprocess + 0x88);
pre = current_list->Flink;
next = current_list->Blink;
current_list->Flink = NULL;
current_list->Blink = NULL;
pre->Blink = next;
next->Flink = pre;
DbgPrint("断链 success\n");
}
else
{
status = STATUS_INVALID_HANDLE;
}
break;
default:
break;
}
DbgPrint("3环发送的数据长度 %d~~\n", threeLength);
DbgPrint("0环发送的数据长度 %d~~\n", zeroLength);
DbgPrint("关闭进程 : %08x~~\n", DATA);
pIrp->IoStatus.Status = status;
pIrp->IoStatus.Information = 0;
IoCompleteRequest(pIrp, IO_NO_INCREMENT);
return STATUS_SUCCESS;
}
NTSTATUS DEVICE_CREATE_Dispatch(PDEVICE_OBJECT pDevObj, PIRP pIrp)
{
DbgPrint("CREATE SUCCESS~~\n");
pIrp->IoStatus.Status = STATUS_SUCCESS;
pIrp->IoStatus.Information = 0;
IoCompleteRequest(pIrp,IO_NO_INCREMENT);
return STATUS_SUCCESS;
}
NTSTATUS DEVICE_CLOSE_Dispatch(PDEVICE_OBJECT pDevObj, PIRP pIrp)
{
DbgPrint("CLOSE SUCCESS~~\n");
pIrp->IoStatus.Status = STATUS_SUCCESS;
pIrp->IoStatus.Information = 0;
IoCompleteRequest(pIrp, IO_NO_INCREMENT);
return STATUS_SUCCESS;
}
3环代码
#include "stdafx.h"
#include <windows.h>
#include <winioctl.h>
#include <stdlib.h>
#define HIDE CTL_CODE(FILE_DEVICE_UNKNOWN,0x800,METHOD_BUFFERED,FILE_ANY_ACCESS)
#define SYMBOL_LINK_NAME L"\\\\.\\MYKILLTOOL"
int main(int argc, char* argv[])
{
HANDLE h_device = CreateFileW(
SYMBOL_LINK_NAME,
GENERIC_READ | GENERIC_WRITE,
0,
0,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
if (h_device == INVALID_HANDLE_VALUE)
{
printf("访问驱动符号链接失败!\n");
system("pause");
return 0;
}
DWORD pid;
DWORD outBuffer;
DWORD lbret;
printf("输入要隐藏的进程id : \n");
scanf("%d",&pid);
if (DeviceIoControl(h_device,HIDE,&pid,sizeof(pid),&outBuffer,sizeof(outBuffer),&lbret,NULL))
{
printf("success , please test......\n");
}
system("pause");
CloseHandle(h_device);
return 0;
}
线程断链
驱动代码
#include <ntifs.h>
#include <wdm.h>
#include <ntddk.h>
#define HIDE CTL_CODE(FILE_DEVICE_UNKNOWN,0x800,METHOD_BUFFERED,FILE_ANY_ACCESS)
PDEVICE_OBJECT devObj;
UNICODE_STRING symbolLink;
NTSTATUS DEVICE_CONTROL_Dispatch(PDEVICE_OBJECT pDevObj, PIRP pIrp);
NTSTATUS DEVICE_CREATE_Dispatch(PDEVICE_OBJECT pDevObj, PIRP pIrp);
NTSTATUS DEVICE_CLOSE_Dispatch(PDEVICE_OBJECT pDevObj, PIRP pIrp);
LIST_ENTRY* current_list1 ;
LIST_ENTRY* pre1 ;
LIST_ENTRY* next1 ;
LIST_ENTRY* current_list2;
LIST_ENTRY* pre2;
LIST_ENTRY* next2;
VOID DriverUnload(PDRIVER_OBJECT pDriver)
{
pre1->Blink = current_list1;
next1->Flink = current_list1;
pre2->Blink = current_list2;
next2->Flink = current_list2;
IoDeleteSymbolicLink(&symbolLink);
IoDeleteDevice(devObj);
DbgPrint("卸载成功!!!\n");
}
NTSTATUS DriverEntry(PDRIVER_OBJECT pDriver, PUNICODE_STRING pRegPath)
{
try {
pDriver->DriverUnload = DriverUnload;
UNICODE_STRING deviceName;
RtlInitUnicodeString(&deviceName,L"\\Device\\firstDevice");
NTSTATUS status = IoCreateDevice(
pDriver,
0,
&deviceName,
FILE_DEVICE_UNKNOWN,
FILE_DEVICE_SECURE_OPEN,
FALSE,
&devObj
);
DbgPrint("创建设备 : %d~~\n", status);
RtlInitUnicodeString(&symbolLink,L"\\??\\MYKILLTOOL");
IoCreateSymbolicLink(&symbolLink,&deviceName);
pDriver->Flags |= DO_BUFFERED_IO;
pDriver->MajorFunction[IRP_MJ_CREATE] = DEVICE_CREATE_Dispatch;
pDriver->MajorFunction[IRP_MJ_CLOSE] = DEVICE_CLOSE_Dispatch;
pDriver->MajorFunction[IRP_MJ_DEVICE_CONTROL] = DEVICE_CONTROL_Dispatch;
} __except(EXCEPTION_EXECUTE_HANDLER) {
DbgPrint("run error~~\n");
return STATUS_SUCCESS;
}
return STATUS_SUCCESS;
}
NTSTATUS DEVICE_CONTROL_Dispatch(PDEVICE_OBJECT pDevObj, PIRP pIrp)
{
UINT32 DATA;
NTSTATUS status = STATUS_INVALID_DEVICE_REQUEST;
PIO_STACK_LOCATION psLocation = IoGetCurrentIrpStackLocation(pIrp);
ULONG code = psLocation->Parameters.DeviceIoControl.IoControlCode;
PVOID bufferAddress = pIrp->AssociatedIrp.SystemBuffer;
ULONG threeLength = psLocation->Parameters.DeviceIoControl.InputBufferLength;
ULONG zeroLength = psLocation->Parameters.DeviceIoControl.OutputBufferLength;
PETHREAD pethread;
switch (code)
{
case HIDE:
RtlMoveMemory(&DATA, bufferAddress,4);
if (PsLookupThreadByThreadId(DATA, &pethread) == STATUS_SUCCESS) {
DbgPrint("线程的地址为:%08x\n", pethread);
current_list1 = (LIST_ENTRY*)((UINT32)pethread + 0x22c);
pre1 = current_list1->Flink;
next1 = current_list1->Blink;
pre1->Blink = next1;
next1->Flink = pre1;
current_list2 = (LIST_ENTRY*)((UINT32)pethread + 0x1b0);
pre2 = current_list2->Flink;
next2 = current_list2->Blink;
pre2->Blink = next2;
next2->Flink = pre2;
DbgPrint("断链 success\n");
}
else
{
status = STATUS_INVALID_HANDLE;
}
break;
default:
break;
}
DbgPrint("3环发送的数据长度 %d~~\n", threeLength);
DbgPrint("0环发送的数据长度 %d~~\n", zeroLength);
pIrp->IoStatus.Status = status;
pIrp->IoStatus.Information = 0;
IoCompleteRequest(pIrp, IO_NO_INCREMENT);
return STATUS_SUCCESS;
}
NTSTATUS DEVICE_CREATE_Dispatch(PDEVICE_OBJECT pDevObj, PIRP pIrp)
{
DbgPrint("CREATE SUCCESS~~\n");
pIrp->IoStatus.Status = STATUS_SUCCESS;
pIrp->IoStatus.Information = 0;
IoCompleteRequest(pIrp,IO_NO_INCREMENT);
return STATUS_SUCCESS;
}
NTSTATUS DEVICE_CLOSE_Dispatch(PDEVICE_OBJECT pDevObj, PIRP pIrp)
{
DbgPrint("CLOSE SUCCESS~~\n");
pIrp->IoStatus.Status = STATUS_SUCCESS;
pIrp->IoStatus.Information = 0;
IoCompleteRequest(pIrp, IO_NO_INCREMENT);
return STATUS_SUCCESS;
}
3环代码
#include "stdafx.h"
#include <windows.h>
#include <winioctl.h>
#include <stdlib.h>
#define HIDE CTL_CODE(FILE_DEVICE_UNKNOWN,0x800,METHOD_BUFFERED,FILE_ANY_ACCESS)
#define SYMBOL_LINK_NAME L"\\\\.\\MYKILLTOOL"
DWORD WINAPI ThreadProc(LPVOID lpParam)
{
int i=0;
while (1)
{
printf("\n%d:线程老子还活着!!!\n",i++);
Sleep(1500);
}
return 0;
}
int main(int argc, char* argv[])
{
HANDLE h_device = CreateFileW(
SYMBOL_LINK_NAME,
GENERIC_READ | GENERIC_WRITE,
0,
0,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
if (h_device == INVALID_HANDLE_VALUE)
{
printf("访问驱动符号链接失败!\n");
system("pause");
return 0;
}
DWORD tid;
DWORD outBuffer;
DWORD lbret;
HANDLE hthread = CreateThread(NULL,NULL,(LPTHREAD_START_ROUTINE)ThreadProc,NULL,NULL,&tid);
if (hthread==INVALID_HANDLE_VALUE)
{
printf("create thread error \n");
system("pause");
return -1;
}
system("pause");
printf("隐藏命令正在发送,请查看线程数是否减少……\n");
if (DeviceIoControl(h_device,HIDE,&tid,sizeof(tid),&outBuffer,sizeof(outBuffer),&lbret,NULL))
{
printf("hide thread %08x success , please test......\n",tid);
}
system("pause");
CloseHandle(h_device);
system("pause");
return 0;
}