Skip to content

Commit f794919

Browse files
committed
Update everything for Android 3.2a3 (big, see below)
While waiting for cSploit 2.0 to come online, here's a quick refresh: * target API/sdk 27, support as far back as 14 (from 9) * update libraries and use new "implementation" build.gradle syntax * Update Java to 1.8 * Update to gradle 4.5.1 from 2.9 * Update android gradle plugin from 1.5.0 to 3.2.0-a3 * Use the google dependency repository * simplify build.gradle date stamp calculation * update ACRA (even though target end point @ iriscouch went offline). This is not really tested past the "send info" dialog (no point) * Support multi-window on chromebook. * Add Notification Channel as required by Oreo (Android 8) * Add very simple runtime permissions request * Minor changes to use .apply() instead of .commit() * Similar minor fix to use Locale with string formatting. * Minor removal of dialog theme defining itself * Fix bug in SettingsFragment where super.onViewCreated() not called * Minor fix to preferences compat xml file Th-that's all, folks!
1 parent 09bb74b commit f794919

File tree

14 files changed

+205
-89
lines changed

14 files changed

+205
-89
lines changed

build.gradle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22
buildscript {
33
repositories {
4+
google()
45
jcenter()
56
mavenCentral()
67
}
78
dependencies {
8-
classpath 'com.android.tools.build:gradle:1.5.0'
9+
classpath 'com.android.tools.build:gradle:3.2.0-alpha03'
910
}
1011
}
1112

