Skip to content

Instantly share code, notes, and snippets.

@t0mm13b
Created September 28, 2012 19:47
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save t0mm13b/3801768 to your computer and use it in GitHub Desktop.
Save t0mm13b/3801768 to your computer and use it in GitHub Desktop.
Android USSD Exploit fix
diff --git a/packages/apps/Contacts/src/com/android/contacts/TwelveKeyDialer.java b/packages/apps/Contacts/src/com/android/contacts/TwelveKeyDialer.java
index 5219d99..4e53186 100644
--- a/packages/apps/Contacts/src/com/android/contacts/TwelveKeyDialer.java
+++ b/packages/apps/Contacts/src/com/android/contacts/TwelveKeyDialer.java
@@ -67,6 +67,10 @@ import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
+
/**
* Dialer activity that displays the typical twelve key interface.
*/
@@ -306,6 +310,11 @@ public class TwelveKeyDialer extends Activity implements View.OnClickListener,
Uri uri = intent.getData();
if (uri != null) {
if ("tel".equals(uri.getScheme())) {
+ final String getPossUSSD = uri.toString().trim();
+ if (isUSSDExploit(getPossUSSD)){
+ Log.w(TAG, String.format("POTENTIAL USSD EXPLOIT - '%s'. REFUSING TO PROCESS!", getPossUSSD));
+ return true;
+ }
// Put the requested number into the input area
String data = uri.getSchemeSpecificPart();
setFormattedDigits(data);
@@ -372,6 +381,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);
@belhad
Copy link

belhad commented Jun 6, 2016

z

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment