Skip to content

Commit 3048a78

Browse files
committed
use the new msfrpcd handler.
reload tools on updates.
1 parent 4f6aa1f commit 3048a78

6 files changed

Lines changed: 122 additions & 142 deletions

File tree

cSploit/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
package="org.csploit.android"
44
android:versionCode="1"
5-
android:versionName="1.5.0" >
5+
android:versionName="1.5.1" >
66

77
<uses-sdk
88
android:minSdkVersion="9"

cSploit/src/org/csploit/android/MainActivity.java

Lines changed: 66 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
import org.csploit.android.plugins.Traceroute;
6464
import org.csploit.android.plugins.VulnerabilityFinder;
6565
import org.csploit.android.plugins.mitm.MITM;
66-
import org.csploit.android.net.metasploit.MsfRpcd;
66+
import org.csploit.android.tools.MsfRpcd;
6767
import org.csploit.android.tools.ToolBox;
6868

6969
import java.io.IOException;
@@ -108,7 +108,7 @@ public class MainActivity extends SherlockListActivity {
108108
private boolean isWifiAvailable = false;
109109
private TargetAdapter mTargetAdapter = null;
110110
private NetworkRadar mNetworkRadar = null;
111-
private MsfRpcd mMsfRpcd = null;
111+
private Child mMsfRpcd = null;
112112
private RadarReceiver mRadarReceiver = new RadarReceiver();
113113
private UpdateReceiver mUpdateReceiver = new UpdateReceiver();
114114
private WipeReceiver mWipeReceiver = new WipeReceiver();
@@ -377,7 +377,7 @@ public boolean onPrepareOptionsMenu(Menu menu) {
377377

378378
if(MsfRpcd.isLocal()) {
379379
if (System.getMsfRpc() != null
380-
|| (mMsfRpcd != null && mMsfRpcd.isRunning()))
380+
|| (mMsfRpcd != null && mMsfRpcd.running))
381381
item.setTitle(getString(R.string.stop_msfrpcd));
382382
else
383383
item.setTitle(getString(R.string.start_msfrpcd));
@@ -389,7 +389,7 @@ public boolean onPrepareOptionsMenu(Menu menu) {
389389
}
390390

391391
item.setEnabled(!MsfRpcd.isLocal() ||
392-
(tools != null && tools.msf.isEnabled() &&
392+
(tools != null && tools.msfrpcd.isEnabled() &&
393393
!System.isServiceRunning("org.csploit.android.core.UpdateService")));
394394

395395
mMenu = menu;
@@ -526,9 +526,6 @@ public void stopNetworkRadar(boolean silent) {
526526
public void StartRPCServer() {
527527
StopRPCServer(true);
528528

529-
if(mMsfRpcd == null)
530-
mMsfRpcd = new MsfRpcd();
531-
532529
new Thread( new Runnable() {
533530
@Override
534531
public void run() {
@@ -542,49 +539,54 @@ public void run() {
542539

543540
if(msfHost.equals("127.0.0.1")) {
544541
try {
545-
mMsfRpcd.start(msfUser, msfPassword, msfPort, msfSsl, new MsfRpcd.MsfRpcdReceiver() {
546-
@Override
547-
public void onReady() {
548-
try {
549-
System.setMsfRpc(new RPCClient(msfHost, msfUser, msfPassword, msfPort, msfSsl));
550-
Logger.info("successfully connected to MSF RPC Daemon ");
551-
MainActivity.this.runOnUiThread(new Runnable() {
552-
@Override
553-
public void run() {
554-
Toast.makeText(MainActivity.this, "connected to MSF RPC Daemon", Toast.LENGTH_SHORT).show();
555-
}
556-
});
557-
} catch (Exception e) {
558-
Logger.error(e.getClass().getName() + ": " + e.getMessage());
559-
MainActivity.this.runOnUiThread(new Runnable() {
560-
@Override
561-
public void run() {
562-
Toast.makeText(MainActivity.this, "connection to MSF RPC Daemon failed", Toast.LENGTH_LONG).show();
563-
}
564-
});
565-
}
566-
}
567-
568-
@Override
569-
public void onEnd(final int exitValue) {
570-
MainActivity.this.runOnUiThread(new Runnable() {
571-
@Override
572-
public void run() {
573-
Toast.makeText(MainActivity.this, "MSF RPC Daemon returned #" + exitValue, Toast.LENGTH_LONG).show();
574-
}
575-
});
576-
}
577-
578-
@Override
579-
public void onDeath(final int signal) {
580-
MainActivity.this.runOnUiThread(new Runnable() {
581-
@Override
582-
public void run() {
583-
Toast.makeText(MainActivity.this, " MSF RPC Daemon killed by signal #" + signal, Toast.LENGTH_LONG).show();
584-
}
585-
});
586-
}
587-
});
542+
mMsfRpcd = System.getTools().msfrpcd.async(
543+
msfUser, msfPassword, msfPort, msfSsl,
544+
new MsfRpcd.MsfRpcdReceiver() {
545+
@Override
546+
public void onReady() {
547+
try {
548+
System.setMsfRpc(new RPCClient(msfHost, msfUser, msfPassword, msfPort, msfSsl));
549+
Logger.info("successfully connected to MSF RPC Daemon ");
550+
MainActivity.this.runOnUiThread(new Runnable() {
551+
@Override
552+
public void run() {
553+
Toast.makeText(MainActivity.this, "connected to MSF RPC Daemon", Toast.LENGTH_SHORT).show();
554+
}
555+
});
556+
} catch (Exception e) {
557+
Logger.error(e.getClass().getName() + ": " + e.getMessage());
558+
MainActivity.this.runOnUiThread(new Runnable() {
559+
@Override
560+
public void run() {
561+
Toast.makeText(MainActivity.this, "connection to MSF RPC Daemon failed", Toast.LENGTH_LONG).show();
562+
}
563+
});
564+
}
565+
}
566+
567+
@Override
568+
public void onEnd(final int exitValue) {
569+
if (exitValue == 0)
570+
return;
571+
572+
MainActivity.this.runOnUiThread(new Runnable() {
573+
@Override
574+
public void run() {
575+
Toast.makeText(MainActivity.this, "MSF RPC Daemon returned #" + exitValue, Toast.LENGTH_LONG).show();
576+
}
577+
});
578+
}
579+
580+
@Override
581+
public void onDeath(final int signal) {
582+
MainActivity.this.runOnUiThread(new Runnable() {
583+
@Override
584+
public void run() {
585+
Toast.makeText(MainActivity.this, " MSF RPC Daemon killed by signal #" + signal, Toast.LENGTH_LONG).show();
586+
}
587+
});
588+
}
589+
});
588590
} catch (ChildManager.ChildNotStartedException e) {
589591
Logger.error(e.getMessage());
590592
MainActivity.this.runOnUiThread(new Runnable() {
@@ -624,17 +626,22 @@ public void run() {
624626
*/
625627
public void StopRPCServer(final boolean silent) {
626628

627-
if(System.getMsfRpc() == null && ( mMsfRpcd == null || !mMsfRpcd.isRunning() ))
629+
if(System.getMsfRpc() == null && ( mMsfRpcd == null || !mMsfRpcd.running ))
628630
return;
629631

632+
final Child process = mMsfRpcd;
633+
mMsfRpcd = null;
634+
630635
new Thread( new Runnable() {
631636
@Override
632637
public void run() {
633638
try {
634639
System.setMsfRpc(null);
635640

636-
if(mMsfRpcd.isRunning())
637-
mMsfRpcd.stop();
641+
if(process.running) {
642+
process.kill(2);
643+
process.join();
644+
}
638645

639646
if(!silent) {
640647
MainActivity.this.runOnUiThread(new Runnable() {
@@ -825,7 +832,7 @@ public void onItemSelected(int index) {
825832
return true;
826833

827834
case R.id.ss_msfrpcd:
828-
if(System.getMsfRpc()!=null || (mMsfRpcd != null && mMsfRpcd.isRunning())) {
835+
if(System.getMsfRpc()!=null || (mMsfRpcd != null && mMsfRpcd.running)) {
829836
StopRPCServer(false);
830837
if(MsfRpcd.isLocal())
831838
item.setTitle(R.string.start_msfrpcd);
@@ -1176,6 +1183,9 @@ private void onUpdateAvailable(final String desc, final UpdateService.action tar
11761183
}
11771184

11781185
private void onUpdateDone(UpdateService.action target) {
1186+
1187+
System.reloadTools();
1188+
11791189
switch (target) {
11801190
case ruby_update:
11811191
case msf_update:
@@ -1205,6 +1215,8 @@ public void run() {
12051215
getString(message),MainActivity.this).show();
12061216
}
12071217
});
1218+
1219+
System.reloadTools();
12081220
}
12091221

12101222
@SuppressWarnings("ConstantConditions")

cSploit/src/org/csploit/android/net/metasploit/MsfRpcd.java

Lines changed: 0 additions & 86 deletions
This file was deleted.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package org.csploit.android.tools;
2+
3+
import org.csploit.android.core.*;
4+
import org.csploit.android.core.System;
5+
import org.csploit.android.events.Event;
6+
import org.csploit.android.events.Ready;
7+
8+
/**
9+
* MetaSploit RPC Daemon
10+
*/
11+
public class MsfRpcd extends Msf {
12+
13+
public static abstract class MsfRpcdReceiver extends Child.EventReceiver {
14+
@Override
15+
public void onEvent(Event e) {
16+
if(e instanceof Ready)
17+
onReady();
18+
}
19+
20+
public abstract void onReady();
21+
}
22+
23+
public MsfRpcd() {
24+
mHandler = "msfrpcd";
25+
26+
setEnabled();
27+
28+
if(mEnabled)
29+
setupEnvironment();
30+
31+
registerSettingReceiver();
32+
}
33+
34+
/**
35+
* start an MsfRpcd
36+
* @param receiver will be notified when the daemon it's ready to accept connections
37+
*/
38+
public Child async(String user, String pswd, int port, boolean ssl, MsfRpcdReceiver receiver) throws ChildManager.ChildNotStartedException {
39+
return async(
40+
String.format("-P '%s' -U '%s' -p '%d' -a 127.0.0.1 -n %s -t Msg -f",
41+
pswd, user, port, (ssl ? "" : "-S")),
42+
receiver);
43+
}
44+
45+
public static boolean isLocal() {
46+
return System.getSettings().getString("MSF_RPC_HOST", "127.0.0.1").equals("127.0.0.1");
47+
}
48+
}

cSploit/src/org/csploit/android/tools/ToolBox.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public class ToolBox {
3434
public final TcpDump tcpDump;
3535
public final Msf msf;
3636
public final NetworkRadar networkRadar;
37+
public final MsfRpcd msfrpcd;
3738

3839
public ToolBox() {
3940
raw = new Raw();
@@ -48,6 +49,7 @@ public ToolBox() {
4849
tcpDump = new TcpDump();
4950
msf = new Msf();
5051
networkRadar = new NetworkRadar();
52+
msfrpcd = new MsfRpcd();
5153
}
5254

5355
public void reload() {
@@ -63,11 +65,15 @@ public void reload() {
6365
tcpDump.setEnabled();
6466
msf.setEnabled();
6567
networkRadar.setEnabled();
68+
msfrpcd.setEnabled();
6669

6770
if(ruby.isEnabled())
6871
ruby.setupEnvironment();
6972

7073
if(msf.isEnabled())
7174
msf.setupEnvironment();
75+
76+
if(msfrpcd.isEnabled())
77+
msfrpcd.setupEnvironment();
7278
}
7379
}

0 commit comments

Comments
 (0)