forked from k0keoyo/kDriver-Fuzzer
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathihm.c
executable file
·174 lines (142 loc) · 5.99 KB
/
ihm.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#include<stdio.h>
#include<stdlib.h>
#include "ioctl_manipulation.h"
/*
IHM functions
*/
// Banner ---------------------------------------------------------------------
void banner() {
printf(" _ _ _ ___ \n");
printf(" (_) _ | || | / __) \n");
printf(" _ ___ ____ _| |_| || |__ _| |__ \n");
printf(" | |/ _ \\ / ___|_ _) || _ (_ __) \n");
printf(" | | |_| ( (___ | |_| || |_) )| | \n");
printf(" |_|\\___/ \\____) \\__)\\_)____/ |_| FrameWork v1.0 \n");
printf(" Author: @koutoo \n");
printf(" Github: https://github.com/koutto/ioctlbf \n");
printf(" Customized by k0shl @KeyZ3r0 \n");
printf(" Github: https://github.com/k0keoyo \n");
printf(" Contact me: [email protected] \n");
return;
}
// Usage/Help message ---------------------------------------------------------
void usage(char *progName) {
banner();
printf(" Usage \n");
printf(" ----- \n");
printf(" %s -d <deviceName> (-i <code>|-r <code>-<code>) [-u] [-q] [-f] [-e]\n\n",
progName);
printf(" Options \n");
printf(" ------- \n");
printf(" -l Enable logger \n");
printf(" -s Search Driver Service Name \n");
printf(" -d Symbolic device name (without \\\\.\\) \n");
printf(" -i IOCTL code used as reference for scanning (see also -u) \n");
printf(" -n Detect IOCTL codes with null pointer \n");
printf(" -r IOCTL codes range (format: 00004000-00008000) to fuzz \n");
printf(" -u Fuzz only the IOCTL specified with -i \n");
printf(" -f Fill 0x00 in Input buffer \n");
printf(" -q Quiet mode (do not display hexdumps when fuzzing) \n");
printf(" -e Display error codes during IOCTL codes scanning \n");
printf(" -h Display this help \n\n");
printf(" Examples \n");
printf(" -------- \n");
printf("Brute IOCTL codes with Device Name:\n");
printf(" > %s -d devicename -b \n\n", progName);
printf("Scanning Driver Service Name:\n");
printf(" > %s -s \n\n", progName);
printf("Scanning range IOCTL codes by null pointer with logger:\n");
printf(" > %s -d deviceName -i 00004000 -n -l \n\n", progName);
printf("Scanning by Function code + Transfer type bruteforce from given valid IOCTL with logger:\n");
printf(" > %s -d deviceName -i 00004000 -l \n\n", progName);
printf("Scanning a given IOCTL codes range (filter enabled fill 0x00) and detect in normal(0x41 fill buffer) with logger:\n");
printf(" > %s -d deviceName -r 00004000-00004fff -f -l \n\n", progName);
printf("Fuzzing only a given IOCTL (quiet mode) without logger:\n");
printf(" > %s -d deviceName -i 00004000 -u -q \n", progName);
printf("\n");
exit(1);
}
// Exit the program -----------------------------------------------------------
void exitProgram(pIOCTLlist listIoctls) {
printf("\n[~] Exiting ...\n");
freeIoctlList(listIoctls);
exit(1);
}
// Gives the error message corresponding to a given Win32 error code ----------
char *errorCode2String(DWORD errorCode) {
LPVOID lpMsgBuf;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
errorCode,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR)&lpMsgBuf,
0, NULL);
return lpMsgBuf;
}
// Print hexdump of a given data ----------------------------------------------
// code taken from IOCTLfuzzer
void Hexdump(PUCHAR Data, ULONG Size) {
unsigned int dp = 0, p = 0;
const char trans[] =
"................................ !\"#$%&'()*+,-./0123456789"
":;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklm"
"nopqrstuvwxyz{|}~...................................."
"....................................................."
"........................................";
char szBuff[0x100], szChr[10];
RtlZeroMemory(szBuff, sizeof(szBuff));
for (dp = 1; dp <= Size; dp++) {
sprintf(szChr, "%02x ", Data[dp - 1]);
strcat(szBuff, szChr);
if ((dp % 8) == 0) {
strcat(szBuff, " ");
}
if ((dp % 16) == 0) {
strcat(szBuff, "| ");
p = dp;
for (dp -= 16; dp < p; dp++) {
sprintf(szChr, "%c", trans[Data[dp]]);
strcat(szBuff, szChr);
}
printf("%s\r\n", szBuff);
RtlZeroMemory(szBuff, sizeof(szBuff));
}
}
if ((Size % 16) != 0) {
p = dp = 16 - (Size % 16);
for (dp = p; dp > 0; dp--) {
strcat(szBuff, " ");
if (((dp % 8) == 0) && (p != 8)) {
strcat(szBuff, " ");
}
}
strcat(szBuff, " | ");
for (dp = (Size - (16 - p)); dp < Size; dp++) {
sprintf(szChr, "%c", trans[Data[dp]]);
strcat(szBuff, szChr);
}
printf("%s\r\n", szBuff);
}
printf("\r\n");
}
// Convert a string into hexadecimal ------------------------------------------
DWORD parseHex(char *str) {
DWORD value = 0;
for (;; ++str) {
switch (*str) {
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
value = value << 4 | *str & 0xf;
break;
case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
value = value << 4 | 9 + *str & 0xf;
break;
default:
return value;
}
}
}