Skip to content

Commit de4bcec

Browse files
committed
Squashed commits of portscan count
The following from the show_portcount branch was refactored w a few bugs fixed. The results were then squashed into this commit, and brought up to date with develop... and a few bugs fixed and possibly new ones introduced. These changes were originally written by fattire, and tux-mind: Three known bugs: * routers not scanned * manually added hosts are not scanned * ports acquired in other activities don't appear until item is scrolled off then returns... Terrible first pass at showing port on main scanner screen (fat-tire) 58e804f alias can be set to null (tux-mind) 4594543 give an handy way to scan without custom ports (tux-mind) 20b5ce6 fixed some little things <3 (tux-mind) 454f31e Fixed NPE (tux-mind) 31893e9 Use labels/badges/whatever for portcount -- no dark theme support yet … (fat-tire) d3ea05b
1 parent 82c9ac7 commit de4bcec

8 files changed

Lines changed: 163 additions & 47 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
3+
<solid android:color="@color/gray_text"/>
4+
<corners android:radius="2dp"/>
5+
</shape>

cSploit/res/layout/actions_layout.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,6 @@
2929
android:divider="#00ffffff"
3030
android:dividerHeight="6dp"
3131
android:showDividers="none" />
32+
android:divider="#00ffffff" />
3233

3334
</LinearLayout>

cSploit/res/layout/target_list_item.xml

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,65 @@
2020
android:layout_width="match_parent"
2121
android:layout_height="wrap_content"
2222
android:layout_alignParentTop="true"
23+
android:layout_toLeftOf="@+id/portCountLayout"
2324
android:layout_toRightOf="@id/itemIcon"
24-
android:textColor="@color/app_color"
25+
android:layout_toStartOf="@+id/portCountLayout"
2526
android:fontFamily="sans-serif-light"
27+
android:textColor="@color/app_color"
2628
android:textSize="16sp" />
2729

2830
<TextView
2931
android:id="@+id/itemDescription"
3032
android:layout_width="match_parent"
3133
android:layout_height="wrap_content"
32-
android:layout_toRightOf="@id/itemIcon"
33-
android:layout_below="@id/itemTitle"
34-
android:textColor="@color/gray_text"
34+
android:layout_alignLeft="@+id/itemTitle"
35+
android:layout_alignStart="@+id/itemTitle"
36+
android:layout_below="@+id/itemTitle"
37+
android:layout_toLeftOf="@+id/portCountLayout"
3538
android:fontFamily="sans-serif-condensed"
39+
android:textColor="@color/gray_text"
3640
android:textSize="14sp" />
3741

42+
<LinearLayout
43+
android:id="@+id/portCountLayout"
44+
android:layout_width="wrap_content"
45+
android:layout_height="wrap_content"
46+
android:layout_alignParentEnd="true"
47+
android:layout_alignParentRight="true"
48+
android:layout_alignParentTop="true"
49+
android:layout_centerInParent="true"
50+
android:animateLayoutChanges="true"
51+
android:stateListAnimator="@anim/slide_in_left"
52+
android:background="@drawable/rounded_square"
53+
android:orientation="vertical"
54+
android:paddingBottom="6dp"
55+
android:paddingLeft="6dp"
56+
android:paddingRight="6dp"
57+
android:paddingTop="4dp">
58+
59+
<TextView
60+
android:id="@+id/textView10"
61+
android:layout_width="match_parent"
62+
android:layout_height="wrap_content"
63+
android:layout_column="0"
64+
android:layout_row="0"
65+
android:gravity="top|center_horizontal"
66+
android:text="@string/ports"
67+
android:textColor="@color/selectable_blue"
68+
android:textSize="12dp"
69+
android:textStyle="bold" />
70+
71+
<TextView
72+
android:id="@+id/portCount"
73+
android:layout_width="match_parent"
74+
android:layout_height="wrap_content"
75+
android:layout_column="0"
76+
android:layout_row="0"
77+
android:gravity="top|center_horizontal"
78+
android:text="22"
79+
android:textColor="@color/background_window"
80+
android:textSize="16dp" />
81+
82+
83+
</LinearLayout>
3884
</RelativeLayout>

