Skip to content

Commit 60c7e35

Browse files
committed
Driver: image filename erasure
1 parent 0a1db26 commit 60c7e35

File tree

9 files changed

+70
-28
lines changed

9 files changed

+70
-28
lines changed

src/BlackBoneDrv/NativeStructs.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,36 @@ typedef struct _OBJECT_HEADER // Size=56
143143
struct _QUAD Body; // Size=8 Offset=48
144144
} OBJECT_HEADER, *POBJECT_HEADER;
145145

146+
typedef union _EX_FAST_REF // Size=8
147+
{
148+
void * Object;
149+
struct
150+
{
151+
unsigned __int64 RefCnt : 4;
152+
};
153+
unsigned __int64 Value;
154+
} EX_FAST_REF, *PEX_FAST_REF;
155+
156+
typedef struct _CONTROL_AREA // Size=120
157+
{
158+
struct _SEGMENT * Segment;
159+
struct _LIST_ENTRY ListHead;
160+
unsigned __int64 NumberOfSectionReferences;
161+
unsigned __int64 NumberOfPfnReferences;
162+
unsigned __int64 NumberOfMappedViews;
163+
unsigned __int64 NumberOfUserReferences;
164+
unsigned long f1;
165+
unsigned long f2;
166+
EX_FAST_REF FilePointer;
167+
// Other fields
168+
} CONTROL_AREA, *PCONTROL_AREA;
169+
170+
typedef struct _SUBSECTION // Size=56
171+
{
172+
PCONTROL_AREA ControlArea;
173+
// Other fields
174+
} SUBSECTION, *PSUBSECTION;
175+
146176
typedef struct _MEMORY_BASIC_INFORMATION_EX
147177
{
148178
PVOID BaseAddress;

src/BlackBoneDrv/NativeStructs10.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ typedef struct _MMVAD // Size=128
127127
{
128128
struct _MMVAD_SHORT Core; // Size=64 Offset=0
129129
union ___unnamed2047 u2; // Size=4 Offset=64
130+
unsigned long pad0; // Size=4 Offset=68
130131
struct _SUBSECTION * Subsection; // Size=8 Offset=72
131132
struct _MMPTE * FirstPrototypePte; // Size=8 Offset=80
132133
struct _MMPTE * LastContiguousPte; // Size=8 Offset=88

src/BlackBoneDrv/NativeStructs7.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,8 @@ typedef struct _MMVAD // Size=120
138138
{
139139
MMVAD_SHORT vadShort;
140140
union ___unnamed715 u2; // Size=4 Offset=64
141-
union
142-
{
143-
struct _SUBSECTION * Subsection; // Size=8 Offset=72
144-
struct _MSUBSECTION * MappedSubsection; // Size=8 Offset=72
145-
};
141+
unsigned long pad0; // Size=4 Offset=68
142+
struct _SUBSECTION * Subsection; // Size=8 Offset=72
146143
struct _MMPTE * FirstPrototypePte; // Size=8 Offset=80
147144
struct _MMPTE * LastContiguousPte; // Size=8 Offset=88
148145
struct _LIST_ENTRY ViewLinks; // Size=16 Offset=96

src/BlackBoneDrv/NativeStructs8.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,7 @@ typedef struct _MMVAD // Size=128
128128
{
129129
struct _MMVAD_SHORT Core; // Size=64 Offset=0
130130
union ___unnamed1883 u2; // Size=4 Offset=64
131-
union
132-
{
133-
struct _SUBSECTION * Subsection; // Size=8 Offset=72
134-
struct _MSUBSECTION * MappedSubsection; // Size=8 Offset=72
135-
};
131+
struct _SUBSECTION * Subsection; // Size=8 Offset=72
136132
struct _MMPTE * FirstPrototypePte; // Size=8 Offset=80
137133
struct _MMPTE * LastContiguousPte; // Size=8 Offset=88
138134
struct _LIST_ENTRY ViewLinks; // Size=16 Offset=96

src/BlackBoneDrv/NativeStructs81.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ typedef struct _MMVAD // Size=128
124124
{
125125
struct _MMVAD_SHORT Core; // Size=64 Offset=0
126126
union ___unnamed1956 u2; // Size=4 Offset=64
127+
unsigned long pad0; // Size=4 Offset=68
127128
struct _SUBSECTION * Subsection; // Size=8 Offset=72
128129
struct _MMPTE * FirstPrototypePte; // Size=8 Offset=80
129130
struct _MMPTE * LastContiguousPte; // Size=8 Offset=88

src/BlackBoneDrv/Routines.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ NTSTATUS BBHideVAD( IN PHIDE_VAD pData )
546546

547547
status = PsLookupProcessByProcessId( (HANDLE)pData->pid, &pProcess );
548548
if (NT_SUCCESS( status ))
549-
status = BBProtectVAD( pProcess, pData->base, MM_ZERO_ACCESS );
549+
status = BBUnlinkVAD( pProcess, pData->base );
550550
else
551551
DPRINT( "BlackBone: %s: PsLookupProcessByProcessId failed with status 0x%X\n", __FUNCTION__, status );
552552

src/BlackBoneDrv/VadHelpers.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
#pragma alloc_text(PAGE, MiPromoteNode)
55
#pragma alloc_text(PAGE, MiRebalanceNode)
6-
#pragma alloc_text(PAGE, MiInsertNode)
76
#pragma alloc_text(PAGE, MiRemoveNode)
87
#pragma alloc_text(PAGE, MiFindNodeOrParent)
98

src/BlackBoneDrv/VadHelpers.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,4 @@
6262
TABLE_SEARCH_RESULT MiFindNodeOrParent( IN PMM_AVL_TABLE Table, IN ULONG_PTR StartingVpn, OUT PMMADDRESS_NODE *NodeOrParent );
6363
VOID MiPromoteNode( IN PMMADDRESS_NODE C );
6464
ULONG MiRebalanceNode( IN PMMADDRESS_NODE S );
65-
VOID MiInsertNode( IN PMMADDRESS_NODE NodeToInsert, IN PMM_AVL_TABLE Table );
6665
VOID MiRemoveNode( IN PMMADDRESS_NODE NodeToDelete, IN PMM_AVL_TABLE Table );

src/BlackBoneDrv/VadRoutines.c

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,11 @@ ULONG MmProtectToValue[32] =
5454
NTSTATUS BBProtectVAD( IN PEPROCESS pProcess, IN ULONG_PTR address, IN ULONG prot )
5555
{
5656
NTSTATUS status = STATUS_SUCCESS;
57-
PMMVAD_SHORT pVad = NULL;
58-
59-
status = BBFindVAD( pProcess, address, &pVad );
60-
if (!NT_SUCCESS( status ))
61-
return status;
57+
PMMVAD_SHORT pVadShort = NULL;
6258

63-
pVad->u.VadFlags.Protection = prot;
59+
status = BBFindVAD( pProcess, address, &pVadShort );
60+
if (NT_SUCCESS( status ))
61+
pVadShort->u.VadFlags.Protection = prot;
6462

6563
return status;
6664
}
@@ -75,15 +73,36 @@ NTSTATUS BBProtectVAD( IN PEPROCESS pProcess, IN ULONG_PTR address, IN ULONG pro
7573
/// <returns>Status code</returns>
7674
NTSTATUS BBUnlinkVAD( IN PEPROCESS pProcess, IN ULONG_PTR address )
7775
{
78-
return BBProtectVAD( pProcess, address, MM_ZERO_ACCESS );
79-
80-
/*
81-
#ifdef _WIN81_
82-
RtlAvlRemoveNode( (PMM_AVL_TABLE)((PUCHAR)pProcess + dynData.VadRoot), (PMMADDRESS_NODE)pVad );
83-
#else
84-
MiRemoveNode( (PMMADDRESS_NODE)pVad, (PMM_AVL_TABLE)((PUCHAR)pProcess + dynData.VadRoot) );
85-
#endif
86-
*/
76+
NTSTATUS status = STATUS_SUCCESS;
77+
PMMVAD_SHORT pVadShort = NULL;
78+
79+
status = BBFindVAD( pProcess, address, &pVadShort );
80+
if (!NT_SUCCESS( status ))
81+
return status;
82+
83+
// Erase image name
84+
if (pVadShort->u.VadFlags.VadType == VadImageMap)
85+
{
86+
PMMVAD pVadLong = (PMMVAD)pVadShort;
87+
if (pVadLong->Subsection && pVadLong->Subsection->ControlArea && pVadLong->Subsection->ControlArea->FilePointer.Object)
88+
{
89+
PFILE_OBJECT pFile = (PFILE_OBJECT)(pVadLong->Subsection->ControlArea->FilePointer.Value & ~0xF);
90+
pFile->FileName.Buffer[0] = L'\0';
91+
pFile->FileName.Length = 0;
92+
}
93+
else
94+
return STATUS_INVALID_ADDRESS;
95+
}
96+
// Make NO_ACCESS
97+
else if (pVadShort->u.VadFlags.VadType == VadDevicePhysicalMemory)
98+
{
99+
pVadShort->u.VadFlags.Protection = MM_ZERO_ACCESS;
100+
}
101+
// Invalid VAD type
102+
else
103+
status = STATUS_INVALID_PARAMETER;
104+
105+
return status;
87106
}
88107

89108
#pragma warning(default : 4055)

0 commit comments

Comments
 (0)