Add whitelist support.
This commit is contained in:
parent
0a9479d98f
commit
7c7f9f57f9
18
OCUploadDownloadServer/OCDaemonHoster/OCDaemonHoster.sln
Normal file
18
OCUploadDownloadServer/OCDaemonHoster/OCDaemonHoster.sln
Normal 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
|
@ -13,7 +13,7 @@ using System.Threading;
|
||||
|
||||
namespace captainalm.network.oc
|
||||
{
|
||||
public class OCNetworkClient {
|
||||
public sealed class OCNetworkClient {
|
||||
private Socket sock;
|
||||
private IPEndPoint remoteAddress;
|
||||
private IPEndPoint localAddress;
|
||||
|
@ -7,6 +7,7 @@
|
||||
* To change this template use Tools | Options | Coding | Edit Standard Headers.
|
||||
*/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Net.NetworkInformation;
|
||||
using System.Net.Sockets;
|
||||
@ -14,7 +15,7 @@ using System.Threading;
|
||||
|
||||
namespace captainalm.network.oc
|
||||
{
|
||||
public class OCNetworkListener {
|
||||
public sealed class OCNetworkListener {
|
||||
private Socket sSock;
|
||||
private Thread lThread;
|
||||
private Boolean listening;
|
||||
@ -23,6 +24,7 @@ namespace captainalm.network.oc
|
||||
private Boolean cExists;
|
||||
private Object slockcl = new Object();
|
||||
private IPEndPoint listeningAddress;
|
||||
private List<String> whitelist;
|
||||
|
||||
public OCNetworkListener(IPEndPoint addressIn) {
|
||||
lThread = new Thread(new ThreadStart(this.run));
|
||||
@ -55,6 +57,11 @@ namespace captainalm.network.oc
|
||||
if (listening) {
|
||||
lThread.Start();
|
||||
}
|
||||
whitelist = new List<String>();
|
||||
}
|
||||
|
||||
public OCNetworkListener(IPEndPoint addressIn, List<String> whitelistIn) : this(addressIn) {
|
||||
whitelist.AddRange(whitelistIn);
|
||||
}
|
||||
|
||||
public OCNetworkClient getAcceptedClient() {
|
||||
@ -79,6 +86,10 @@ namespace captainalm.network.oc
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<String> getWhiteList() {
|
||||
return whitelist;
|
||||
}
|
||||
|
||||
public IPEndPoint getListeningAddress() {
|
||||
return listeningAddress;
|
||||
@ -117,7 +128,7 @@ namespace captainalm.network.oc
|
||||
sSock = null;
|
||||
}
|
||||
|
||||
protected void run() {
|
||||
private void run() {
|
||||
while (listening) {
|
||||
while (cExists) {
|
||||
try {
|
||||
@ -128,22 +139,50 @@ namespace captainalm.network.oc
|
||||
}
|
||||
try {
|
||||
Socket sa = sSock.Accept();
|
||||
sa.ReceiveBufferSize = Int16.MaxValue;
|
||||
sa.SendBufferSize = Int16.MaxValue;
|
||||
sa.ReceiveTimeout = 5000;
|
||||
sa.SendTimeout = 5000;
|
||||
acceptedClient = new OCNetworkClient(sa);
|
||||
cWaiting = true;
|
||||
while (cWaiting) {
|
||||
try {
|
||||
Thread.Sleep(100);
|
||||
} catch (ThreadInterruptedException e) {
|
||||
break;
|
||||
if (shouldAccept(sa)) {
|
||||
sa.ReceiveBufferSize = Int16.MaxValue;
|
||||
sa.SendBufferSize = Int16.MaxValue;
|
||||
sa.ReceiveTimeout = 5000;
|
||||
sa.SendTimeout = 5000;
|
||||
acceptedClient = new OCNetworkClient(sa);
|
||||
cWaiting = true;
|
||||
while (cWaiting) {
|
||||
try {
|
||||
Thread.Sleep(100);
|
||||
} catch (ThreadInterruptedException e) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
sa.Shutdown(SocketShutdown.Both);
|
||||
} catch (SocketException e) {
|
||||
}
|
||||
try {
|
||||
sa.Close();
|
||||
} catch (SocketException e) {
|
||||
}
|
||||
sa = null;
|
||||
}
|
||||
} 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -69,7 +69,12 @@ namespace OCDaemonHoster
|
||||
} 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 'Address:Port' : " + server.getListeningAddress().Address.ToString()
|
||||
+ ":" + server.getListeningAddress().Port);
|
||||
@ -286,9 +291,10 @@ namespace OCDaemonHoster
|
||||
writeLine("");
|
||||
writeLine("Usage:");
|
||||
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("-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("-cache : caches the target file once (File Host Mode Only).");
|
||||
writeLine("-enumeration : allows for file/directory enumeration (File Access Mode Only).");
|
||||
|
Loading…
Reference in New Issue
Block a user