cSploit/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<string name="enter_redirection_details">Enter redirection details below:</string>
1010
<string name="address">Address</string>
1111
<string name="port">Port</string>
12+
<string name="ports">Ports</string>
1213
<string name="target">Target</string>
1314
<string name="unknown">No information</string>
1415
<string name="services">Services</string>

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

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import android.net.Uri;
2828
import android.os.Build;
2929
import android.os.Bundle;
30+
import android.support.v4.content.ContextCompat;
3031
import android.support.v7.app.AppCompatActivity;
3132
import android.support.v7.view.ActionMode;
3233
import android.text.Html;
@@ -42,6 +43,7 @@
4243
import android.widget.AdapterView.OnItemLongClickListener;
4344
import android.widget.BaseAdapter;
4445
import android.widget.ImageView;
46+
import android.widget.LinearLayout;
4547
import android.widget.ListView;
4648
import android.widget.RelativeLayout;
4749
import android.widget.TextView;
@@ -135,6 +137,7 @@ private void createUpdateStatusText() {
135137
layout.addView(mUpdateStatus);
136138
}
137139

140+
138141
private void createUpdateLayout() {
139142

140143
lv.setVisibility(View.GONE);
@@ -860,30 +863,40 @@ public View getView(int position, View convertView, ViewGroup parent) {
860863
row.setBackgroundResource(R.drawable.card_background_dark);
861864

862865
holder = new TargetHolder();
863-
holder.itemImage = (ImageView) row.findViewById(R.id.itemIcon);
864-
holder.itemTitle = (TextView) row.findViewById(R.id.itemTitle);
865-
holder.itemDescription = (TextView) row.findViewById(R.id.itemDescription);
866-
867-
row.setTag(holder);
866+
holder.itemImage = (ImageView) (row != null ? row
867+
.findViewById(R.id.itemIcon) : null);
868+
holder.itemTitle = (TextView) (row != null ? row
869+
.findViewById(R.id.itemTitle) : null);
870+
holder.itemDescription = (TextView) (row != null ? row
871+
.findViewById(R.id.itemDescription) : null);
872+
holder.portCount = (TextView) (row != null ? row
873+
.findViewById(R.id.portCount) : null);
874+
holder.portCountLayout = (LinearLayout) (row != null ? row
875+
.findViewById(R.id.portCountLayout) : null);
876+
if (row != null)
877+
row.setTag(holder);
868878
} else
869879
holder = (TargetHolder) row.getTag();
870880

871-
Target target = list.get(position);
881+
final Target target = list.get(position);
872882

873-
if (target.hasAlias())
883+
if (target.hasAlias()){
874884
holder.itemTitle.setText(Html.fromHtml("<b>"
875885
+ target.getAlias() + "</b> <small>( "
876886
+ target.getDisplayAddress() + " )</small>"));
877-
878-
else
887+
} else {
879888
holder.itemTitle.setText(target.toString());
880-
881-
holder.itemTitle.setTextColor(getResources().getColor((target.isConnected() ? R.color.app_color : R.color.gray_text)));
889+
}
890+
holder.itemTitle.setTextColor(ContextCompat.getColor(getApplicationContext(), (target.isConnected() ? R.color.app_color : R.color.gray_text)));
882891

883892
holder.itemTitle.setTypeface(null, Typeface.NORMAL);
884893
holder.itemImage.setImageResource(target.getDrawableResourceId());
885894
holder.itemDescription.setText(target.getDescription());
886895

896+
int openedPorts = target.getOpenPorts().size();
897+
898+
holder.portCount.setText(String.format("%d", openedPorts));
899+
holder.portCountLayout.setVisibility(openedPorts < 1 ? View.GONE : View.VISIBLE);
887900
return row;
888901
}
889902

@@ -948,6 +961,8 @@ class TargetHolder {
948961
ImageView itemImage;
949962
TextView itemTitle;
950963
TextView itemDescription;
964+
TextView portCount;
965+
LinearLayout portCountLayout;
951966
}
952967
}
953968

cSploit/src/org/csploit/android/plugins/ExploitFinder.java

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -65,25 +65,29 @@
6565
import static org.csploit.android.net.metasploit.MsfExploit.Ranking;
6666

