-
Notifications
You must be signed in to change notification settings - Fork 2
/
privicy_pcap.py
115 lines (101 loc) · 4.73 KB
/
privicy_pcap.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
__author__ = 'Hao Fu'
#!/usr/bin/env python2
#-*-encoding:utf-8-*-
__author__ = 'hao'
import os
import time
import difflib
import subprocess
import re
from datetime import datetime
import logging
# 获取设备中的所有包名
def appName():
cmd = 'adb -s ' + series + ' shell pm list packages'
app_process = subprocess.Popen(cmd, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT, shell = True)
#p = check_output(cmd, shell = True)
app_process.wait()
output = app_process.stdout.readlines()
output = set(x.split(':')[1].strip() for x in output)
return output
#series = 'emulator-5554'
series = '014E233C1300800B'
#series = '01b7006e13dd12a1'
#os.popen('rm -r -f data')
os.popen('mkdir data')
#package = 'com.google.android.deskclock'
#package = 'com.android.settings'
ISOTIMEFORMAT = '%m%d-%H-%M-%S'
filelist = os.listdir('.') # list files at current dir
# set threashold large to check behaviors underware
logger = logging.getLogger('UiDroid-Console')
logger.setLevel(logging.DEBUG)
consolehandler = logging.StreamHandler()
consolehandler.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
consolehandler.setFormatter(formatter)
logger.addHandler(consolehandler)
package_pattern = re.compile(r'.*apk')
register_pattern = re.compile(r'.*(Regis|REGIS|Sign|SIGN).*')
for fline in filelist:
fmatch = package_pattern.match(fline)
if not fmatch:
continue
os.popen('adb devices')
before = appName()
os.popen('adb -s ' + series +' install ' + fline)
after = appName()
applist = after - before
if len(applist) != 1:
logger.info(fline)
logger.info(applist)
logger.info('error! not a single app selected!')
# break
continue
for package in applist:
os.popen('adb -s ' + series + ' shell am start -n fu.hao.uidroid/.TaintDroidNotifyController')
current_time = time.strftime(ISOTIMEFORMAT, time.localtime())
os.popen('adb -s ' + series + ' shell "su 0 date -s `date +%Y%m%d.%H%M%S`"')
cmd = 'adb -s ' + series + ' shell /data/local/tcpdump -p -vv -s 0 -w /sdcard/' + package + current_time +'.pcap'
subprocess.Popen(cmd, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT, shell=True)
logger.info('tcpdump begins')
os.popen('adb logcat -c')
logger.info('clear logcat')
os.popen('adb -s ' + series + ' shell "logcat -v threadtime | grep --line-buffered UiDroid > /sdcard/' + package + current_time +'.log " &')
logger.info('logcat start')
os.popen('adb -s ' + series + ' shell monkey -p ' + package + ' --ignore-crashes 1')
time.sleep(30)
#package_list = os.popen('adb -s ' + series + ' shell cat /data/system/packages.list')
#logger.info(package_list.readlines())
#ps_list = os.popen('adb -s ' + series + ' shell ps')
#logger.info(ps_list.readlines())
dir_data = 'data/' + package + current_time + '/'
os.popen('mkdir ' + dir_data)
filehandler = logging.FileHandler(dir_data + '/UiDroid-Console.log')
filehandler.setLevel(logging.DEBUG)
logger.addHandler(filehandler)
filehandler.setFormatter(formatter)
time.sleep(60)
#package_list = os.popen('adb -s ' + series + ' shell cat /data/system/packages.list')
#logger.info(package_list.readlines())
#ps_list = os.popen('adb -s ' + series + ' shell ps')
#logger.info(ps_list.readlines())
os.popen('adb -s ' + series + ' shell am force-stop ' + package)
os.popen('adb -s ' + series + ' uninstall ' + package)
logger.info('uninstall')
os.popen('adb logcat -c')
kill_status = os.popen('adb -s ' + series + ' shell ps | grep logcat | awk \'{print $2}\' | xargs adb -s ' + series + ' shell kill')
logger.info(kill_status.readlines())
kill_status = os.popen('adb -s ' + series + ' shell ps | grep tcpdump | awk \'{print $2}\' | xargs adb -s ' + series + ' shell kill')
logger.info(kill_status.readlines())
kill_status = os.popen('adb -s ' + series + ' shell am force-stop org.appanalysis')
logger.info(kill_status.readlines())
pull_status = os.popen('adb -s ' + series + ' pull /sdcard/' + package + current_time + '.pcap ' + dir_data)
logger.info(pull_status.readlines())
os.popen('adb -s ' + series + ' shell rm /sdcard/' + package + current_time + '.pcap')
pull_status = os.popen('adb -s ' + series + ' pull /sdcard/' + package + current_time + '.log ' + dir_data)
logger.info(pull_status.readlines())
os.popen('adb -s ' + series + ' shell rm /sdcard/' + package + current_time + '.log')
os.system('mv ' + fline + ' ' + dir_data)