1
+ /* Benjamin DELPY `gentilkiwi`
2
+ http://blog.gentilkiwi.com
3
+ benjamin@gentilkiwi.com
4
+ Licence : https://creativecommons.org/licenses/by/4.0/
5
+ */
6
+ #include "kdhcp.h"
7
+
8
+ HMODULE kdhcp_nextLibrary = NULL ;
9
+ LPDHCP_NEWPKT kdhcp_nextLibraryCalloutNewPkt = NULL ;
10
+
11
+ BOOL APIENTRY DllMain (HMODULE hModule , DWORD ul_reason_for_call , LPVOID lpReserved )
12
+ {
13
+ if ((ul_reason_for_call == DLL_PROCESS_DETACH ) && kdhcp_nextLibrary )
14
+ FreeLibrary (kdhcp_nextLibrary );
15
+ return TRUE;
16
+ }
17
+
18
+ DWORD CALLBACK kdhcp_DhcpServerCalloutEntry (IN LPWSTR ChainDlls , IN DWORD CalloutVersion , IN OUT LPDHCP_CALLOUT_TABLE CalloutTbl )
19
+ {
20
+ LPDHCP_ENTRY_POINT_FUNC nextEntry ;
21
+ RtlZeroMemory (CalloutTbl , sizeof (DHCP_CALLOUT_TABLE ));
22
+
23
+ if (ChainDlls )
24
+ if (kdhcp_nextLibrary = LoadLibrary (ChainDlls ))
25
+ if (nextEntry = (LPDHCP_ENTRY_POINT_FUNC ) GetProcAddress (kdhcp_nextLibrary , DHCP_CALLOUT_ENTRY_POINT ))
26
+ nextEntry (ChainDlls + lstrlenW (ChainDlls ) + 1 , CalloutVersion , CalloutTbl );
27
+
28
+ if (CalloutTbl -> DhcpNewPktHook )
29
+ kdhcp_nextLibraryCalloutNewPkt = CalloutTbl -> DhcpNewPktHook ;
30
+ CalloutTbl -> DhcpNewPktHook = kdhcp_DhcpNewPktHook ;
31
+
32
+ return ERROR_SUCCESS ;
33
+ }
34
+
35
+ const BYTE macToBlack [][MAC_ADDRESS_SIZE ] = {
36
+ {0x00 , 0x0c , 0x29 , 0x00 , 0x00 , 0x00 },
37
+ {0x00 , 0x50 , 0x56 , 0x00 , 0x00 , 0x00 }
38
+ };
39
+ DWORD CALLBACK kdhcp_DhcpNewPktHook (IN OUT LPBYTE * Packet , IN OUT DWORD * PacketSize , IN DWORD IpAddress , IN LPVOID Reserved , IN OUT LPVOID * PktContext , OUT LPBOOL ProcessIt )
40
+ {
41
+ DWORD status = ERROR_SUCCESS , m ;
42
+ * ProcessIt = TRUE;
43
+
44
+ for (m = 0 ; m < ARRAYSIZE (macToBlack ); m ++ )
45
+ {
46
+ if (RtlEqualMemory (* Packet + MAC_SOURCE_ADDRESS_OFFSET , macToBlack [m ], MAC_ADDRESS_SIZE / 2 )) // just the start of the address
47
+ {
48
+ * ProcessIt = FALSE;
49
+ status = DHCP_DROP_INVALID ;
50
+ break ;
51
+ }
52
+ }
53
+ if (kdhcp_nextLibraryCalloutNewPkt && * ProcessIt )
54
+ status = kdhcp_nextLibraryCalloutNewPkt (Packet , PacketSize , IpAddress , Reserved , PktContext , ProcessIt );
55
+ return status ;
56
+ }
0 commit comments