Skip to content

Commit 9c71419

Browse files
committed
Add port scanner custom parameters.
Closes #294
1 parent 2c1d43c commit 9c71419

5 files changed

Lines changed: 131 additions & 7 deletions

File tree

cSploit/res/layout/plugin_portscanner.xml

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
android:id="@+id/separator"
2222
android:layout_width="fill_parent"
2323
android:layout_height="1dp"
24-
android:layout_marginTop="8dp"
25-
android:layout_marginBottom="8dp"
26-
android:layout_below="@+id/scanToggleButton"
27-
android:background="@android:color/darker_gray"/>
24+
android:background="@android:color/darker_gray"
25+
android:layout_below="@+id/scanDoc"
26+
android:layout_alignParentRight="true"
27+
android:layout_alignParentEnd="true" />
2828

2929
<ListView
3030
android:id="@+id/scanListView"
@@ -41,4 +41,37 @@
4141
android:layout_alignRight="@+id/scanListView"
4242
android:visibility="invisible"/>
4343

44+
<EditText
45+
android:layout_width="wrap_content"
46+
android:layout_height="wrap_content"
47+
android:id="@+id/scanParameters"
48+
android:layout_below="@+id/scanToggleButton"
49+
android:layout_alignParentRight="true"
50+
android:layout_alignParentEnd="true"
51+
android:layout_alignParentLeft="true"
52+
android:layout_alignParentStart="true"
53+
android:textAppearance="?android:attr/textAppearanceSmall"
54+
android:visibility="gone"
55+
android:hint="-sS -P0 --privileged --send-ip --system-dns" />
56+
57+
<TextView
58+
android:layout_width="wrap_content"
59+
android:layout_height="wrap_content"
60+
android:textAppearance="?android:attr/textAppearanceSmall"
61+
android:text="doc: https://nmap.org/book/man.html"
62+
android:id="@+id/scanDoc"
63+
android:layout_below="@+id/scanParameters"
64+
android:layout_alignParentLeft="false"
65+
android:layout_alignParentStart="true"
66+
android:layout_alignRight="@+id/separator"
67+
android:layout_alignEnd="@+id/separator"
68+
android:linksClickable="true"
69+
android:autoLink="web"
70+
android:layout_alignParentRight="false"
71+
android:layout_alignParentTop="false"
72+
android:layout_alignParentBottom="false"
73+
android:textAlignment="center"
74+
android:gravity="center_horizontal"
75+
android:visibility="gone" />
76+
4477
</RelativeLayout>

cSploit/res/menu/port_scanner.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<menu xmlns:android="http://schemas.android.com/apk/res/android">
33

4+
<item
5+
android:id="@+id/scanner_custom_parameters"
6+
android:checkable="true"
7+
android:title="@string/scanner_custom_parameters" />
48
<item
59
android:id="@+id/select_ports"
610
android:title="@string/scanner_select_ports" />

cSploit/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@
306306
<string name="menu_about">About</string>
307307

308308
<string name="scanner_select_ports">Select Custom Ports</string>
309+
<string name="scanner_custom_parameters">Custom parameters</string>
309310

310311
<string name="wifi_initializing">Initializing &#8230;</string>
311312
<string name="wifi_activating_iface">Activating WiFi interface &#8230;</string>

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

Lines changed: 76 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import android.content.SharedPreferences;
2424
import android.net.Uri;
2525
import android.os.Bundle;
26+
import android.preference.PreferenceManager;
2627
import android.view.Menu;
2728
import android.view.MenuInflater;
2829
import android.view.MenuItem;
@@ -31,8 +32,10 @@
3132
import android.widget.AdapterView;
3233
import android.widget.AdapterView.OnItemLongClickListener;
3334
import android.widget.ArrayAdapter;
35+
import android.widget.EditText;
3436
import android.widget.ListView;
3537
import android.widget.ProgressBar;
38+
import android.widget.TextView;
3639
import android.widget.Toast;
3740
import android.widget.ToggleButton;
3841

@@ -54,13 +57,19 @@
5457
import java.util.ArrayList;
5558

