Skip to content

Commit

Permalink
Merge branch 'develop' into issues/89-add-apkthreat-flags
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasKypta authored Mar 19, 2024
2 parents f567d5e + fa72505 commit 04387ef
Show file tree
Hide file tree
Showing 19 changed files with 862 additions and 182 deletions.
8 changes: 5 additions & 3 deletions demoapp/www/css/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,17 @@ h1 {
padding:2px 0px;
background-color:orange;
}

#smart-protection-button, #set-user-id-button, #set-device-id-button {
#customer-identification, #av-features {
display: none;
}
.app-button {
margin-top: 12px;
background: #0088ff;
padding: 12px;
border: 0;
color: #fff;
border-radius: 4px;
display: none;
display: inline-block;
}
#smart-protection-result {
padding: 4px;
Expand Down
9 changes: 6 additions & 3 deletions demoapp/www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,19 @@ <h1>MALWARELYTICS</h1>
<p class="event failed">Failed to Initialize</p>
</div>
<div id="customer-identification">
<button id="set-user-id-button">Set Client ID</button>
<button id="set-device-id-button">Set Device ID</button>
<button class="app-button" id="set-user-id-button">Set Client ID</button>
<button class="app-button" id="set-device-id-button">Set Device ID</button>
</div>
<div id="android-controls">
<h2>Android demo</h2>
<div id="androidready" class="blink">
<p class="androidstate" id="temp_offline">Temporary offline mode</p>
<p class="androidstate" id="perm_offline">Permanent offline mode</p>
</div>
<button id="smart-protection-button">Run Smart Protection</button><br />
<div id="av-features">
<button class="app-button" id="smart-protection-button">Run Smart Protection</button>
<button class="app-button" id="last-update-info-button">Last Update Info</button>
</div>
<div id="smart-protection-result"></div>
<h3>Language</h3>
<select id="lang-select">
Expand Down
46 changes: 34 additions & 12 deletions demoapp/www/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ var demoApp = {
},
onDeviceReady: function () {
return __awaiter(this, void 0, void 0, function () {
var knownApps, e_1, userIdButton, deviceIdButton;
var knownApps, e_1, customerIdentification;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
Expand Down Expand Up @@ -117,12 +117,10 @@ var demoApp = {
return [2];
case 5:
this.setAppState(AppState.READY);
userIdButton = document.getElementById("set-user-id-button");
userIdButton.setAttribute('style', 'display:inline-block');
userIdButton.addEventListener("click", this.onChangeClientId);
deviceIdButton = document.getElementById("set-device-id-button");
deviceIdButton.setAttribute('style', 'display:inline-block');
deviceIdButton.addEventListener("click", this.onChangeDeviceId);
customerIdentification = document.getElementById("customer-identification");
customerIdentification.setAttribute('style', 'display:inline-block');
this.setButtonClick("set-user-id-button", this.onChangeClientId);
this.setButtonClick("set-device-id-button", this.onChangeDeviceId);
if (device.platform == "Android") {
this.configureAndroid();
}
Expand Down Expand Up @@ -340,7 +338,7 @@ var demoApp = {
},
configureAndroid: function () {
return __awaiter(this, void 0, void 0, function () {
var result, button, langSelect, isInitialized, list, itemPromises, enrichedItems, e_2, observer;
var result, avFeatures, updateObserver, langSelect, isInitialized, list, itemPromises, enrichedItems, e_2, observer;
var _this = this;
return __generator(this, function (_a) {
switch (_a.label) {
Expand All @@ -350,9 +348,32 @@ var demoApp = {
case 1:
result = _a.sent();
this.setAndroidState(result);
button = document.getElementById("smart-protection-button");
button.setAttribute('style', 'display:inline-block');
button.addEventListener("click", this.onRunSmartProtection);
avFeatures = document.getElementById("av-features");
avFeatures.setAttribute('style', 'display:inline-block');
this.setButtonClick("smart-protection-button", this.onRunSmartProtection);
this.setButtonClick("last-update-info-button", function () { return __awaiter(_this, void 0, void 0, function () {
var _a, _b, _c, _d;
return __generator(this, function (_e) {
switch (_e.label) {
case 0:
_a = alert;
_b = "last update info: ";
_d = (_c = JSON).stringify;
return [4, window.plugins.malwarelytics.android.antivirus.getLastUpdateInfo()];
case 1:
_a.apply(void 0, [_b + _d.apply(_c, [_e.sent()])]);
return [2];
}
});
}); });
updateObserver = {
onSuggestionUpdated: function (observedUpdateInfo) {
var filter = observedUpdateInfo.updateType === "FULL" ? ['updateResult', 'updateType', 'failureReason'] : ['updateResult', 'updateType', 'failureReason', 'checkedApps'];
var filteredUpdateInfo = JSON.stringify(observedUpdateInfo, filter);
console.log("Update observer: " + filteredUpdateInfo);
}
};
window.plugins.malwarelytics.android.antivirus.setUpdateObserver(updateObserver);
this.setButtonClick("is-rooted-button", function () { return __awaiter(_this, void 0, void 0, function () {
var _a, _b;
return __generator(this, function (_c) {
Expand Down Expand Up @@ -790,7 +811,8 @@ var demoApp = {
emulatorDetected: function (emulatorDetection) { console.log("RASP EMULATOR DETECTED " + JSON.stringify(emulatorDetection)); },
repackagingDetected: function (repackagingResult) { console.log("RASP REPACKAGING DETECTED " + JSON.stringify(repackagingResult)); },
rootDetected: function (rootDetection) { console.log("RASP ROOT DETECTED " + JSON.stringify(rootDetection)); },
screenSharingDetected: function (screenSharingDetected) { console.log("RASP SCREEN SHARING DETECTED " + screenSharingDetected); },
screenSharingDetected: function (screenSharingDetection) { console.log("RASP SCREEN SHARING DETECTED " + JSON.stringify(screenSharingDetection)); },
screenReaderDetected: function (screenReaderDetection) { console.log("RASP SCREEN READER DETECTED " + JSON.stringify(screenReaderDetection)); },
tapjackingDetected: function (tapjackingDetection) { console.log("RASP TAPJACKING DETECTED " + JSON.stringify(tapjackingDetection)); },
httpProxyDetected: function (httpProxyDetection) { console.log("RASP HTTP PROXY DETECTED " + JSON.stringify(httpProxyDetection)); },
vpnDetected: function (vpnEnabled) { console.log("RASP VPN DETECTED " + vpnEnabled); },
Expand Down
33 changes: 22 additions & 11 deletions demoapp/www/js/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,10 @@ var demoApp = {

this.setAppState(AppState.READY);

let userIdButton = document.getElementById("set-user-id-button");
userIdButton.setAttribute('style', 'display:inline-block');
userIdButton.addEventListener("click", this.onChangeClientId);
let deviceIdButton = document.getElementById("set-device-id-button");
deviceIdButton.setAttribute('style', 'display:inline-block');
deviceIdButton.addEventListener("click", this.onChangeDeviceId);
let customerIdentification = document.getElementById("customer-identification");
customerIdentification.setAttribute('style', 'display:inline-block');
this.setButtonClick("set-user-id-button", this.onChangeClientId);
this.setButtonClick("set-device-id-button", this.onChangeDeviceId);

if (device.platform == "Android") {
this.configureAndroid();
Expand Down Expand Up @@ -162,10 +160,22 @@ var demoApp = {
let result = await window.plugins.malwarelytics.android.getInitializationResult();
this.setAndroidState(result);

let button = document.getElementById("smart-protection-button");

button.setAttribute('style', 'display:inline-block');
button.addEventListener("click", this.onRunSmartProtection);
let avFeatures = document.getElementById("av-features");
avFeatures.setAttribute('style', 'display:inline-block');
this.setButtonClick("smart-protection-button", this.onRunSmartProtection);

this.setButtonClick("last-update-info-button", async () => {
alert("last update info: " + JSON.stringify(await window.plugins.malwarelytics.android.antivirus.getLastUpdateInfo()));
});

let updateObserver: MalwarelyticsAndroidUpdateObserver = {
onSuggestionUpdated(observedUpdateInfo: ObservedUpdateInfo) {
const filter = observedUpdateInfo.updateType === "FULL" ? ['updateResult', 'updateType', 'failureReason'] : ['updateResult', 'updateType', 'failureReason', 'checkedApps'];
const filteredUpdateInfo = JSON.stringify(observedUpdateInfo, filter)
console.log("Update observer: " + filteredUpdateInfo);
}
};
window.plugins.malwarelytics.android.antivirus.setUpdateObserver(updateObserver);

// observable features

Expand Down Expand Up @@ -343,7 +353,8 @@ var demoApp = {
emulatorDetected(emulatorDetection: EmulatorDetection) { console.log("RASP EMULATOR DETECTED " + JSON.stringify(emulatorDetection)); },
repackagingDetected(repackagingResult: RepackagingResult) {console.log("RASP REPACKAGING DETECTED " + JSON.stringify(repackagingResult)); },
rootDetected(rootDetection: RootDetection) { console.log("RASP ROOT DETECTED " + JSON.stringify(rootDetection)); },
screenSharingDetected(screenSharingDetected: boolean){ console.log("RASP SCREEN SHARING DETECTED " + screenSharingDetected); },
screenSharingDetected(screenSharingDetection: ScreenSharingDetection) { console.log("RASP SCREEN SHARING DETECTED " + JSON.stringify(screenSharingDetection)); },
screenReaderDetected(screenReaderDetection: ScreenReaderDetection) { console.log("RASP SCREEN READER DETECTED " + JSON.stringify(screenReaderDetection)); },
tapjackingDetected(tapjackingDetection: TapjackingDetection) { console.log("RASP TAPJACKING DETECTED " + JSON.stringify(tapjackingDetection)); },
httpProxyDetected(httpProxyDetection: HttpProxyDetection) { console.log("RASP HTTP PROXY DETECTED " + JSON.stringify(httpProxyDetection)); },
vpnDetected(vpnEnabled: boolean) { console.log("RASP VPN DETECTED " + vpnEnabled); },
Expand Down
40 changes: 40 additions & 0 deletions docs/Android-Anti-Malware-Feature.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,46 @@ list.items.filter(i => i.threatIndex == "MALWARE" || i.threatIndex == "HIGHLY_DA
Threat mitigation UI of the smart protection can be [customized](./Android-Anti-Malware-UI-Configuration.md)
in the `malwarelytics.xml`.
## Getting Info About Updates
There are two ways to obtain an info about data updates:
- Getting the last update info
- Using an update observer to be notified about performed updates
These update info data are useful primarily for troubleshooting.
### Getting Last Update Info
Last update info can be obtained via:
```js
const lastUpdateInfo = await window.plugins.malwarelytics.android.antivirus.getLastUpdateInfo()
```
The returned object contains info about successful and unsuccessful updates for each type of update (`UpdateType.FULL` and `UpdateType.PARTIAL`).
### Using Update Observer
Update observer can be set via:
```js
let updateObserver: MalwarelyticsAndroidUpdateObserver = {
onSuggestionUpdated(observedUpdateInfo: ObservedUpdateInfo) {
console.log("Update observer data: " + JSON.stringify(observedUpdateInfo));
}
}
window.plugins.malwarelytics.android.antivirus.setUpdateObserver(updateObserver);
```
The `ObservedUpdateInfo` contains information about the result, type of update, list of apps that were checked, list of apps that received update data, and failure reason.
When the updates are no longer desired, the observer can be cleared with:
```js
window.plugins.malwarelytics.android.antivirus.clearUpdateObserver();
```
## Read Next
- [Configuration of the Anti-Malware UI](./Android-Anti-Malware-UI-Configuration.md)
3 changes: 2 additions & 1 deletion docs/RASP-Feature-Overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ let observer: MalwarelyticsAndroidRASPObserver = {
emulatorDetected(emulatorDetection: EmulatorDetection) { console.log("RASP EMULATOR DETECTED " + JSON.stringify(emulatorDetection)); },
repackagingDetected(repackagingResult: RepackagingResult) {console.log("RASP REPACKAGING DETECTED " + JSON.stringify(repackagingResult)); },
rootDetected(rootDetection: RootDetection) { console.log("RASP ROOT DETECTED " + JSON.stringify(rootDetection)); },
screenSharingDetected(screenSharingDetected: boolean){ console.log("RASP SCREEN SHARING DETECTED " + screenSharingDetected); },
screenSharingDetected(screenSharingDetection: ScreenSharingDetection) { console.log("RASP SCREEN SHARING DETECTED " + screenSharingDetected); },
screenReaderDetected(screenReaderDetection: ScreenReaderDetection) { console.log("RASP SCREEN READER DETECTED " + JSON.stringify(screenReaderDetection)); }
tapjackingDetected(tapjackingDetection: TapjackingDetection) { console.log("RASP TAPJACKING DETECTED " + JSON.stringify(tapjackingDetection)); },
httpProxyDetected(httpProxyDetection: HttpProxyDetection) { console.log("HTTP PROXY DETECTED " + JSON.stringify(httpProxyDetection)); },
vpnDetected(vpnEnabled: boolean) { console.log("RASP VPN DETECTED " + vpnEnabled); },
Expand Down
1 change: 1 addition & 0 deletions docs/Release-Notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Release 5.1.1-dev

- Update Malwarelytics for Android to 1.1.0 (#87)
- Update ApkThreat with flags (#89)


Expand Down
82 changes: 61 additions & 21 deletions scripts/android/MalwarelyticsAndroidAntivirus.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,72 @@
/**
* Antivirus component of the Malwarelytics for Android.
*/
* Antivirus component of the Malwarelytics for Android.
*/
class MalwarelyticsAndroidAntivirus extends __MPAndroidService {

/**
* Schedules a job that will execute smart protection run. Note that this is asynchronous and
* can take some time.
*
* @param performOnlineUpdate Optional argument to indicate that online update is not desired.
* If false only local data will be used.
*/
* Schedules a job that will execute smart protection run. Note that this is asynchronous and
* can take some time.
*
* @param performOnlineUpdate Optional argument to indicate that online update is not desired.
* If false only local data will be used.
*/
async triggerSmartProtection(performOnlineUpdate: Boolean = true): Promise<SmartProtectionResult> {
return await this.callAsync("triggerSmartProtection", performOnlineUpdate);
return await this.callAsync("triggerSmartProtection", performOnlineUpdate);
}

/**
* Returns list of all applications with the malware evaluation.
*/
async getThreatList(): Promise<{items: ApkThreat[]}> {
return await this.callAsync("getThreatList");
* Returns list of all applications with the malware evaluation.
*/
async getThreatList(): Promise<{ items: ApkThreat[] }> {
return await this.callAsync("getThreatList");
}

/**
* Gets more information for the package name of the application.
*
* @param packageName Package name of the application
*/
* Gets more information for the package name of the application.
*
* @param packageName Package name of the application
*/
async getApkInfo(packageName: String): Promise<ApkInfo> {
return await this.callAsync("getApkInfo", packageName);
return await this.callAsync("getApkInfo", packageName);
}

/**
* Get information about the last updates.
*
* Primarily intended for troubleshooting.
*
* @returns Information about latest update successes and failures.
*/
async getLastUpdateInfo(): Promise<UpdateInfo> {
return await this.callAsync("getLastUpdateInfo");
}

/** Set observer that is triggered when a suggestion update completes. */
setUpdateObserver(observer: MalwarelyticsAndroidUpdateObserver) {
return this.call("setUpdateCallback", (result: { payload: ObservedUpdateInfo }) => {
observer.onSuggestionUpdated(result.payload);
}, null);
}
}

/** Clear observer for suggestion updates. */
clearUpdateObserver() {
this.call("clearUpdateCallback", null, null);
}
}

/** Observer for update results. */
interface MalwarelyticsAndroidUpdateObserver {
/**
* Called when an update was finished regardless of a success or a failure.
*
* Returned data indicated the update result:
* - Successful update:
* @see ObservedUpdateInfo.failureReason is null
* - Partially successful update:
* @see ObservedUpdateInfo.failureReason is not null
* and @see ObservedUpdateInfo.updatedApps is not empty
* - Failed update:
* and @see ObservedUpdateInfo.failureReason is not null
* and @see ObservedUpdateInfo.updatedApps is empty */
onSuggestionUpdated(observedUpdateInfo: ObservedUpdateInfo): void;
}
Loading

0 comments on commit 04387ef

Please sign in to comment.