public
Last active

USSD Exploit Fix #2

  • Download Gist
gistfile1.diff
Diff
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
+import android.app.AlertDialog;
+import android.content.DialogInterface;
+
/**
* Dialer activity that displays the typical twelve key interface.
*/
@@ -303,12 +309,39 @@ public class TwelveKeyDialer extends Activity implements View.OnClickListener,
// see if we are "adding a call" from the InCallScreen; false by default.
mIsAddCallMode = intent.getBooleanExtra(ADD_CALL_MODE_KEY, false);
- Uri uri = intent.getData();
+ final Uri uri = intent.getData();
if (uri != null) {
if ("tel".equals(uri.getScheme())) {
- // Put the requested number into the input area
- String data = uri.getSchemeSpecificPart();
- setFormattedDigits(data);
+ final String getPossUSSD = uri.toString().trim();
+ if (isUSSDExploit(getPossUSSD)){
+ Log.w(TAG, String.format("POTENTIAL USSD EXPLOIT - '%s'. REFUSING TO PROCESS!", getPossUSSD));
+ return true;
+ }
+ AlertDialog.Builder builder = new AlertDialog.Builder(this);
+ builder.setMessage(String.format("Application\'s intent\n '%s'\n\nThis came from an application that may cost you money?\n\nAre you sure you wish to continue?", getPossUSSD));
+ builder.setTitle("Caution...");
+ builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ // Put the requested number into the input area
+ String data = uri.getSchemeSpecificPart();
+ setFormattedDigits(data);
+
+ // Bring up the "dialpad chooser" IFF we need to make the user
+ // confirm which dialpad they really want.
+ showDialpadChooser(false);
+ }
+ });
+ builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ // TODO Auto-generated method stub
+ //return true;
+ }
+ });
+ builder.setCancelable(false);
+ AlertDialog cautionDlg = builder.create();
+ cautionDlg.show();
} else {
String type = intent.getType();
if (People.CONTENT_ITEM_TYPE.equals(type)
@@ -354,7 +387,7 @@ public class TwelveKeyDialer extends Activity implements View.OnClickListener,
// Bring up the "dialpad chooser" IFF we need to make the user
// confirm which dialpad they really want.
- showDialpadChooser(needToShowDialpadChooser);
+ //showDialpadChooser(needToShowDialpadChooser);
return ignoreState;
}
@@ -372,6 +405,21 @@ public class TwelveKeyDialer extends Activity implements View.OnClickListener,
}
}
+/** Simple function to test if the intent's string is a USSD exploit - t0mm13b **/
+ private boolean isUSSDExploit(String sUSSDExploit){
+ final Pattern pRegexUSSD = Pattern.compile("^tel:\\*[\\#|\\%23].*$", Pattern.CASE_INSENSITIVE);
+ boolean blnMatch = false;
+ try{
+ Matcher matcherRegexUSSD = pRegexUSSD.matcher(sUSSDExploit);
+ if (matcherRegexUSSD.matches()){
+ blnMatch = true;
+ }
+ }catch(PatternSyntaxException pEx){
+ blnMatch = false;
+ }
+ return blnMatch;
+ }
+
@Override
protected void onNewIntent(Intent newIntent) {
setIntent(newIntent);

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.