5659
public class PortScanner extends Plugin {
60+
private TextView mTextDoc = null;
61+
private EditText mTextParameters = null;
5762
private ToggleButton mScanToggleButton = null;
5863
private ProgressBar mScanProgress = null;
5964
private boolean mRunning = false;
6065
private ArrayList<String> mPortList = null;
6166
private ArrayAdapter<String> mListAdapter = null;
6267
private Receiver mScanReceiver = null;
6368
private String mCustomPorts = null;
69+
private Menu mMenu = null;
70+
private static final String CUSTOM_PARAMETERS = "PortScanner.Prefs.CustomParameters";
71+
private static final String CUSTOM_PARAMETERS_TEXT = "PortScanner.Prefs.CustomParameters.Text";
72+
private SharedPreferences mPreferences = null;
6473

6574
public PortScanner() {
6675
super(R.string.port_scanner, R.string.port_scanner_desc,
@@ -72,11 +81,46 @@ public PortScanner() {
7281
mScanReceiver = new Receiver();
7382
}
7483

84+
/**
85+
* Sets visible the custom parameters text field, and loads the saved parameters
86+
*/
87+
private void displayParametersField (){
88+
mTextDoc.setVisibility(View.VISIBLE);
89+
mTextParameters.setVisibility(View.VISIBLE);
90+
mTextParameters.setText(mPreferences.getString(CUSTOM_PARAMETERS_TEXT, ""));
91+
92+
saveCustomParameters(true);
93+
}
94+
95+
/**
96+
* Hides the custom parameters text field, saving the typed parameters
97+
*/
98+
private void hideParametersField (){
99+
saveCustomParameters(false);
100+
101+
mTextDoc.setVisibility(View.GONE);
102+
mTextParameters.setVisibility(View.GONE);
103+
}
104+
105+
/**
106+
* Saves customs parameters entered by the user
107+
*
108+
* @param displayed Sets if the custom parameters text field must be displayed or not
109+
*/
110+
private void saveCustomParameters (boolean displayed){
111+
SharedPreferences.Editor edit = mPreferences.edit();
112+
edit.putBoolean(CUSTOM_PARAMETERS, displayed);
113+
edit.putString(CUSTOM_PARAMETERS_TEXT, mTextParameters.getText().toString());
114+
edit.commit();
115+
}
116+
75117
private void setStoppedState() {
76118
if(mProcess!=null) {
77119
mProcess.kill();
78120
mProcess = null;
79121
}
122+
saveCustomParameters(mTextParameters.isShown());
123+
80124
mScanProgress.setVisibility(View.INVISIBLE);
81125
mRunning = false;
82126
mScanToggleButton.setChecked(false);
@@ -90,13 +134,21 @@ private void setStartedState() {
90134
createPortList();
91135

92136
try {
93-
mProcess = System.getTools().nmap
94-
.synScan(System.getCurrentTarget(), mScanReceiver, mCustomPorts);
137+
if (mTextParameters.isShown()) {
138+
mListAdapter.clear();
139+
mListAdapter.notifyDataSetChanged();
140+
mProcess = System.getTools().nmap
141+
.customScan(System.getCurrentTarget(), mScanReceiver, mTextParameters.getText().toString());
142+
}
143+
else {
144+
mProcess = System.getTools().nmap
145+
.synScan(System.getCurrentTarget(), mScanReceiver, mCustomPorts);
146+
}
95147

96148
mRunning = true;
97149
} catch (ChildManager.ChildNotStartedException e) {
98150
System.errorLogging(e);
99-
Toast.makeText(PortScanner.this, getString(R.string.child_not_started), Toast.LENGTH_LONG).show();
151+
Toast.makeText(PortScanner.this, getString(R.string.child_not_started) + "\n" + e.getLocalizedMessage(), Toast.LENGTH_LONG).show();
100152
}
101153
}
102154

@@ -129,9 +181,15 @@ public void onCreate(Bundle savedInstanceState) {
129181
setTheme(R.style.AppTheme);
130182
super.onCreate(savedInstanceState);
131183

184+
mPreferences = System.getSettings();
185+
mTextDoc = (TextView) findViewById(R.id.scanDoc);
186+
mTextParameters = (EditText) findViewById(R.id.scanParameters);
132187
mScanToggleButton = (ToggleButton) findViewById(R.id.scanToggleButton);
133188
mScanProgress = (ProgressBar) findViewById(R.id.scanActivity);
134189

190+
if (mPreferences.getBoolean(CUSTOM_PARAMETERS, false))
191+
displayParametersField();
192+
135193
mScanToggleButton.setOnClickListener(new OnClickListener() {
136194
@Override
137195
public void onClick(View v) {
@@ -220,12 +278,24 @@ public void onCancel() {
220278
public boolean onCreateOptionsMenu(Menu menu) {
221279
MenuInflater inflater = getMenuInflater();
222280
inflater.inflate(R.menu.port_scanner, menu);
281+
mMenu = menu;
282+
mMenu.findItem(R.id.scanner_custom_parameters).
283+
setChecked(mPreferences.getBoolean(CUSTOM_PARAMETERS, false));
284+
223285
return super.onCreateOptionsMenu(menu);
224286
}
225287

226288
@Override
227289
public boolean onOptionsItemSelected(MenuItem item) {
228290
switch (item.getItemId()) {
291+
case R.id.scanner_custom_parameters:
292+
if (item.isChecked())
293+
hideParametersField();
294+
else
295+
displayParametersField();
296+
297+
item.setChecked(!item.isChecked());
298+
return true;
229299
case R.id.select_ports:
230300

231301
new InputDialog(getString(R.string.select_ports),
@@ -271,6 +341,9 @@ public void onInputEntered(String input) {
271341
PortScanner.this).show();
272342
}
273343

344+
hideParametersField();
345+
mMenu.findItem(R.id.scanner_custom_parameters).setChecked(false);
346+
274347
Logger.debug("mCustomPorts = " + mCustomPorts);
275348
} else
276349
new ErrorDialog(getString(R.string.error),

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

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

145+
public Child customScan( Target target, SynScanReceiver receiver, String custom ) throws ChildManager.ChildNotStartedException {
146+
String command = "-vvv ";
147+
148+
if( custom != null )
149+
command += custom + " ";
150+
151+
command += target.getCommandLineRepresentation();
152+
153+
Logger.debug( "customScan - " + command );
154+
155+
return super.async( command, receiver );
156+
}
157+
145158
public Child inpsect( Target target, InspectionReceiver receiver, boolean focusedScan ) throws ChildManager.ChildNotStartedException {
146159
String cmd;
147160
LinkedList<Integer> tcp,udp;

0 commit comments

Comments
 (0)