6767
public class ExploitFinder extends Plugin {
68-
private ToggleButton mSearchToggleButton = null;
69-
private ProgressBar mSearchProgress = null;
70-
private ListView mListView = null;
71-
private Future job = null;
72-
private ExploitAdapter mAdapter = null;
73-
74-
private static ExploitFinder UIThread = null;
75-
76-
public class ExploitAdapter extends ArrayAdapter<Exploit> {
77-
class ExploitHolder {
78-
ImageView itemImage;
79-
TextView itemTitle;
80-
TextView itemDescription;
81-
TextView itemRanking;
82-
}
8368

84-
public ExploitAdapter() {
85-
super(ExploitFinder.this, R.layout.plugin_exploit_finder_item, (List<Exploit>) System.getCurrentExploits());
86-
}
69+
private ToggleButton mSearchToggleButton = null;
70+
private ProgressBar mSearchProgress = null;
71+
private ListView mListView = null;
72+
private Future job = null;
73+
private ExploitAdapter mAdapter = null;
74+
75+
private static ExploitFinder UIThread = null;
76+
77+
public class ExploitAdapter extends ArrayAdapter<Exploit> {
78+
79+
class ExploitHolder {
80+
ImageView itemImage;
81+
TextView itemTitle;
82+
TextView itemDescription;
83+
TextView itemRanking;
84+
}
85+
86+
public ExploitAdapter() {
87+
super(ExploitFinder.this, R.layout.plugin_exploit_finder_item, (List<Exploit>) System.getCurrentExploits());
88+
}
89+
90+
8791

8892
@Override
8993
public View getView(int position, View convertView, ViewGroup parent) {

cSploit/src/org/csploit/android/services/NetworkRadar.java

Lines changed: 54 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88
import org.csploit.android.core.Logger;
99
import org.csploit.android.core.System;
1010
import org.csploit.android.core.ChildManager;
11+
import org.csploit.android.net.Endpoint;
12+
import org.csploit.android.net.Network;
1113
import org.csploit.android.net.Target;
14+
import org.csploit.android.tools.NMap;
15+
import org.csploit.android.tools.NetworkRadar.HostReceiver;
1216

1317
import java.net.InetAddress;
1418

@@ -64,36 +68,57 @@ public void buildMenuItem(MenuItem item) {
6468
item.setEnabled(System.getTools().networkRadar.isEnabled());
6569
}
6670

67-
private class Receiver extends org.csploit.android.tools.NetworkRadar.HostReceiver {
71+
private void onNewHostFound(Target target) {
72+
try {
73+
System.getTools().nmap.synScan(target, new ScanReceiver(target));
74+
} catch (ChildManager.ChildNotStartedException e) {
75+
System.errorLogging(e);
76+
}
77+
}
78+
79+
private class Receiver extends HostReceiver {
6880

6981
@Override
7082
public void onHostFound(byte[] macAddress, InetAddress ipAddress, String name) {
7183
Target t;
7284
boolean notify = false;
85+
boolean justFound;
7386

7487
t = System.getTargetByAddress(ipAddress);
88+
justFound = t == null;
7589

76-
if(t==null) {
90+
if(justFound) {
7791
t = new Target(ipAddress, macAddress);
78-
79-
System.addOrderedTarget(t);
80-
81-
notify = true;
82-
}
83-
84-
if( !t.isConnected() ) {
85-
t.setConneced(true);
86-
notify = true;
87-
}
88-
89-
if (name != null && !name.equals(t.getAlias())) {
9092
t.setAlias(name);
93+
System.addOrderedTarget(t);
9194
notify = true;
95+
} else {
96+
if (!t.isConnected()) {
97+
t.setConneced(true);
98+
notify = true;
99+
}
100+
101+
if (name != null && !name.equals(t.getAlias())) {
102+
t.setAlias(name);
103+
notify = true;
104+
}
105+
106+
//TODO: remove me ( and imports )
107+
Endpoint e = new Endpoint(ipAddress, macAddress);
108+
if(!e.equals(t.getEndpoint())) {
109+
Logger.warning(
110+
String.format("target '%s' changed it's mac address from '%s' to '%s'",
111+
t.toString(), t.getEndpoint().getHardwareAsString(), e.getHardwareAsString()));
112+
}
92113
}
93114

94115
if(notify) {
95116
sendIntent(NRDR_CHANGED);
96117
}
118+
119+
if(justFound) {
120+
onNewHostFound(t);
121+
}
97122
}
98123

99124
@Override
@@ -120,4 +145,19 @@ public void onDeath(int signal) {
120145
sendIntent(NRDR_STOPPED);
121146
}
122147
}
148+
149+
private class ScanReceiver extends NMap.SynScanReceiver {
150+
151+
private final Target target;
152+
153+
public ScanReceiver(Target target) {
154+
this.target = target;
155+
}
156+
157+
@Override
158+
public void onPortFound(int port, String protocol) {
159+
target.addOpenPort(port, Network.Protocol.fromString(protocol));
160+
sendIntent(NRDR_CHANGED);
161+
}
162+
}
123163
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ public Child synScan( Target target, SynScanReceiver receiver, String custom ) t
142142
return super.async( command, receiver );
143143
}
144144

145+
public Child synScan( Target target, SynScanReceiver receiver) throws ChildManager.ChildNotStartedException {
146+
return synScan(target, receiver, null);
147+
}
148+
145149
public Child customScan( Target target, SynScanReceiver receiver, String custom ) throws ChildManager.ChildNotStartedException {
146150
String command = "-vvv ";
147151

0 commit comments

Comments
 (0)