-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathairdroid.py
executable file
·361 lines (290 loc) · 10.8 KB
/
airdroid.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
#!/usr/bin/env python
"""
OverAirdroid
An unofficial API script to make automating Airdroid functions easier.
Created by Matthew Bryant
"""
import datetime
import requests
import base64
import urllib
import time
import json
import md5
import sys
from bs4 import BeautifulSoup
class overairdroid:
"""
Converts the callback Javascript to a dict of the JSON
@input_json Inputted JSON packed in Airdroid callback stuff
return Returns a dict of inputted Airdroid Javascript
"""
def air2json( self, input_json ):
init_json = input_json
init_json = init_json.replace("_jqjsp(", "")
init_json = init_json[:-1]
init_json = json.loads( init_json )
return init_json
"""
Make viewing trees a lot easier
@input_dict The input dictionary for viewing
return None
"""
def pprint( self, input_dict):
print json.dumps(input_dict, sort_keys=True, indent=4, separators=(',', ': '))
"""
Initialize all of the needed variables
@inut_dict The input dict with all of our needed values
return None
"""
def initialize_variables( self, input_dict ):
self.channel_token = input_dict['result']['device'][0]['channelToken']
self.device_id = input_dict['result']['device'][0]['deviceId']
self.id = str( input_dict['result']['device'][0]['id'] )
self.imsi = input_dict['result']['device'][0]['imsi']
self.logic_key = input_dict['result']['device'][0]['logicKey']
self.content_id = input_dict['result']['device'][0]['id']
self.account_id = input_dict['result']['id']
self.manufacturer = input_dict['result']['device'][0]['manu']
self.model = input_dict['result']['device'][0]['model']
self.phone_ip = str( input_dict['result']['device'][0]['netOpts']['ip'] )
self.phone_port = str( input_dict['result']['device'][0]['netOpts']['port'] )
self.phone_socket_port = str( input_dict['result']['device'][0]['netOpts']['socket_port'] )
self.phone_ssl_port = str( input_dict['result']['device'][0]['netOpts']['ssl_port'] )
self.phone_wifi = input_dict['result']['device'][0]['netOpts']['usewifi']
self.get_bb()
def statusmsg( self, input_string ):
if self.verbose:
print "[ STATUS ] " + input_string
def errormsg( self, input_string ):
if self.verbose:
print "[ ERROR ] " + input_string
"""
Initialize the OverTheAirdroid object
@in_username The Airdroid username
@in_password The Airdroid password
@in_verbose Should the program be verbose?
return None
"""
def __init__(self, in_username, in_password, in_verbose = True):
self.username = in_username
self.password = in_password
self.verbose = in_verbose
global_headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; rv:25.0) Gecko/20100101 Firefox/25.0',
}
self.s = requests.Session()
self.s.headers.update( global_headers )
# Internal variables
self.channel_token = ""
self.device_id = ""
self.logic_key = ""
self.imsi = ""
self.id = ""
self.account_id = ""
self.model = ""
self.manufacturer = ""
self.phone_ip = ""
self.phone_port = ""
self.phone_socket_port = ""
self.phone_ssl_port = ""
self.phone_wifi = False
self.var_7bb = ""
# Extra phone info variables
self.battery_charge = ""
self.is_charging = ""
self.app_count = ""
self.contact_count = ""
self.music_count = ""
self.ebook_count = ""
self.photo_count = ""
self.video_count = ""
self.external_sd_location = ""
self.gsm_bars = ""
self.model = ""
self.orientation = ""
self.os_version = ""
self.external_sd_size = ""
self.external_sd_free = ""
self.storage_size = ""
self.storage_size_free = ""
self.wifi_name = ""
self.wifi_bars = ""
# Attempt a log in
self.is_loggedin = self.login()
"""
Login to Airdroid
return True on success and False on failure
"""
def login( self ):
self.statusmsg( "Logging in to AirDroid..." )
r = self.s.get('http://web.airdroid.com/', )
get_data = {
'mail': self.username,
'pwd': self.password,
'callback': '_jqjsp',
'keep': '0',
}
r = self.s.get('https://id.airdroid.com/p9/user/signIn.html', params=get_data)
info = self.air2json( r.text )
if info['msg'] == "success!":
self.initialize_variables( info )
self.statusmsg( "Login was successful!" )
self.statusmsg( "Phone address: " + self.phone_ip + ":" + self.phone_port )
return True
else:
self.errormsg( "Login failed!" )
return False
"""
Wakeup the Android device if an action hasn't been preformed in a while
return True on success and False on failure
"""
def wakeup( self ):
n = datetime.datetime.now()
get_data = {
"id": self.device_id,
"accountId": self.account_id,
"logicKey": self.logic_key,
"callback": "_jqjsp",
"_" + str( int( time.mktime(n.timetuple()) ) ): "",
}
r = self.s.get( 'http://lb.airdroid.com:9081/wakePhone', params=get_data )
response = self.air2json( r.text )
if response['msg'] == "wake phone success":
return True
else:
return False
"""
Get the "bb" value needed to preform Airdroid actions
return String of bb value
"""
def get_bb( self ):
n = datetime.datetime.now()
unix_time = str( int( time.mktime(n.timetuple()) ) )
m = md5.new()
m.update( unix_time + self.device_id + self.logic_key )
key = unix_time + m.digest().encode("hex")
get_data = {
"keeplogin": 0,
"type": 2,
"key": key,
"7bb": "null",
"callback": "_jqjsp",
"_" + unix_time: "",
}
r = self.s.get('http://' + self.phone_ip + ':' + self.phone_port + '/sdctl/comm/checklogin/', params=get_data)
self.var_7bb = self.air2json( r.text )['7bb']
"""
Open URL on Android device
@url String of the URL to open
return None
"""
def url_open( self, url ):
n = datetime.datetime.now()
unix_time = str( int( time.mktime(n.timetuple()) ) )
get_data = {
"url": url,
"7bb": self.var_7bb,
"callback": "_jqjsp",
"_" + unix_time: "",
}
r = self.s.get('http://' + self.phone_ip + ':' + self.phone_port + '/sdctl/comm/openurl/', params=get_data)
"""
Why is this still here?
"""
def display_info( self ):
n = datetime.datetime.now()
unix_time = str( int( time.mktime(n.timetuple()) ) )
get_data = {
"7bb": self.var_7bb,
"callback": "_jqjsp",
"_" + unix_time: "",
}
r = self.s.get('http://' + self.phone_ip + ':' + self.phone_port + '/sdctl/device/overview/', params=get_data)
info = self.air2json( r.text )
self.battery_charge = info['battery']
self.is_charging = info['batterycharging']
self.app_count = info['counts']['app']
self.contact_count = info['counts']['contacts']
self.music_count = info['counts']['music']
self.ebook_count = info['counts']['ebook']
self.photo_count = info['counts']['photo']
self.video_count = info['counts']['video']
self.external_sd_location = info['ex_sd']
self.gsm_bars = info['gsm_signal']
self.model = info['model']
self.orientation = info['orientation']
self.os_version = info['osversion']
self.external_sd_size = info['size']['ext_sd_avail']
self.external_sd_free = info['size']['ext_sd_size']
self.storage_size = info['size']['sys_size']
self.storage_size_free = info['size']['sys_avail']
self.wifi_name = info['wifi_name']
self.wifi_bars = info['wifi_signal']
"""
Set the Android clipboard
@data Data to set the clipboard to
return True on success and False on failure
"""
def set_clipboard( self, data ):
n = datetime.datetime.now()
unix_time = str( int( time.mktime(n.timetuple()) ) )
layer_data = {
"content": base64.b64encode( data )
}
post_data = {
"content": urllib.quote_plus( json.dumps( layer_data ) ),
}
r = self.s.post('http://' + self.phone_ip + ':' + self.phone_port + '/sdctl/comm/clipboard/set?7bb=' + self.var_7bb, data=post_data)
result = json.loads( r.text )
if result['result'] == 0:
return True
else:
return False
"""
Get the Android device's clipboard
return The clipboard contents
"""
def get_clipboard( self ):
self.statusmsg( "Grabbing clipboard contents..." )
n = datetime.datetime.now()
unix_time = str( int( time.mktime(n.timetuple()) ) )
get_data = {
"7bb": self.var_7bb,
"callback": "_jqjsp",
"_" + unix_time: "",
}
r = self.s.get('http://' + self.phone_ip + ':' + self.phone_port + '/sdctl/comm/clipboard/get', params=get_data)
response = self.air2json( r.text )
data = json.loads( urllib.unquote_plus( base64.b64decode( response['content'] ) ) )
self.statusmsg( "Clipboard contents grabbed!" )
return data['result']
"""
Send an SMS from Android phone
@phone_number Integer of the phone number to send the SMS to
@message String of the SMS message to be sent
return True on success and False on failure
"""
def sms( self, phone_number, message ):
self.statusmsg( "Sending SMS..." )
n = datetime.datetime.now()
unix_time = str( int( time.mktime(n.timetuple()) ) )
layer1 = {
"number": phone_number,
"content": str( message ),
"threadId": unix_time,
}
layer2 = {
"content": base64.b64encode( urllib.quote_plus( urllib.quote_plus( json.dumps( layer1 ) ) ) ),
}
post_data = {
"params": json.dumps( layer2 ),
}
r = self.s.post('http://' + self.phone_ip + ':' + self.phone_port + '/sdctl/sms/send/single/?7bb=' + self.var_7bb, data=post_data)
response = json.loads( r.text )
if "threadId" in base64.b64decode( response['content'] ):
self.statusmsg( "SMS sent!" )
return True
else:
self.errormsg( "Error sending SMS!" )
return False