Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add taint parameter and change rules #29

Merged
merged 7 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/src/main/java/co/ostorlab/insecure_app/BugRule.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ abstract public class BugRule {

public void setContext(Context context){ this.context = context;}
public Context getContext(){ return context;}
abstract public void run() throws Exception;
abstract public void run(String input) throws Exception;
abstract public String getDescription();
public String toString()
{
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/java/co/ostorlab/insecure_app/BugRuleCaller.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ <T extends BugRule> void addRule(T rule){
rules.add(rule);
}

void callRules() throws Exception{
void callRules(String user_input) throws Exception{
for(final BugRule rule: rules){
runInThread(rule);
runInThread(rule, user_input);
}
}

Expand All @@ -50,11 +50,11 @@ String listBugRules() throws Exception{
return buffer.toString();
}

private void runInThread(final BugRule rule) throws Exception {
private void runInThread(final BugRule rule, String user_input) throws Exception {
new Thread(new Runnable() {
public void run() {
try {
rule.run();
rule.run(user_input);
}
catch (Exception e) {
e.printStackTrace();
Expand Down
14 changes: 10 additions & 4 deletions app/src/main/java/co/ostorlab/insecure_app/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.EditText;

import androidx.appcompat.app.AppCompatActivity;

Expand Down Expand Up @@ -39,7 +40,8 @@

public class MainActivity extends AppCompatActivity {
private TextView outputView;
private Button runAllButton ;
private Button runAllButton;
private EditText inputField;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -50,8 +52,10 @@ protected void onCreate(Bundle savedInstanceState) {
// Trigger flutter directly when the app starts.
triggerFlutter();


final Button runAllButton = findViewById(R.id.runAllId);
final Button runAllFlutterButton = findViewById(R.id.runAllFlutterId);
final EditText inputField = findViewById(R.id.editText);
runAllFlutterButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Expand All @@ -62,8 +66,10 @@ public void onClick(View view) {
runAllButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String user_input = inputField.getText().toString();
outputView.setText("Running \n");
executeAllRules();

executeAllRules(user_input);
}
});

Expand All @@ -73,7 +79,7 @@ private void triggerFlutter(){
FlutterActivity.createDefaultIntent(MainActivity.this)
);
}
private void executeAllRules() {
private void executeAllRules(String user_input) {
BugRuleCaller caller = new BugRuleCaller(getApplicationContext());
outputView.append("Adding rules ...\n");
caller.addRule(new ECBModeCipher());
Expand Down Expand Up @@ -106,7 +112,7 @@ private void executeAllRules() {
caller.addRule(new RegisterReceiverExported(this));

try {
caller.callRules();
caller.callRules(user_input);
outputView.append(caller.listBugRules());

} catch (Exception e){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ public String getDescription() {
}

@Override
public void run() throws Exception{
public void run(String user_input) throws Exception{
String clearText = "Jan van Eyck was here 1434";
if (user_input.length() != 0){
clearText = user_input;
}
String key = "ThisIs128bitSize";
SecretKeySpec skeySpec = new SecretKeySpec(key.getBytes(), "AES");
Cipher cipher = Cipher.getInstance("AES");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class ArrayCall extends BugRule {
private static final String TAG = ArrayCall.class.toString();

@Override
public void run() throws Exception {
public void run(String user_input) throws Exception {

int[] ages = new int[5];
handle_array(ages, 5, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
public final class BiometricFingerprintManagerVulnerability extends BugRule {

@Override
public void run() throws Exception {
public void run(String user_input) throws Exception {
Context context = getContext();
// The class FingerprintManager
FingerprintManager fingerprintManager = (FingerprintManager) context.getSystemService(Context.FINGERPRINT_SERVICE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public BiometricFingerprintPromptVulnerability(FragmentActivity activity) {
}

@Override
public void run() throws Exception {
public void run(String user_input) throws Exception {
Context context = getContext();

BiometricPrompt.AuthenticationCallback authenticationCallback = new BiometricPrompt.AuthenticationCallback() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class ClearTextTraffic extends BugRule {
private static final String TAG = ClearTextTraffic.class.toString();

@Override
public void run() throws Exception {
public void run(String user_input) throws Exception {
OkHttpClient client = new OkHttpClient.Builder()
.build();
Request request = new Request.Builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@ public class CommandExec extends BugRule {
private static final String TAG = CommandExec.class.toString();

@Override
public void run() throws Exception {
public void run(String user_input) throws Exception {

String domainName = "google.com";
String command = "";

// Tainted command.
if (user_input.length() != 0){
executeCommand(command, null);
}

// command contains chmod
command = "chmod 777" + domainName;
executeCommand(command, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,20 @@ public String getDescription() {
}

@Override
public void run() throws Exception {
public void run(String user_input) throws Exception {
/*
Dex class loading from user input
*/
if (user_input.length() != 0){
String apkFile = Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + "user_input";
DexClassLoader classLoader1 = new DexClassLoader(
apkFile,
apkFile,
apkFile,
ClassLoader.getSystemClassLoader());
classLoader1.loadClass("a.b.c");
}

/*
Dex class loading from external storage
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ public String getDescription() {
}

@Override
public void run() throws Exception{
public void run(String user_input) throws Exception{
String clearText = "Jan van Eyck was here 1434";
if (user_input.length() != 0){
clearText = user_input;
}
String key = "ThisIs128bitSize";
SecretKeySpec skeySpec = new SecretKeySpec(key.getBytes(), "AES");
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5PADDING");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,15 @@ public String get_url() {
}

@Override
public void run() throws Exception {
public void run(String user_input) throws Exception {
if (user_input.length() != 0){
ContextCompat.getMainExecutor(getContext()).execute(() -> {
Log.i(TAG, String.format("Message: %s", user_input));
WebView webView = new WebView(getContext());
webView.loadUrl(user_input);
});
}

ContextCompat.getMainExecutor(getContext()).execute(() -> {
Log.i(TAG, String.format("Message: %s", get_url()));
WebView webView = new WebView(getContext());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class HashCall extends BugRule {
private static final String TAG = HashCall.class.toString();

@Override
public void run() throws Exception {
public void run(String user_input) throws Exception {

String monMessage = "Ostorlab hidden message";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

public class ImplicitPendingIntentVulnerability extends BugRule {
@Override
public void run() throws Exception {
public void run(String user_input) throws Exception {
// Create an implicit base Intent and wrap it in a PendingIntent

Intent base = new Intent("ACTION_FOO");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ public class InsecureCommands extends BugRule {
private static final String TAG = InsecureCommands.class.toString();

@Override
public void run() throws Exception {
public void run(String user_input) throws Exception {
if (user_input.length() != 0){
executeCommand(user_input, null);
}
executeCommand("chmod 755 test_file", "/data/data/");
executeCommand("ping -c 3 www.ostorlab.co", "/sdcard/ostorlab");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,18 @@ public String getDescription() {
}

@Override
public void run() throws Exception {
public void run(String user_input) throws Exception {
String filename = "test_filename";
openFileOutputWorldReadable(filename);
openFileOutputWorldWritable(filename);
setReadableAll(filename);
setWritableAll(filename);
if (user_input.length() != 0){
openFileOutputWorldReadable(user_input);
openFileOutputWorldWritable(user_input);
setReadableAll(user_input);
setWritableAll(user_input);
}
}

private void openFileOutputWorldReadable(String filename) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

public final class InsecureRandom extends BugRule {
@Override
public void run() throws Exception {
public void run(String user_input) throws Exception {
SecureRandom secureRandom = new SecureRandom();
Random random = new Random();
random = new Random(12345);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public String getDescription() {
}

@Override
public void run() throws Exception{
public void run(String user_input) throws Exception{
String myPreference = "myPreference";
getContext().getSharedPreferences("PrivateOnly", Context.MODE_PRIVATE);
getContext().getSharedPreferences("WorldReadableOnly", Context.MODE_WORLD_READABLE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class IntentCall extends BugRule {
private static final String TAG = IntentCall.class.toString();

@Override
public void run() throws Exception {
public void run(String user_input) throws Exception {
Intent intent = new Intent("co.ostorlab");
intent.putExtra("token", "SuperSecretToken");
getContext().sendBroadcast(intent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public String getDescription() {
}

@Override
public void run() throws Exception{
public void run(String user_input) throws Exception{
String input = String.join("", Collections.nCopies(200, "()"));
triggerStackOverflow(input);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public final class MobileOnlyDownloadManager extends BugRule {
private static final String TAG = co.ostorlab.insecure_app.bugs.calls.MobileOnlyDownloadManager.class.toString();

@Override
public void run() throws Exception {
public void run(String user_input) throws Exception {
// True Positive
startDownloadManager(DownloadManager.Request.NETWORK_MOBILE);
// False Positive
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public String getDescription() {
}

@Override
public void run() {
public void run(String user_input) {
Context context = getContext();
PackageManager packageManager = context.getPackageManager();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void writeToParcel(android.os.Parcel parcel, int i) {
}

@Override
public void run() throws Exception {
public void run(String user_input) throws Exception {
Parcel tmp = Parcel.obtain();
MemoryObjectParcelable var = new MemoryObjectParcelable(tmp);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,15 @@ public String getDescription() {
}

@Override
public void run() throws Exception{
public void run(String user_input) throws Exception{
/*
Path class loading from external storage
*/
if (user_input.length() != 0){
String apkFile = Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + user_input;
PathClassLoader classLoader1 = new PathClassLoader(apkFile, ClassLoader.getSystemClassLoader());
classLoader1.loadClass("a.b.c");
}
/*
Path class loading from external storage
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,16 @@ public ParcelFileDescriptor openFile(Uri uri, @NonNull String mode) throws FileN

}
@Override
public void run() throws Exception {
public void run(String user_input) throws Exception {
if (user_input.length() != 0){
Provider taint_provider = new Provider();
Uri.Builder taint_builder = new Uri.Builder();
taint_builder.scheme("https");
taint_builder.authority(user_input);
Uri uri = taint_builder.build();
taint_provider.openFile(uri, "not used parameter");
}

Provider provider = new Provider();
Uri.Builder builder = new Uri.Builder();
builder.scheme("https");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public RegisterReceiverExported(FragmentActivity mActivity) {
}

@Override
public void run() throws Exception {
public void run(String user_input) throws Exception {
IntentFilter intentFilter = new IntentFilter(WifiManager.WIFI_STATE_CHANGED_ACTION);
mActivity.registerReceiver(new WifiStateReceiver(), intentFilter, Context.RECEIVER_EXPORTED);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@
public class SQLiteDatabaseCall extends BugRule {

@Override
public void run() throws Exception {
public void run(String user_input) throws Exception {

MySQLiteOpenHelper mySQLiteOpenHelper = new MySQLiteOpenHelper(this.getContext());
SQLiteDatabase db = mySQLiteOpenHelper.getWritableDatabase();
mySQLiteOpenHelper.createTable();
String insert_query = "INSERT INTO accounts(name, amount) VALUES(?, ?)";
db.execSQL(insert_query, new Object[]{"Jack", 3000});
if (user_input.length() != 0){
db.execSQL(user_input, new Object[]{"Taint", 3001});
}
mySQLiteOpenHelper.dropTable();
db.close();

Expand Down
Loading
Loading