I’ve been working on a function to enumerate shares in Windows using Win32 C++ and hit a snag. For some reason net share
shows all the shares with the default shares and that is good. But for some reason with this code, the program gives no shares back as a result. I tried using _SHARE_INFO_1
, _SHARE_INFO_2
, and _SHARE_INFO_501
.
In IDA Free, net.exe calls NetShareEnum
and it gets the servername I think from NetWkstaGetInfo
, Ghidra says the imports are there and it doesn’t look like there are any other imports to like GetComputerNameEx
or something.
Anyway, I’m wondering if I have to call a log in, or if maybe my AV is preventing me or something? Here is the code:
std::list<String> FileSystem::listShares() {
std::list<String> shares;
_SHARE_INFO_501* buffer, p;
LPWKSTA_INFO_100 pBuf = NULL;
NET_API_STATUS nStatus;
// Retrieve workstation information at level 100
nStatus = NetWkstaGetInfo(NULL, 100, (LPBYTE*)&pBuf);
if (nStatus != NERR_Success) {
Util::printError(L"NetWkstaGetInfo");
}
LPWSTR serverName = pBuf->wki100_computername;
DWORD entriesRead;
DWORD totalEntries;
DWORD resumeHandle;
DWORD result = NetShareEnum(serverName, 501, (LPBYTE*)&buffer, MAX_PREFERRED_LENGTH, &entriesRead, &totalEntries, &resumeHandle);
std::wstringstream ss;
if (result == 0) {
for (DWORD i = 0; i < entriesRead; i++) {
p = buffer[i];
ss << L"Share Name: " << p.shi501_netname << L"ntShare Type: " << p.shi501_type << L"ntRemark: " << p.shi501_remark << std::endl;
shares.push_back(ss.str());
ss.str(L"");
}
}
else {
Util::printError(L"NetShareEnum");
}
return shares;
}
My question is; what am I doing wrong and how do I fix it?