Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions cSploit/res/layout/target_list_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,33 @@
android:layout_toRightOf="@id/itemIcon"
android:textColor="@color/app_color"
android:fontFamily="sans-serif-light"
android:textSize="16sp" />
android:textSize="16sp"
android:layout_toLeftOf="@+id/portCount"
android:layout_toStartOf="@+id/portCount" />

<TextView
android:id="@+id/itemDescription"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/itemIcon"
android:layout_below="@id/itemTitle"
android:textColor="@color/gray_text"
android:fontFamily="sans-serif-condensed"
android:textSize="14sp" />
android:textSize="14sp"
android:layout_toRightOf="@+id/itemIcon"
android:layout_toLeftOf="@+id/portCount"
android:layout_toStartOf="@+id/portCount"
android:layout_below="@+id/itemTitle" />

<TextView
android:id="@+id/portCount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/selectable_blue"
android:fontFamily="sans-serif-condensed"
android:textSize="20sp"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:padding="6dp"
android:gravity="center"
android:layout_alignBottom="@+id/itemDescription" />
</RelativeLayout>
67 changes: 63 additions & 4 deletions cSploit/src/org/csploit/android/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.view.ActionMode;
import android.text.Html;
Expand All @@ -48,6 +49,7 @@
import android.widget.Toast;

import org.csploit.android.core.Child;
import org.csploit.android.core.ChildManager;
import org.csploit.android.core.Client;
import org.csploit.android.core.CrashReporter;
import org.csploit.android.core.Logger;
Expand Down Expand Up @@ -83,6 +85,7 @@
import org.csploit.android.services.UpdateService;
import org.csploit.android.services.receivers.MsfRpcdServiceReceiver;
import org.csploit.android.services.receivers.NetworkRadarReceiver;
import org.csploit.android.tools.NMap;
import org.csploit.android.update.CoreUpdate;
import org.csploit.android.update.MsfUpdate;
import org.csploit.android.update.RubyUpdate;
Expand Down Expand Up @@ -132,6 +135,7 @@ private void createUpdateStatusText() {
layout.addView(mUpdateStatus);
}


private void createUpdateLayout() {

lv.setVisibility(View.GONE);
Expand Down Expand Up @@ -841,13 +845,14 @@ public View getView(int position, View convertView, ViewGroup parent) {
.findViewById(R.id.itemTitle) : null);
holder.itemDescription = (TextView) (row != null ? row
.findViewById(R.id.itemDescription) : null);

holder.portCount = (TextView) (row != null ? row
.findViewById(R.id.portCount) : null);
if (row != null)
row.setTag(holder);
} else
holder = (TargetHolder) row.getTag();

Target target = System.getTarget(position);
final Target target = System.getTarget(position);

if (target.hasAlias())
holder.itemTitle.setText(Html.fromHtml("<b>"
Expand All @@ -856,15 +861,31 @@ public View getView(int position, View convertView, ViewGroup parent) {

else
holder.itemTitle.setText(target.toString());

holder.itemTitle.setTextColor(getResources().getColor((target.isConnected() ? R.color.app_color : R.color.gray_text)));
holder.itemTitle.setTextColor(ContextCompat.getColor(getContext(), (target.isConnected() ? R.color.app_color : R.color.gray_text)));

if (row != null && (getSharedPreferences("THEME", 0).getBoolean("isDark", false)))
row.setBackgroundResource(R.drawable.card_background_dark);
holder.itemTitle.setTypeface(null, Typeface.NORMAL);
holder.itemImage.setImageResource(target.getDrawableResourceId());
holder.itemDescription.setText(target.getDescription());

// only do a portscan if/when target rolls into view and ports haven't been found...
if (target.getType() != Target.Type.NETWORK && target.getOpenPorts().size() == 0) {
final Receiver r = new Receiver(position, convertView);
Thread thread = new Thread() {
@Override
public void run() {
try {
System.getTools().nmap
.synScan(target, r, null);
} catch (ChildManager.ChildNotStartedException e) {
e.printStackTrace();
}
}
};
thread.run();
}

return row;
}

Expand Down Expand Up @@ -918,6 +939,7 @@ class TargetHolder {
ImageView itemImage;
TextView itemTitle;
TextView itemDescription;
TextView portCount;
}
}

Expand Down Expand Up @@ -1093,4 +1115,41 @@ public void onReceive(Context context, Intent intent) {
}
}
}

