Work on DDoS Protection switcher
This commit is contained in:
parent
a66e877028
commit
64903ae4b4
@ -126,6 +126,29 @@
|
||||
</jar>
|
||||
<copy file="../bin/Mineplexer.jar" todir="../../Testing/Proxy/plugins"/>
|
||||
</target>
|
||||
<target name ="DDoSProtectionSwitcher" description="DDoSProtectionSwitcher">
|
||||
<jar jarfile="../bin/DDoSProtectionSwitcher.jar">
|
||||
<fileset dir="../Mineplex.DDoSProtectionSwitcher/bin">
|
||||
<include name="**/*.class"/>
|
||||
</fileset>
|
||||
|
||||
<zipfileset src="../Libraries/mysql.zip" />
|
||||
|
||||
<manifest>
|
||||
<attribute name="Main-Class"
|
||||
value="mineplex.ddos.DDoSProtectionSwitcher"/>
|
||||
</manifest>
|
||||
|
||||
<zipfileset src="../Libraries/httpclient-4.2.jar" />
|
||||
<zipfileset src="../Libraries/httpcore-4.2.jar" />
|
||||
<zipfileset src="../Libraries/httpclient-cache-4.2.jar" />
|
||||
<zipfileset src="../Libraries/httpmime-4.2.jar" />
|
||||
<zipfileset src="../Libraries/gson-2.2.1.jar" />
|
||||
<zipfileset src="../Libraries/commons-logging-1.1.1.jar" />
|
||||
<zipfileset src="../Libraries/commons-codec-1.6.jar" />
|
||||
</jar>
|
||||
<copy file="../bin/DDoSProtectionSwitcher.jar" todir="../../Testing/DDoSProtectionSwitcher/"/>
|
||||
</target>
|
||||
<target name ="ServerMonitor" description="ServerMonitor">
|
||||
<jar jarfile="../bin/ServerMonitor.jar">
|
||||
<fileset dir="../Mineplex.Core.Common/bin">
|
||||
|
@ -2,5 +2,9 @@
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jre7"/>
|
||||
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/httpclient-4.2.jar"/>
|
||||
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/httpcore-4.2.jar"/>
|
||||
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/commons-codec-1.6.jar"/>
|
||||
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/gson-2.2.1.jar"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
|
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<launchConfiguration type="org.eclipse.ant.AntBuilderLaunchConfigurationType">
|
||||
<stringAttribute key="org.eclipse.ant.ui.ATTR_ANT_AFTER_CLEAN_TARGETS" value="DDoSProtectionSwitcher,"/>
|
||||
<stringAttribute key="org.eclipse.ant.ui.ATTR_ANT_AUTO_TARGETS" value="DDoSProtectionSwitcher,"/>
|
||||
<stringAttribute key="org.eclipse.ant.ui.ATTR_ANT_MANUAL_TARGETS" value="DDoSProtectionSwitcher,"/>
|
||||
<booleanAttribute key="org.eclipse.ant.ui.ATTR_TARGETS_UPDATED" value="true"/>
|
||||
<booleanAttribute key="org.eclipse.ant.ui.DEFAULT_VM_INSTALL" value="false"/>
|
||||
<stringAttribute key="org.eclipse.debug.core.ATTR_REFRESH_SCOPE" value="${project}"/>
|
||||
<booleanAttribute key="org.eclipse.debug.ui.ATTR_LAUNCH_IN_BACKGROUND" value="false"/>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.ant.ui.AntClasspathProvider"/>
|
||||
<booleanAttribute key="org.eclipse.jdt.launching.DEFAULT_CLASSPATH" value="true"/>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value=""/>
|
||||
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${BUILD_FILES}/common.xml"/>
|
||||
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_RUN_BUILD_KINDS" value="full,incremental,auto,"/>
|
||||
<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_TRIGGERS_CONFIGURED" value="true"/>
|
||||
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_WORKING_DIRECTORY" value="${workspace_loc:/Mineplex.DDoSProtectionSwitcher}"/>
|
||||
</launchConfiguration>
|
@ -10,6 +10,16 @@
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.ui.externaltools.ExternalToolBuilder</name>
|
||||
<triggers>auto,full,incremental,</triggers>
|
||||
<arguments>
|
||||
<dictionary>
|
||||
<key>LaunchConfigHandle</key>
|
||||
<value><project>/.externalToolBuilders/DDoSProtectionSwitcher.launch</value>
|
||||
</dictionary>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
|
@ -1,116 +1,65 @@
|
||||
package mineplex.ddos;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Locale;
|
||||
import java.util.TimeZone;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
import mineplex.ddos.api.ApiGetCall;
|
||||
import mineplex.ddos.api.ApiPostCall;
|
||||
import mineplex.ddos.api.token.ARecord;
|
||||
import mineplex.ddos.api.token.DnsRecord;
|
||||
import mineplex.ddos.api.token.DomainRecords;
|
||||
|
||||
public class DDoSProtectionSwitcher
|
||||
{
|
||||
public static void main (String args[])
|
||||
{
|
||||
SchemeRegistry schemeRegistry = new SchemeRegistry();
|
||||
schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
|
||||
|
||||
PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager(schemeRegistry);
|
||||
connectionManager.setMaxTotal(200);
|
||||
connectionManager.setDefaultMaxPerRoute(20);
|
||||
/*
|
||||
List<ARecord> records = new ArrayList<ARecord>();
|
||||
records.add(new ARecord("us2", "108.178.20.166", 300));
|
||||
records.add(new ARecord("us2", "108.163.217.110", 300));
|
||||
records.add(new ARecord("us2", "108.178.34.142", 300));
|
||||
records.add(new ARecord("us2", "108.163.254.134", 300));
|
||||
records.add(new ARecord("us2", "108.163.216.250", 300));
|
||||
records.add(new ARecord("us2", "108.163.216.106", 300));
|
||||
records.add(new ARecord("us2", "184.154.215.170", 300));
|
||||
records.add(new ARecord("us2", "96.127.174.206", 300));
|
||||
records.add(new ARecord("us2", "184.154.127.10", 300));
|
||||
records.add(new ARecord("us2", "96.127.174.146", 300));
|
||||
records.add(new ARecord("us2", "108.178.7.206", 300));
|
||||
records.add(new ARecord("us2", "184.154.39.146", 300));
|
||||
records.add(new ARecord("us2", "108.163.217.250", 300));
|
||||
records.add(new ARecord("us2", "69.175.15.242", 300));
|
||||
records.add(new ARecord("us2", "107.6.129.126", 300));
|
||||
records.add(new ARecord("us2", "108.163.222.174", 300));
|
||||
records.add(new ARecord("us2", "108.178.34.118", 300));
|
||||
records.add(new ARecord("us2", "69.175.4.38", 300));
|
||||
records.add(new ARecord("us2", "107.6.158.78", 300));
|
||||
records.add(new ARecord("us2", "184.154.13.118", 300));
|
||||
|
||||
HttpClient httpClient = new DefaultHttpClient(connectionManager);
|
||||
InputStream in = null;
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
HttpGet request = new HttpGet("http://api.dnsmadeeasy.com/V2.0/dns/managed/962728/records/");
|
||||
|
||||
String timeStamp = getServerTime();
|
||||
SecretKeySpec keySpec = new SecretKeySpec("8c9af8cc-d306-4df3-8de8-944deafa8239".getBytes(), "HmacSHA1");
|
||||
Mac mac = Mac.getInstance("HmacSHA1");
|
||||
mac.init(keySpec);
|
||||
byte[] hashBytes = mac.doFinal((timeStamp + "").getBytes());
|
||||
Hex.encodeHexString(hashBytes);
|
||||
|
||||
request.addHeader("x-dnsme-apiKey", "610e21ee-4250-4b55-b637-a1fcc3847850");
|
||||
request.addHeader("x-dnsme-requestDate", timeStamp + "");
|
||||
request.addHeader("x-dnsme-hmac", Hex.encodeHexString(hashBytes));
|
||||
request.addHeader("Content-Type", "application/json");
|
||||
|
||||
HttpResponse response = httpClient.execute(request);
|
||||
|
||||
if (response != null)
|
||||
{
|
||||
in = response.getEntity().getContent();
|
||||
System.out.println(convertStreamToString(in));
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
System.out.println("JsonWebCall.Execute() Error:\n" + ex.getMessage());
|
||||
|
||||
for (StackTraceElement trace : ex.getStackTrace())
|
||||
{
|
||||
System.out.println(trace);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
httpClient.getConnectionManager().shutdown();
|
||||
|
||||
if (in != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
in.close();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static String getServerTime()
|
||||
{
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US);
|
||||
dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||
return dateFormat.format(calendar.getTime());
|
||||
}
|
||||
|
||||
private static String convertStreamToString(InputStream is)
|
||||
{
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
String line = null;
|
||||
try
|
||||
new ApiPostCall("http://api.dnsmadeeasy.com/V2.0/dns/managed/", 962728, "/records/", "createMulti").Execute(records);
|
||||
*/
|
||||
|
||||
DomainRecords records = new ApiGetCall("https://api.dnsmadeeasy.com/V2.0/dns/managed/", 962728, "/records", "").Execute(DomainRecords.class);
|
||||
List<DnsRecord> recordsToDelete = new ArrayList<DnsRecord>();
|
||||
|
||||
// Switch off ddos protection
|
||||
for (DnsRecord record : records.data)
|
||||
{
|
||||
while ((line = reader.readLine()) != null)
|
||||
if (record.type.equalsIgnoreCase("CNAME"))
|
||||
{
|
||||
sb.append(line + "\n");
|
||||
if (record.name.equalsIgnoreCase("eu"))
|
||||
recordsToDelete.add(record);
|
||||
}
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
finally
|
||||
{
|
||||
try
|
||||
{
|
||||
is.close();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
|
||||
// Remove CNAME record for eu to us
|
||||
// Loop through and update us to neustar, us2 to us, eu2 to us.
|
||||
|
||||
// Loop through and update us to us2, eu to eu2 and neustar to us.
|
||||
// Add CNAME record for eu to us
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,9 @@
|
||||
package mineplex.ddos;
|
||||
|
||||
public class DnsMadeEasyRepository
|
||||
{
|
||||
public DnsMadeEasyRepository()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package mineplex.ddos.api;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
public class ApiGetCall extends DnsMadeEasyApiCallBase
|
||||
{
|
||||
private String _action;
|
||||
|
||||
public ApiGetCall(String apiUrl, int domainId, String category, String action)
|
||||
{
|
||||
super(apiUrl, domainId, category);
|
||||
|
||||
_action = action;
|
||||
}
|
||||
|
||||
public void Execute()
|
||||
{
|
||||
HttpGet request = new HttpGet(ApiUrl + DomainId + Category + _action);
|
||||
|
||||
System.out.println(execute(request));
|
||||
}
|
||||
|
||||
public <T> T Execute(Type returnType)
|
||||
{
|
||||
HttpGet request = new HttpGet(ApiUrl + DomainId + Category + _action);
|
||||
|
||||
String response = execute(request);
|
||||
System.out.println(response);
|
||||
return new Gson().fromJson(response, returnType);
|
||||
}
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
package mineplex.ddos.api;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.message.BasicHeader;
|
||||
import org.apache.http.protocol.HTTP;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
public class ApiPostCall extends DnsMadeEasyApiCallBase
|
||||
{
|
||||
private String _action;
|
||||
|
||||
public ApiPostCall(String apiUrl, int domainId, String category, String action)
|
||||
{
|
||||
super(apiUrl, domainId, category);
|
||||
|
||||
_action = action;
|
||||
}
|
||||
|
||||
public void Execute(Object argument)
|
||||
{
|
||||
Gson gson = new Gson();
|
||||
HttpPost request = new HttpPost(ApiUrl + DomainId + Category + _action);
|
||||
|
||||
System.out.println(request.getURI().toString());
|
||||
|
||||
try
|
||||
{
|
||||
StringEntity params = new StringEntity(gson.toJson(argument));
|
||||
params.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
|
||||
request.setEntity(params);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
System.out.println("Error executing ApiPostCall(Object): \n" + exception.getMessage());
|
||||
|
||||
for (StackTraceElement trace : exception.getStackTrace())
|
||||
{
|
||||
System.out.println(trace);
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println(execute(request));
|
||||
}
|
||||
|
||||
public <T> T Execute(Class<T> returnClass)
|
||||
{
|
||||
return Execute(returnClass, (Object)null);
|
||||
}
|
||||
|
||||
public <T> T Execute(Type returnType, Object argument)
|
||||
{
|
||||
Gson gson = new Gson();
|
||||
HttpPost request = new HttpPost(ApiUrl + DomainId + Category + _action);
|
||||
System.out.println(request.getURI().toString());
|
||||
try
|
||||
{
|
||||
StringEntity params = new StringEntity(gson.toJson(argument));
|
||||
params.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
|
||||
request.setEntity(params);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
System.out.println("Error executing ApiPostCall(Type, Object): \n" + exception.getMessage());
|
||||
|
||||
for (StackTraceElement trace : exception.getStackTrace())
|
||||
{
|
||||
System.out.println(trace);
|
||||
}
|
||||
}
|
||||
|
||||
String response = execute(request);
|
||||
System.out.println(response);
|
||||
return new Gson().fromJson(response, returnType);
|
||||
}
|
||||
}
|
@ -0,0 +1,140 @@
|
||||
package mineplex.ddos.api;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Locale;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import javax.crypto.Mac;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
|
||||
import org.apache.commons.codec.binary.Hex;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.methods.HttpRequestBase;
|
||||
import org.apache.http.conn.scheme.PlainSocketFactory;
|
||||
import org.apache.http.conn.scheme.Scheme;
|
||||
import org.apache.http.conn.scheme.SchemeRegistry;
|
||||
import org.apache.http.impl.client.DefaultHttpClient;
|
||||
import org.apache.http.impl.conn.PoolingClientConnectionManager;
|
||||
|
||||
public abstract class DnsMadeEasyApiCallBase
|
||||
{
|
||||
protected String ApiUrl = "http://api.dnsmadeeasy.com/V2.0/dns/managed/";
|
||||
protected int DomainId = 962728;
|
||||
protected String Category = "/records/";
|
||||
|
||||
public DnsMadeEasyApiCallBase(String apiUrl, int domainId, String category)
|
||||
{
|
||||
ApiUrl = apiUrl;
|
||||
DomainId = domainId;
|
||||
Category = category;
|
||||
}
|
||||
|
||||
protected String execute(HttpRequestBase request)
|
||||
{
|
||||
SchemeRegistry schemeRegistry = new SchemeRegistry();
|
||||
schemeRegistry.register(new Scheme("https", 80, PlainSocketFactory.getSocketFactory()));
|
||||
|
||||
PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager(schemeRegistry);
|
||||
connectionManager.setMaxTotal(200);
|
||||
connectionManager.setDefaultMaxPerRoute(20);
|
||||
|
||||
HttpClient httpClient = new DefaultHttpClient(connectionManager);
|
||||
InputStream in = null;
|
||||
String response = "";
|
||||
|
||||
try
|
||||
{
|
||||
String timeStamp = getServerTime();
|
||||
SecretKeySpec keySpec = new SecretKeySpec("8c9af8cc-d306-4df3-8de8-944deafa8239".getBytes(), "HmacSHA1");
|
||||
Mac mac = Mac.getInstance("HmacSHA1");
|
||||
mac.init(keySpec);
|
||||
byte[] hashBytes = mac.doFinal((timeStamp + "").getBytes());
|
||||
Hex.encodeHexString(hashBytes);
|
||||
|
||||
request.addHeader("x-dnsme-apiKey", "610e21ee-4250-4b55-b637-a1fcc3847850");
|
||||
request.addHeader("x-dnsme-requestDate", timeStamp + "");
|
||||
request.addHeader("x-dnsme-hmac", Hex.encodeHexString(hashBytes));
|
||||
request.addHeader("Content-Type", "application/json");
|
||||
|
||||
HttpResponse httpResponse = httpClient.execute(request);
|
||||
|
||||
if (httpResponse != null)
|
||||
{
|
||||
in = httpResponse.getEntity().getContent();
|
||||
response = convertStreamToString(in);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
System.out.println("DnsMadeEasyApiCall Error:\n" + ex.getMessage());
|
||||
|
||||
for (StackTraceElement trace : ex.getStackTrace())
|
||||
{
|
||||
System.out.println(trace);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
httpClient.getConnectionManager().shutdown();
|
||||
|
||||
if (in != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
in.close();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
protected String getServerTime()
|
||||
{
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US);
|
||||
dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||
return dateFormat.format(calendar.getTime());
|
||||
}
|
||||
|
||||
protected String convertStreamToString(InputStream is)
|
||||
{
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
String line = null;
|
||||
try
|
||||
{
|
||||
while ((line = reader.readLine()) != null)
|
||||
{
|
||||
sb.append(line + "\n");
|
||||
}
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
finally
|
||||
{
|
||||
try
|
||||
{
|
||||
is.close();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package mineplex.ddos.api.token;
|
||||
|
||||
public class ARecord extends DnsRecord
|
||||
{
|
||||
public ARecord(String recordName, String ip, int recordTtl)
|
||||
{
|
||||
name = recordName;
|
||||
value = ip;
|
||||
ttl = recordTtl;
|
||||
|
||||
type = "A";
|
||||
gtdLocation = "DEFAULT";
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
package mineplex.ddos.api.token;
|
||||
|
||||
public class DnsRecord
|
||||
{
|
||||
public String name;
|
||||
public String type;
|
||||
public String value;
|
||||
public String gtdLocation;
|
||||
public int ttl;
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package mineplex.ddos.api.token;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class DomainRecords
|
||||
{
|
||||
public List<DnsRecord> data;
|
||||
public int page;
|
||||
public int totalPage;
|
||||
public int totalRecords;
|
||||
}
|
Loading…
Reference in New Issue
Block a user