mirror of
https://github.com/rapid7/metasploit-payloads
synced 2025-03-06 09:13:02 +01:00
Better edgecase handling, process termination on exit
This commit is contained in:
parent
0455f5271d
commit
c96724fab5
@ -189,5 +189,7 @@ public class Payload {
|
||||
myClass.getMethod("start",
|
||||
new Class[]{DataInputStream.class, OutputStream.class, String[].class})
|
||||
.invoke(stage, in, out, parameters);
|
||||
Log.d("msf", "Session finished, terminating process");
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
|
@ -203,6 +203,7 @@ public class Meterpreter {
|
||||
|
||||
this.transports.moveNext(this);
|
||||
}
|
||||
System.out.println("msf : and we're done, cleaing channels");
|
||||
synchronized (this) {
|
||||
for (Iterator it = channels.iterator(); it.hasNext(); ) {
|
||||
Channel c = (Channel) it.next();
|
||||
@ -210,6 +211,7 @@ public class Meterpreter {
|
||||
c.close();
|
||||
}
|
||||
}
|
||||
System.out.println("msf : done executing");
|
||||
}
|
||||
|
||||
protected String getPayloadTrustManager() {
|
||||
|
@ -162,6 +162,7 @@ public class TcpTransport extends Transport {
|
||||
public boolean dispatch(Meterpreter met) {
|
||||
System.out.println("msf : In the dispatch loop");
|
||||
long lastPacket = System.currentTimeMillis();
|
||||
int result = 0;
|
||||
while (!met.hasSessionExpired() &&
|
||||
System.currentTimeMillis() < lastPacket + this.commTimeout) {
|
||||
try {
|
||||
@ -178,7 +179,7 @@ public class TcpTransport extends Transport {
|
||||
lastPacket = System.currentTimeMillis();
|
||||
|
||||
TLVPacket response = request.createResponse();
|
||||
int result = met.getCommandManager().executeCommand(met, request, response);
|
||||
result = met.getCommandManager().executeCommand(met, request, response);
|
||||
System.out.println("msf : command executed: " + result);
|
||||
|
||||
this.writePacket(response, TLVPacket.PACKET_TYPE_RESPONSE);
|
||||
@ -191,7 +192,15 @@ public class TcpTransport extends Transport {
|
||||
// socket comms timeout, didn't get a packet,
|
||||
// this is ok, so we ignore it
|
||||
System.out.println("msf : Socket timeout (OK)");
|
||||
} catch (Exception ex) {
|
||||
} catch (SocketException ex) {
|
||||
// sometimes we'll have issues where writing a response when we're exiting
|
||||
// the dispatch is intended, so we'll check for that here too
|
||||
if (result == Command.EXIT_DISPATCH) {
|
||||
System.out.println("msf : Exception in exit of dispatch, indicating intention");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
// any other type of exception isn't good.
|
||||
System.out.println("msf : Some other exception: " + ex.getClass().getName());
|
||||
break;
|
||||
|
Loading…
x
Reference in New Issue
Block a user