Ejemplo n.º 1
0
//Windows Firewall Test
inline size_t __fastcall FirewallTest(uint16_t Protocol)
{
	SYSTEM_SOCKET FirewallSocket = 0;
	sockaddr_storage SockAddr = {0};

//Ramdom number generator initialization
	std::random_device RamdomDevice;
	std::mt19937 RamdomEngine(RamdomDevice()); //Mersenne Twister Engine
	std::uniform_int_distribution<int> Distribution(1, U16_MAXNUM);
	auto RamdomGenerator = std::bind(Distribution, RamdomEngine);

//Socket initialization
	if (Protocol == AF_INET6) //IPv6
	{
		FirewallSocket = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
		SockAddr.ss_family = AF_INET6;
		((PSOCKADDR_IN6)&SockAddr)->sin6_addr = in6addr_any;
		((PSOCKADDR_IN6)&SockAddr)->sin6_port = htons((uint16_t)RamdomGenerator());

	//Bind local socket.
		if (FirewallSocket == INVALID_SOCKET || bind(FirewallSocket, (PSOCKADDR)&SockAddr, sizeof(sockaddr_in6)) == SOCKET_ERROR)
		{
			closesocket(FirewallSocket);
			return EXIT_FAILURE;
		}
	}
	else { //IPv4
		FirewallSocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
		SockAddr.ss_family = AF_INET;
		((PSOCKADDR_IN)&SockAddr)->sin_addr.S_un.S_addr = INADDR_ANY;
		((PSOCKADDR_IN)&SockAddr)->sin_port = htons((uint16_t)RamdomGenerator());

	//Bind local socket.
		if (FirewallSocket == INVALID_SOCKET || bind(FirewallSocket, (PSOCKADDR)&SockAddr, sizeof(sockaddr_in)) == SOCKET_ERROR)
		{
			closesocket(FirewallSocket);
			return EXIT_FAILURE;
		}
	}

	closesocket(FirewallSocket);
	return EXIT_SUCCESS;
}
Ejemplo n.º 2
0
//GlobalStatus class constructor settings
void __fastcall GlobalStatusSetting(
	GlobalStatus *GlobalRunningStatusParameter)
{
#if defined(PLATFORM_LINUX)
	GlobalRunningStatusParameter->Daemon = true;
#endif
	std::random_device RamdomDevice;
	GlobalRunningStatusParameter->RamdomEngine->seed(RamdomDevice());
	memset(GlobalRunningStatusParameter->DomainTable, 0, strlen(RFC_DOMAIN_TABLE) + 1U);
	strncpy_s(GlobalRunningStatusParameter->DomainTable, strlen(RFC_DOMAIN_TABLE) + 1U, RFC_DOMAIN_TABLE, strlen(RFC_DOMAIN_TABLE));
	GlobalRunningStatusParameter->GatewayAvailable_IPv4 = true;
	memset(GlobalRunningStatusParameter->LocalAddress_Response[0], 0, PACKET_MAXSIZE);
	memset(GlobalRunningStatusParameter->LocalAddress_Response[1U], 0, PACKET_MAXSIZE);

//Windows XP with SP3 support
#if (defined(PLATFORM_WIN32) && !defined(PLATFORM_WIN64))
	GetFunctionPointer(FUNCTION_GETTICKCOUNT64);
	GetFunctionPointer(FUNCTION_INET_NTOP);
	GetFunctionPointer(FUNCTION_INET_PTON);
#endif

	return;
}
Ejemplo n.º 3
0
//Configuration class constructor
ConfigurationTable::ConfigurationTable(void)
{
	memset(this, 0, sizeof(CONFIGURATION_TABLE));
	try {
	//[Listen] block
		ListenPort = new std::vector<uint16_t>();
	//[Addresses] block
		ListenAddress_IPv6 = new std::vector<sockaddr_storage>();
		ListenAddress_IPv4 = new std::vector<sockaddr_storage>();
		DNSTarget.IPv6_Multi = new std::vector<DNS_SERVER_DATA>();
		DNSTarget.IPv4_Multi = new std::vector<DNS_SERVER_DATA>();
	//[Data] block(A part)
	#if defined(ENABLE_PCAP)
		ICMPPaddingData = new char[ICMP_PADDING_MAXSIZE]();
		DomainTestData = new char[DOMAIN_MAXSIZE]();
	#endif
	//[Data] block(B part)
		LocalFQDNResponse = new char[DOMAIN_MAXSIZE]();
		LocalFQDNString = new std::string();
	#if !defined(PLATFORM_MACX)
		LocalServerResponse = new char[DOMAIN_MAXSIZE + sizeof(dns_record_ptr) + sizeof(dns_record_opt)]();
	#endif
		LocalAddressResponse[0] = new char[PACKET_MAXSIZE]();
		LocalAddressResponse[1U] = new char[PACKET_MAXSIZE]();
	#if !defined(PLATFORM_MACX)
		LocalAddressPTRResponse[0] = new std::vector<std::string>();
		LocalAddressPTRResponse[1U] = new std::vector<std::string>();
	#endif
	//Global block
		LocalSocket = new std::vector<SYSTEM_SOCKET>();
		RamdomEngine = new std::default_random_engine();
		Path = new std::vector<std::wstring>();
		HostsFileList = new std::vector<std::wstring>();
		IPFilterFileList = new std::vector<std::wstring>();
		ErrorLogPath = new std::wstring();
	#if (defined(PLATFORM_LINUX) || defined(PLATFORM_MACX))
		sPath = new std::vector<std::string>();
		sHostsFileList = new std::vector<std::string>();
		sIPFilterFileList = new std::vector<std::string>();
		sErrorLogPath = new std::string();
	#endif
		DomainTable = new char[strlen(RFC_DOMAIN_TABLE) + 1U]();
		AcceptTypeList = new std::vector<uint16_t>();
	}
	catch (std::bad_alloc)
	{
	//[Listen] block
		delete ListenPort;
	//[Addresses] block
		delete ListenAddress_IPv6;
		delete ListenAddress_IPv4;
		delete DNSTarget.IPv6_Multi;
		delete DNSTarget.IPv4_Multi;
	//[Data] block(A part)
	#if defined(ENABLE_PCAP)
		delete[] ICMPPaddingData;
		delete[] DomainTestData;
	#endif
	//[Data] block(B part)
		delete[] LocalFQDNResponse;
		delete LocalFQDNString;
	#if !defined(PLATFORM_MACX)
		delete[] LocalServerResponse;
	#endif
		delete[] LocalAddressResponse[0];
		delete[] LocalAddressResponse[1U];
	#if !defined(PLATFORM_MACX)
		delete LocalAddressPTRResponse[0];
		delete LocalAddressPTRResponse[1U];
	#endif
	//Global block
		delete LocalSocket;
		delete RamdomEngine;
		delete Path;
		delete HostsFileList;
		delete IPFilterFileList;
		delete ErrorLogPath;
		delete[] DomainTable;
		delete AcceptTypeList;

		exit(EXIT_FAILURE);
		return;
	}

//Initialization
	//[Data] block(A part)
#if defined(ENABLE_PCAP)
	memset(ICMPPaddingData, 0, ICMP_PADDING_MAXSIZE);
	memset(DomainTestData, 0, DOMAIN_MAXSIZE);
#endif
	//[Data] block(B part)
	memset(LocalFQDNResponse, 0, DOMAIN_MAXSIZE);
#if !defined(PLATFORM_MACX)
	memset(LocalServerResponse, 0, DOMAIN_MAXSIZE + sizeof(dns_record_ptr) + sizeof(dns_record_opt));
#endif
	memset(LocalAddressResponse[0], 0, PACKET_MAXSIZE);
	memset(LocalAddressResponse[1U], 0, PACKET_MAXSIZE);
	//Global block
	memset(DomainTable, 0, strlen(RFC_DOMAIN_TABLE) + 1U);

//Default settings
	strncpy_s(DomainTable, strlen(RFC_DOMAIN_TABLE) + 1U, RFC_DOMAIN_TABLE, strlen(RFC_DOMAIN_TABLE));
	std::random_device RamdomDevice;
	RamdomEngine->seed(RamdomDevice());

//Default values
	FileRefreshTime = DEFAULT_FILEREFRESH_TIME * SECOND_TO_MILLISECOND;
	LogMaxSize = DEFAULT_LOG_MAXSIZE;
	HostsDefaultTTL = DEFAULT_HOSTS_TTL;
	AlternateTimes = DEFAULT_ALTERNATE_TIMES;
	AlternateTimeRange = DEFAULT_ALTERNATE_RANGE * SECOND_TO_MILLISECOND;
	AlternateResetTime = DEFAULT_ALTERNATERESET_TIME * SECOND_TO_MILLISECOND;
#if defined(PLATFORM_WIN)
	ReliableSocketTimeout = DEFAULT_RELIABLE_SOCKET_TIMEOUT;
	UnreliableSocketTimeout = DEFAULT_UNRELIABLE_SOCKET_TIMEOUT;
#elif (defined(PLATFORM_LINUX) || defined(PLATFORM_MACX))
	ReliableSocketTimeout.tv_sec = DEFAULT_RELIABLE_SOCKET_TIMEOUT;
	UnreliableSocketTimeout.tv_sec = DEFAULT_UNRELIABLE_SOCKET_TIMEOUT;
#endif
#if defined(PLATFORM_MACX)
	Console = true;
#endif
#if defined(ENABLE_PCAP)
	PcapReadingTimeout = DEFAULT_PCAP_CAPTURE_TIMEOUT;
	#if defined(PLATFORM_MACX)
		ICMPID = htons(*(uint16_t *)pthread_self());
	#else
		ICMPID = htons((uint16_t)GetCurrentProcessId()); //Default ICMP ID is current process ID.
	#endif
		ICMPSequence = htons(DEFAULT_SEQUENCE);
		DomainTestSpeed = DEFAULT_DOMAINTEST_INTERVAL_TIME * SECOND_TO_MILLISECOND;
	#if defined(PLATFORM_MACX)
		DomainTestID = htons(*(uint16_t *)pthread_self());
	#else
		DomainTestID = htons((uint16_t)GetCurrentProcessId()); //Default DNS ID is current process ID.
	#endif
	#if defined(PLATFORM_WIN)
		ICMPPaddingDataLength = strlen(DEFAULT_PADDINGDATA) + 1U;
		memcpy_s(ICMPPaddingData, ICMP_PADDING_MAXSIZE, DEFAULT_PADDINGDATA, Parameter.ICMPPaddingDataLength - 1U); //Load default padding data.
	#elif defined(PLATFORM_LINUX)
		size_t CharData = ICMP_STRING_START_NUM_LINUX;
		for (size_t Index = 0;Index < ICMP_PADDING_LENGTH_LINUX;++Index, ++CharData)
			ICMPPaddingData[Index] = CharData;
		ICMPPaddingDataLength = strlen(ICMPPaddingData) + 1U;
	#elif defined(PLATFORM_MACX)
		size_t CharData = ICMP_STRING_START_NUM_MAC;
		for (size_t Index = 0;Index < ICMP_PADDING_LENGTH_MAC;++Index, ++CharData)
			ICMPPaddingData[Index] = CharData;
		ICMPPaddingDataLength = strlen(ICMPPaddingData) + 1U;
	#endif
#endif

//Default status
	GatewayAvailable_IPv4 = true;

	return;
}
Ejemplo n.º 4
0
//Configuration class constructor
ConfigurationTable::ConfigurationTable(void)
{
	memset(this, 0, sizeof(CONFIGURATION_TABLE));
	try {
	//[Listen] block
		ListenPort = new std::vector<uint16_t>();
	//[Addresses] block
		ListenAddress_IPv6 = new std::vector<sockaddr_storage>();
		ListenAddress_IPv4 = new std::vector<sockaddr_storage>();
		DNSTarget.IPv6_Multi = new std::vector<DNS_SERVER_DATA>();
		DNSTarget.IPv4_Multi = new std::vector<DNS_SERVER_DATA>();
	//[Data] block(A part)
		ICMPPaddingData = new char[ICMP_PADDING_MAXSIZE]();
		DomainTestData = new char[DOMAIN_MAXSIZE]();
	//[Data] block(B part)
		LocalFQDN = new char[DOMAIN_MAXSIZE]();
		LocalFQDNString = new std::string();
		LocalServerResponse = new char[DOMAIN_MAXSIZE + sizeof(dns_record_ptr) + sizeof(dns_record_opt)]();
		LocalAddress[0] = new char[PACKET_MAXSIZE]();
		LocalAddress[1U] = new char[PACKET_MAXSIZE]();
		LocalAddressPTR[0] = new std::vector<std::string>();
		LocalAddressPTR[1U] = new std::vector<std::string>();
	//Global block
		LocalSocket = new std::vector<SYSTEM_SOCKET>();
		RamdomEngine = new std::default_random_engine();
		Path = new std::vector<std::wstring>();
		HostsFileList = new std::vector<std::wstring>();
		IPFilterFileList = new std::vector<std::wstring>();
		ErrorLogPath = new std::wstring();
		RunningLogPath = new std::wstring();
		RunningLogWriteQueue = new std::vector<RUNNING_LOG_DATA>();
		DomainTable = new char[strlen(RFC_DOMAIN_TABLE) + 1U]();
		AcceptTypeList = new std::vector<uint16_t>();
	}
	catch (std::bad_alloc)
	{
	//[Listen] block
		delete ListenPort;
	//[Addresses] block
		delete ListenAddress_IPv6;
		delete ListenAddress_IPv4;
		delete DNSTarget.IPv6_Multi;
		delete DNSTarget.IPv4_Multi;
	//[Data] block(A part)
		delete[] ICMPPaddingData;
		delete[] DomainTestData;
	//[Data] block(B part)
		delete[] LocalFQDN;
		delete LocalFQDNString;
		delete[] LocalServerResponse;
		delete[] LocalAddress[0];
		delete[] LocalAddress[1U];
		delete LocalAddressPTR[0];
		delete LocalAddressPTR[1U];
	//Global block
		delete LocalSocket;
		delete RamdomEngine;
		delete Path;
		delete HostsFileList;
		delete IPFilterFileList;
		delete ErrorLogPath;
		delete RunningLogPath;
		delete RunningLogWriteQueue;
		delete[] DomainTable;
		delete AcceptTypeList;

//		WSACleanup();
//		TerminateService();
		exit(EXIT_FAILURE);
		return;
	}

//Initialization
	//[Data] block(A part)
	memset(ICMPPaddingData, 0, ICMP_PADDING_MAXSIZE);
	memset(DomainTestData, 0, DOMAIN_MAXSIZE);
	//[Data] block(B part)
	memset(LocalFQDN, 0, DOMAIN_MAXSIZE);
	memset(LocalServerResponse, 0, DOMAIN_MAXSIZE + sizeof(dns_record_ptr) + sizeof(dns_record_opt));
	memset(LocalAddress[0], 0, PACKET_MAXSIZE);
	memset(LocalAddress[1U], 0, PACKET_MAXSIZE);
	//Global block
	memset(DomainTable, 0, strlen(RFC_DOMAIN_TABLE) + 1U);

//Default values
//	strncpy(DomainTable, RFC_DOMAIN_TABLE, strlen(RFC_DOMAIN_TABLE));
	strncpy_s(DomainTable, strlen(RFC_DOMAIN_TABLE) + 1U, RFC_DOMAIN_TABLE, strlen(RFC_DOMAIN_TABLE));
	std::random_device RamdomDevice;
	RamdomEngine->seed(RamdomDevice());

//Default settings
	LogMaxSize = DEFAULT_LOG_MAXSIZE;
	GatewayAvailable_IPv4 = true;
//	ListenPort->push_back(htons(IPPORT_DNS));
	ReliableSocketTimeout = DEFAULT_RELIABLE_SOCKET_TIMEOUT;
	UnreliableSocketTimeout = DEFAULT_UNRELIABLE_SOCKET_TIMEOUT;
	ICMPID = htons((uint16_t)GetCurrentProcessId()); //Default ICMP ID is current process ID.
	ICMPSequence = htons(DEFAULT_SEQUENCE);
	DomainTestSpeed = DEFAULT_DOMAINTEST_INTERVAL_TIME * SECOND_TO_MILLISECOND;
	DomainTestID = htons((uint16_t)GetCurrentProcessId()); //Default DNS ID is current process ID.
	//Load default padding data from Microsoft Windows Ping.
	ICMPPaddingDataLength = strlen(DEFAULT_PADDINGDATA) + 1U;
//	memcpy(ICMPPaddingData, DEFAULT_PADDINGDATA, Parameter.ICMPPaddingDataLength - 1U);
	memcpy_s(ICMPPaddingData, ICMP_PADDING_MAXSIZE, DEFAULT_PADDINGDATA, Parameter.ICMPPaddingDataLength - 1U);
	HostsDefaultTTL = DEFAULT_HOSTS_TTL;

	return;
}