<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Programm die I-Verbindung verbieten]]></title><description><![CDATA[<p>Hi!</p>
<p>Gibt es eine quick-and-dirty lösung, wie ich einem programm die internet-verbindung verbieten kann?</p>
<p>Ich möchte deswegen nich extra ne firewall installieren bzw. laufen lassen.</p>
<p>Also einfach einer bestimmten exe/prozess vorgaukeln, dass das i-net nicht verfügbar ist.</p>
<p>Geht sowas in ein paar Zeilen, oder ist das ein riesen Act?</p>
<p>PS: Nein ich bin nicht an einer 1000 Seitigen doku interessiert. Es geht mir wirklich nur um das kleine programm <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/topic/123993/programm-die-i-verbindung-verbieten</link><generator>RSS for Node</generator><lastBuildDate>Tue, 07 Jul 2026 04:25:04 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/123993.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 22 Oct 2005 09:45:27 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Programm die I-Verbindung verbieten on Sat, 22 Oct 2005 09:45:27 GMT]]></title><description><![CDATA[<p>Hi!</p>
<p>Gibt es eine quick-and-dirty lösung, wie ich einem programm die internet-verbindung verbieten kann?</p>
<p>Ich möchte deswegen nich extra ne firewall installieren bzw. laufen lassen.</p>
<p>Also einfach einer bestimmten exe/prozess vorgaukeln, dass das i-net nicht verfügbar ist.</p>
<p>Geht sowas in ein paar Zeilen, oder ist das ein riesen Act?</p>
<p>PS: Nein ich bin nicht an einer 1000 Seitigen doku interessiert. Es geht mir wirklich nur um das kleine programm <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/898528</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/898528</guid><dc:creator><![CDATA[Ybbs]]></dc:creator><pubDate>Sat, 22 Oct 2005 09:45:27 GMT</pubDate></item><item><title><![CDATA[Reply to Programm die I-Verbindung verbieten on Sat, 22 Oct 2005 17:05:06 GMT]]></title><description><![CDATA[<p>spontan fällt mir ein, in den prozess ne dll-datei zu injizieren, die die Importabschnitte bestimmter Socketfunktionen überschreibt. z.b. connect. das ganze wäre gut in 150 zeilen code machbar.</p>
<p>mfg</p>
]]></description><link>https://www.c-plusplus.net/forum/post/898844</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/898844</guid><dc:creator><![CDATA[Black Shadow__]]></dc:creator><pubDate>Sat, 22 Oct 2005 17:05:06 GMT</pubDate></item><item><title><![CDATA[Reply to Programm die I-Verbindung verbieten on Sun, 23 Oct 2005 12:36:58 GMT]]></title><description><![CDATA[<p>Danke, muss ich mich doch mal etwas einlesen... <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/899265</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/899265</guid><dc:creator><![CDATA[Ybbus]]></dc:creator><pubDate>Sun, 23 Oct 2005 12:36:58 GMT</pubDate></item><item><title><![CDATA[Reply to Programm die I-Verbindung verbieten on Sun, 23 Oct 2005 15:14:54 GMT]]></title><description><![CDATA[<p>Hallo,<br />
hatte was ähnliches schonmal programmiert und habe den code jetzt umgeschrieben, der sollte so funktionieren (zumindest tat er das bei icq und firefox):<br />
Deine exe-datei muss folgende Funktion aufrufen:</p>
<pre><code class="language-cpp">bool InjectDllInProcess(DWORD dwProcessId)
{
	HANDLE hProcess, hThread;
	char szDllPathName[MAX_PATH];
	DWORD dwDllStringSize;
	void *pRemoteString;
	PTHREAD_START_ROUTINE pfnThreadRoutine;

	pfnThreadRoutine = (PTHREAD_START_ROUTINE)
	GetProcAddress(GetModuleHandle(&quot;Kernel32&quot;), &quot;LoadLibraryA&quot;);
	// could the address of LoadLibraryA function be found?
	if(!pfnThreadRoutine)
		return false;
	// open remote process with threadcreation- and writing-flags
	hProcess = OpenProcess(PROCESS_CREATE_THREAD | PROCESS_VM_OPERATION
				| PROCESS_VM_WRITE | PROCESS_VM_READ, false, dwProcessId);
	if(!hProcess)
		return false;
	// get the whole path+name of dll file, then the size of this string:
	wsprintfA(szDllPathName, &quot;%s\\%s&quot;, g_szMyPath, g_szInjDll);
	dwDllStringSize = lstrlenA(szDllPathName) + 1;	// +1 = zero
	// reserve memory in the remote thread for the name of phtm-dll:
	pRemoteString = VirtualAllocEx(hProcess, 0, dwDllStringSize,
									MEM_COMMIT, PAGE_READWRITE);
	if(!pRemoteString)
	{
		// cleanup
		CloseHandle(hProcess);
		return false;
	}
	// copy dll string into the remote process:
	if(!WriteProcessMemory(hProcess, pRemoteString, szDllPathName,
					dwDllStringSize, 0))
	{
		// cleanup
		VirtualFreeEx(hProcess, pRemoteString, dwDllStringSize, MEM_RELEASE);
		CloseHandle(hProcess);
		return false;
	}

	hThread = CreateRemoteThread(hProcess, 0, 0,
					pfnThreadRoutine, pRemoteString, 0, 0);
	if(!hThread)
	{
		// cleanup
		VirtualFreeEx(hProcess, pRemoteString, dwDllStringSize, MEM_RELEASE);
		CloseHandle(hProcess);
		return false;
	}
	// wait until remote thread ends:
	WaitForSingleObject(hThread, INFINITE);
	// cleanup:
	VirtualFreeEx(hProcess, pRemoteString, dwDllStringSize, MEM_RELEASE);
	CloseHandle(hThread);
	CloseHandle(hProcess);

	return true;
}
</code></pre>
<p>das geht aber nur unter WinNT/2k/xp!<br />
windows.h zu includieren müsste reichen. Die ProcessId ist das einzige was du übergeben musst. die kriegst du z.b. indem du selbst den prozess erstellst oder wenn du n window handle hast mit GetWindowThreadProcessId oder mit den toolhelp-funktionen (CreateToolhelp32Snapshot) etc.<br />
du brauchst für die funktion hier noch 2 globale variablen - g_szMyPath und g_szInjDll - die werden zu szDllPathName zusammengefügt, was der komplette Pfad+Dateiname (z.b. C:\dll.dll) sein muss. kannst ja bei dir anpassen.</p>
<p>Der Code deiner dll-datei:</p>
<pre><code class="language-cpp">#define APIH_LOADLIB	0x01
#define APIH_CONNECT	0x02

#pragma comment(lib, &quot;user32&quot;)
#pragma comment(lib, &quot;imagehlp&quot;)

#include &lt;winsock2.h&gt;
#include &lt;windows.h&gt;
#include &lt;imagehlp.h&gt;
#include &lt;tlhelp32.h&gt;

HANDLE hMod;

BOOL ReplaceFuncsInThisProcess(DWORD);
BOOL ReplaceFunctionIn1Mod(char*, void*, void*, HMODULE);

char szKernel32Dll[] = &quot;kernel32.dll&quot;;
char szWinsockDll[] = &quot;wsock32.dll&quot;;
char szWinsock2Dll[] = &quot;ws2_32.dll&quot;;

// LoadLibrary:
// unicode/ANSI!
HMODULE WINAPI MyLoadLibraryW(LPCWSTR);
HMODULE WINAPI MyLoadLibraryA(LPCSTR);
const char szLoadLibraryW[] = &quot;LoadLibraryW&quot;;
const char szLoadLibraryA[] = &quot;LoadLibraryA&quot;;
void *pLoadLibraryASys, *pLoadLibraryWSys;

// connect from ws2_32.dll and wsock2.dll:
int FAR PASCAL MyConnect(SOCKET, const struct sockaddr FAR*, int);
const char szConnect[] = &quot;connect&quot;;
void *pConnectSys, *pConnect2Sys;
// wsaconnect from ws2_32.dll:
int FAR PASCAL MyWSAConnect(SOCKET, const struct sockaddr FAR*,
    int, LPWSABUF, LPWSABUF, LPQOS, LPQOS);
const char szWSAConnect[] = &quot;WSAConnect&quot;;
void *pWSAConnectSys;

BOOL APIENTRY DllMain(HANDLE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved)
{
    switch (ul_reason_for_call)
    {
        case DLL_PROCESS_ATTACH:
            hMod = hModule;
			// get system module references to our functions:
			pLoadLibraryWSys = GetProcAddress(GetModuleHandle(szKernel32Dll), szLoadLibraryW);
			pLoadLibraryASys = GetProcAddress(GetModuleHandle(szKernel32Dll), szLoadLibraryA);
			pConnectSys = GetProcAddress(GetModuleHandle(szWinsockDll), szConnect);
			pConnect2Sys = GetProcAddress(GetModuleHandle(szWinsock2Dll), szConnect);
			pWSAConnectSys = GetProcAddress(GetModuleHandle(szWinsock2Dll), szWSAConnect);
			ReplaceFuncsInThisProcess(APIH_LOADLIB | APIH_CONNECT);
			break;          
    }
    return true;
}

/*
Diese Funktion ruft für jedes Modul, das sich in diesem Prozess befindet,
die Funktion ReplaceFunctionIn1Mod auf. Da jedes Modul (dll-datei)
in diesem Prozess theoretisch die Funktion aufrufen könnte,
die wir einhaken wollen.
*/
BOOL ReplaceFuncsInThisProcess(DWORD dwFlags)
{
	HANDLE hSnapshot;
	MODULEENTRY32 me32;

	hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, GetCurrentProcessId());
	if(hSnapshot == INVALID_HANDLE_VALUE)
	{
	//	MessageBox(0, &quot;Error: ToolhelpSnapshot&quot;, &quot;&quot;, 0);
		return false;
	}

	me32.dwSize = sizeof(MODULEENTRY32);
	if(Module32First(hSnapshot, &amp;me32))
	{
		do
		{
			// dont hook our own module and kernel32:
			if(hMod != me32.hModule
				&amp;&amp; strcmpi(me32.szModule, szKernel32Dll)
				&amp;&amp; strcmpi(me32.szModule, szWinsockDll)
				&amp;&amp; strcmpi(me32.szModule, szWinsock2Dll))
			{
				if(dwFlags &amp; APIH_LOADLIB)
				{
					ReplaceFunctionIn1Mod(szKernel32Dll, pLoadLibraryASys,
						MyLoadLibraryA, me32.hModule);
					ReplaceFunctionIn1Mod(szKernel32Dll, pLoadLibraryWSys,
						MyLoadLibraryW, me32.hModule);
				}
				if(dwFlags &amp; APIH_CONNECT)
				{
					ReplaceFunctionIn1Mod(szWinsockDll, pConnectSys,
						MyConnect, me32.hModule);
					ReplaceFunctionIn1Mod(szWinsock2Dll, pConnect2Sys,
						MyConnect, me32.hModule);
					ReplaceFunctionIn1Mod(szWinsock2Dll, pWSAConnectSys,
						MyWSAConnect, me32.hModule);
				}
			}
		} while(Module32Next(hSnapshot, &amp;me32));
	}
	else
	{
	//	MessageBox(0, &quot;Error: module32first&quot;, &quot;&quot;, 0);
		return false;
	}

	CloseHandle(hSnapshot);

	return true;
}

/*
MS Windows Programmierung für Experten - Richter, S. 697, abgewandelt:
*/
BOOL ReplaceFunctionIn1Mod(char *pszDllName, void *pfnOld,
					void *pfnNew, HMODULE hModCaller)
{
	unsigned long ulSize;
	PIMAGE_IMPORT_DESCRIPTOR pImpDesc;

	pImpDesc = (PIMAGE_IMPORT_DESCRIPTOR)ImageDirectoryEntryToData(hModCaller, true,
									IMAGE_DIRECTORY_ENTRY_IMPORT, &amp;ulSize);
	if(!pImpDesc)
		return false;

	while(pImpDesc-&gt;Name)
	{
		char *pszMod = (char*)((BYTE*)hModCaller + pImpDesc-&gt;Name);
		if(lstrcmpiA(pszMod, pszDllName) == 0)
			break;	// importaddress from pszDllName found
		pImpDesc++;
	}

	if(!pImpDesc-&gt;Name)
		return false;

	PIMAGE_THUNK_DATA pThunk = (PIMAGE_THUNK_DATA)
		((BYTE*)hModCaller + pImpDesc-&gt;FirstThunk);
	while(pThunk-&gt;u1.Function)
	{
		PROC *ppfn = (PROC*)&amp;pThunk-&gt;u1.Function;
		if(*ppfn == pfnOld)
		{
			HANDLE hProcess;

			hProcess = GetCurrentProcess();
			// overwrite the function:
			if(!WriteProcessMemory(hProcess, ppfn, &amp;pfnNew, sizeof(pfnNew), 0)
				&amp;&amp; GetLastError() == 998)
			{
				// set read-only page writeable:
				DWORD dwOldProtect;
				if(!VirtualProtectEx(hProcess, ppfn, sizeof(pfnNew),
							PAGE_READWRITE, &amp;dwOldProtect))
				{
					return false;
				}
				// write again:
				if(!WriteProcessMemory(hProcess, ppfn, &amp;pfnNew, sizeof(pfnNew), 0))
				{
					return false;
				}
				// write process was successful. now give old protection back:
				VirtualProtectEx(hProcess, ppfn, sizeof(pfnNew), dwOldProtect, &amp;dwOldProtect);
			}
			return true;
		}

		pThunk++;
	}

	return true;
}

HMODULE WINAPI MyLoadLibraryW(LPCWSTR lpLibFileName)
{
	HMODULE hThisMod = LoadLibraryW(lpLibFileName);

	ReplaceFunctionIn1Mod(szWinsockDll, pConnectSys,
			MyConnect, hThisMod);
	ReplaceFunctionIn1Mod(szWinsock2Dll, pConnect2Sys,
			MyConnect, hThisMod);
	ReplaceFunctionIn1Mod(szWinsock2Dll, pWSAConnectSys,
			MyWSAConnect, hThisMod);

	return hThisMod;
}

HMODULE WINAPI MyLoadLibraryA(LPCSTR lpLibFileName)
{
	HMODULE hThisMod = LoadLibraryA(lpLibFileName);

	ReplaceFunctionIn1Mod(szWinsockDll, pConnectSys,
			MyConnect, hThisMod);
	ReplaceFunctionIn1Mod(szWinsock2Dll, pConnect2Sys,
			MyConnect, hThisMod);
	ReplaceFunctionIn1Mod(szWinsock2Dll, pWSAConnectSys,
			MyWSAConnect, hThisMod);

	return hThisMod;
}

int FAR PASCAL MyConnect(SOCKET s, const struct sockaddr FAR * name, int namelen)
{
	// if you want to connect:
	// return connect(s, name, namelen);
	// otherwise:
	return 0;
}

int FAR PASCAL MyWSAConnect(SOCKET s, const struct sockaddr FAR * name,
    int namelen, LPWSABUF lpCallerData, LPWSABUF lpCalleeData, LPQOS lpSQOS,
    LPQOS lpGQOS)
{
	return 0;
}
</code></pre>
<p>kannst eigentlich so kompilieren!<br />
wird die dll in nen prozess injiziert überschreibt sie connect (aus ws2_32.dll und wsock2.dll) und WSAConnect (ws2_32.dll) damit zur laufzeit geladene module nicht verbinden können wird auch LoadLibraryA und LoadLibraryW überwacht.<br />
man brauch hier auch win nt, 2k, xp</p>
<p>mfg</p>
]]></description><link>https://www.c-plusplus.net/forum/post/899369</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/899369</guid><dc:creator><![CDATA[Black Shadow]]></dc:creator><pubDate>Sun, 23 Oct 2005 15:14:54 GMT</pubDate></item></channel></rss>