Ex2 done
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.example.maliciousapp">
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.READ_INTERNAL_STORAGE" />
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
|
||||
@@ -1,16 +1,24 @@
|
||||
package com.example.maliciousapp;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import android.Manifest;
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
|
||||
public class HashfileActivity extends AppCompatActivity {
|
||||
@@ -20,10 +28,11 @@ public class HashfileActivity extends AppCompatActivity {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_hashfile);
|
||||
|
||||
Log.d("MOBIOTSEC", "Activity called oh yes");
|
||||
|
||||
Log.d("MOBIOTSEC", "Activity called..");
|
||||
|
||||
Intent intent = getIntent();
|
||||
String filePath = intent.getData().getPath();
|
||||
String filePath = intent.getData().getEncodedPath();
|
||||
|
||||
// calculate hash
|
||||
String hash = calcHash(filePath);
|
||||
@@ -34,19 +43,51 @@ public class HashfileActivity extends AppCompatActivity {
|
||||
setResult(Activity.RESULT_OK, resultIntent);
|
||||
finish();
|
||||
|
||||
|
||||
Log.d("MOBIOTSEC", "Activity finished..");
|
||||
}
|
||||
|
||||
static public String calcHash(String filePath) {
|
||||
public String calcHash(String filePath) {
|
||||
|
||||
if (this.isStoragePermissionGranted()) {
|
||||
|
||||
File file = new File(filePath);
|
||||
byte[] bytes = new byte[0];
|
||||
Log.d("MOBIOTSEC", "HELLOOOOO");
|
||||
int size = (int) file.length();
|
||||
byte[] bytes = new byte[size];
|
||||
try {
|
||||
bytes = FileUtils.readFileToByteArray(file);
|
||||
BufferedInputStream buf = new BufferedInputStream(new FileInputStream(file));
|
||||
buf.read(bytes, 0, bytes.length);
|
||||
buf.close();
|
||||
} catch (FileNotFoundException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
return DigestUtils.sha256Hex(bytes);
|
||||
|
||||
}
|
||||
else
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
public boolean isStoragePermissionGranted() {
|
||||
if (Build.VERSION.SDK_INT >= 23) {
|
||||
|
||||
if (checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE)
|
||||
== PackageManager.PERMISSION_GRANTED) {
|
||||
Log.d("MOBIOTSEC", "Permission is granted");
|
||||
return true;
|
||||
} else {
|
||||
|
||||
Log.d("MOBIOTSEC", "Permission is revoked");
|
||||
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, 1);
|
||||
return false;
|
||||
}
|
||||
} else { //permission is automatically granted on sdk<23 upon installation
|
||||
Log.d("MOBIOTSEC", "Permission is granted");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,9 +1,13 @@
|
||||
package com.example.maliciousapp;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
|
||||
import android.Manifest;
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
|
||||
@@ -19,37 +23,6 @@ public class MainActivity extends AppCompatActivity {
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
Intent intent = getIntent();
|
||||
Log.d("MOBIOTSEC", intent.toString());
|
||||
Log.d("MOBIOTSEC", "ACTION = " + intent.getAction());
|
||||
|
||||
if(intent.getAction() != null) {
|
||||
String filePath = intent.getData().getPath();
|
||||
|
||||
// calculate hash
|
||||
String hash = calcHash(filePath);
|
||||
|
||||
// return the hash in a "result" intent
|
||||
Intent resultIntent = new Intent();
|
||||
resultIntent.putExtra("hash", hash);
|
||||
setResult(Activity.RESULT_OK, resultIntent);
|
||||
finish();
|
||||
}
|
||||
|
||||
Log.d("MOBIOTSEC", "123 END HELLOOOOO");
|
||||
}
|
||||
|
||||
static public String calcHash(String filePath) {
|
||||
File file = new File(filePath);
|
||||
byte[] bytes = new byte[0];
|
||||
Log.d("MOBIOTSEC", "HELLOOOOO");
|
||||
try {
|
||||
bytes = FileUtils.readFileToByteArray(file);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return DigestUtils.sha256Hex(bytes);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
--------- beginning of main
|
||||
--------- beginning of system
|
||||
--------- beginning of kernel
|
||||
03-08 16:23:39.191 8344 8344 I MOBIOTSEC: /storage/emulated/0/YM3oPnYG.dat
|
||||
03-08 16:23:40.933 8372 8372 D MOBIOTSEC: Activity called oh yes
|
||||
03-08 16:23:40.933 8372 8372 D MOBIOTSEC: HELLOOOOO
|
||||
03-08 17:06:52.125 6728 6728 I MOBIOTSEC: /storage/emulated/0/YM3oPnYG.dat
|
||||
03-08 17:06:53.912 6771 6771 D MOBIOTSEC: Activity called..
|
||||
03-08 17:06:53.914 6771 6771 D MOBIOTSEC: Permission is granted
|
||||
03-08 17:06:53.946 6771 6771 D MOBIOTSEC: Activity finished..
|
||||
03-08 17:06:54.120 6728 6728 I MOBIOTSEC: Good job! The expected hash and the received hash match! The flag is FLAG{piger_ipse_sibi_obstat}
|
||||
|
||||
Reference in New Issue
Block a user