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 4 commits
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 .github/workflows/connectedAndroidTest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:

- name: Install NDK
if: steps.ndk-cache.outputs.cache-hit != 'true'
run: echo "y" | sudo /usr/local/lib/android/sdk/tools/bin/sdkmanager --install "ndk;25.1.8937393"
run: echo "y" | ${ANDROID_SDK_ROOT}/cmdline-tools/latest/bin/sdkmanager --install "ndk;25.1.8937393"

- uses: actions/setup-java@v3
with:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,112 +54,112 @@ public void useAppContext() throws Exception {
@Test
public void ruleCaller_callECBModeCipher_NoExceptionThrown() throws Exception{
caller.addRule(new ECBModeCipher());
caller.callRules();
caller.callRules("");

Assert.assertEquals(caller.getRules().size(), 1);
}

@Test
public void ruleCaller_callClearTextTraffic_NoExceptionThrown() throws Exception{
caller.addRule(new ClearTextTraffic());
caller.callRules();
caller.callRules("");

Assert.assertEquals(caller.getRules().size(), 1);
}
@Test
public void ruleCaller_callTLSTraffic_NoExceptionThrown() throws Exception{
caller.addRule(new TLSTraffic());
caller.callRules();
caller.callRules("");

Assert.assertEquals(caller.getRules().size(), 1);
}
@Test
public void ruleCaller_callAESCipher_NoExceptionThrown() throws Exception{
caller.addRule(new AESCipher());
caller.callRules();
caller.callRules("");

Assert.assertEquals(caller.getRules().size(), 1);
}
@Test
public void ruleCaller_callStaticIV_NoExceptionThrown() throws Exception{
caller.addRule(new StaticIV());
caller.callRules();
caller.callRules("");

Assert.assertEquals(caller.getRules().size(), 1);
}
@Test
public void ruleCaller_callHardcodedKeyInUrl_NoExceptionThrown() throws Exception{
caller.addRule(new HardcodedUrlInUrl());
caller.callRules();
caller.callRules("");

Assert.assertEquals(caller.getRules().size(), 1);
}
@Test
public void ruleCaller_callPathClassLoader_NoExceptionThrown() throws Exception{
caller.addRule(new PathClassLoaderCall());
caller.callRules();
caller.callRules("");

Assert.assertEquals(caller.getRules().size(), 1);
}
@Test
public void ruleCaller_callDexClassLoader_NoExceptionThrown() throws Exception{
caller.addRule(new DexClassLoaderCall());
caller.callRules();
caller.callRules("");

Assert.assertEquals(caller.getRules().size(), 1);
}
@Test
public void ruleCaller_callInsecureFilePermissions_NoExceptionThrown() throws Exception{
caller.addRule(new InsecureFilePermissions());
caller.callRules();
caller.callRules("");

Assert.assertEquals(caller.getRules().size(), 1);
}

@Test
public void ruleCaller_callInsecureSharedPreferences_NoExceptionThrown() throws Exception{
caller.addRule(new InsecureSharedPreferences());
caller.callRules();
caller.callRules("");

Assert.assertEquals(caller.getRules().size(), 1);
}

@Test
public void ruleCaller_callInsecureCommands_NoExceptionThrown() throws Exception{
caller.addRule(new InsecureCommands());
caller.callRules();
caller.callRules("");

Assert.assertEquals(caller.getRules().size(), 1);
}

@Test
public void ruleCaller_callWebviewInsecureSettings_NoExceptionThrown() throws Exception{
caller.addRule(new WebviewInsecureSettings());
caller.callRules();
caller.callRules("");

Assert.assertEquals(caller.getRules().size(), 1);
}

@Test
public void ruleCaller_callMobileOnlyDownloadManager_NoExceptionThrown() throws Exception{
caller.addRule(new MobileOnlyDownloadManager());
caller.callRules();
caller.callRules("");

Assert.assertEquals(caller.getRules().size(), 1);
}

@Test
public void ruleCaller_callInsecureRandom_NoExceptionThrown() throws Exception{
caller.addRule(new InsecureRandom());
caller.callRules();
caller.callRules("");

Assert.assertEquals(caller.getRules().size(), 1);
}

@Test
public void ruleCaller_callIntent_NoExceptionThrown() throws Exception{
caller.addRule(new IntentCall());
caller.callRules();
caller.callRules("");

Assert.assertEquals(caller.getRules().size(), 1);
}
Expand Down
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
Loading