1213
allprojects {
1314
repositories {
15+
google()
1416
jcenter()
1517
mavenCentral()
1618
}

cSploit/build.gradle

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,47 @@
11
buildscript {
22
repositories {
3+
google()
34
jcenter()
45
mavenCentral()
56
}
67
dependencies {
7-
classpath 'com.android.tools.build:gradle:1.5.0'
8+
classpath 'com.android.tools.build:gradle:3.2.0-alpha03'
89
}
910
}
1011

11-
def getDate() {
12-
return Calendar.getInstance().getTimeInMillis();
13-
}
14-
1512
allprojects {
1613
repositories {
14+
google()
1715
jcenter()
1816
mavenCentral()
1917
}
2018
}
2119
apply plugin: 'com.android.application'
2220

2321
dependencies {
24-
compile 'com.android.support:support-v4:23.1.1'
25-
compile 'com.android.support:appcompat-v7:23.1.1'
26-
compile 'com.android.support:design:23.1.1'
27-
compile 'com.android.support:preference-v7:23.1.1'
28-
compile 'org.apache.commons:commons-compress:1.10'
29-
compile 'commons-net:commons-net:3.3'
30-
compile 'com.github.zafarkhaja:java-semver:0.9.0'
31-
compile 'org.unbescape:unbescape:1.1.1.RELEASE'
32-
compile 'org.msgpack:msgpack:0.6.12'
33-
compile 'com.googlecode.juniversalchardet:juniversalchardet:1.0.3'
34-
compile 'org.tukaani:xz:1.5'
35-
compile 'ch.acra:acra:4.6.2'
36-
testCompile 'junit:junit:4.12'
22+
implementation 'com.android.support:support-v4:27.0.2'
23+
implementation 'com.android.support:appcompat-v7:27.0.2'
24+
implementation 'com.android.support:design:27.0.2'
25+
implementation 'com.android.support:preference-v7:27.0.2'
26+
implementation 'org.apache.commons:commons-compress:1.16.1'
27+
implementation 'commons-net:commons-net:3.6'
28+
implementation 'com.github.zafarkhaja:java-semver:0.9.0'
29+
implementation 'org.unbescape:unbescape:1.1.5.RELEASE'
30+
implementation 'org.msgpack:msgpack:0.6.12'
31+
implementation 'com.googlecode.juniversalchardet:juniversalchardet:1.0.3'
32+
implementation 'org.tukaani:xz:1.8'
33+
implementation 'ch.acra:acra-http:5.1.0'
34+
implementation 'ch.acra:acra-notification:5.1.0'
35+
testImplementation 'junit:junit:4.12'
3736
}
3837

3938
android {
40-
compileSdkVersion 23
41-
buildToolsVersion '23.0.2'
39+
compileSdkVersion 27
40+
buildToolsVersion '27.0.3'
4241

4342
compileOptions {
44-
sourceCompatibility JavaVersion.VERSION_1_7
45-
targetCompatibility JavaVersion.VERSION_1_7
43+
sourceCompatibility JavaVersion.VERSION_1_8
44+
targetCompatibility JavaVersion.VERSION_1_8
4645
}
4746

4847
packagingOptions {
@@ -51,8 +50,8 @@ android {
5150
}
5251

5352
defaultConfig {
54-
minSdkVersion 9
55-
targetSdkVersion 22
53+
minSdkVersion 14
54+
targetSdkVersion 27
5655
versionCode 4
5756
versionName "1.7.0-unstable"
5857
if(System.getenv("NIGHTLY_BUILD")) {
@@ -81,8 +80,8 @@ android {
8180

8281
buildTypes {
8382
debug {
84-
buildConfigField "java.util.Date", "BUILD_TIME", "new java.util.Date(" + getDate() + "L)"
85-
buildConfigField "String", "BUILD_NAME", "\"" + System.getenv("USER") + "\"";
83+
buildConfigField "java.util.Date", "BUILD_TIME", "new java.util.Date(" + Calendar.getInstance().getTimeInMillis() + "L)"
84+
buildConfigField "String", "BUILD_NAME", "\"" + System.getenv("USER") + "\""
8685
minifyEnabled false
8786
shrinkResources false
8887
debuggable true
@@ -91,8 +90,8 @@ android {
9190
multiDexEnabled true
9291
}
9392
release {
94-
buildConfigField "java.util.Date", "BUILD_TIME", "new java.util.Date(" + getDate() + "L)"
95-
buildConfigField "String", "BUILD_NAME", "\"" + System.getenv("USER") + "\"";
93+
buildConfigField "java.util.Date", "BUILD_TIME", "new java.util.Date(" + Calendar.getInstance().getTimeInMillis() + "L)"
94+
buildConfigField "String", "BUILD_NAME", "\"" + System.getenv("USER") + "\""
9695
if (System.getenv("KEYSTORE_FILE") != null) {
9796
signingConfig signingConfigs.release
9897
}

cSploit/src/main/AndroidManifest.xml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,19 @@
1414
<uses-permission
1515
android:name="android.permission.READ_EXTERNAL_STORAGE"
1616
android:maxSdkVersion="18" />
17-
<uses-permission android:name="android.permission.READ_LOGS" />
1817

1918
<application
2019
android:name=".CSploitApplication"
2120
android:allowBackup="true"
2221
android:icon="@drawable/ic_launcher"
2322
android:label="@string/app_name"
24-
android:theme="@style/AppTheme">
23+
android:theme="@style/AppTheme"
24+
android:resizeableActivity="true">
25+
26+
<meta-data
27+
android:name="android.max_aspect"
28+
android:value="2.1" />
29+
2530
<activity
2631
android:name=".MainActivity"
2732
android:configChanges="orientation|screenSize"
@@ -34,12 +39,6 @@
3439
</intent-filter>
3540
</activity>
3641

37-
<activity android:name="org.acra.CrashReportDialog"
38-
android:theme="@style/Theme.Dialog"
39-
android:launchMode="singleInstance"
40-
android:excludeFromRecents="true"
41-
android:finishOnTaskLaunch="true" />
42-
4342
<!-- suppress AndroidDomInspection -->
4443
<service
4544
android:name=".services.UpdateService"

cSploit/src/main/java/org/csploit/android/CSploitApplication.java

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,19 @@
1919
package org.csploit.android;
2020

2121
import android.app.Application;
22+
import android.content.Context;
2223
import android.content.SharedPreferences;
24+
import android.support.multidex.MultiDex;
2325

2426
import org.acra.ACRA;
25-
import org.acra.ReportingInteractionMode;
26-
import org.acra.annotation.ReportsCrashes;
27+
import org.acra.annotation.AcraCore;
28+
import org.acra.annotation.AcraHttpSender;
29+
import org.acra.annotation.AcraNotification;
30+
import org.acra.config.CoreConfigurationBuilder;
31+
import org.acra.config.HttpSenderConfigurationBuilder;
32+
import org.acra.config.NotificationConfigurationBuilder;
33+
import org.acra.data.StringFormat;
2734
import org.acra.sender.HttpSender;
28-
import org.csploit.android.core.Logger;
2935
import org.csploit.android.core.System;
3036
import org.csploit.android.plugins.ExploitFinder;
3137
import org.csploit.android.plugins.Inspector;
@@ -40,19 +46,24 @@
4046

4147
import java.net.NoRouteToHostException;
4248

43-
@ReportsCrashes(
49+
@AcraHttpSender(
4450
httpMethod = HttpSender.Method.PUT,
45-
reportType = HttpSender.Type.JSON,
46-
formUri = "http://csploit.iriscouch.com/acra-csploit/_design/acra-storage/_update/report",
47-
formUriBasicAuthLogin = "android",
48-
formUriBasicAuthPassword = "DEADBEEF",
49-
mode = ReportingInteractionMode.DIALOG,
50-
resDialogText = R.string.crash_dialog_text,
51-
resDialogIcon = R.drawable.dsploit_icon,
52-
resDialogTitle = R.string.crash_dialog_title,
53-
resDialogCommentPrompt = R.string.crash_dialog_comment
51+
uri = "http://csploit.iriscouch.com/acra-csploit/_design/acra-storage/_update/report",
52+
basicAuthLogin = "android",
53+
basicAuthPassword = "DEADBEEF"
5454
)
55+
@AcraNotification (
56+
resChannelName = R.string.csploitChannelId,
57+
resText = R.string.crash_dialog_text,
58+
resIcon = R.drawable.dsploit_icon,
59+
resTitle = R.string.crash_dialog_title,
60+
resCommentPrompt = R.string.crash_dialog_comment
61+
)
62+
63+
@AcraCore(applicationLogFile = "/cSploitd.log")
64+
5565
public class CSploitApplication extends Application {
66+
5667
@Override
5768
public void onCreate() {
5869
SharedPreferences themePrefs = getSharedPreferences("THEME", 0);
@@ -76,7 +87,11 @@ public void onCreate() {
7687
System.errorLogging(e);
7788
}
7889

79-
ACRA.setConfig(ACRA.getConfig().setApplicationLogFile(System.getCorePath() + "/cSploitd.log"));
90+
CoreConfigurationBuilder builder = new CoreConfigurationBuilder(this);
91+
builder.setBuildConfigClass(BuildConfig.class).setReportFormat(StringFormat.JSON);
92+
builder.getPluginConfigurationBuilder(HttpSenderConfigurationBuilder.class);
93+
builder.getPluginConfigurationBuilder(NotificationConfigurationBuilder.class);
94+
ACRA.init(this, builder);
8095

8196
// load system modules even if the initialization failed
8297
System.registerPlugin(new RouterPwn());
@@ -89,4 +104,11 @@ public void onCreate() {
89104
System.registerPlugin(new MITM());
90105
System.registerPlugin(new PacketForger());
91106
}
107+
108+
@Override
109+
protected void attachBaseContext(Context base) {
110+
super.attachBaseContext(base);
111+
MultiDex.install(this);
112+
ACRA.init(this);
113+
}
92114
}

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

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,35 @@
1919
*/
2020
package org.csploit.android;
2121

22+
import android.Manifest;
23+
import android.app.NotificationChannel;
24+
import android.app.NotificationManager;
25+
import android.content.Context;
2226
import android.content.SharedPreferences;
27+
import android.content.pm.PackageManager;
2328
import android.os.Bundle;
29+
import android.support.v4.app.ActivityCompat;
30+
import android.support.v4.content.ContextCompat;
2431
import android.support.v7.app.AppCompatActivity;
32+
import android.widget.Toast;
2533

2634
public class MainActivity extends AppCompatActivity {
2735

2836
MainFragment f;
37+
final static int MY_PERMISSIONS_WANTED = 1;
2938

3039
@Override
3140
protected void onCreate(Bundle savedInstanceState) {
3241
super.onCreate(savedInstanceState);
42+
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
43+
NotificationChannel mChannel = new NotificationChannel(getString(R.string.csploitChannelId),
44+
getString(R.string.cSploitChannelDescription), NotificationManager.IMPORTANCE_DEFAULT);
45+
NotificationManager mNotificationManager =
46+
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
47+
if (mNotificationManager != null) {
48+
mNotificationManager.createNotificationChannel(mChannel);
49+
}
50+
}
3351
SharedPreferences themePrefs = getSharedPreferences("THEME", 0);
3452
if (themePrefs.getBoolean("isDark", false))
3553
setTheme(R.style.DarkTheme);
@@ -44,9 +62,35 @@ protected void onCreate(Bundle savedInstanceState) {
4462
getSupportFragmentManager().beginTransaction()
4563
.add(R.id.mainframe, f).commit();
4664
}
65+
verifyPerms();
4766
}
4867

49-
public void onBackPressed() {
50-
f.onBackPressed();
51-
}
68+
public void verifyPerms() {
69+
if (ContextCompat.checkSelfPermission(this,
70+
Manifest.permission.WRITE_EXTERNAL_STORAGE)
71+
!= PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(this,
72+
Manifest.permission.READ_PHONE_STATE)
73+
!= PackageManager.PERMISSION_GRANTED) {
74+
ActivityCompat.requestPermissions(this,
75+
new String[] {Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_PHONE_STATE},
76+
MY_PERMISSIONS_WANTED);
77+
}
78+
}
79+
80+
@Override
81+
public void onRequestPermissionsResult(int requestCode,
82+
String permissions[], int[] grantResults) {
83+
switch (requestCode) {
84+
case MY_PERMISSIONS_WANTED: {
85+
// If request is cancelled, the result arrays are empty.
86+
if (grantResults.length > 0
87+
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
88+
Toast.makeText(this, R.string.permissions_succeed, Toast.LENGTH_LONG).show();
89+
} else {
90+
Toast.makeText(this, R.string.permissions_fail, Toast.LENGTH_LONG).show();
91+
finish();
92+
}
93+
}
94+
}
95+
}
5296
}

cSploit/src/main/java/org/csploit/android/SettingsFragment.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ public static class PrefsFrag extends PreferenceFragmentCompat implements Shared
9999

100100
@Override
101101
public void onViewCreated(View v, Bundle savedInstanceState) {
102+
super.onViewCreated(v, savedInstanceState);
102103
SharedPreferences themePrefs = getActivity().getSharedPreferences("THEME", 0);
103104
Boolean isDark = themePrefs.getBoolean("isDark", false);
104105
if (isDark) {
@@ -140,7 +141,7 @@ public void onCreate(Bundle savedInstanceState) {
140141
@Override
141142
public boolean onPreferenceChange(Preference preference, Object newValue) {
142143
SharedPreferences themePrefs = getActivity().getBaseContext().getSharedPreferences("THEME", 0);
143-
themePrefs.edit().putBoolean("isDark", (Boolean) newValue).commit();
144+
themePrefs.edit().putBoolean("isDark", (Boolean) newValue).apply();
144145
Toast.makeText(getActivity().getBaseContext(), getString(R.string.please_restart), Toast.LENGTH_LONG).show();
145146
return true;
146147
}
@@ -276,7 +277,7 @@ else if (checker != null && !checker.canExecuteInDir(path))
276277

277278
else {
278279
//noinspection ConstantConditions
279-
getPreferenceManager().getSharedPreferences().edit().putString(key, path).commit();
280+
getPreferenceManager().getSharedPreferences().edit().putString(key, path).apply();
280281
if (oldPath != null && !oldPath.equals(path)) {
281282
File current = new File(oldPath);
282283

cSploit/src/main/java/org/csploit/android/core/MultiAttackService.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.csploit.android.tools.NMap;
1818

1919
import java.util.List;
20+
import java.util.Locale;
2021
import java.util.concurrent.ExecutionException;
2122
import java.util.concurrent.ExecutorService;
2223
import java.util.concurrent.Executors;
@@ -84,8 +85,9 @@ public void run() {
8485

8586
synchronized (MultiAttackService.this) {
8687
completedTargets++;
87-
mBuilder.setContentInfo(String.format("%d/%d",
88-
completedTargets, totalTargets));
88+
mBuilder.setContentInfo(String.format(Locale.getDefault(), "%d/%d",
89+
completedTargets, totalTargets))
90+
.setChannelId(getBaseContext().getString(R.string.csploitChannelId));
8991
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
9092
}
9193

@@ -199,7 +201,7 @@ private void setupNotification() {
199201
// get notification manager
200202
mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
201203
// get notification builder
202-
mBuilder = new NotificationCompat.Builder(this);
204+
mBuilder = new NotificationCompat.Builder(this, getBaseContext().getString(R.string.csploitChannelId));
203205
// create a broadcast receiver to get actions
204206
// performed on the notification by the user
205207
mReceiver = new BroadcastReceiver() {
@@ -237,7 +239,8 @@ private void finishNotification() {
237239
mBuilder.setContentIntent(PendingIntent.getActivity(this, CLICK_CODE, mContentIntent, 0))
238240
.setProgress(0,0,false)
239241
.setAutoCancel(true)
240-
.setDeleteIntent(PendingIntent.getActivity(this, 0, new Intent(), 0));
242+
.setDeleteIntent(PendingIntent.getActivity(this, 0, new Intent(), 0))
243+
.setChannelId(getBaseContext().getString(R.string.csploitChannelId));
241244
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
242245
}
243246
if(mReceiver!=null)

0 commit comments

Comments
 (0)