首页
社区
课程
招聘
[原创]调戏:局域网检测与网关特征的梗
发表于: 2014-11-19 07:03 10076

[原创]调戏:局域网检测与网关特征的梗

2014-11-19 07:03
10076

调戏系列,从上次的硬断梗之后,很久没有更新,今天更新的梗有2个,不过合并成一个了。
第一个:
局域网检测,只是用来检测局域网规模,主要代码从MSDN上复制而来,没啥特别的东西,只是用来举个例子。使用netapi探测局域网主机而已(TODO:进一步完善则是在探测到之后进行连接特定的端口进行某些特殊的确认——类似IDA的局域网授权检测,but IDA的授权检测是广播模式)。

#include "stdafx.h"
#include <windows.h>
#include <WinNetWk.h>
#include <stdio.h>
#include <Shlwapi.h>
#pragma comment(lib,"shlwapi.lib")
#pragma comment(lib,"mpr.lib")

BOOL WINAPI EnumerateFunc(LPNETRESOURCE lpnr);
void DisplayStruct(int i, LPNETRESOURCE lpnrLocal);
ULONG m_Count=0;
int _tmain(int argc, _TCHAR* argv[])
{

	LPNETRESOURCE lpnr = NULL;
	printf("运行局域网扫描将占用你的一部分时间,请稍等\r\n");
	if (EnumerateFunc(lpnr) == FALSE) {
		printf("Call to EnumerateFunc failed\n");
		return 1;
	}
	else
	{
		printf("\n扫描结束\n总共发现主机数量:%d\n按任意键退出\r\n",m_Count);
		system("PAUSE");
		return 0;
	}
}

BOOL WINAPI EnumerateFunc(LPNETRESOURCE lpnr)
{
	DWORD dwResult, dwResultEnum;
	HANDLE hEnum;
	DWORD cbBuffer = 16384;     // 16K is a good size
	DWORD cEntries = -1;        // enumerate all possible entries
	LPNETRESOURCE lpnrLocal;    // pointer to enumerated structures
	DWORD i;
	//
	// Call the WNetOpenEnum function to begin the enumeration.
	//
	dwResult = WNetOpenEnum(RESOURCE_GLOBALNET, // all network resources
		RESOURCETYPE_ANY,   // all resources
		0,  // enumerate all resources
		lpnr,       // NULL first time the function is called
		&hEnum);    // handle to the resource

	if (dwResult != NO_ERROR) {
		//printf("WnetOpenEnum failed with error %d\n", dwResult);
		return FALSE;
	}
	//
	// Call the GlobalAlloc function to allocate resources.
	//
	lpnrLocal = (LPNETRESOURCE) GlobalAlloc(GPTR, cbBuffer);
	if (lpnrLocal == NULL) {
		//printf("WnetOpenEnum failed with error %d\n", dwResult);
		//      NetErrorHandler(hwnd, dwResult, (LPSTR)"WNetOpenEnum");
		return FALSE;
	}

	do {
		//
		// Initialize the buffer.
		//
		ZeroMemory(lpnrLocal, cbBuffer);
		//
		// Call the WNetEnumResource function to continue
		//  the enumeration.
		//
		dwResultEnum = WNetEnumResource(hEnum,  // resource handle
			&cEntries,      // defined locally as -1
			lpnrLocal,      // LPNETRESOURCE
			&cbBuffer);     // buffer size
		//
		// If the call succeeds, loop through the structures.
		//
		if (dwResultEnum == NO_ERROR) {
			for (i = 0; i < cEntries; i++) {
				// Call an application-defined function to
				//  display the contents of the NETRESOURCE structures.
				//
				DisplayStruct(i, &lpnrLocal[i]);

				// If the NETRESOURCE structure represents a container resource, 
				//  call the EnumerateFunc function recursively.

				if (RESOURCEUSAGE_CONTAINER == (lpnrLocal[i].dwUsage
					& RESOURCEUSAGE_CONTAINER))

					EnumerateFunc(&lpnrLocal[i]);
				
			}
		}
		// Process errors.
		//
		else if (dwResultEnum != ERROR_NO_MORE_ITEMS) {
			break;
		}
	}
	//
	// End do.
	//
	while (dwResultEnum != ERROR_NO_MORE_ITEMS);
	//
	// Call the GlobalFree function to free the memory.
	//
	GlobalFree((HGLOBAL) lpnrLocal);
	//
	// Call WNetCloseEnum to end the enumeration.
	//
	dwResult = WNetCloseEnum(hEnum);

	if (dwResult != NO_ERROR) {

		return FALSE;
	}

	return TRUE;
}

void DisplayStruct(int i, LPNETRESOURCE lpnrLocal)
{
	if (lpnrLocal->lpRemoteName!=NULL
		&&_tcsstr(lpnrLocal->lpRemoteName,_T("\\\\"))!=NULL)
	{
		printf("发现主机 %S\n",lpnrLocal->lpRemoteName);
		if(_tcsstr(&lpnrLocal->lpRemoteName[2],_T("\\"))==NULL)
			InterlockedIncrement(&m_Count);
	}
}

[培训]科锐逆向工程师培训第53期2025年7月8日开班!

收藏
免费 3
支持
分享
最新回复 (13)
雪    币: 8679
活跃值: (3225)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
2
用模板,感觉高大上
2014-11-19 07:30
0
雪    币: 32
活跃值: (34)
能力值: ( LV3,RANK:20 )
在线值:
发帖
回帖
粉丝
3
也有这么早的
2014-11-19 07:54
0
雪    币: 294
活跃值: (119)
能力值: ( LV5,RANK:70 )
在线值:
发帖
回帖
粉丝
4
学习了~~~~
2014-11-19 08:04
0
雪    币: 56
活跃值: (34)
能力值: ( LV4,RANK:50 )
在线值:
发帖
回帖
粉丝
5
多谢分享~
2014-11-19 08:52
0
雪    币: 135
活跃值: (63)
能力值: ( LV5,RANK:60 )
在线值:
发帖
回帖
粉丝
6
学习,起床准备抢沙发的,手机不给力。
2014-11-19 09:02
0
雪    币: 180
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
7
同吧聊天可能就是这样做到的吧
2014-11-19 09:23
0
雪    币: 12038
活跃值: (18892)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
8
看起来做得很好了
2014-11-19 09:58
0
雪    币: 1144
活跃值: (318)
能力值: ( LV5,RANK:75 )
在线值:
发帖
回帖
粉丝
9
v神,威武霸气
2014-11-19 10:11
0
雪    币: 485
活跃值: (113)
能力值: ( LV4,RANK:40 )
在线值:
发帖
回帖
粉丝
10
看来老V最近研究得比较“低端”
2014-11-19 11:58
0
雪    币: 124
活跃值: (609)
能力值: ( LV4,RANK:50 )
在线值:
发帖
回帖
粉丝
11
收藏
2014-11-19 22:01
0
雪    币: 90
活跃值: (91)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
12
已经不是前排了
2014-11-19 22:54
0
雪    币: 2
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
13
支持大大
2014-12-4 11:34
0
雪    币: 1737
活跃值: (110)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
14
好顶赞,回复竟然不能用表情...
2015-8-13 08:22
0
游客
登录 | 注册 方可回帖
返回