Add whitelist support.

This commit is contained in:
Captain ALM 2020-01-11 15:52:14 +00:00
parent 0a9479d98f
commit 7c7f9f57f9
4 changed files with 79 additions and 16 deletions

View File

@ -0,0 +1,18 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
# SharpDevelop 4.4
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OCDaemonHoster", "OCDaemonHoster.csproj", "{08F6D48F-9EAB-4861-9D50-F9F1BC10C074}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{08F6D48F-9EAB-4861-9D50-F9F1BC10C074}.Debug|Any CPU.Build.0 = Debug|Any CPU
{08F6D48F-9EAB-4861-9D50-F9F1BC10C074}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{08F6D48F-9EAB-4861-9D50-F9F1BC10C074}.Release|Any CPU.Build.0 = Release|Any CPU
{08F6D48F-9EAB-4861-9D50-F9F1BC10C074}.Release|Any CPU.ActiveCfg = Release|Any CPU
EndGlobalSection
EndGlobal

View File

@ -13,7 +13,7 @@ using System.Threading;
namespace captainalm.network.oc namespace captainalm.network.oc
{ {
public class OCNetworkClient { public sealed class OCNetworkClient {
private Socket sock; private Socket sock;
private IPEndPoint remoteAddress; private IPEndPoint remoteAddress;
private IPEndPoint localAddress; private IPEndPoint localAddress;

View File

@ -7,6 +7,7 @@
* To change this template use Tools | Options | Coding | Edit Standard Headers. * To change this template use Tools | Options | Coding | Edit Standard Headers.
*/ */
using System; using System;
using System.Collections.Generic;
using System.Net; using System.Net;
using System.Net.NetworkInformation; using System.Net.NetworkInformation;
using System.Net.Sockets; using System.Net.Sockets;
@ -14,7 +15,7 @@ using System.Threading;
namespace captainalm.network.oc namespace captainalm.network.oc
{ {
public class OCNetworkListener { public sealed class OCNetworkListener {
private Socket sSock; private Socket sSock;
private Thread lThread; private Thread lThread;
private Boolean listening; private Boolean listening;
@ -23,6 +24,7 @@ namespace captainalm.network.oc
private Boolean cExists; private Boolean cExists;
private Object slockcl = new Object(); private Object slockcl = new Object();
private IPEndPoint listeningAddress; private IPEndPoint listeningAddress;
private List<String> whitelist;
public OCNetworkListener(IPEndPoint addressIn) { public OCNetworkListener(IPEndPoint addressIn) {
lThread = new Thread(new ThreadStart(this.run)); lThread = new Thread(new ThreadStart(this.run));
@ -55,6 +57,11 @@ namespace captainalm.network.oc
if (listening) { if (listening) {
lThread.Start(); lThread.Start();
} }
whitelist = new List<String>();
}
public OCNetworkListener(IPEndPoint addressIn, List<String> whitelistIn) : this(addressIn) {
whitelist.AddRange(whitelistIn);
} }
public OCNetworkClient getAcceptedClient() { public OCNetworkClient getAcceptedClient() {
@ -79,6 +86,10 @@ namespace captainalm.network.oc
} }
} }
} }
public List<String> getWhiteList() {
return whitelist;
}
public IPEndPoint getListeningAddress() { public IPEndPoint getListeningAddress() {
return listeningAddress; return listeningAddress;
@ -117,7 +128,7 @@ namespace captainalm.network.oc
sSock = null; sSock = null;
} }
protected void run() { private void run() {
while (listening) { while (listening) {
while (cExists) { while (cExists) {
try { try {
@ -128,22 +139,50 @@ namespace captainalm.network.oc
} }
try { try {
Socket sa = sSock.Accept(); Socket sa = sSock.Accept();
sa.ReceiveBufferSize = Int16.MaxValue; if (shouldAccept(sa)) {
sa.SendBufferSize = Int16.MaxValue; sa.ReceiveBufferSize = Int16.MaxValue;
sa.ReceiveTimeout = 5000; sa.SendBufferSize = Int16.MaxValue;
sa.SendTimeout = 5000; sa.ReceiveTimeout = 5000;
acceptedClient = new OCNetworkClient(sa); sa.SendTimeout = 5000;
cWaiting = true; acceptedClient = new OCNetworkClient(sa);
while (cWaiting) { cWaiting = true;
try { while (cWaiting) {
Thread.Sleep(100); try {
} catch (ThreadInterruptedException e) { Thread.Sleep(100);
break; } catch (ThreadInterruptedException e) {
break;
}
} }
} else {
try {
sa.Shutdown(SocketShutdown.Both);
} catch (SocketException e) {
}
try {
sa.Close();
} catch (SocketException e) {
}
sa = null;
} }
} catch (SocketException e) { } catch (SocketException e) {
} }
} }
} }
private bool shouldAccept(Socket si) {
if (whitelist.Count > 0) {
String addr = ((IPEndPoint) si.RemoteEndPoint).Address.ToString();
bool toret = false;
for (int i = 0; i < whitelist.Count; i++) {
if (whitelist[i].Equals(addr)) {
toret = true;
break;
}
}
return toret;
} else {
return true;
}
}
} }
} }

View File

@ -69,7 +69,12 @@ namespace OCDaemonHoster
} catch (IOException e) { } catch (IOException e) {
} }
} }
OCNetworkListener server = new OCNetworkListener(address); List<String> wl = new List<String>();
if (settings.ContainsKey("whitelist")) {
wl.AddRange(settings["whitelist"].Split(",".ToCharArray()));
}
OCNetworkListener server = new OCNetworkListener(address, wl);
writeLine("[INFO] : Listener Started!"); writeLine("[INFO] : Listener Started!");
writeLine("[INFO] : Listener 'Address:Port' : " + server.getListeningAddress().Address.ToString() writeLine("[INFO] : Listener 'Address:Port' : " + server.getListeningAddress().Address.ToString()
+ ":" + server.getListeningAddress().Port); + ":" + server.getListeningAddress().Port);
@ -286,9 +291,10 @@ namespace OCDaemonHoster
writeLine(""); writeLine("");
writeLine("Usage:"); writeLine("Usage:");
writeLine( writeLine(
"OCDH.exe <listening IP Address> <listening Port> [-mode=<MODE>] [-target=<target file path>] [-cache] [-enumeration] [-creation] [-deletion]"); "OCDH.exe <listening IP Address> <listening Port> [-mode=<MODE>] [-whitelist=<IP Address [Seperated By ,]>] [-target=<target file path>] [-cache] [-enumeration] [-creation] [-deletion]");
writeLine(""); writeLine("");
writeLine("-mode=<MODE> : allows to select a Hosting Mode."); writeLine("-mode=<MODE> : allows to select a Hosting Mode.");
writeLine("-whitelist=<IP Address [Seperated By ,]> : allows IP Address to connect, if there is no whitelist switch then any IP Address can connect.");
writeLine("-target=<target file path> : allows to select a file for hosting (File Host Mode Only)."); writeLine("-target=<target file path> : allows to select a file for hosting (File Host Mode Only).");
writeLine("-cache : caches the target file once (File Host Mode Only)."); writeLine("-cache : caches the target file once (File Host Mode Only).");
writeLine("-enumeration : allows for file/directory enumeration (File Access Mode Only)."); writeLine("-enumeration : allows for file/directory enumeration (File Access Mode Only).");