<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Sirack Hailu on Medium]]></title>
        <description><![CDATA[Stories by Sirack Hailu on Medium]]></description>
        <link>https://medium.com/@sirackh?source=rss-823af4078647------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*qFu8waYE7jP8V-yE1cFJog.jpeg</url>
            <title>Stories by Sirack Hailu on Medium</title>
            <link>https://medium.com/@sirackh?source=rss-823af4078647------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 12:33:01 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sirackh/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Is detecting mobile compromise a losing game?]]></title>
            <link>https://sirackh.medium.com/is-detecting-mobile-compromise-a-losing-game-def0061cd2cf?source=rss-823af4078647------2</link>
            <guid isPermaLink="false">https://medium.com/p/def0061cd2cf</guid>
            <dc:creator><![CDATA[Sirack Hailu]]></dc:creator>
            <pubDate>Fri, 20 Oct 2023 13:02:53 GMT</pubDate>
            <atom:updated>2023-10-20T13:02:53.338Z</atom:updated>
            <content:encoded><![CDATA[<p>Detecting mobile compromise is not easy. Mobile OSs put heavy restrictions on what can be done by an app or analysis tool. Even though the intention is good, it limits the available options for blue team engineers to evaluate and protect the device. Over the years sophisticated tools like MagikHide, LibertyOS, HideJB, etc have found ways of masking root &amp; jailbreak making detection even harder.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/0*xjCbgGBrraqd4Lkg.jpeg" /></figure><h4>The old way</h4><p>This is where it starts. A compromise leaves traces of evidence. This includes the presence of su/busybox/privileged apps, etc. Even though the mere presence of these tools doesn’t necessarily mean a device is compromised, it’s a good place to start an investigation. Similar checks look for installed apps, system configs, boot loader lock states that indicate a device might be compromised. Then came tools like Magisk, LibertyOS, Zygisk and made detecting the above traces very difficult if not impossible.</p><h4>The new way</h4><p>The next iteration of detection methods try to detect these new tools. This made the detection logic tool specific but important nonetheless. These hiders are easy to install and use. Ordinary folks with limited technical knowledge are capable of using them to bypass root detecting apps. There are numerous forums on XDA discussing the various ways to bypass restrictions levied by banking apps, games &amp; other licensed apps.</p><h4>The future</h4><p>With the advent of a hardware-backed trusted execution environment, the tide is turning in favor of blue team engineers. TEE is a special environment that’s separate from the operating system both physically and logically. There is a dedicated hardware chip tasked with storing key material securely. Compromising this environment is very hard! Google’s Pixel phones come with <a href="https://safety.google/intl/en_us/pixel/">Titan M</a>. Code executed inside this chip is considered safe. An attacker needs to compromise both the OS and this chip to be able to bypass the root. To this day there are only two vulnerabilities found (CVE-2021–0449 &amp; CVE-2021–0453). iOS has something equivalent called <a href="https://support.apple.com/en-lamr/guide/security/sec59b0b31ff/web">Secure Enclave</a>.</p><p>From the application side, we will need to generate a keypair and store it on the dedicated chip. The generated key material contains metadata about the operating system state. This piece of information reveals whether a device is rooted or not. Let’s see this in action.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*XHftkWlH7kbGjzOv.png" /></figure><ol><li>Obtain randomly generated nonce from the server</li><li>Use a KeyStore object’s getCertificateChain() method to get a reference to the chain of X.509 certificates associated with the hardware-backed keystore.</li><li>Check each certificate’s validity using a X509Certificate object’s checkValidity() method. Also verify that the root certificate is trustworthy.</li><li>On a separate server that you trust, obtain a reference to the ASN.1 parser library that is most appropriate for your toolset. Use this parser to extract the attestation certificate extension data, which appears within the first element of the certificate chain.</li><li>Compare the extension data that you’ve retrieved from your ASN.1 parser with the set of values that you expect the hardware-backed key to contain.</li></ol><p>The above steps are adapted from the official doc from <a href="https://developer.android.com/training/articles/security-key-attestation">here</a></p><p>Below is the output from the server side. It’s from a rooted Android 12 Pixel 3a device</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1SdFTDs7VTxSwJF1.png" /></figure><p>As you can see, there is a “Root of Trust” block that has four properties under it. The most important line is device locked &amp; boot state. These values should be true &amp; VERIFIED for non-compromised devices. There are many more checks that the server needs to complete before fully trusting the device. These include checking for certificate validity (including revocation status), attestation security level (indicates whether the keypair is generated on hardware-backed TEE). Software backed keypairs are not as secure as hardware-based ones. This doesn’t mean the device is compromised. We can only be neutral or possibly categorize it under “not trusted” if we are operating under stricter requirements.</p><p>For comparison, here is the extension data for non-rooted Android 10 device.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*rC2zECmAGKCmgzJ1.png" /></figure><h4>Conclusion</h4><p>The discussed methods are implemented in <a href="https://pwned.report/">Pwned Report</a>. Be sure to give it a try!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*FNx0Yzu-QkNyA5FN.png" /></figure><p><em>Originally published at </em><a href="https://ismyapppwned.com/2022/08/17/is_detecting_compromise_loosing_game/"><em>https://ismyapppwned.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=def0061cd2cf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introducing Pwned Report]]></title>
            <link>https://sirackh.medium.com/introducing-pwned-report-32bca177206f?source=rss-823af4078647------2</link>
            <guid isPermaLink="false">https://medium.com/p/32bca177206f</guid>
            <dc:creator><![CDATA[Sirack Hailu]]></dc:creator>
            <pubDate>Fri, 20 Oct 2023 13:01:07 GMT</pubDate>
            <atom:updated>2023-10-20T13:01:07.735Z</atom:updated>
            <content:encoded><![CDATA[<p>In this post, I will give introduction to <a href="https://pwned.report/">Pwned Report</a>. A side project I have been working on that scans your device for vulnerability or suspected compromise. More than ever, people are aware attackers can take over their devices using sophisticated methods. But, it’s mere suspicion for most. Phrases like my phone going haywire, some app is eating my data, my battery is not lasting long, etc are potential signs of compromise either by malware or an unauthorized party.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*JdxT7-6rmP54dwIF.png" /></figure><h3>Initiation</h3><p>The most important requirement while designing Pwned Report is to reduce the friction of installing an app or tool to analyze your device. It should be as simple as clicking a button and waiting for a result. Many sophisticated tools claim to scan your device and overwhelm the user with configurations, cumbersome UI, and technical jargon that most people don’t understand. I wanted Pwned Report be dead simple. A single click and you have your result. There are drawbacks which I will discuss later on. But at this point, I have chosen simplicity over functionality.</p><p>Secondly, it’s increasingly difficult to assess the security posture of a device just by analyzing a single device. Google &amp; Apple are closing down APIs in the name of privacy and sensitivity which is hindering the detection routines. Hence, a different approach is needed where behavior and patterns across thousands of devices should be observed to make meaningful conclusions.</p><h3>Components</h3><p>Pwned Report has three components</p><ol><li>Instant app — A tiny instant app (Less than 2MB). You won’t need to install it from GooglePlay store. It launches automatically when you visit <a href="https://pwned.report/scan/V9Hh">Scan</a>. This choice was deliberately taken to avoid installing an app.</li><li>Site — A landing page where users come to scan their devices. There is a single action button that instructs users to commence scanning. Once clicked, the instant app will launch and start scanning the device</li><li>Backend — After scanning the device, any IOC, device usage patterns will be shipped to the server for analysis and tagging. No PII will be associated thereby preserving the user’s privacy</li></ol><h3>Internals</h3><p>Pwned Report attempts to determine if your device is compromised by using different techniques. First, it checks if your device is rooted/jailbroken. This action is deliberately done by the user or nefariously by an unauthorized party. This check is comprised of multiple sub-tasks that scan for the presence of su (super-user), altered system partitions, modified configurations, etc. Secondly, it uses past usage patterns to look for odd signals that might be linked to compromise. These include suspicious apps that were installed, an app consuming (especially outbound/egress) data, an app with sensitive permission running in the background for prolonged intervals, etc</p><p>The first part of the check is static where the app looks for known IOC. This is what most “root checkers” on GooglePlay store do while the second part of the check relies on patterns that resemble malicious actors or have previously been reported as malicious. This is where Pwned Report shines. By aggregating usage patterns from thousands of devices, it can classify patterns that are dangerous, suspicious, or normal.</p><h3>Drawbacks</h3><p>AndroidOS puts a stricter limitation on what an instant app can access. These include permission, less visibility to installed apps, size of the app, etc. Hence, not all checks are performed during instant app scan and are deferred at a later point when the full app is installed. Secondly, judging compromise based on usage patterns is susceptible to false positives. It needs large data from multiple device profiles to reliably classify compromised devices.</p><h3>Try it out</h3><p>Visit <a href="https://pwned.report/">Pwned Report</a> to try it out. There are multiple backlog items that are on the pipeline. I will be sharing details in the coming weeks. Stay tuned!</p><p><em>Originally published at </em><a href="https://ismyapppwned.com/2022/05/30/pwned_report_introduction/"><em>https://ismyapppwned.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=32bca177206f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The curious case of banking trojans]]></title>
            <link>https://sirackh.medium.com/the-curious-case-of-banking-trojans-5bd351cb8e9b?source=rss-823af4078647------2</link>
            <guid isPermaLink="false">https://medium.com/p/5bd351cb8e9b</guid>
            <category><![CDATA[trojan]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[mobile-security]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <dc:creator><![CDATA[Sirack Hailu]]></dc:creator>
            <pubDate>Tue, 03 Aug 2021 12:41:05 GMT</pubDate>
            <atom:updated>2021-08-03T13:14:24.003Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://ismyapppwned.com/2021/07/10/banking_trojans/"><strong>Permanent link to this post ➜</strong></a></p><p>Banking trojans are a class of trojans that target financial apps to steal user’s credentials to commit some kind of banking fraud. Different trojans employ different kinds of techniques to trick users into providing their credentials.</p><p>These range from simple impersonation to complex vulnerability exploitation. In this article, I will discuss these techniques and analyze over 2000+ banking trojans for possible similarities.</p><h4>Techniques</h4><p>Most techniques revolve around tricking the user to provide his/her banking login password or steal two factor authentication tokens. Most trojans misuse/abuse features provided by the operating system to their advantage. Over the years, the Android OS has been cracking down on framework APIs &amp; features that can potentially expose sensitive information. It has implemented hurdles that include protecting sensitive actions with permission, depreciate dangerous APIs, apps that utilize private APIs, etc. These measures have obviously reduced the attack surface but haven’t completely eliminated them. Moreover, attackers keep coming up with workarounds to bypass restrictions imposed by the OS &amp; Google Play store.</p><h4>Exploiting accessibility permission</h4><p>Most operating systems provide some kind of accessibility feature that allows disabled users to use their operating system. Voice narration is a good example. An artificially sensitized voice reads what’s currently shown on the screen. The platform exposes APIs for developers to build features for addressing accessibility gaps within the OS. Unfortunately, this has allowed attackers to misuse it for malicious intent</p><pre>&lt;service android:name=&quot;.service.AppAccessibilityService&quot;<br>  android:permission=&quot;android.permission.BIND_ACCESSIBILITY_SERVICE&quot;<br>  android:label=&quot;@string/accessibility_service_label&quot;&gt;<br>  &lt;intent-filter&gt;<br>      &lt;action android:name=&quot;android.accessibilityservice.AccessibilityService&quot; /&gt;<br>  &lt;/intent-filter&gt;<br><br>  &lt;meta-data<br>      android:name=&quot;android.accessibilityservice&quot;<br>      android:resource=&quot;@xml/accessibility_service_config&quot; /&gt;<br>&lt;/service&gt;</pre><h4>Notification permission</h4><p>This permission allows developers to get notified when app notifications are posted to the system tray. This lets malicious actors snoop on users by reading any messages that are visible on the tray. Notification messages can hold very sensitive infos including second-factor auth tokens, private chat messages, authenticator tokens, etc. Additionally, attackers use such events as a signal to launch actual attacks. Recently, a new wormhole was found by CheckPoint that auto replies to whatsapp messages with phishing websites</p><p><a href="https://www.instagram.com/p/CNXpGCZAv36">Credit</a>. You can read more about this <a href="https://research.checkpoint.com/2021/new-wormable-android-malware-spreads-by-creating-auto-replies-to-messages-in-whatsapp/">here</a></p><h4>Privilege Escalation</h4><p>There is a class of apps that exploit system vulnerability to gain root access. Such access will allow the app to have unlimited access to all sensitive information. Both system &amp; user data will be compromised. This is especially true on older versions of Android. It is increasingly difficult to find these exploits and if found they are used for targeting individuals (state actors) than for the masses (bank users or mid-sized companies)</p><h4>Overlay</h4><p>Application overlay permits an attacker to draw on top of any window and application running on the infected device. First, malicious applications monitor which applications are started by the user on the infected system. Once the malware detects an app (e.g. banking or payment facilitating) it will redraw an exact login screen on top of the legitimate one. The user is incapable of distinguishing the fake from the original and enters his credentials in the wrong dialog. The malware will then upload the stolen credentials to its Command &amp; Control server.</p><figure><img alt="Overlay attack flow. Credit screenshot for accessibility permission &amp; impersonating UI is taken from f-secure" src="https://cdn-images-1.medium.com/max/1024/0*lHur1YIVe2SWDm9k.png" /><figcaption>Overlay attack flow. Credit screenshot for accessibility permission &amp; impersonating UI is taken from <a href="https://labs.f-secure.com/blog/how-are-we-doing-with-androids-overlay-attacks-in-2020/">f-secure</a></figcaption></figure><h4>Exploitability Index</h4><p>From an attackers point of view, each of the discussed methods have their own pros and cons. I call this exploitability index. It measures the difficulty in exploiting OS gaps vs the ease of delivering malicious payload. For example, privilege escalation is the hardest to exploit but relatively easier to deliver (a simple installation would do the trick). Another class of trojans requires the user to take extra steps before the actual malicious payload executes. A good example is an unsuspecting user heading to settings to enable accessibility permission.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/532/0*6kIQtsvTthbCwlff.png" /></figure><h4>Analysis</h4><p>Below, I analyzed over 2k+ banking trojans that were collected from VirusTotal between 2017–2018. They had been classified as “banking trojans” by at least 10 vendors. The dataset might not be big enough to make meaningful conclusions but will provide good insight into trends and popular methods used. Here are few questions that we are trying to answer</p><ol><li>How many trojans exploit accessibility/notification permission?</li><li>How many trojans rely on dangerous telephony permissions?</li><li>How man malicious apps misuse overlay alert?</li><li>Is there code reuse between these apps? Can we create a cluster of apps that use the same malicious code?</li></ol><p>To help with this analysis, I will be using <a href="https://appdetonator.run/">App Detonator</a>. App detonator is an API-based analysis engine where samples are detonated in a sandboxed environment for static &amp; dynamic analysis. Static detonation is really fast. Depending on the size of the app, it takes somewhere between 5–10 seconds. Such analysis provides us with details about app signing certificate, manifest entries, dex class &amp; method used, native code details, etc. With these, we can safely answer #1, #2 &amp; #3. I will come to #4 later on</p><p>Here is a sample response from <em>/analyze</em> API.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*N31jA2R8FsNC7l3P.png" /></figure><p>We now proceed to detonating 2506 banking trojan samples. Here is a <a href="https://gist.github.com/atlantis0/854a8b73fd0f958e900b9eda1a6608da">python script</a> that iterates through malicious trojans and generate the report needed.</p><pre>Accessabiblity permission count 9<br> Notification permission count 2<br> Dangerous telephony permission count 1850<br> SYSTEM_ALERT_WINDOW permission count 1080</pre><p>Looks like our dataset is skewed towards apps that utilize telephony permission &amp; apps that misuse the system alert feature. 73% of apps at least contain <em>RECEIVE_SMS</em>, <em>SEND_SMS</em>, <em>READ_SMS</em>, <em>READ_CONTACTS</em> or <em>CALL_PHONE</em></p><p>To answer our fourth question, we need to analyze the actual code which is buried inside classes.dex file. There are different methodologies that we can employ to check if two apps are using the same code. Fuzzy hash solutions like <a href="https://ssdeep-project.github.io/ssdeep/index.html">ssdeep</a> generate a similarity digest by dividing a file into segments using the rolling Hash method, unlike the existing hashing method that guarantees integrity. But ssdeep is very generic. But it would be nice if these fuzzy hashes take into account the structure of dex file. <a href="https://www.virusbulletin.com/virusbulletin/2019/11/dexofuzzy-android-malware-similarity-clustering-method-using-opcode-sequence/">Dexofuzzy</a> is a project that parses the dex file inside the APK file to extract the opcode, and the extracted features are used to generate similarity digests using ssdeep. The features are also used to search for similar malicious code by tokenizing the generated Dexofuzzy to N-gram size and using the sliding window technique.</p><pre>$ dexofuzzy -f 09f2b02d23754bbda99f93c97cf832287e9527b98a70be1ca8186069a999d727.apk<br>  768:1DaLb5+PRGF3JtZZVtbJx+QgfdmpcFVdvS3lkM5672b:1av8PRGF3fZrt9gfdmpc9K4Sb</pre><p>Next, we cluster these apps into groups whose N-gram token match. Here we choose n to be 20 allowing us to group the most similar apps into a single cluster. Here is an interactive graph that shows 44 clusters and the top classes used y apps in these clusters. We can clearly deduct that telephony-based trojans dominate.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/668/0*vEI4shCOd-FZ9ePo.png" /></figure><p><a href="https://observablehq.com/@atlantis0/malware_cluster_n_20">Click here for interactive chart</a></p><p>What happens if we set n to be 7. Obviously, there will be more clusters and we will start to see different class &amp; methods used. Besides telephony framework APIs, classes such as <strong>Lcom/mix/kr/SMSReceiver$1</strong>, <strong>Lcom/mix/kr/Contact$1</strong>, etc are found in 29 apps. Hence, there is a code reuse among these apps.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/728/0*jnukZg3W154TIPl9.png" /></figure><p><a href="https://observablehq.com/@atlantis0/malware_cluster_n_7">Click here for interactive chart</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/836/0*36NOa5pRJvzoii1D.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5bd351cb8e9b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Privacy Grade for Apps]]></title>
            <link>https://sirackh.medium.com/privacy-grade-for-apps-fe793da5539e?source=rss-823af4078647------2</link>
            <guid isPermaLink="false">https://medium.com/p/fe793da5539e</guid>
            <category><![CDATA[privacy]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Sirack Hailu]]></dc:creator>
            <pubDate>Tue, 18 May 2021 12:12:28 GMT</pubDate>
            <atom:updated>2021-05-18T12:12:28.484Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://ismyapppwned.com/2020/11/19/privacy_model_apps/"><strong>Permanent link to this post ➜</strong></a></p><h3>Introduction</h3><p>Personal devices are ubiquitous. We carry them around everywhere we go and give them unprecedented access to our private/sensitive information. Where we work, live &amp; sleep, etc. Tech giants like Google and Facebook have found ways to aggregate this information and sell it to different companies in search of potential customers. Data collection is a big part of this process. Google with its Android ecosystem is in a unique position to control this flow of data between our devices and its servers. Apple in its part controls the same with its iOS platform. On top of these platforms, third-party developers publish different apps that collect their copy of our private information and accumulate it on their own servers (E.g. Facebook) or send it to Advertising companies. To make matters worse, data broker companies aggregate data from various sources and sell back “enhanced” data to customers looking to advertise their products.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/251/0*kbQXTeJ5iUfWoNTE.png" /></figure><p>In this article, I will review how data is collected, categorized, and processed on our mobile devices along with the permission model needed to access it. We will mostly focus on Android but most of the concepts hold for iOS unless specified otherwise.</p><h3>Current model &amp; safeguards</h3><p>Obtaining sensitive information can be achieved by various means.</p><ol><li>Asking users — Apps ask users to provide email, phone, name or other information via form like UIs. The user is aware of the implication behind these forms and willingly provide them with less suspicion</li><li>Request OS level permission — Some device level operations such as location, camera &amp; microphone will need to go through the OS. The OS requests these permissions on the app’s behalf. The assumption behind this model is — user understands the risk associated with granting such permissions. In reality, users skim through such dialogs and are in the habit of pressing “Ok” for the sake of completing what’s required on the screen</li><li>Inference — Not all APIs are protected by permissions. This opens up the possibility for apps to collect device level properties to build a fingerprint model to attribute a user with his/her physical device. This allows advertisers to track the user across apps and eases the process of attribution</li></ol><p>Over the years, Google has been reviewing how permissions work. It began by granting app permissions at install time. Users are presented with list of permissions during installation. Once accepted, there is no way to revoke/revert such decisions. More recently, Google introduced the concept of runtime permissions allowing users the ability to grant/deny individual permissions during it’s lifecycle. With Android 11, Google released a set of APIs for Auditing permission usage giving much needed visibility into access behavior. <a href="https://developer.android.com/about/versions/11/privacy/data-access-auditing">https://developer.android.com/about/versions/11/privacy/data-access-auditing</a>. This powerful API allows developers and sys integrators to assess permission usage more transparently.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Fdl1Q1AKaqONrFCU.png" /></figure><h3>Privacy grade</h3><p>To evaluate the privacy risk associated with an app, we have to look at different parameters. The most important behavior is advertising tracker. How many trackers do an app have? How frequently are they contacted? Besides know trackers, (Google Ad mob, Facebook Audience network, etc), the app itself might collect and send it to its own servers. We can model these as third-party trackers. Another indicator is how often permissions are accessed and the context around its request. Is it appropriate for GPS tracking app to request contact permission? This also raises the question of vulnerability. Does the app contain loopholes for an attacker to exploit? Does the exploit allow him/her to export private data? Is the OS environment secure enough to shield private app data from begin accessed by malicious actors? i.e. is the device rooted/jailbroken?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/514/0*k-N1OeBNpp9y0sQf.png" /></figure><p>Each evaluation vector will be graded out of 10 based on its severity impact. For example, if 10 trackers are sending sensitive info every 30 minutes, it will be assigned the worst possible score (0/10). The same will be done for the remaining vectors. Finally, we can sum up the scores to get an average score. The scoring can be enhanced by attaching a weight to individual vectors. Higher weight will influence the final score as compared to vectors with lower weight</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/868/0*lru9PqS2JWOFohR7.png" /></figure><p>A score above 80% will be considered the safest while scores between 0–40% will need to be scrutinized further because its privacy practice might be questionable.</p><h3>Implementation</h3><p>Implementing this system requires an app to be analyzed both statically and dynamically. Dynamic analysis will reveal the app’s traffic and the possible presence of ad trackers. Other vectors are harder to evaluate. For example, to audit permission, we can inspect the app’s manifest entries but the frequency of access and context will need to be determined by obtaining device logs (Running app on a rooted device) or by injecting monitoring code inside the app. Even though it’s relatively easy to do this for one app, automating for larger set of apps will be a challenge. I will be working on a POC version of this system which I will be sharing in the coming weeks. Stay tuned.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fe793da5539e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Android meet ElasticBeats — Architecting lightweight endpoint sensor]]></title>
            <link>https://sirackh.medium.com/android-meet-elasticbeats-architecting-lightweight-endpoint-sensor-f38d758e8b5a?source=rss-823af4078647------2</link>
            <guid isPermaLink="false">https://medium.com/p/f38d758e8b5a</guid>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[endpoint-security]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[elasticsearch]]></category>
            <dc:creator><![CDATA[Sirack Hailu]]></dc:creator>
            <pubDate>Tue, 18 May 2021 12:08:19 GMT</pubDate>
            <atom:updated>2021-05-18T12:13:27.725Z</atom:updated>
            <content:encoded><![CDATA[<h3>Android meet ElasticBeats — Architecting lightweight endpoint sensor</h3><p><a href="https://ismyapppwned.com/2021/02/26/elastic_beats_android/"><strong>Permanent link to this post ➜</strong></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/0*VNPRBez3Vri5dJfs.png" /></figure><h3>Introduction</h3><p>This blog aims to explore how one can build a lightweight endpoint sensor for mobile capable of collecting device meta-data, forensics, and potential indicators of compromise using ELK stack. Most endpoint management solutions have some kind of backend that processes data from agent apps. Engineering spends a considerable amount of time building, maintaining, optimizing numerous backend services to make sense of this data.</p><p><a href="https://www.osquery.io/">OSquery</a>, even though it is for desktop/server platform, alleviated this problem by allowing administrators to query a device using SQL-like statements. This lead to countless security products which applied querying, merging &amp; aggregating techniques on endpoint data. But OSquery is not available for mobile, necessitating the need to architect such a system for mobile (Android/iOS).</p><p>In this article, I will try to build such a system using ELK and a lightweight endpoint sensor based on <a href="https://www.elastic.co/beats/">ElasticBeats</a>. ElasticBeats is designed to collect and transport data from a given source (server/desktop/container/pod) to ElasticSearch. There are “pre-made” beats for different use-cases. E.g. PacketBeat for sending network traffic, FileBeat for shipping and forwarding logs to central server, etc. Similarly, we will build AndroidBeat to carry and ship device meta-data along with threat information.</p><p>ElasticBeat is developed using golang. Every beat app includes a library named libBeat which is responsible for sending operational data to Elasticsearch, either directly or via Logstash, so it can be visualized with Kibana. The challenge is to port ElasticBeats to mobile which involves cross-compiling native libraries for ARM and building the necessary scheduler for executing beats command to trigger data collection &amp; transport.</p><h3>Architecture</h3><p>Traditionally, endpoints need some kind of middleware to structure data before it’s stored on backend servers for further processing. Such requirements force us to design and scale middleware APIs to handle traffic originating from endpoints. Furthermore, this setup creates further rigidity by forcing the communication between the two entities to conform to predefined data structures. Adding a single meta-data on the mobile end will need to be understood by the middleware, where to route, store, and process need to be answered.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/453/0*dbQWpMsmlR0I58_p.png" /></figure><h3>Introducing AndroidBeat</h3><p>I want to short-circuit this constraint by removing components that sit between our endpoint and backend services. AndroidBeat is an ElasitcBeat app designed to collect device meta-data and forensic and send it directly to ElasticSearch. This eliminates the need to maintain a custom backend and adds the flexibility to query the collected data easily on Kibana.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/467/0*1jIaS82o89k3klPx.png" /></figure><h3>Components</h3><p><strong>AndroidBeat</strong> — Native library built for arm/arm64/x86. It’s responsible for collecting data and shipping it to ElasticSearch Server. There is a yaml configuration file that dictates how often data should be pushed and the location of the elastic server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/608/0*Pzc9nUUJcetnjJLh.png" /></figure><p><strong>Scheduler</strong> — Is responsible for scheduling how often a beat should run. Normally, on other platforms (say Linux server or container pod), the beat executable is allowed to run indefinitely under supervisord or other process control mechanisms. On Android, since resource consumption is restricted we would have to build a scheduler based on <a href="https://developer.android.com/reference/android/app/job/JobScheduler">JobScheduler</a> or <a href="https://developer.android.com/reference/android/app/AlarmManager">AlarmManager</a>. This not only helps reduce battery consumption but makes our app stay responsive and not get killed for misuse. This component can be implemented as a separate module and can be shared with other beat apps that need similar functionality.</p><p><strong>Trigger</strong> — This is a component responsible for triggering the scheduler kicking off the whole process. We have two options here</p><ol><li>Via URL (Instant App) — This trigger is handy because we can simply send a URL to a user either via email or messenger to install an instant app. <a href="https://developer.android.com/topic/google-play-instant/">Instant apps</a> are “mini” apps designed by Google that are installed directly from a URL and deliver an app-like experience.</li><li>App — Installable APK containing all the components discussed above.</li></ol><p><strong>ELK Server</strong> — Hosted ELK server where we accumulate our data</p><h3>Technicalities</h3><p>There is a good guide for creating custom elastic beats here <a href="https://www.elastic.co/guide/en/beats/devguide/current/new-beat.html">https://www.elastic.co/guide/en/beats/devguide/current/new-beat.html</a>. The guide explains how to setup dependencies and create a basic skeleton beat application. You can follow the step by step instructions there. What’s important here is the ability to cross compile our beats app for Android/ARM. That can be achieved by using golang’s GOOS &amp; GOARCH environment variables</p><pre>GOOS=android GOARCH=arm64 go build</pre><h3>Use Cases</h3><p>This setup greatly reduces many complexities while running an endpoint data gathering &amp; aggregation tasks. Here are some use cases for it</p><ol><li>Vulnerability search — Search for vulnerable devices by querying device settings remotely. Hence, bringing the power of OSQuery idea to mobile</li><li>Threat hunt — Search IOCs by inspecting list of installed apps &amp; network configs to get an idea of the device’s health status.</li><li>Threat intelligence for mobile</li><li>Endpoint detection and response for mobile</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f38d758e8b5a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Decentralized threat hunting with PolySwarm]]></title>
            <link>https://sirackh.medium.com/decentralized-threat-hunting-with-polyswarm-d6875f55ec0?source=rss-823af4078647------2</link>
            <guid isPermaLink="false">https://medium.com/p/d6875f55ec0</guid>
            <category><![CDATA[threat-intelligence]]></category>
            <category><![CDATA[decentralization]]></category>
            <category><![CDATA[polyswarm]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[security]]></category>
            <dc:creator><![CDATA[Sirack Hailu]]></dc:creator>
            <pubDate>Tue, 18 May 2021 11:56:23 GMT</pubDate>
            <atom:updated>2021-05-18T11:56:23.937Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://ismyapppwned.com/2021/04/25/polyswarm_threat_hunting"><strong>Permanent link to this post →</strong></a></p><p>Hunting malware has largely been about a specific vendor. Symantec, Lookout and the likes develop different engines capable of detecting malware samples. They do this either by looking up the hash of the file on their database or detonating it in a secure VM and observing the results.</p><p>This approach forces enterprises to select the “best” AV vendor on the market which in-turn locks the company with the product for the duration of their subscription. A company like VirusTotal attempts to solve this problem by aggregating results from different vendors.</p><p>Polyswarm is a decentralized threat detection platform that involves industry and participating parties including security experts, consumers &amp; vendors; to name a few. It’s the first decentralized threat intelligence market made possible by Etherum smart contracts and blockchain technology. Experts develop “micro-engines” that compete in the market by investigating artifacts for malicious behavior.</p><p>The market consists of</p><ol><li>End Users</li><li>Ambassadors</li><li>Security Experts / AV vendors</li><li>Arbiters</li></ol><p>End users participate by submitting artifact samples to the market. They attach bounties as an incentive for market participants.</p><p>Ambassadors introduce bounties and offers into the market on their clients’ behalf. It is the ambassador’s responsibility to distill the Assertions of various Experts into a simple malicious or benign Verdict that they deliver to their clients .</p><p>Security experts take these samples and run them through connected micro engines for analysis &amp; assertion. Upon completion they assert their result to the market. If correctly classified, they get a portion of the bounty pot, based on how many engines were correct. (NCT nectar)</p><p>Arbiters offer ground truth regarding the malintent of the artifact.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*pJNdV2igDKsrqpVS.png" /></figure><h3>Micro Engine</h3><p>Micro-engines are responsible for scanning samples and providing a verdict. There are multiple engines in the marketplace specializing in different areas of infosec. Currently, PolySwarm accepts two types of samples/input; URL &amp; File. A micro engine can either participate or pass on a given sample. E.g. If an engine is not confident about its assertion, it can skip and wait for another bounty to arrive. This dynamic allows engines to bet on samples based on their confidence level/technology.</p><p>In this article we will build a very simple microengine that can detect Metasploit based malwares. <a href="https://www.metasploit.com/">Metasploit</a> is a framework for pen-testers to evaluate applications for various security related benchmarks. It also allows attackers to remotely “control” an app and pull in sensitive data.</p><p>Polyswarm is constantly evolving, hence, the steps discussed below might change. Refer <a href="https://docs.polyswarm.io/">https://docs.polyswarm.io</a> for the latest</p><p>Start by installing the following prerequisites.</p><ol><li>Docker</li><li>Python, pip &amp; Virtual Environment (virtualenv)</li><li>Cookiecutter <a href="https://github.com/cookiecutter/cookiecutter">https://github.com/cookiecutter/cookiecutter</a></li></ol><p>Polyswarm has created a template from which developers can start building their engines. Using <em>cookiecutter</em> we can setup a basic working micro-engine capable of receiving samples from the network and making a verdict.</p><p>Run the command below and answer the questions as they come. They are mostly self explanatory.</p><pre>cookiecutter <a href="https://github.com/polyswarm/participant-template">https://github.com/polyswarm/participant-template</a></pre><p><strong><em>participant_type</em></strong> — Can be microengine or arbiter. In this case, we are interested in building a scanning engine, hence choose 1 (microengine)</p><p><strong><em>microengine_arbiter_supports_scanning_files</em></strong> — Choose true. Since our engine makes verdict on files</p><p><strong><em>microengine_arbiter_supports_scanning_urls</em></strong> — Choose false. We will not operate on URLs. This will be a good use-case for engines/AV vendors that analyze phishing URLs.</p><p><strong><em>microengine_arbiter__scan_mode</em></strong> — There are two options; Sync &amp; Async. Choose sync for now.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*xCvN9NyaEdw64XCS.png" /></figure><p>A new directory will be created with the name of your engine that contains multiple files generated by cookiecutter. The most important files reside inside the directory. Look for a file named &lt;participant_name_slung&gt;.py. It contains three classes. BidStrategy, Scanner &amp; &lt;participant_name_slung&gt;. BidStrategy is responsible for staking NCT token. This will be our bidding price on the market. Scanner is responsible for setting up what’s needed for our detection to work. It receives artifacts from the PolySwarm network and makes it available for the &lt;participant_name_slung&gt; class to handle. Specifically, PolySwarm doesn’t send artifacts to engines, a “signed URL” in the bounty will be sent, where the engine can perform a download action to get the artifact. Finally, our detection logic returns a ScanResult object that represents our decision. Based on our analysis, we can either skip or stake our assertion with a certain confidence level.</p><p>In this example, our engine detection relies on yara rule that matches apps injected with metasploit framework. We have two rules. The first one looks for Payload classes while the second one looks for methods that are used by metasploit.</p><pre>rule metasploit <br>{<br>    meta:<br>        description = &quot;This rule detects apps made with metasploit framework&quot;<br>        sample = &quot;cb9a217032620c63b85a58dde0f9493f69e4bda1e12b180047407c15ee491b41&quot;<br><br>    strings:<br>        $a = &quot;*Lcom/metasploit/stage/PayloadTrustManager;&quot;<br>        $b = &quot;(com.metasploit.stage.PayloadTrustManager&quot;<br>        $c = &quot;Lcom/metasploit/stage/Payload$1;&quot;<br>        $d = &quot;Lcom/metasploit/stage/Payload;&quot;<br><br>    condition:<br>        all of them<br><br>}<br><br>rule metasploit_obsfuscated<br>{<br>    meta:<br>        description = &quot;This rule tries to detect apps made with metasploit framework but with the paths changed&quot;<br><br>    strings:<br>        $a = &quot;currentDir&quot;<br>        $b = &quot;path&quot;<br>        $c = &quot;timeouts&quot;<br>        $d = &quot;sessionExpiry&quot;<br>        $e = &quot;commTimeout&quot;<br>        $f = &quot;retryTotal&quot;<br>        $g = &quot;retryWait&quot;<br>        $h = &quot;payloadStart&quot;<br>        $i = &quot;readAndRunStage&quot;<br>        $j = &quot;runStageFromHTTP&quot;<br>        $k = &quot;useFor&quot;<br><br><br>    condition:<br>        all of them<br><br>}</pre><p>The details of the implementation can be found here, <a href="https://github.com/atlantis0/polyswarm-metasploit-microengine/blob/master/addis_ababa/addis.py#L169">https://github.com/atlantis0/polyswarm-metasploit-microengine/blob/master/addis_ababa/addis.py#L169</a></p><p>The code checks if the incoming artifact is indeed an APK and proceeds to run the yara command to check if any of the <em>classes.dex</em> files match the two rules we declared above.</p><h3>How artifacts are routed</h3><p>In the current architecture, a websocket is opened between the engine and the sidechain bounty manager “polyswarmd”. Each bounty is sent to each engine via the websocket. The bounty information is in a JSON. One of the fields in that JSON is a signed URL where the engine can submit a request to download the artifact.</p><h3>Bid Strategy</h3><p>Bidding is an important concept in Polyswarm’s decentralized market. When artifacts are submitted, they will be assigned a minimum &amp; maximum bid amount. Micro-engines are supposed to select a value somewhere in the middle based on different factors. E.g. An engine might bid higher (closer to max bid) if it thinks it has high confidence with its assertion, or might bid lower if the cost of analysis consumes high CPU cycles making infrastructure cost not feasible for the given price range.</p><h3>Ground Truth &amp; Bounty Grants</h3><p>It is assumed Arbiters have enough threat intel to have the final say or competent enough to judge if a sample is malicious or not. Obviously, they can do their own analysis. Polyswarm is tight lipped about how they onboard these players . You &amp; I can’t be arbiters. Engines provide proof of work by setting meta-data / malware family. It’s a simple json file containing your “proof” on why you think it’s malicious or clean. Furthermore, engine participants can challenge Arbiters by submitting a blog post or technical paper. It remains to be seen how this can be automated when participants are processing huge number of artifacts per day.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/803/0*HIw6bNArr0yS1cm9.png" /></figure><p>In the above example, Engine A correctly predicts while B &amp; C made the wrong assertion. Engine D abstained and did not make any decision. Hence, B &amp;C will lose 3 &amp; 2 NCT respectively. Their loss will be disbursed to Engine A. If multiple engines predict correctly, the amount of NCT awarded is proportional to the Expert’s Bid amount relative to the total pool of accurate Bids.</p><p>Polyswarm is also introducing two additional states for asserting a sample. Hence, we have, unknown, suspicious, benign &amp; malicious</p><h3>Testing &amp; Integration</h3><p>Before publishing our engine, we have to test our implementation. Unit tests validate if our engine is catching malwares and skipping benign samples. When creating our project using polyswarm-client-template, it creates basic tests located inside the test folder. Running it is as simple as building the docker image and running the container with docker compose command</p><pre>$ docker build -t basename ${PWD} -f docker/Dockerfile .<br>$ docker-compose -f docker/test-unit.yml up</pre><h3><strong>Production</strong></h3><p>Finally, we need to publish our engine to a production environment so we can start accepting artifacts. It’s up-to the developers to maintain, test &amp; deploy their work. I typically work with GCP and will spin up a dedicated compute instance. Before publishing, we will need few more things</p><ol><li>ETH account</li><li>NCT token</li><li>Production Keyfile</li></ol><p>To participate in the marketplace, we need Polyswarm’s NCT token (the currency we are bidding with). Start by purchasing ETH from your favorite wallet app. It’s critical that you have access to your keypairs (public/private) keys so we can package it with our engine. Purchasing ETH &amp; NCT is outside the scope of this article, but, you can follow a detailed explanation here, <a href="https://blog.polyswarm.io/how-to-buy-polyswarm-nectar-using-uniswap">https://blog.polyswarm.io/how-to-buy-polyswarm-nectar-using-uniswap</a></p><p>Once you have your account in place, its time to generate an encrypted keyfile. We will utilize <em>geth</em> command to import an existing private key into our local machine. The file (<em>private.bin</em>) is an unencrypted private key as canonical EC raw bytes encoded into hex. I was able to obtain this from my favorite crypto wallet app <a href="https://metamask.io/">metamask.io</a>. You will be prompted to enter a passphrase/password. Memorize this password and never disclose it to any other party except you and your engine. Polyswarm is working on a feature to offload transaction signing process to another device thereby providing a more secure way of handling keys.</p><pre>geth account import private.bin</pre><p>But for now, running the above command will generate a keyfile (json file). You can get the file path by running the command geth account list. Copy this file into your engine repository and update your docker/marketplace.env file. This file needs three variables; Keyfile, passphrase &amp; API key. The first two you already obtained using the above command. You can obtain an API key by signing up for Polyswarm here, <a href="https://polyswarm.network/login">https://polyswarm.network/login</a></p><h3>Relevant Links</h3><p><a href="https://polyswarm.io/polyswarm-whitepaper.pdf">Polyswarm white paper</a><br><a href="https://github.com/atlantis0/polyswarm-metasploit-microengine">Engine source code</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d6875f55ec0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[አዲስ Radio: The zen of media playback in Android]]></title>
            <link>https://sirackh.medium.com/%E1%8A%A0%E1%8B%B2%E1%88%B5-radio-the-zen-of-media-playback-in-android-1881bc05f7cb?source=rss-823af4078647------2</link>
            <guid isPermaLink="false">https://medium.com/p/1881bc05f7cb</guid>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[sheger]]></category>
            <category><![CDATA[addis-ababa]]></category>
            <category><![CDATA[radio]]></category>
            <dc:creator><![CDATA[Sirack Hailu]]></dc:creator>
            <pubDate>Fri, 17 Jun 2016 07:16:51 GMT</pubDate>
            <atom:updated>2016-07-31T07:05:38.062Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j6VD04r3IkVn2kaiFjGDGg.png" /></figure><p>I recently published my application on Google Play Store.</p><p><a href="https://play.google.com/store/apps/details?id=com.sheger.plus">https://play.google.com/store/apps/details?id=com.sheger.plus</a></p><p>It is an app that enables users listen to various Ethiopian radio stations through the web. Although it could be convenient for anyone, i particularly designed it having the Ethiopian diaspora community in mind. It is my belief that it will provide a much better alternative to similar applications available on Google Play, particularly with regards to functionality and quality.</p><p>In this blog, I will go through a detailed implementation of the application and will share what I have learned so far.</p><p>A while back, I was involved in developing media streaming application for a client and was surprised to see the drawback of Media Playback APIs on Android. Media playback is handled by a famous class, MediaPlayer (<a href="https://developer.android.com/reference/android/media/MediaPlayer.html">https://developer.android.com/reference/android/media/MediaPlayer.html</a>). It handles playing/pausing/stoping a media from local and remote sources. In production, this class caused lots of issues. Some of the issues are well documented here [<a href="http://www.piterwilson.com/blog/2014/03/11/android-mediaplayer-not-quite-there-yet/">http://www.piterwilson.com/blog/2014/03/11/android-mediaplayer-not-quite-there-yet/</a>].</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LYMHVFBCbR1TFka_q_wtdw.png" /></figure><p>Looking at the Crashlytics logs, it was clear that I needed to change MediaPlayer implementation and move to a more robust library. Powerful APIs were introduced in Android JellyBean 4.1. These newly introduced APIs allow you to control how your media is processed. You can write a custom player on top of these classes.</p><p>ExoPlayer [<a href="https://github.com/google/ExoPlayer">https://github.com/google/ExoPlayer</a>] is one example. It is used by various Google apps including YouTube. It allows you to play media from a remote source with little/no hassle. But that’s not all. Media playback is not about the player. It about the controls and how it behaves with with other media apps on the system. It also about the notification support, wear controls, etc.</p><p><strong>Media Playback</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/913/1*rF56T7yVm7IV54mdaqf89A.png" /></figure><p>The entire playback system is composed of the following components.</p><ol><li>Media Service — is a standard android service component (extends from [<a href="https://developer.android.com/reference/android/app/Service.html">https://developer.android.com/reference/android/app/Service.html</a>]). Its main function is to maintain the player instance and provide callback to media controller.</li><li>Media Controller — is the logical interface between application UI and media service component.</li><li>Player (ExoPlayer) — Component responsible to play the actual media content</li><li>User Interface — Holds media related UI (e.g. play button, stop button, etc)</li></ol><p>Media service contains a single instance of MediaSessionCompat ([<a href="https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat.html">https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat.html</a>]) object which is very important in transferring playback state back end forth to our media controller class. The media controller class will then forward these states to our UI. Once the UI receives these events it will update Play/Pause/Stop buttons appropriately.</p><p>Transferring states from our service to the UI is by means of session token. It is obtained from MediaSessionCompat upon media service creation.</p><p><strong>Audio Focus</strong></p><p>Media applications should play well with other media apps on the device. They should not play over music or during phone calls. Android notifies your registered receiver when another media starts playing (permanent audio focus loss) or during temporary audio focus loss (phone call comes in).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0a546eb10b315286c2b6daaed6f015cb/href">https://medium.com/media/0a546eb10b315286c2b6daaed6f015cb/href</a></iframe><p><strong>Media Metadata</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MB_nF3_VHdEnwyaswVllgg.png" /></figure><p>While playing media, you will need to tell the android system informations like artist, album name, album art and other necessary info. If provided correctly these informations will appear on android lock screen, Android wear and Android auto 😉 . This is achieved by constructing <em>MediaMetadataCompat</em> (<a href="https://developer.android.com/reference/android/support/v4/media/MediaMetadataCompat.html">https://developer.android.com/reference/android/support/v4/media/MediaMetadataCompat.html</a>).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1c02e841b1955530e829f752384c7f8e/href">https://medium.com/media/1c02e841b1955530e829f752384c7f8e/href</a></iframe><p><strong>Notification</strong></p><p>Its important to provide the above metadata not only on the app, but also on the Notification Drawer. When building your notification you will need to provide the following information.</p><ol><li>Content Title — Which is usually the Track you are playing (in my case, it was the radio station)</li><li>Sub Text — Text that appears below the content (should provide supporting info)</li><li>Action Button. These include play, pause or stop.</li><li>Notification touch action — What action to take when the user taps on the notification. In this case, launch the main activity.</li></ol><p>Finally, you will need to call <em>startForeground()</em>. This will show the notification as long as your media service is alive. This is important since Android might kill your service when device memory is low. Showing persistent notification will whitelist your app from these scenarios.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5c390afedfdc54b058498e6a53e883f1/href">https://medium.com/media/5c390afedfdc54b058498e6a53e883f1/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Zg1jGinfY23dxpcfq3fnYQ.png" /></figure><p><strong>Conclusion</strong></p><p>One of the biggest challenges I faced was the dreaded <strong><em>BehindLiveWindowException.</em></strong> Its well documented here, <a href="https://github.com/google/ExoPlayer/issues/1074">https://github.com/google/ExoPlayer/issues/1074</a>. This will cause the app to abruptly stop streaming. This happens when the source (the FM radio stations) fail to provide stream segments. If anyone has a better solution for this, I would be happy to learn more about it.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1881bc05f7cb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Managing social networks and App APIs for Events Ethiopia]]></title>
            <link>https://sirackh.medium.com/managing-social-networks-and-app-api-s-for-events-ethiopia-14c31a9391f6?source=rss-823af4078647------2</link>
            <guid isPermaLink="false">https://medium.com/p/14c31a9391f6</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[mobile]]></category>
            <dc:creator><![CDATA[Sirack Hailu]]></dc:creator>
            <pubDate>Fri, 05 Feb 2016 17:10:46 GMT</pubDate>
            <atom:updated>2016-02-09T16:09:41.606Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wIaBl1tc-TYhKm5JaLf80g.png" /></figure><p>We recently released our app on Google Play and App Store. If you haven’t seen it already, go download!</p><p><strong>Android</strong> — <a href="https://play.google.com/store/apps/details?id=com.master.deuce"><em>https://play.google.com/store/apps/details?id=com.master.deuce</em></a></p><p><strong>IOS</strong> — <a href="https://itunes.apple.com/us/app/events-ethiopia/id1071603724?ls=1&amp;mt=8"><em>https://itunes.apple.com/us/app/events-ethiopia/id1071603724?ls=1&amp;mt=8</em></a></p><p>Events Ethiopia has over 14K Twitter followers and over 2K Facebook Fans. We have been posting events on our social networks for over 6 years now (Long time ;) ). We deliver event news to our users living in Addis Ababa and abroad (Especially Ethiopian diaspora community around the world). When we started developing our Apps, it was very critical for us to maintain consistency in publishing events to both social network and the app. For this, we needed to design an admin console that publishes content to all of our channels and reduces the burden of managing our product.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/496/1*ZLN5fbCccnZuBgLf4Qwrmw.png" /><figcaption>Admin Console Workflow</figcaption></figure><p>Calling our backend API is very trivial, but posting to our social networks (FB/Twitter) might require some effort. To publish a story on Facebook, you need to have a valid access token which you obtain after authenticating your application with Facebook.</p><p>This poses a serious workflow issue.</p><ol><li>Admin must authenticate with FB/Twitter/Google+/.. every time they want to make a single post.</li><li>If authentication fails (for any reason), the event won’t be posted and most importantly we won’t have any retry mechanisms in place to handle the failure.</li></ol><p>So we moved the code that handles social networks to the backend. We don’t want our client side code to worry about authentication at this stage for a number of reasons. First, the admin must log in with multiple social networks before posting anything. Currently, we have Twitter and Facebook, but adding support for an extra network will be painful. It would be insane to ask an administrator to log in with 3 social networks to make a single entry to the system (ouch !!!!). Secondly, maintaining code will be much easier since an admin will have one single entry API for managing everything. (Basically a god API!).</p><p>So, we designed the following system.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/845/1*Fx4wuK5O_ey1IleTZR7gaA.png" /><figcaption>Access Token Verification</figcaption></figure><p>One of the first things the admin console does is check if we have a valid access token on our database. This access token is saved into our database whenever someone from our team authenticates with FB/Twitter. This process is separate from the above diagram and is only done every three months (Depends on the expiration date of the token). If the token is valid, we can go ahead with posting the event to Facebook/Twitter. If not, we save the event on our task queue. Queuing events allows us to process them later when we obtain a valid access token.</p><p>Whenever we have a task on our queue, we immediately email administrators instructing them to re-login. Such process will refresh our tokens and we regain our prior capabilities back.</p><p>After this, we span a new service.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/635/1*2U72dpCxUAwoyc6ys8p_EQ.png" /><figcaption>Event Queue Processor</figcaption></figure><p>Event queue processor picks up these events and posts them one by one. Retry limit is three. If an event fails to be posted for more than three times, it will automatically be rejected.</p><p>That’s it. This is how we manage our backend API’s and our social network at the same time (with less pain of course ;) ). If you have any suggestions, please drop us a comment.</p><p>Ta ta</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=14c31a9391f6" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>