private class Receiver extends NMap.SynScanReceiver {
int position;
final View cv;

public Receiver(int position, View cv) {
this.position = position;
this.cv = cv;
}

@Override
public void onEnd(int exitCode) {
MainActivity.this.runOnUiThread(
new Runnable() {
@Override
public void run() {
System.setCurrentTarget(position);
// new items may have snuck in so the order can change. Double check this
if (cv != null) {
TextView tv = (TextView) cv.findViewById(R.id.portCount);
if (tv != null) {
tv.setText(String.format("%d", System.getCurrentTarget().getOpenPorts().size()));
tv.setVisibility(System.getCurrentTarget().getOpenPorts().size() < 1 ? View.GONE : View.VISIBLE);
}
}
}
}
);
super.onEnd(exitCode);
}

@Override
public void onPortFound(int port, String protocol) {
System.setCurrentTarget(position);
System.addOpenPort(port, null);
}
}
}
1 change: 1 addition & 0 deletions msf/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
8 changes: 8 additions & 0 deletions msf/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apply plugin: 'java'

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'junit:junit:4.12'
compile 'commons-io:commons-io:2.4'
compile 'org.apache.commons:commons-lang3:3.4'
}
37 changes: 37 additions & 0 deletions msf/src/main/java/org/csploit/msf/Author.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package org.csploit.msf;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
* Represent an author
*/
public class Author {
private static Pattern MAIL = Pattern.compile("<(.+)>");

private String name;
private String email;

public Author(String name, String email) {
this.name = name;
this.email = email;
}

@Override
public String toString() {
if(email != null) {
return name + " <" + email + ">";
} else {
return name;
}
}

public static Author fromString(String s) {
Matcher matcher = MAIL.matcher(s);
if(matcher.matches()) {
return new Author(s.substring(0, matcher.start()), matcher.group(1));
} else {
return new Author(s, null);
}
}
}
8 changes: 8 additions & 0 deletions msf/src/main/java/org/csploit/msf/DataHolder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.csploit.msf;

/**
* A class that hold a DataStore instance
*/
public interface DataHolder {
DataStore getDataStore();
}
113 changes: 113 additions & 0 deletions msf/src/main/java/org/csploit/msf/DataStore.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package org.csploit.msf;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

/**
* The data store is just a bitbucket that holds keyed values. It is used
* by various classes to hold option values and other state information.
*/
public class DataStore extends HashMap<String, String> {
protected Set<String> imported = new HashSet<>();
protected Set<String> defaults = new HashSet<>();

@Override
public String put(String key, String value) {
key = findKeyCase(key);

defaults.remove(key);
imported.remove(key);

return super.put(key, value);
}

@Override
public String get(Object key) {
String k = (key instanceof String) ? (String) key : key.toString();
return super.get(findKeyCase(k));
}

public void updateValue(String key, String value) {
super.put(key, value);
}

/**
* This method is a helper method that imports the default value for
* all of the supplied options
*/
public void importOptions(OptionContainer options, boolean isDefault, boolean overwrite) {
for(Option opt : options.values()) {
String name = opt.getName();
if(containsKey(name) && !overwrite) {
continue;
}
if(opt.haveDefaultValue() && (overwrite || get(name) == null)) {
String val = opt.display(opt.defaultValue);
importOption(name, val, true, isDefault);
}
}
}

public void importOptions(OptionContainer options, boolean isDefault) {
importOptions(options, isDefault, false);
}

public void importOptions(OptionContainer options) {
importOptions(options, false, false);
}

public void importOption(String name, String val, boolean imported, boolean isDefault) {
if(imported) {
this.imported.add(name);
}

if(isDefault) {
defaults.add(name);
}

super.put(name, val);
}

public void importOption(String name, String val, boolean imported) {
importOption(name, val, imported, false);
}

public void importOption(String name, String val) {
importOption(name, val, true, false);
}

public synchronized Map<String, String> userDefined() {
Map<String, String> res = new HashMap<>();

for (String key : keySet()) {
if (!imported.contains(key)) {
res.put(key, super.get(key));
}
}

return res;
}

public void clearNotUserDefined() {
for(String key : imported) {
if(defaults.remove(key)) {
remove(key);
}
}
}

protected String findKeyCase(String k) {

if(k == null)
return null;

for(String key : keySet()) {
if(key.toLowerCase().equals(k.toLowerCase()))
return key;
}

return k;
}
}
Loading