· 5 years ago · Feb 05, 2021, 08:50 PM
1<?php
2
3$block_size = AES.block_size;
4$unpad = lambda $s : $s[0:-ord($s[-1]);
5
6$lg_deckey = "wleldpadptmdkdnt";
7$lg_enckey = "qlxnTldlsvntzl!#";
8
9function pad($plain_text) {
10 /*
11 func to pad cleartext to be multiples of 8-byte blocks.
12 If you want to encrypt a text message that is not multiples of 8-byte blocks,
13 the text message must be padded with additional bytes to make the text message to be multiples of 8-byte blocks.
14 */
15 $number_of_bytes_to_pad = $block_size - len($plain_text) % $block_size;
16 $ascii_string = chr($number_of_bytes_to_pad);
17 $padding_str = $number_of_bytes_to_pad * $ascii_string;
18 $padded_plain_text = $plain_text + $padding_str;
19 return $padded_plain_text;
20}
21
22function lg_encrypt($string) {
23 $key = $lg_enckey;
24 $plain = pad($string);
25 $iv = str("\x00"*AES.$block_size);
26 $cipher = AES.new($key, AES.MODE_CBC, $iv);
27 $encrypted_text = cipher.encrypt($plain);
28 return base64.b64encode($encrypted_text).replace("+", "m").replace("/", "f");
29}
30
31function lg_decrypt($string) {
32 if (len($string) == 0 or $string == "\n") {
33 return ""
34 }
35
36 $key = $lg_deckey;
37 $crypted = base64.b64decode($string);
38 $iv = str("\x00"*AES.$block_size);
39 $cipher = AES.new($key, AES.MODE_ECB);
40 $decrypted_text = cipher.decrypt($crypted);
41 return unpad($decrypted_text);
42}
43$imei = "lol";
44
45$esn = lg_encrypt($imei);
46$data = "{'esn':esn}"; #JSON que vem da API
47# Faz um post na $url da API
48$r = requests.post($url = "https://csmg.lgmobile.com:49002/csmg/nb2c/gn_auth_model_check2.jsp", data = data);
49
50function xml_recurse($node) {
51 $dec = lg_decrypt($node.text);
52 if ($node.tag == "sw_url") {
53 # pega o final da API de baixo
54 $dec = "http://tool.lime.gdms.lge.com/dn/downloader.dev?" + dec.split("?")[1];
55 }
56
57 print ("$node.tag, $node.attrib, $dec");
58 for $child in $node () {
59 xml_recurse(child);
60 }
61}
62$root = $ET.fromstring($r.text);
63xml_recurse($root);