├── .gitignore ├── LICENSE ├── README.md └── src ├── MobileNetkeeper.py ├── OpenSNet └── OpenSNet │ ├── DaoCloud │ ├── Dockerfile │ └── bin │ │ ├── OpenSNet │ │ └── entrypoint.sh │ ├── Makefile │ ├── SNAttributes.c │ ├── SNAttributes.h │ ├── SNConstants.h │ ├── SNHeartBeat.c │ ├── SNHeartBeat.h │ ├── SNNets.c │ ├── SNNets.h │ ├── SNUtils.c │ ├── SNUtils.h │ └── main.c ├── OpenShineto ├── LongBase64.py ├── README.md ├── ShinetoHeartBeat.py ├── ShinetoLogin.py └── __init__.py ├── SNAccount.py ├── SNAccount2.py ├── SNAttribute.py ├── SNConstants.py ├── SNHeartBeat.py ├── SNUtils.py ├── TPEnc.py ├── XLStringEnc.py └── pyAes.py /.gitignore: -------------------------------------------------------------------------------- 1 | # Mac 2 | .DS_Store 3 | .idea/ 4 | *.xcodeproj 5 | test.py 6 | 7 | # Byte-compiled / optimized / DLL files 8 | __pycache__/ 9 | *.py[cod] 10 | 11 | # C extensions 12 | *.so 13 | 14 | # Distribution / packaging 15 | .Python 16 | env/ 17 | build/ 18 | develop-eggs/ 19 | dist/ 20 | downloads/ 21 | eggs/ 22 | lib/ 23 | lib64/ 24 | parts/ 25 | sdist/ 26 | var/ 27 | *.egg-info/ 28 | .installed.cfg 29 | *.egg 30 | 31 | # PyInstaller 32 | # Usually these files are written by a python script from a template 33 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 34 | *.manifest 35 | *.spec 36 | 37 | # Installer logs 38 | pip-log.txt 39 | pip-delete-this-directory.txt 40 | 41 | # Unit test / coverage reports 42 | htmlcov/ 43 | .tox/ 44 | .coverage 45 | .cache 46 | nosetests.xml 47 | coverage.xml 48 | 49 | # Translations 50 | *.mo 51 | *.pot 52 | 53 | # Django stuff: 54 | *.log 55 | 56 | # Sphinx documentation 57 | docs/_build/ 58 | 59 | # PyBuilder 60 | target/ 61 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | {description} 294 | Copyright (C) {year} {fullname} 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | {signature of Ty Coon}, 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | 341 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Anti_teNelgniS 2 | Some core functions about new sx 3 | -------------------------------------------------------------------------------- /src/MobileNetkeeper.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding=utf-8 3 | 4 | import re 5 | from hashlib import md5 6 | from requests import session 7 | 8 | import pyAes as AES 9 | 10 | 11 | class MobileNetkeeper(object): 12 | INIT_KEY = '7%ChIna3#@Net*%' 13 | _UUID = '261D80CF8890F63571350565F605174746C2B3E294CA37A6E993A155BF3CFE51' 14 | _HEADERS = { 15 | 'User-Agent': 'China Telecom Client', 16 | 'Accept': '*/*', 17 | 'Accept-Language': 'zh-Hans, en, fr, de, ja, nl, it, es, pt, pt-PT, da, fi, nb, sv, ko, zh-Hant, ru, pl, tr, uk, ar, hr, cs, el, he, ro, sk, th, id, ms, en-GB, ca, hu, vi, en-us;q=0.8', 18 | 'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8', 19 | 'Accept-Encoding': 'gzip, deflate', 20 | } 21 | 22 | def __init__(self, username, UUID=None): 23 | self.username = username 24 | if UUID is not None: 25 | self._UUID = UUID 26 | 27 | self.session = session() 28 | self.session.headers = self._HEADERS 29 | 30 | @classmethod 31 | def encrypt_password(cls, password): 32 | aes_key = md5(cls.INIT_KEY).digest() 33 | aes = AES.new(aes_key, AES.MODE_ECB) 34 | 35 | # padding 36 | l = 16 - len(password) % 16 37 | ram_data = password + l * chr(l) 38 | ram_data = ram_data.encode('utf-8') 39 | 40 | return aes.encrypt(ram_data).encode('hex').upper() 41 | 42 | def update_uuid(self, new_uuid): 43 | self._UUID = new_uuid 44 | 45 | def request_uuid(self, ipaddress=None): 46 | params = { 47 | 'wlanuserip': ipaddress, 48 | 'acname': 'BPSS_BRAS_1' 49 | } 50 | 51 | req = self.session.post(url='http://115.239.134.163:8080/showlogin.do', 52 | data=params, 53 | timeout=5) 54 | searched = re.search(r'([A-Z0-9]{64})', req.content) 55 | if searched: 56 | return searched.group(1) 57 | raise Exception('Request UUID failed.') 58 | 59 | def http_login(self, password, ipaddress): 60 | self._UUID = self.request_uuid(ipaddress) 61 | 62 | login_params = { 63 | 'ratingtype': '1', 64 | 'password': self.encrypt_password(password), 65 | 'uuid': self._UUID, 66 | 'userip': ipaddress, 67 | 'username': self.username, 68 | 'acname': 'BPSS_BRAS_1', 69 | } 70 | 71 | req = self.session.post(url='http://115.239.134.163:8080/servlets/G3loginServlet', 72 | data=login_params, 73 | timeout=5) 74 | searched = re.search(r'(\d.*)', req.content) 75 | if searched is not None: 76 | return int(searched.group(1)), self._UUID 77 | raise Exception('Request login failed.') 78 | 79 | def http_logout(self, ipaddress): 80 | logout_params = { 81 | 'userip': ipaddress, 82 | 'ratingtype': '1', 83 | 'uuid': self._UUID 84 | } 85 | 86 | req = self.session.post(url='http://115.239.134.163:8080/servlets/G3logoutServlet', 87 | data=logout_params, 88 | timeout=5) 89 | searched = re.search(r'(\d.*)', req.content) 90 | if searched is not None: 91 | return int(searched.group(1)) 92 | raise Exception('Request logout failed') 93 | 94 | 95 | if __name__ == '__main__': 96 | pass -------------------------------------------------------------------------------- /src/OpenSNet/OpenSNet/DaoCloud/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM busybox:latest 2 | 3 | ADD ./bin /opt/bin 4 | 5 | ENV PORT 8080 6 | ENV INTERVAL 180 7 | ENV TARGET 115.239.134.167 8 | 9 | EXPOSE 8080 10 | 11 | ENTRYPOINT ["/opt/bin/entrypoint.sh"] 12 | CMD ["/opt/bin/OpenSNet"] 13 | -------------------------------------------------------------------------------- /src/OpenSNet/OpenSNet/DaoCloud/bin/OpenSNet: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singlenet/Anti_teNelgniS/e11dd1560533b88f776c36241946529adcd74035/src/OpenSNet/OpenSNet/DaoCloud/bin/OpenSNet -------------------------------------------------------------------------------- /src/OpenSNet/OpenSNet/DaoCloud/bin/entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | echo "OpenSNet Starting..." 4 | 5 | if [[ -z "$USERNAME" ]]; then 6 | echo "You have to set USERNAME" 7 | exit 1 8 | fi 9 | 10 | if [[ -z "$IPADDRESS" ]]; then 11 | echo "You have to set IPADDRESS" 12 | exit 1 13 | fi 14 | 15 | exec "$@" "-u" "$USERNAME" "-i" "$IPADDRESS" "-I" "$INTERVAL" "-t" "$TARGET" "-P" "$PORT" -------------------------------------------------------------------------------- /src/OpenSNet/OpenSNet/Makefile: -------------------------------------------------------------------------------- 1 | CC = gcc 2 | CFLAGS = -g -Wall -Wimplicit-function-declaration -I /usr/local/include/ 3 | 4 | OpenSNet: main.o SNAttributes.o SNNets.o SNHeartBeat.o SNUtils.o 5 | $(CC) -o $@ $^ $(CFLAGS) /usr/local/lib/libmbedcrypto.a 6 | 7 | main.o: main.c SNAttributes.h SNNets.h SNHeartBeat.h SNConstants.h 8 | $(CC) -o $@ $< $(CFLAGS) -c 9 | 10 | SNAttributes.o: SNAttributes.c SNAttributes.h SNConstants.h 11 | $(CC) -o $@ $< $(CFLAGS) -c 12 | 13 | SNHeartBeat.o: SNHeartBeat.c SNHeartBeat.h SNConstants.h 14 | $(CC) -o $@ $< $(CFLAGS) -c 15 | 16 | SNNets.o: SNNets.c SNNets.h SNConstants.h 17 | $(CC) -o $@ $< $(CFLAGS) -c 18 | 19 | SNUtils.o: SNUtils.c SNUtils.h SNConstants.h 20 | $(CC) -o $@ $< $(CFLAGS) -c 21 | 22 | clean: 23 | rm *.o OpenSNet 24 | -------------------------------------------------------------------------------- /src/OpenSNet/OpenSNet/SNAttributes.c: -------------------------------------------------------------------------------- 1 | // 2 | // SNAttribute.c 3 | // OpenSNet 4 | // 5 | // Created by realityone on 15/10/24. 6 | // Copyright © 2015年 realityone. All rights reserved. 7 | // 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include "SNAttributes.h" 14 | #include "SNConstants.h" 15 | #include "SNUtils.h" 16 | 17 | char *calc_keepalive_data(time_t timestamp) { 18 | static char keepalive_data[64]; 19 | u_char timebytes[4]; 20 | u_char md5_result[16]; 21 | mbedtls_md5_context md5; 22 | 23 | if (strlen(keepalive_data) == 0) { 24 | strcpy(keepalive_data, DEFAULT_KEEPALIVE_DATA); 25 | } 26 | 27 | int2byte((int)timestamp, timebytes); 28 | 29 | mbedtls_md5_init(&md5); 30 | mbedtls_md5_starts(&md5); 31 | mbedtls_md5_update(&md5, timebytes, 4); 32 | mbedtls_md5_update(&md5, (const u_char *)keepalive_data, strlen(keepalive_data)); 33 | mbedtls_md5_finish(&md5, md5_result); 34 | 35 | byte2str(md5_result, 16, keepalive_data); 36 | return keepalive_data; 37 | } 38 | 39 | size_t generate_attribute(u_char parent_id, u_char *attr_data, size_t attr_data_len, SNAttribute *output) { 40 | if (attr_data_len > MAX_ATTRIBUTE_DATA_LEN) { 41 | fprintf(stderr, "ERROR: Attribute data length is too long."); 42 | return -1; 43 | } 44 | 45 | bzero(output, sizeof(SNAttribute)); 46 | 47 | output->parent_id = parent_id; 48 | output->length = attr_data_len; 49 | memcpy(output->data, attr_data, attr_data_len); 50 | 51 | return attr_data_len; 52 | } 53 | 54 | size_t sn_username(const char *username, SNAttribute *output) { 55 | return generate_attribute(USERNAME_ID, (u_char *)username, strlen(username), output); 56 | } 57 | 58 | size_t sn_cliet_ip_address(const char *ipaddress, SNAttribute *output) { 59 | in_addr_t ipaddr; 60 | u_char ip_bytes[4]; 61 | 62 | ipaddr = ntohl(inet_addr(ipaddress)); 63 | if (ipaddr == INADDR_NONE) { 64 | perror("ERROR:"); 65 | return -1; 66 | } 67 | int2byte(ipaddr, ip_bytes); 68 | 69 | return generate_attribute(CLIENT_IPADDRESS_ID, ip_bytes, 4, output); 70 | } 71 | 72 | size_t sn_client_verison(const char *version, SNAttribute *output) { 73 | return generate_attribute(CLIENT_VERSION_ID, (u_char *)version, strlen(version), output); 74 | } 75 | 76 | size_t sn_keepalive_time(time_t timestamp, SNAttribute *output) { 77 | u_char timebytes[4]; 78 | int2byte((int)timestamp, timebytes); 79 | 80 | return generate_attribute(KEEPALIVE_TIME_ID, timebytes, 4, output); 81 | } 82 | 83 | size_t sn_keepalive_data(const char *keepalive_data, SNAttribute *output) { 84 | return generate_attribute(KEEPALIVE_DATA_ID, (u_char *)keepalive_data, strlen(keepalive_data), output); 85 | } 86 | 87 | size_t mashup_attribtes_data(SNAttribute *attributes_array[], size_t arr_nums, u_char *output) { 88 | int i; 89 | size_t attr_data_len; 90 | size_t tmp_attr_data_len; 91 | u_char *poutput; 92 | 93 | poutput = output; 94 | for (i = 0; i < arr_nums; i++) { 95 | attr_data_len = attributes_array[i]->length + ATTRIBUTE_HEADER_LEN; 96 | tmp_attr_data_len = htons(attr_data_len); 97 | 98 | poutput[0] = attributes_array[i]->parent_id; 99 | memcpy(poutput + 1, &tmp_attr_data_len, sizeof(u_short)); 100 | memcpy(poutput + ATTRIBUTE_HEADER_LEN, attributes_array[i]->data, attributes_array[i]->length); 101 | poutput += attr_data_len; 102 | } 103 | return poutput - output; 104 | } 105 | -------------------------------------------------------------------------------- /src/OpenSNet/OpenSNet/SNAttributes.h: -------------------------------------------------------------------------------- 1 | // 2 | // SNAttribute.h 3 | // OpenSNet 4 | // 5 | // Created by realityone on 15/10/24. 6 | // Copyright © 2015年 realityone. All rights reserved. 7 | // 8 | 9 | #ifndef SNAttribute_h 10 | #define SNAttribute_h 11 | 12 | #include 13 | #include 14 | 15 | #define ATTRIBUTE_HEADER_LEN (sizeof(u_char) + sizeof(u_short)) 16 | #define MAX_ATTRIBUTE_DATA_LEN 128 17 | 18 | #define USERNAME_ID 0x1 19 | #define CLIENT_IPADDRESS_ID 0x2 20 | #define CLIENT_VERSION_ID 0x3 21 | #define KEEPALIVE_TIME_ID 0x12 22 | #define KEEPALIVE_DATA_ID 0x14 23 | 24 | typedef struct SNAttribute { 25 | u_char parent_id; 26 | u_short length; 27 | u_char data[MAX_ATTRIBUTE_DATA_LEN]; 28 | } SNAttribute; 29 | 30 | char *calc_keepalive_data(time_t timestamp); 31 | 32 | size_t generate_attribute(u_char parent_id, u_char *attr_data, size_t attr_data_len, SNAttribute *output); 33 | size_t sn_username(const char *username, SNAttribute *output); 34 | size_t sn_cliet_ip_address(const char *ipaddress, SNAttribute *output); 35 | size_t sn_client_verison(const char *version, SNAttribute *output); 36 | size_t sn_keepalive_time(time_t timestamp, SNAttribute *output); 37 | size_t sn_keepalive_data(const char *keepalive_data, SNAttribute *output); 38 | 39 | size_t mashup_attribtes_data(SNAttribute *attributes_array[], size_t arr_nums, u_char *output_data); 40 | 41 | #endif /* SNAttribute_h */ 42 | -------------------------------------------------------------------------------- /src/OpenSNet/OpenSNet/SNConstants.h: -------------------------------------------------------------------------------- 1 | // 2 | // SNConstants.h 3 | // OpenSNet 4 | // 5 | // Created by realityone on 15/10/24. 6 | // Copyright © 2015年 realityone. All rights reserved. 7 | // 8 | 9 | #ifndef SNConstants_h 10 | #define SNConstants_h 11 | 12 | #define CLIENT_TYPE "singleNet" 13 | #define CLIENT_VERSION "1.2.22.36" 14 | 15 | #define DEFAULT_KEEPALIVE_DATA "llwl" 16 | 17 | #define SIGNATURE_SLAT "LLWLXA_TPSHARESECRET" 18 | 19 | #endif /* SNConstants_h */ 20 | -------------------------------------------------------------------------------- /src/OpenSNet/OpenSNet/SNHeartBeat.c: -------------------------------------------------------------------------------- 1 | // 2 | // SNHeartBeat.c 3 | // OpenSNet 4 | // 5 | // Created by realityone on 15/10/24. 6 | // Copyright © 2015年 realityone. All rights reserved. 7 | // 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include "SNHeartBeat.h" 14 | #include "SNAttributes.h" 15 | #include "SNConstants.h" 16 | 17 | 18 | u_char calc_timecode(time_t timestamp) { 19 | int temp_num; 20 | temp_num = (int)(timestamp * 0x343FD + 0x269EC3); 21 | return (temp_num >> 0x10) & 0xFF; 22 | } 23 | 24 | 25 | size_t generate_heartbeat(u_char packet_id, time_t timestamp, u_char *attr_data, 26 | size_t attr_data_len, SNHeartBeat *output) { 27 | size_t heartbeat_length; 28 | bzero(output, sizeof(SNHeartBeat)); 29 | 30 | heartbeat_length = attr_data_len + HEARTBEAT_HEADER_LEN; 31 | 32 | output->magic_number = MAGIC_NUMBER; 33 | output->length = heartbeat_length; 34 | output->packet_id = packet_id; 35 | output->timecode = calc_timecode(timestamp); 36 | 37 | memcpy(output->attributes_data, attr_data, attr_data_len); 38 | return heartbeat_length; 39 | } 40 | 41 | 42 | void set_signature(time_t timestamp, SNHeartBeat *heartbeat, size_t heartbeat_len) { 43 | u_char md5_result[16]; 44 | mbedtls_md5_context md5; 45 | 46 | mbedtls_md5_init(&md5); 47 | mbedtls_md5_starts(&md5); 48 | mbedtls_md5_update(&md5, (const u_char *)heartbeat, heartbeat_len); 49 | mbedtls_md5_update(&md5, (const u_char *)SIGNATURE_SLAT, strlen(SIGNATURE_SLAT)); 50 | mbedtls_md5_finish(&md5, md5_result); 51 | 52 | memcpy(heartbeat->signature, md5_result, 16); 53 | } 54 | 55 | 56 | size_t sn_thunderprotocol(const char *username, const char *ipaddress, time_t timestamp, 57 | const char *version, const char *keepalive_data, SNHeartBeat *output) { 58 | u_char attr_data[MAX_ATTRIBUTES_DATA_LEN]; 59 | size_t attr_data_len; 60 | SNAttribute attr_client_ip_address; 61 | SNAttribute attr_client_version; 62 | SNAttribute attr_keepalive_data; 63 | SNAttribute attr_keepalive_time; 64 | SNAttribute attr_username; 65 | 66 | sn_cliet_ip_address(ipaddress, &attr_client_ip_address); 67 | sn_client_verison(version, &attr_client_version); 68 | sn_keepalive_data(keepalive_data, &attr_keepalive_data); 69 | sn_keepalive_time(timestamp, &attr_keepalive_time); 70 | sn_username(username, &attr_username); 71 | 72 | SNAttribute *(TP_Attributes[]) = { 73 | &attr_client_ip_address, 74 | &attr_client_version, 75 | &attr_keepalive_data, 76 | &attr_keepalive_time, 77 | &attr_username 78 | }; 79 | 80 | attr_data_len = mashup_attribtes_data(TP_Attributes, 81 | sizeof(TP_Attributes) / sizeof(*TP_Attributes), attr_data); 82 | return generate_heartbeat(ThunderProtocolID, timestamp, attr_data, attr_data_len, output); 83 | } 84 | 85 | size_t generate_send_data(time_t timestamp, SNHeartBeat *heartbeat) { 86 | u_short length; 87 | 88 | length = heartbeat->length; 89 | heartbeat->magic_number = htons(heartbeat->magic_number); 90 | heartbeat->length = htons(heartbeat->length); 91 | 92 | set_signature(timestamp, heartbeat, length); 93 | return length; 94 | } 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | -------------------------------------------------------------------------------- /src/OpenSNet/OpenSNet/SNHeartBeat.h: -------------------------------------------------------------------------------- 1 | // 2 | // SNHeartBeat.h 3 | // OpenSNet 4 | // 5 | // Created by realityone on 15/10/24. 6 | // Copyright © 2015年 realityone. All rights reserved. 7 | // 8 | 9 | #ifndef SNHeartBeat_h 10 | #define SNHeartBeat_h 11 | 12 | #include 13 | #include 14 | 15 | #define HEARTBEAT_HEADER_LEN (sizeof(u_short) + sizeof(u_short) + sizeof(u_char) + sizeof(u_char) + sizeof(u_char) * 16) 16 | #define MAX_ATTRIBUTES_DATA_LEN 512 17 | #define MAX_HEARTBEAT_LEN (HEARTBEAT_HEADER_LEN + MAX_ATTRIBUTES_DATA_LEN) 18 | 19 | #define MAGIC_NUMBER 0x534E 20 | 21 | #define ThunderProtocolID 0x3 22 | 23 | typedef struct SNHeartBeat { 24 | u_short magic_number; 25 | u_short length; 26 | u_char packet_id; 27 | u_char timecode; 28 | u_char signature[16]; 29 | u_char attributes_data[MAX_ATTRIBUTES_DATA_LEN]; 30 | } SNHeartBeat; 31 | 32 | size_t generate_heartbeat(u_char packet_id, time_t timestamp, u_char *attr_data, 33 | size_t attr_data_len, SNHeartBeat *output); 34 | 35 | size_t sn_thunderprotocol(const char *username, const char *ipaddress, time_t timestamp, 36 | const char *version, const char *keepalive_data, SNHeartBeat *output); 37 | 38 | size_t generate_send_data(time_t timestamp, SNHeartBeat *heartbeat); 39 | #endif /* SNHeartBeat_h */ 40 | -------------------------------------------------------------------------------- /src/OpenSNet/OpenSNet/SNNets.c: -------------------------------------------------------------------------------- 1 | // 2 | // SNNets.c 3 | // OpenSNet 4 | // 5 | // Created by realityone on 15/10/25. 6 | // Copyright © 2015年 realityone. All rights reserved. 7 | // 8 | 9 | #include "SNNets.h" 10 | 11 | int udp_init(const char *target, int port, struct sockaddr_in *out_s_addr) { 12 | out_s_addr->sin_family = AF_INET; 13 | out_s_addr->sin_addr.s_addr = inet_addr(target); 14 | out_s_addr->sin_port = htons(port); 15 | 16 | return socket(AF_INET, SOCK_DGRAM, IPPROTO_IP); 17 | } 18 | 19 | void udp_close(int sockfd) { 20 | close(sockfd); 21 | } 22 | 23 | int udp_set_timeout(int csockfd, struct timeval timeout) { 24 | return setsockopt(csockfd, SOL_SOCKET, SO_RCVTIMEO, (char *)&timeout, sizeof(struct timeval)); 25 | } 26 | 27 | size_t udp_sendto(int sockfd, struct sockaddr_in *s_addr, u_char *send_data, size_t length) { 28 | return sendto(sockfd, send_data, 29 | length, 0, 30 | (struct sockaddr *)s_addr, sizeof(struct sockaddr)); 31 | } 32 | 33 | size_t udp_rcvfrom(int sockfd, u_char *rcv_buffer, size_t buffer_size) { 34 | return recvfrom(sockfd, rcv_buffer, 35 | buffer_size, 0, NULL, NULL); 36 | } -------------------------------------------------------------------------------- /src/OpenSNet/OpenSNet/SNNets.h: -------------------------------------------------------------------------------- 1 | // 2 | // SNNets.h 3 | // OpenSNet 4 | // 5 | // Created by realityone on 15/10/25. 6 | // Copyright © 2015年 realityone. All rights reserved. 7 | // 8 | 9 | #ifndef SNNets_h 10 | #define SNNets_h 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | int udp_init(const char *target, int port, struct sockaddr_in *out_s_addr); 22 | void udp_close(int sockfd); 23 | 24 | int udp_set_timeout(int sockfd, struct timeval timeout); 25 | size_t udp_sendto(int sockfd, struct sockaddr_in *s_addr, u_char *send_data, size_t length); 26 | size_t udp_rcvfrom(int sockfd, u_char *rcv_buffer, size_t buffer_size); 27 | 28 | #endif /* SNNets_h */ 29 | -------------------------------------------------------------------------------- /src/OpenSNet/OpenSNet/SNUtils.c: -------------------------------------------------------------------------------- 1 | // 2 | // SNUtils.c 3 | // OpenSNet 4 | // 5 | // Created by realityone on 15/10/24. 6 | // Copyright © 2015年 realityone. All rights reserved. 7 | // 8 | 9 | #include "SNUtils.h" 10 | 11 | void int2byte(int num, u_char *output) { 12 | int i; 13 | for (i = 0; i < 4; i++) { 14 | output[i] = (u_char)(num >> (8 * (3 - i)) & 0xFF); 15 | } 16 | } 17 | 18 | void byte2str(u_char *byte_arr, size_t byte_len, char *output) { 19 | static char hex[] = "0123456789abcdef"; 20 | char *pout = output; 21 | 22 | int i; 23 | for (i = 0; i < byte_len; i++, pout += 2) { 24 | pout[0] = hex[byte_arr[i] >> 4 & 0xF]; 25 | pout[1] = hex[byte_arr[i] & 0xF]; 26 | } 27 | 28 | pout[0] = '\0'; 29 | } -------------------------------------------------------------------------------- /src/OpenSNet/OpenSNet/SNUtils.h: -------------------------------------------------------------------------------- 1 | // 2 | // SNUtils.h 3 | // OpenSNet 4 | // 5 | // Created by realityone on 15/10/24. 6 | // Copyright © 2015年 realityone. All rights reserved. 7 | // 8 | 9 | #ifndef SNUtils_h 10 | #define SNUtils_h 11 | 12 | #include 13 | #include 14 | 15 | void int2byte(int num, u_char *output); 16 | void byte2str(u_char *byte_arr, size_t byte_len, char *output); 17 | 18 | #endif /* SNUtils_h */ 19 | -------------------------------------------------------------------------------- /src/OpenSNet/OpenSNet/main.c: -------------------------------------------------------------------------------- 1 | // 2 | // main.c 3 | // OpenSNet 4 | // 5 | // Created by realityone on 15/10/24. 6 | // Copyright © 2015年 realityone. All rights reserved. 7 | // 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | #include "SNAttributes.h" 19 | #include "SNHeartBeat.h" 20 | #include "SNConstants.h" 21 | #include "SNNets.h" 22 | 23 | #define DEFAULT_TIMEOUT {2, 0} 24 | 25 | static const char short_opts[] = "u:i:I:t:P:h"; 26 | static struct option long_options[] = { 27 | {"username", required_argument, NULL, 'u'}, 28 | {"ip", required_argument, NULL, 'i'}, 29 | {"interval", required_argument, NULL, 'I'}, 30 | {"target", required_argument, NULL, 't'}, 31 | {"port", required_argument, NULL, 'P'}, 32 | {"help", no_argument, NULL, 'h'}, 33 | {NULL, 0, NULL, 0} 34 | }; 35 | 36 | static struct UserConfig { 37 | const char username[32]; 38 | const char ipaddress[16]; 39 | const char target[16]; 40 | int port; 41 | int interval; 42 | }user_config; 43 | 44 | void print_usage() { 45 | fprintf(stdout, "Usage: OpenSNet [OPTIONS]\n"); 46 | fprintf(stdout, "Options:\n"); 47 | fprintf(stdout, " --username, -u: Username.\n"); 48 | fprintf(stdout, " --ipaddress, -i: IP Address.\n"); 49 | fprintf(stdout, " --interval, -I: Interval.\n"); 50 | fprintf(stdout, " --target, -t: Target.\n"); 51 | fprintf(stdout, " --port, -P: Port.\n"); 52 | fprintf(stdout, " --help, -h: Help.\n"); 53 | exit(0); 54 | } 55 | 56 | void validate_config() { 57 | if (!strlen(user_config.username) || 58 | !strlen(user_config.ipaddress) || 59 | !strlen(user_config.target) || 60 | !user_config.port || 61 | !user_config.interval) { 62 | fprintf(stderr, "Missing arguments.\n"); 63 | print_usage(); 64 | } 65 | } 66 | 67 | void parse_args(int argc, const char * argv[]) { 68 | int opt; 69 | 70 | while ((opt = getopt_long(argc, (char *const *)argv, short_opts, long_options, NULL)) != -1) { 71 | switch (opt) { 72 | case 'h': 73 | print_usage(); 74 | break; 75 | 76 | case 'u': 77 | strcpy((char *)user_config.username, optarg); 78 | break; 79 | 80 | case 'i': 81 | strcpy((char *)user_config.ipaddress, optarg); 82 | break; 83 | 84 | case 't': 85 | strcpy((char *)user_config.target, optarg); 86 | break; 87 | 88 | case 'P': 89 | user_config.port = atoi(optarg); 90 | break; 91 | 92 | case 'I': 93 | user_config.interval = atoi(optarg); 94 | break; 95 | 96 | default: 97 | print_usage(); 98 | break; 99 | } 100 | } 101 | validate_config(); 102 | } 103 | 104 | void main_loop(int argc, const char * argv[]) { 105 | int times; 106 | int sockfd; 107 | int result; 108 | time_t timestamp; 109 | size_t packet_len; 110 | char *keepalive_data; 111 | SNHeartBeat ThunderProtocol; 112 | struct sockaddr_in target_addr; 113 | struct timeval timeout = DEFAULT_TIMEOUT; 114 | 115 | parse_args(argc, argv); 116 | 117 | sockfd = udp_init(user_config.target, user_config.port, &target_addr); 118 | udp_set_timeout(sockfd, timeout); 119 | 120 | times = 0; 121 | while (1) { 122 | times += 1; 123 | timestamp = time(NULL); 124 | keepalive_data = calc_keepalive_data(timestamp); 125 | packet_len = sn_thunderprotocol(user_config.username, user_config.ipaddress, 126 | timestamp, CLIENT_VERSION, keepalive_data, &ThunderProtocol); 127 | packet_len = generate_send_data(timestamp, &ThunderProtocol); 128 | if ((result = (int)udp_sendto(sockfd, &target_addr, (u_char *)&ThunderProtocol, packet_len)) > 0) { 129 | fprintf(stdout, "INFO: Send packet succeed.\n"); 130 | bzero(&ThunderProtocol, sizeof(SNHeartBeat)); 131 | if ((result = (int)udp_rcvfrom(sockfd, (u_char *)&ThunderProtocol, packet_len)) > 0) { 132 | fprintf(stdout, "INFO: Recv packet succeed.\n"); 133 | } else { 134 | fprintf(stderr, "ERROR: Wait for packet timeout.\n"); 135 | } 136 | } else { 137 | fprintf(stderr, "ERROR: Send packet failed.\n"); 138 | } 139 | fprintf(stdout, "INFO: Wait %d seconds.\n", user_config.interval); 140 | sleep(user_config.interval); 141 | } 142 | } 143 | 144 | int main(int argc, const char * argv[]) { 145 | main_loop(argc, argv); 146 | return 0; 147 | } 148 | -------------------------------------------------------------------------------- /src/OpenShineto/LongBase64.py: -------------------------------------------------------------------------------- 1 | import time 2 | import base64 3 | 4 | 5 | class LongBase64(object): 6 | """ 7 | usage: 8 | lb64 = LongBase64() 9 | lb64.Long_EnCode(string) 10 | lb64.Long_DeCode(encode_string) 11 | """ 12 | _encrypt_seed_1 = [ 13 | 'salku!doew%oi3ry*khasl$kjf#gdksh', 14 | 'pjf/726;lsjfgo^s9234khsldfk:lkjl', 15 | 'klu\owe8*6>sjdhf8yi6,+-!ksdfh@19', 16 | '834k|hdf3yg>m+", 70 | "(8oisndfht*^&RT^&bubdsolhn;Pmlkm", 71 | "OI&*(hf87tgfkU!`09ujo$ksfjh*(jou", 72 | "09u*)IJHsoidh{L}\m;lmweo89JL,:\/", 73 | "IU(*7yfc98wh8t^*HBOHfwsdnfiuy)ko", 74 | "*(&(*houhsyibgsiyt976t8H)OJP:[ 12 or int_day > 31: 91 | return None 92 | if int_mon < 1 or int_day < 1: 93 | return None 94 | 95 | seed_1 = self._encrypt_seed_1[int_day - 1] 96 | seed_2 = self._encrypt_seed_2[abs(30 - int_day)] 97 | 98 | i = abs(int_day - 2 * int_mon) 99 | if i == 0: 100 | i = int_mon 101 | s1_len = len(seed_1) 102 | s2_len = len(seed_2) 103 | 104 | if int_mon % 2 == 0: 105 | s1_pos = seed_1[0: i] 106 | s2_pos = seed_2[int_mon - 1: 2 * int_mon - 1] 107 | else: 108 | s1_pos = seed_1[s1_len - i: s1_len] 109 | s2_pos = seed_2[int_mon - 1: 2 * int_mon - 1] 110 | 111 | tmp_str = s2_pos + s1_pos 112 | 113 | value_insert = '' 114 | for c in tmp_str: 115 | if ord(c) >= 48 and ord(c) <= 57: 116 | j = int(c) % s2_len 117 | else: 118 | j = ord(c) % s2_len 119 | if j == 0: 120 | j = 5 121 | value_insert = value_insert + seed_2[j - 1] 122 | 123 | if int_day <= 15: 124 | i = 15 - int_day 125 | if i == 0: 126 | i = 7 127 | j = int_mon 128 | if j < 6: 129 | j += 3 130 | if int_day % 2 == 0: 131 | value_insert = value_insert + seed_2[0: i] + seed_2[s2_len - j: s2_len] 132 | else: 133 | value_insert = value_insert + seed_1[0: 15 - int_day] + seed_1[s1_len - int_day: s1_len] 134 | else: 135 | i = int_day % 9 136 | if i == 0: 137 | i = 9 138 | j = int_mon 139 | if j < 6: 140 | j += 4 141 | 142 | if int_day % 2 == 0: 143 | value_insert = value_insert + seed_2[s2_len - i: s2_len] + seed_1[0: j] 144 | else: 145 | value_insert = value_insert + seed_1[s2_len - i: s2_len] + seed_2[0: j] 146 | 147 | return value_insert 148 | 149 | def _string_of_char(self, char, times): 150 | return char * times 151 | 152 | def _do_output(self, a_str, b_str): 153 | base = base64.decodestring(a_str) 154 | 155 | base_len = len(base) 156 | b_len = len(b_str) 157 | r = '' 158 | 159 | if base_len >= b_len: 160 | diff = base_len - b_len 161 | tmp_str = b_str + self._string_of_char(b_str[0], diff) 162 | 163 | for i in xrange(base_len): 164 | r = r + chr((ord(base[i]) ^ ord(tmp_str[i]))) 165 | else: 166 | for i in xrange(base_len): 167 | r += chr(ord(base[i]) ^ ord(b_str[i])) 168 | 169 | res = base64.decodestring(r) 170 | 171 | return res 172 | 173 | def _get_random(self): 174 | self._random_num = int(time.time()) & 0x0FFFFFFF 175 | self._random_num = 95394635 176 | re = {} 177 | 178 | def calc_number(diff_value): 179 | self._random_num = self._random_num * 0x8088405 + 1 180 | self._random_num = self._random_num & 0xFFFFFFFF 181 | return (self._random_num * diff_value) >> 32 182 | 183 | def get_number(num1, num2): 184 | if num2 >= num1: 185 | return num1 + calc_number(num2 - num1) 186 | else: 187 | return num2 + calc_number(num1 - num2) 188 | 189 | re['year'] = get_number(1998, 9999) 190 | re['month'] = get_number(1, 12) 191 | re['day'] = get_number(1, 29) 192 | 193 | return re 194 | 195 | def _en_num(self, num): 196 | opt_num = int(num) 197 | re = ((opt_num - 19970701) * 8 + 2046) * 3 198 | return '%d|' % re 199 | 200 | def _do_insert(self, a_str, b_str): 201 | a_len = len(a_str) 202 | b_len = len(b_str) 203 | res = '' 204 | 205 | if a_len > b_len: 206 | diff = a_len - b_len 207 | t_replay = b_str[0] 208 | tmp_str = b_str + self._string_of_char(t_replay, diff) 209 | 210 | for i in xrange(a_len): 211 | res += chr(ord(a_str[i]) ^ ord(tmp_str[i])) 212 | else: 213 | for i in xrange(a_len): 214 | res += chr(ord(a_str[i]) ^ ord(b_str[i])) 215 | 216 | res = base64.encodestring(res) 217 | res = res.replace('\n', '') 218 | 219 | return res 220 | 221 | def encodestring(self, plaintext): 222 | r_time = self._get_random() 223 | 224 | mon = '%02d' % r_time['month'] 225 | day = '%02d' % r_time['day'] 226 | 227 | mmdd = mon + day 228 | value_insert = self._get_value_insert(mmdd) 229 | 230 | base_str = base64.encodestring('%s$LONGMIMASPLIT$%d' % (plaintext, int(time.time() * 1000))) 231 | base_str = base_str.replace('\n', '') 232 | 233 | new_string = self._do_insert(base_str, value_insert) 234 | new_string = self._en_num('%d%s' % (r_time['year'], mmdd)) + new_string 235 | 236 | return new_string 237 | 238 | def decodestring(self, ciphertext): 239 | tmp = ciphertext.split('|') 240 | deCode = self._decode_num(tmp[0]) 241 | 242 | value_insert = self._get_value_insert(deCode) 243 | new_string = self._do_output(tmp[1], value_insert) 244 | 245 | new_string = new_string.split('$LONGMIMASPLIT$') 246 | return new_string[0] 247 | 248 | 249 | if __name__ == '__main__': 250 | pass -------------------------------------------------------------------------------- /src/OpenShineto/README.md: -------------------------------------------------------------------------------- 1 | # OpenShineTo 2 | 3 | Some core functions about shineto. 4 | 5 | Anyway, ShineTo maybe has gone. 6 | -------------------------------------------------------------------------------- /src/OpenShineto/ShinetoHeartBeat.py: -------------------------------------------------------------------------------- 1 | import time 2 | import copy 3 | import struct 4 | import hashlib 5 | 6 | 7 | def generate_uuid(basestr='Administrator'): 8 | md5 = hashlib.md5(basestr) 9 | md5_hex = md5.hexdigest().upper() 10 | return '%s-%s-%s-%s' % (md5_hex[0:6], md5_hex[7:12], md5_hex[13:21], md5_hex[22:28]) 11 | 12 | 13 | class MagicNum(object): 14 | def __init__(self, tick=None): 15 | self.tick = tick or (int(time.time()) & 0x0FFFFFFFF) 16 | 17 | def _calc_number(self, diff_value): 18 | result_num = (self.tick * 0x8088405 + 1) & 0xFFFFFFFF 19 | return (result_num * diff_value) >> 32 20 | 21 | def _get_number(self, num1, num2): 22 | if num2 >= num1: 23 | return num1 + self._calc_number(num2 - num1) 24 | else: 25 | return num2 + self._calc_number(num1 - num2) 26 | 27 | def _second_num(self, first_num): 28 | num_int = [first_num / 100 % 10, first_num / 10 % 10, first_num % 10] 29 | 30 | result = (num_int[0] * num_int[1]) * 8 31 | result += (num_int[0] + num_int[1]) * 9 32 | result += (num_int[1] + num_int[2]) * 8 33 | result += (num_int[0] * num_int[2]) * 9 34 | 35 | return result 36 | 37 | def magic_number(self): 38 | first_num = self._get_number(101, 999) 39 | second_num = self._second_num(first_num) 40 | return int('%s%s' % (first_num, second_num)) 41 | 42 | 43 | class BaseHeartBeat(object): 44 | """ 45 | ('mail.189joy.com', 8987) 46 | """ 47 | _actions = { 48 | 'login': 0xE6D2FB51, 49 | 'keep': 0xE6D2FB52, 50 | 'logout': 0xE6D2FB53, 51 | 'recv_succ': 0xE6D2FB54 52 | } 53 | _fmt_str = '> (i + 4 * j)) & 1) << (7 - j)) 26 | 27 | pin27_byte = [0] * 8 28 | pin27_byte[0] = ((time_hash[0] >> 2) & 0x3F) 29 | pin27_byte[1] = ((time_hash[0] & 0x03) << 4 & 0xff) | ((time_hash[1] >> 4) & 0x0F) 30 | pin27_byte[2] = ((time_hash[1] & 0x0F) << 2 & 0xff) | ((time_hash[2] >> 6) & 0x03) 31 | pin27_byte[3] = time_hash[2] & 0x3F 32 | pin27_byte[4] = ((time_hash[3] >> 2) & 0x3F) 33 | pin27_byte[5] = ((time_hash[3] & 0x03) << 4 & 0xff) 34 | for i in xrange(6): 35 | pin27_byte[i] = {True: (pin27_byte[i] + 0x20) & 0xff, 36 | False: (pin27_byte[i] + 0x21) & 0xff}[((pin27_byte[i] + 0x20) & 0xff) < 0x40] 37 | 38 | pin27_str = '' 39 | for i in xrange(6): 40 | pin27_str = pin27_str + chr(pin27_byte[i]) 41 | 42 | before_md5 = struct.pack('>I', time_div_by_five) + username.split('@')[0] + share_key 43 | pin89_str = hashlib.md5(before_md5).hexdigest()[0:2] 44 | 45 | pin = prefix + pin27_str + pin89_str 46 | return pin 47 | 48 | if __name__ == '__main__': 49 | pass -------------------------------------------------------------------------------- /src/SNAccount2.py: -------------------------------------------------------------------------------- 1 | import time 2 | import struct 3 | from SNConstants import HNSNAccount 4 | 5 | 6 | def hash_key(key_str): 7 | length = len(key_str) 8 | result = 0 9 | fmt_str = '<%dH' % (length / 2) 10 | 11 | if length % 2: 12 | result = ord(key_str[-1]) 13 | key_str = key_str[:-1] 14 | 15 | result += sum(struct.unpack(fmt_str, key_str)) 16 | 17 | if result & 0xFFFF0000: 18 | result = ((result >> 0x10) + result) & 0xFFFF 19 | 20 | result = ~result & 0xFFFF 21 | return result 22 | 23 | 24 | def new_calc_pin(username, share_key=None, sec_key=None, timestamp=None): 25 | share_key = share_key or HNSNAccount['SHARE_KEY'] 26 | sec_key = sec_key or HNSNAccount['SEC_KEY'] 27 | KEY_TABLE = HNSNAccount['KEY_TABLE'] 28 | 29 | timestamp = (timestamp or int(time.time())) & 0xFFFFFFFF 30 | 31 | first_key = struct.pack( 32 | '>I', timestamp) + share_key + username.split('@')[0] 33 | first_hash = hash_key(first_key) 34 | 35 | second_key = struct.pack('>H', first_hash) + sec_key 36 | second_hash = hash_key(second_key) 37 | 38 | final_key = struct.pack('>H', timestamp >> 16) 39 | final_key += struct.pack('H', timestamp & 0xFFFF) 41 | final_key += struct.pack('> 0x3 & 0x1F) 49 | vectors.append( 50 | ((final_table[i - 1] & 0x7) << 0x2) | (final_table[i] >> 0x6 & 0x3)) 51 | vectors.append(final_table[i] & 0x3F) 52 | 53 | result = map(lambda position: KEY_TABLE[position % 64], vectors) 54 | return '~LL_%s_' % ''.join(result) 55 | 56 | if __name__ == '__main__': 57 | pass 58 | -------------------------------------------------------------------------------- /src/SNAttribute.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding=utf-8 3 | import time 4 | import struct 5 | import socket 6 | import hashlib 7 | import SNConstants 8 | 9 | 10 | class SNAttribute(object): 11 | 12 | def __init__(self, typename, parent_id, type_id, value_type, value): 13 | self.typename = typename 14 | self.parent_id = parent_id 15 | self.type_id = type_id 16 | self.value_type = value_type 17 | self.value = value 18 | 19 | @property 20 | def length(self): 21 | return len(self.value) 22 | 23 | def digest(self): 24 | fmt_str = '>BH%ds' % self.length 25 | return struct.pack(fmt_str, self.parent_id, self.length + 3, self.value) 26 | 27 | def hexdigest(self): 28 | return self.digest().encode('hex') 29 | 30 | 31 | class USER_NAME(SNAttribute): 32 | 33 | """ 34 | un = USER_NAME('18088888888@HYXY.XY') 35 | un.digest() 36 | """ 37 | 38 | def __init__(self, username): 39 | super(USER_NAME, self).__init__(typename='User-Name', 40 | parent_id=0x1, type_id=0x0, value_type=0x2, value=username) 41 | 42 | 43 | class CLIENT_IP_ADDRESS(SNAttribute): 44 | 45 | """ 46 | cia = CLIENT_IP_ADDRESS('192.168.1.1') 47 | cia.digest() 48 | """ 49 | 50 | def __init__(self, client_ip_address): 51 | client_ip_address = socket.inet_aton(client_ip_address) 52 | super(CLIENT_IP_ADDRESS, self).__init__(typename='Client-IP-Address', 53 | parent_id=0x2, type_id=0x0, value_type=0x1, value=client_ip_address) 54 | 55 | 56 | class CLIENT_VERSION(SNAttribute): 57 | 58 | """ 59 | cv = CLIENT_VERSION('1.2.16.20') 60 | cv.digest() 61 | """ 62 | 63 | def __init__(self, client_version): 64 | super(CLIENT_VERSION, self).__init__(typename='Client-Version', 65 | parent_id=0x3, type_id=0x0, value_type=0x2, value=client_version) 66 | 67 | 68 | class CLIENT_TYPE(SNAttribute): 69 | 70 | """ 71 | ct = CLIENT_TYPE('Mac-SingleNet') 72 | ct.digest() 73 | """ 74 | 75 | def __init__(self, client_type): 76 | super(CLIENT_TYPE, self).__init__(typename='Client-Type', 77 | parent_id=0x4, type_id=0x0, value_type=0x2, value=client_type) 78 | 79 | 80 | class OS_VERSION(SNAttribute): 81 | 82 | """ 83 | ov = OS_VERSION('Microsoft Windows XP Service Pack 3') 84 | ov.digest() 85 | """ 86 | 87 | def __init__(self, os_version): 88 | super(OS_VERSION, self).__init__(typename='OS-Version', 89 | parent_id=0x5, type_id=0x0, value_type=0x2, value=os_version) 90 | 91 | 92 | class OS_LANG(SNAttribute): 93 | 94 | """ 95 | ol = OS_LANG('Chinese-RPC') 96 | ol.digest() 97 | """ 98 | 99 | def __init__(self, os_lang): 100 | super(OS_LANG, self).__init__(typename='OS-Lang', 101 | parent_id=0x6, type_id=0x0, value_type=0x2, value=os_lang) 102 | 103 | 104 | class CPU_INFO(SNAttribute): 105 | 106 | """ 107 | ci = CPU_INFO('Intel(R) Core(TM) i5-3210M CPU @ 2.50GHz') 108 | ci.digest() 109 | """ 110 | 111 | def __init__(self, cpu_info): 112 | super(CPU_INFO, self).__init__(typename='CPU-Info', 113 | parent_id=0x8, type_id=0x0, value_type=0x2, value=cpu_info) 114 | 115 | 116 | class MAC_ADDRESS(SNAttribute): 117 | 118 | """ 119 | ma = MAC_ADDRESS('10:dd:b1:d5:95:ca') 120 | ma.digest() 121 | """ 122 | 123 | def __init__(self, mac_address): 124 | super(MAC_ADDRESS, self).__init__(typename='MAC-Address', 125 | parent_id=0x9, type_id=0x0, value_type=0x2, value=mac_address) 126 | 127 | 128 | class MEMORY_SIZE(SNAttribute): 129 | 130 | """ 131 | mz = MEMORY_SIZE(0x000001FF) 132 | mz.digest() 133 | """ 134 | 135 | def __init__(self, memory_size): 136 | memory_size = struct.pack('>I', memory_size) 137 | super(MEMORY_SIZE, self).__init__(typename='Memory-Size', 138 | parent_id=0xa, type_id=0x0, value_type=0x0, value=memory_size) 139 | 140 | 141 | class DEFAULT_EXPLORER(SNAttribute): 142 | 143 | """ 144 | de = DEFAULT_EXPLORER('IE 6.0.2900.5512') 145 | de.digest() 146 | """ 147 | 148 | def __init__(self, default_explorer): 149 | super(DEFAULT_EXPLORER, self).__init__(typename='Default-Explorer', 150 | parent_id=0xb, type_id=0x0, value_type=0x2, value=default_explorer) 151 | 152 | 153 | class KEEPALIVE_DATA(SNAttribute): 154 | last_data = None 155 | 156 | """ 157 | keepalive_data = KEEPALIVE_DATA.get_keepalive_data() 158 | kv = KEEPALIVE_DATA(keepalive_data) 159 | kv.digest() 160 | """ 161 | 162 | def __init__(self, keepalive_data): 163 | super(KEEPALIVE_DATA, self).__init__(typename='KeepAlive-Data', 164 | parent_id=0x14, type_id=0x0, value_type=0x2, value=keepalive_data) 165 | 166 | @classmethod 167 | def get_keepalive_data(cls, timestamp=None): 168 | timestamp = timestamp or int(time.time()) 169 | salt = cls.last_data or SNConstants.HBDefault['DEFAULT_HB_DATA'] 170 | 171 | m = hashlib.md5() 172 | m.update(struct.pack('>I', timestamp)) 173 | m.update(salt) 174 | 175 | cls.last_data = keepalive_data = m.hexdigest() 176 | return keepalive_data 177 | 178 | 179 | class KEEPALIVE_TIME(SNAttribute): 180 | 181 | """ 182 | kt = KEEPALIVE_TIME(int(time.time())) 183 | kt.digest() 184 | """ 185 | 186 | def __init__(self, keepalive_time): 187 | keepalive_time = struct.pack('>I', keepalive_time) 188 | super(KEEPALIVE_TIME, self).__init__(typename='KeepAlive-Time', 189 | parent_id=0x12, type_id=0x0, value_type=0x0, value=keepalive_time) 190 | 191 | 192 | if __name__ == '__main__': 193 | pass -------------------------------------------------------------------------------- /src/SNConstants.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding=utf-8 3 | import base64 4 | 5 | NKAccount = { 6 | 'SHARE_KEY': base64.decodestring('emp4aW5saXN4MDE=') 7 | } 8 | 9 | SNAccount = { 10 | 'SHARE_KEY': base64.decodestring('c2luZ2xlbmV0MDE=') 11 | } 12 | 13 | HNSNAccount = { 14 | 'SHARE_KEY': base64.decodestring('aG5neDAx'), 15 | 'SEC_KEY': base64.decodestring('MDAwYzI5MjcwNzEy'), 16 | 'KEY_TABLE': base64.decodestring('YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXoxMjM0NTY3ODkwWllYV1ZVVFNSUVBPTk1MS0pJSEdGRURDQkE6Xw==') 17 | } 18 | 19 | SNClient = { 20 | 'CLIENT_VERSION': '1.2.22.36', 21 | 'CLIENT_TYPE': base64.decodestring('c2luZ2xlTmV0') 22 | } 23 | 24 | HBDefault = { 25 | 'DEFAULT_HB_DATA': base64.decodestring('bGx3bA=='), 26 | 'SIG_SALT': base64.decodestring('TExXTFhBX1RQU0hBUkVTRUNSRVQ='), 27 | 'SIG_SALT_MAC': base64.decodestring('TExXTFhB'), 28 | 'ADAPTER_INFO': 'AMD PCNET Family PCI Ethernet Adapter - 数据包计划程序微型端口', 29 | 'DEFAULT_EXPLORER': 'IE 6.0.2900.5512', 30 | 'MEMORY_SIZE': 0x000001FF, 31 | 'MAC_ADDRESS': '00-0C-29-F1-51-37', 32 | 'CPU_INFO': 'Intel(R) Core(TM) i5-3210M CPU @ 2.50GHz', 33 | 'OS_LANG': 'Chinese-RPC', 34 | 'OS_VERSION': 'Microsoft Windows XP Service Pack 3' 35 | } 36 | -------------------------------------------------------------------------------- /src/SNHeartBeat.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding=utf-8 3 | 4 | import time 5 | import struct 6 | import hashlib 7 | import SNAttribute 8 | from SNConstants import HBDefault, SNClient 9 | 10 | 11 | class SNHeartBeat(object): 12 | 13 | def __init__(self, code, timestamp, attribute_list, magic_num=0x534E): 14 | self.code = code 15 | self.timeflag = self.calc_timeflag(timestamp=timestamp) 16 | self.magic_num = magic_num 17 | self.attribute_list = attribute_list 18 | 19 | self._fmt_str = '>HHBB16s' 20 | 21 | @property 22 | def attributes_data(self): 23 | return ''.join(map(lambda a:a.digest(), self.attribute_list)) 24 | 25 | @property 26 | def length(self): 27 | return struct.calcsize(self._fmt_str) + len(self.attributes_data) 28 | 29 | @property 30 | def signature(self): 31 | salt = HBDefault['SIG_SALT'] 32 | 33 | temp_data = struct.pack(self._fmt_str, self.magic_num, 34 | self.length, self.code, 35 | self.timeflag, '\x00' * 16) 36 | temp_data += self.attributes_data 37 | 38 | m = hashlib.md5() 39 | m.update(temp_data) 40 | m.update(salt) 41 | 42 | return m.digest() 43 | 44 | @classmethod 45 | def calc_timeflag(cls, timestamp=None): 46 | timestamp = timestamp or int(time.time()) 47 | temp_num = (((timestamp * 0x343FD) + 0x269EC3) & 0xFFFFFFFF) 48 | timeflag = (temp_num >> 0x10) & 0xFF 49 | return timeflag 50 | 51 | def digest(self): 52 | rawdata = struct.pack(self._fmt_str, self.magic_num, 53 | self.length, self.code, 54 | self.timeflag, self.signature) 55 | rawdata += self.attributes_data 56 | return rawdata 57 | 58 | def hexdigest(self): 59 | return self.digest().encode('hex') 60 | 61 | 62 | class SNThunderProtocol(SNHeartBeat): 63 | 64 | def __init__(self, username, ipaddress, timestamp, version=None): 65 | version = version or SNClient['CLIENT_VERSION'] 66 | attribute_list = [ 67 | SNAttribute.CLIENT_IP_ADDRESS(ipaddress), 68 | SNAttribute.CLIENT_VERSION(version), 69 | SNAttribute.KEEPALIVE_DATA( 70 | SNAttribute.KEEPALIVE_DATA.get_keepalive_data(timestamp)), 71 | SNAttribute.KEEPALIVE_TIME(timestamp), 72 | SNAttribute.USER_NAME(username), 73 | ] 74 | super(SNThunderProtocol, self).__init__( 75 | code=0x3, timestamp=timestamp, attribute_list=attribute_list) 76 | 77 | 78 | class SNRegister_Bubble(SNHeartBeat): 79 | 80 | def __init__(self, bubble_id, ipaddress, username, timestamp): 81 | attribute_list = [ 82 | SNAttribute.CLIENT_IP_ADDRESS(ipaddress), 83 | SNAttribute.USER_NAME(username) 84 | ] 85 | super(SNRegister_Bubble, self).__init__( 86 | code=bubble_id, timestamp=timestamp, attribute_list=attribute_list) 87 | 88 | 89 | class SNRegister_MAC(SNHeartBeat): 90 | 91 | """ 92 | 115.239.134.166:8000 93 | """ 94 | 95 | cpu_info = 'Intel(R) Core(TM) i5-3210M CPU @ 2.50GHz' 96 | default_explorer = '' 97 | client_type = 'Mac-SingletNet' 98 | client_version = '1.0.1' 99 | memory_size = 0x00001000 100 | os_version = 'Mac OS X Version 10.9.5 (Build 13F1077)' 101 | os_lang = 'zh_CN' 102 | 103 | def __init__(self, username, ipaddress, mac_address='10:dd:b1:d5:95:ca'): 104 | attribute_list = [ 105 | SNAttribute.USER_NAME(username), 106 | SNAttribute.CLIENT_VERSION(self.client_version), 107 | SNAttribute.CLIENT_TYPE(self.client_type), 108 | SNAttribute.CLIENT_IP_ADDRESS(ipaddress), 109 | SNAttribute.MAC_ADDRESS(mac_address), 110 | SNAttribute.DEFAULT_EXPLORER(self.default_explorer), 111 | SNAttribute.CPU_INFO(self.cpu_info), 112 | SNAttribute.MEMORY_SIZE(self.memory_size), 113 | SNAttribute.OS_VERSION(self.os_version), 114 | SNAttribute.OS_LANG(self.os_lang) 115 | ] 116 | super(SNRegister_MAC, self).__init__(code=0x1, 117 | timestamp=0, attribute_list=attribute_list) 118 | self.timeflag = 0x1 119 | 120 | @property 121 | def signature(self): 122 | salt = HBDefault['SIG_SALT_MAC'] 123 | 124 | temp_data = struct.pack(self._fmt_str, self.magic_num, 125 | self.length, self.code, 126 | self.timeflag, '\x00' * 16) 127 | temp_data += self.attributes_data 128 | 129 | m = hashlib.md5() 130 | m.update(temp_data) 131 | m.update(salt) 132 | 133 | return m.digest() 134 | 135 | 136 | if __name__ == '__main__': 137 | pass -------------------------------------------------------------------------------- /src/SNUtils.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding=utf-8 3 | 4 | -------------------------------------------------------------------------------- /src/TPEnc.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding=utf-8 3 | 4 | 5 | def security_encode(pwd, key='RDpbLfCPsJZ7fiv'): 6 | charbox = ('yLwVl0zKqws7LgKPRQ84Mdt708T1qQ3Ha7xv3H7NyU84p21BriUWBU43odz3iP4rBL3cD02KZciX' 7 | 'TysVXiV8ngg6vL48rPJyAUw0HurW20xqxv9aYb4M9wK1Ae0wlro510qXeU07kV57fQMc8L6aLgML' 8 | 'wygtc0F10a0Dg70TOoouyFhdysuRMO51yY5ZlOZZLEal1h0t9YQW0Ko7oBwmCAHoic4HYbUyVeU3' 9 | 'sfQ1xtXcPcf1aT303wAQhv66qzW') 10 | 11 | keyl = len(key) 12 | pwdl = len(pwd) 13 | charboxl = len(charbox) 14 | 15 | # times = keyl if keyl > pwdl else pwdl 16 | times = max(keyl, pwdl) 17 | 18 | ciphertext = '' 19 | for index in xrange(times): 20 | cl = cr = 0xBB 21 | 22 | if index >= keyl: 23 | cr = ord(pwd[index]) 24 | elif index >= pwdl: 25 | cl = ord(key[index]) 26 | else: 27 | cl = ord(key[index]) 28 | cr = ord(pwd[index]) 29 | 30 | ciphertext += charbox[(cl ^ cr) % charboxl] 31 | 32 | return ciphertext 33 | 34 | if __name__ == '__main__': 35 | print security_encode('537953795379') 36 | -------------------------------------------------------------------------------- /src/XLStringEnc.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding=utf-8 3 | 4 | 5 | class XLStringEnc(object): 6 | 7 | """ 8 | usage: 9 | xl = XLStringEnc() 10 | print xl.decrypt('e4b5faf2c04576af98fa3dd354d32da2') 11 | print xl.encrypt('xlzjhrprotocol3x') 12 | """ 13 | 14 | base_key = 'f12acd03b45e9678' 15 | base_box = ('SDJJLKNASDHFUIAk' 16 | 'hfu340985LIASDJF' 17 | 'OISDLKJFOIESJFDK' 18 | 'SMFMLKdLKASDJFOI' 19 | 'DJKKfhisdfisdfks' 20 | 'OIAJEFJLKALSDKFj' 21 | 'kdhfiehsdKA') 22 | 23 | def update_basestring(self, base_key, base_box): 24 | self.base_key = base_key 25 | self.base_box = base_box 26 | 27 | def decrypt(self, ciphertext): 28 | length = len(ciphertext) 29 | assert length > 2 30 | 31 | plaintext = '' 32 | for k in xrange(length / 2): 33 | m = k * 2 34 | step = ciphertext[m:m + 2] 35 | 36 | # for i in xrange(16): 37 | # if self.base_key[i] == step[0]: 38 | # break 39 | # for j in xrange(16): 40 | # if self.base_key[j] == step[1]: 41 | # break 42 | i = self.base_key.find(step[0]) 43 | j = self.base_key.find(step[1]) 44 | 45 | # print step, i, j, m 46 | plaintext += chr( 47 | ord(self.base_box[(m / 2) % 40]) ^ (i | (16 * (i ^ j)))) 48 | 49 | return plaintext 50 | 51 | def encrypt(self, plaintext): 52 | length = len(plaintext) 53 | assert length > 0 54 | 55 | ciphertext = '' 56 | for k, c in enumerate(plaintext): 57 | temp_num = ord(c) ^ ord(self.base_box[k % 40]) 58 | i, j = self._brute_force(temp_num) 59 | ciphertext += self.base_key[i] + self.base_key[j] 60 | 61 | return ciphertext 62 | 63 | def _brute_force(self, value): 64 | for i in xrange(16): 65 | for j in xrange(16): 66 | if (i | (16 * (i ^ j))) == value: 67 | return i, j 68 | 69 | 70 | class SNStringEnc(XLStringEnc): 71 | 72 | """ 73 | usage: 74 | sn = SNStringEnc() 75 | print sn.decrypt('b413f30110a9') 76 | """ 77 | 78 | base_key = 'f18a9d03c45e267' 79 | base_box = ('WYHNIKmkEDCYHNig' 80 | 'LcdAUJMFBVNEDCGW' 81 | 'SXLYUIEWERTIXCVB' 82 | '2NM0E1SDF4QAS4YH' 83 | 'N1FGU4SRwKMBaERT' 84 | 'nSDRgPOIlMNB2RTY' 85 | '0GHU1KIH4FD414') 86 | 87 | 88 | if __name__ == '__main__': 89 | xl = XLStringEnc() 90 | print xl.decrypt('eb1ab586d3b5f22fe4680c5b98471049') 91 | -------------------------------------------------------------------------------- /src/pyAes.py: -------------------------------------------------------------------------------- 1 | """Simple AES cipher implementation in pure Python following PEP-272 API 2 | 3 | Homepage: https://bitbucket.org/intgr/pyaes/ 4 | 5 | The goal of this module is to be as fast as reasonable in Python while still 6 | being Pythonic and readable/understandable. It is licensed under the permissive 7 | MIT license. 8 | 9 | Hopefully the code is readable and commented enough that it can serve as an 10 | introduction to the AES cipher for Python coders. In fact, it should go along 11 | well with the Stick Figure Guide to AES: 12 | http://www.moserware.com/2009/09/stick-figure-guide-to-advanced.html 13 | 14 | Contrary to intuition, this implementation numbers the 4x4 matrices from top to 15 | bottom for efficiency reasons:: 16 | 17 | 0 4 8 12 18 | 1 5 9 13 19 | 2 6 10 14 20 | 3 7 11 15 21 | 22 | Effectively it's the transposition of what you'd expect. This actually makes 23 | the code simpler -- except the ShiftRows step, but hopefully the explanation 24 | there clears it up. 25 | 26 | """ 27 | 28 | #### 29 | # Copyright (c) 2010 Marti Raudsepp 30 | # 31 | # Permission is hereby granted, free of charge, to any person obtaining a copy 32 | # of this software and associated documentation files (the "Software"), to deal 33 | # in the Software without restriction, including without limitation the rights 34 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 35 | # copies of the Software, and to permit persons to whom the Software is 36 | # furnished to do so, subject to the following conditions: 37 | # 38 | # The above copyright notice and this permission notice shall be included in 39 | # all copies or substantial portions of the Software. 40 | # 41 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 42 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 43 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 44 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 45 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 46 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 47 | # THE SOFTWARE. 48 | #### 49 | 50 | 51 | from array import array 52 | 53 | # Globals mandated by PEP 272: 54 | # http://www.python.org/dev/peps/pep-0272/ 55 | MODE_ECB = 1 56 | MODE_CBC = 2 57 | #MODE_CTR = 6 58 | 59 | block_size = 16 60 | # variable length key: 16, 24 or 32 bytes 61 | key_size = None 62 | 63 | def new(key, mode, IV=None): 64 | if mode == MODE_ECB: 65 | return ECBMode(AES(key)) 66 | elif mode == MODE_CBC: 67 | if IV is None: 68 | raise ValueError, "CBC mode needs an IV value!" 69 | 70 | return CBCMode(AES(key), IV) 71 | else: 72 | raise NotImplementedError 73 | 74 | #### AES cipher implementation 75 | 76 | class AES(object): 77 | block_size = 16 78 | 79 | def __init__(self, key): 80 | self.setkey(key) 81 | 82 | def setkey(self, key): 83 | """Sets the key and performs key expansion.""" 84 | 85 | self.key = key 86 | self.key_size = len(key) 87 | 88 | if self.key_size == 16: 89 | self.rounds = 10 90 | elif self.key_size == 24: 91 | self.rounds = 12 92 | elif self.key_size == 32: 93 | self.rounds = 14 94 | else: 95 | raise ValueError, "Key length must be 16, 24 or 32 bytes" 96 | 97 | self.expand_key() 98 | 99 | def expand_key(self): 100 | """Performs AES key expansion on self.key and stores in self.exkey""" 101 | 102 | # The key schedule specifies how parts of the key are fed into the 103 | # cipher's round functions. "Key expansion" means performing this 104 | # schedule in advance. Almost all implementations do this. 105 | # 106 | # Here's a description of AES key schedule: 107 | # http://en.wikipedia.org/wiki/Rijndael_key_schedule 108 | 109 | # The expanded key starts with the actual key itself 110 | exkey = array('B', self.key) 111 | 112 | # extra key expansion steps 113 | if self.key_size == 16: 114 | extra_cnt = 0 115 | elif self.key_size == 24: 116 | extra_cnt = 2 117 | else: 118 | extra_cnt = 3 119 | 120 | # 4-byte temporary variable for key expansion 121 | word = exkey[-4:] 122 | # Each expansion cycle uses 'i' once for Rcon table lookup 123 | for i in xrange(1, 11): 124 | 125 | #### key schedule core: 126 | # left-rotate by 1 byte 127 | word = word[1:4] + word[0:1] 128 | 129 | # apply S-box to all bytes 130 | for j in xrange(4): 131 | word[j] = aes_sbox[word[j]] 132 | 133 | # apply the Rcon table to the leftmost byte 134 | word[0] ^= aes_Rcon[i] 135 | #### end key schedule core 136 | 137 | for z in xrange(4): 138 | for j in xrange(4): 139 | # mix in bytes from the last subkey 140 | word[j] ^= exkey[-self.key_size + j] 141 | exkey.extend(word) 142 | 143 | # Last key expansion cycle always finishes here 144 | if len(exkey) >= (self.rounds+1) * self.block_size: 145 | break 146 | 147 | # Special substitution step for 256-bit key 148 | if self.key_size == 32: 149 | for j in xrange(4): 150 | # mix in bytes from the last subkey XORed with S-box of 151 | # current word bytes 152 | word[j] = aes_sbox[word[j]] ^ exkey[-self.key_size + j] 153 | exkey.extend(word) 154 | 155 | # Twice for 192-bit key, thrice for 256-bit key 156 | for z in xrange(extra_cnt): 157 | for j in xrange(4): 158 | # mix in bytes from the last subkey 159 | word[j] ^= exkey[-self.key_size + j] 160 | exkey.extend(word) 161 | 162 | self.exkey = exkey 163 | 164 | def add_round_key(self, block, round): 165 | """AddRoundKey step in AES. This is where the key is mixed into plaintext""" 166 | 167 | offset = round * 16 168 | exkey = self.exkey 169 | 170 | for i in xrange(16): 171 | block[i] ^= exkey[offset + i] 172 | 173 | #print 'AddRoundKey:', block 174 | 175 | def sub_bytes(self, block, sbox): 176 | """SubBytes step, apply S-box to all bytes 177 | 178 | Depending on whether encrypting or decrypting, a different sbox array 179 | is passed in. 180 | """ 181 | 182 | for i in xrange(16): 183 | block[i] = sbox[block[i]] 184 | 185 | #print 'SubBytes :', block 186 | 187 | def shift_rows(self, b): 188 | """ShiftRows step. Shifts 2nd row to left by 1, 3rd row by 2, 4th row by 3 189 | 190 | Since we're performing this on a transposed matrix, cells are numbered 191 | from top to bottom first:: 192 | 193 | 0 4 8 12 -> 0 4 8 12 -- 1st row doesn't change 194 | 1 5 9 13 -> 5 9 13 1 -- row shifted to left by 1 (wraps around) 195 | 2 6 10 14 -> 10 14 2 6 -- shifted by 2 196 | 3 7 11 15 -> 15 3 7 11 -- shifted by 3 197 | """ 198 | 199 | b[1], b[5], b[ 9], b[13] = b[ 5], b[ 9], b[13], b[ 1] 200 | b[2], b[6], b[10], b[14] = b[10], b[14], b[ 2], b[ 6] 201 | b[3], b[7], b[11], b[15] = b[15], b[ 3], b[ 7], b[11] 202 | 203 | #print 'ShiftRows :', b 204 | 205 | def shift_rows_inv(self, b): 206 | """Similar to shift_rows above, but performed in inverse for decryption.""" 207 | 208 | b[ 5], b[ 9], b[13], b[ 1] = b[1], b[5], b[ 9], b[13] 209 | b[10], b[14], b[ 2], b[ 6] = b[2], b[6], b[10], b[14] 210 | b[15], b[ 3], b[ 7], b[11] = b[3], b[7], b[11], b[15] 211 | 212 | #print 'ShiftRows :', b 213 | 214 | def mix_columns(self, block): 215 | """MixColumns step. Mixes the values in each column""" 216 | 217 | # Cache global multiplication tables (see below) 218 | mul_by_2 = gf_mul_by_2 219 | mul_by_3 = gf_mul_by_3 220 | 221 | # Since we're dealing with a transposed matrix, columns are already 222 | # sequential 223 | for col in xrange(0, 16, 4): 224 | v0, v1, v2, v3 = block[col : col+4] 225 | 226 | block[col ] = mul_by_2[v0] ^ v3 ^ v2 ^ mul_by_3[v1] 227 | block[col+1] = mul_by_2[v1] ^ v0 ^ v3 ^ mul_by_3[v2] 228 | block[col+2] = mul_by_2[v2] ^ v1 ^ v0 ^ mul_by_3[v3] 229 | block[col+3] = mul_by_2[v3] ^ v2 ^ v1 ^ mul_by_3[v0] 230 | 231 | #print 'MixColumns :', block 232 | 233 | def mix_columns_inv(self, block): 234 | """Similar to mix_columns above, but performed in inverse for decryption.""" 235 | 236 | # Cache global multiplication tables (see below) 237 | mul_9 = gf_mul_by_9 238 | mul_11 = gf_mul_by_11 239 | mul_13 = gf_mul_by_13 240 | mul_14 = gf_mul_by_14 241 | 242 | # Since we're dealing with a transposed matrix, columns are already 243 | # sequential 244 | for col in xrange(0, 16, 4): 245 | v0, v1, v2, v3 = block[col : col+4] 246 | 247 | block[col ] = mul_14[v0] ^ mul_9[v3] ^ mul_13[v2] ^ mul_11[v1] 248 | block[col+1] = mul_14[v1] ^ mul_9[v0] ^ mul_13[v3] ^ mul_11[v2] 249 | block[col+2] = mul_14[v2] ^ mul_9[v1] ^ mul_13[v0] ^ mul_11[v3] 250 | block[col+3] = mul_14[v3] ^ mul_9[v2] ^ mul_13[v1] ^ mul_11[v0] 251 | 252 | #print 'MixColumns :', block 253 | 254 | def encrypt_block(self, block): 255 | """Encrypts a single block. This is the main AES function""" 256 | 257 | # For efficiency reasons, the state between steps is transmitted via a 258 | # mutable array, not returned 259 | self.add_round_key(block, 0) 260 | 261 | for round in xrange(1, self.rounds): 262 | self.sub_bytes(block, aes_sbox) 263 | self.shift_rows(block) 264 | self.mix_columns(block) 265 | self.add_round_key(block, round) 266 | 267 | self.sub_bytes(block, aes_sbox) 268 | self.shift_rows(block) 269 | # no mix_columns step in the last round 270 | self.add_round_key(block, self.rounds) 271 | 272 | def decrypt_block(self, block): 273 | """Decrypts a single block. This is the main AES decryption function""" 274 | 275 | # For efficiency reasons, the state between steps is transmitted via a 276 | # mutable array, not returned 277 | self.add_round_key(block, self.rounds) 278 | 279 | # count rounds down from (self.rounds) ... 1 280 | for round in xrange(self.rounds-1, 0, -1): 281 | self.shift_rows_inv(block) 282 | self.sub_bytes(block, aes_inv_sbox) 283 | self.add_round_key(block, round) 284 | self.mix_columns_inv(block) 285 | 286 | self.shift_rows_inv(block) 287 | self.sub_bytes(block, aes_inv_sbox) 288 | self.add_round_key(block, 0) 289 | # no mix_columns step in the last round 290 | 291 | 292 | #### ECB mode implementation 293 | 294 | class ECBMode(object): 295 | """Electronic CodeBook (ECB) mode encryption. 296 | 297 | Basically this mode applies the cipher function to each block individually; 298 | no feedback is done. NB! This is insecure for almost all purposes 299 | """ 300 | 301 | def __init__(self, cipher): 302 | self.cipher = cipher 303 | self.block_size = cipher.block_size 304 | 305 | def ecb(self, data, block_func): 306 | """Perform ECB mode with the given function""" 307 | 308 | if len(data) % self.block_size != 0: 309 | raise ValueError, "Input length must be multiple of 16" 310 | 311 | block_size = self.block_size 312 | data = array('B', data) 313 | 314 | for offset in xrange(0, len(data), block_size): 315 | block = data[offset : offset+block_size] 316 | block_func(block) 317 | data[offset : offset+block_size] = block 318 | 319 | return data.tostring() 320 | 321 | def encrypt(self, data): 322 | """Encrypt data in ECB mode""" 323 | 324 | return self.ecb(data, self.cipher.encrypt_block) 325 | 326 | def decrypt(self, data): 327 | """Decrypt data in ECB mode""" 328 | 329 | return self.ecb(data, self.cipher.decrypt_block) 330 | 331 | #### CBC mode 332 | 333 | class CBCMode(object): 334 | """Cipher Block Chaining (CBC) mode encryption. This mode avoids content leaks. 335 | 336 | In CBC encryption, each plaintext block is XORed with the ciphertext block 337 | preceding it; decryption is simply the inverse. 338 | """ 339 | 340 | # A better explanation of CBC can be found here: 341 | # http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Cipher-block_chaining_.28CBC.29 342 | 343 | def __init__(self, cipher, IV): 344 | self.cipher = cipher 345 | self.block_size = cipher.block_size 346 | self.IV = array('B', IV) 347 | 348 | def encrypt(self, data): 349 | """Encrypt data in CBC mode""" 350 | 351 | block_size = self.block_size 352 | if len(data) % block_size != 0: 353 | raise ValueError, "Plaintext length must be multiple of 16" 354 | 355 | data = array('B', data) 356 | IV = self.IV 357 | 358 | for offset in xrange(0, len(data), block_size): 359 | block = data[offset : offset+block_size] 360 | 361 | # Perform CBC chaining 362 | for i in xrange(block_size): 363 | block[i] ^= IV[i] 364 | 365 | self.cipher.encrypt_block(block) 366 | data[offset : offset+block_size] = block 367 | IV = block 368 | 369 | self.IV = IV 370 | return data.tostring() 371 | 372 | def decrypt(self, data): 373 | """Decrypt data in CBC mode""" 374 | 375 | block_size = self.block_size 376 | if len(data) % block_size != 0: 377 | raise ValueError, "Ciphertext length must be multiple of 16" 378 | 379 | data = array('B', data) 380 | IV = self.IV 381 | 382 | for offset in xrange(0, len(data), block_size): 383 | ctext = data[offset : offset+block_size] 384 | block = ctext[:] 385 | self.cipher.decrypt_block(block) 386 | 387 | # Perform CBC chaining 388 | #for i in xrange(block_size): 389 | # data[offset + i] ^= IV[i] 390 | for i in xrange(block_size): 391 | block[i] ^= IV[i] 392 | data[offset : offset+block_size] = block 393 | 394 | IV = ctext 395 | #data[offset : offset+block_size] = block 396 | 397 | self.IV = IV 398 | return data.tostring() 399 | 400 | #### 401 | 402 | def galois_multiply(a, b): 403 | """Galois Field multiplicaiton for AES""" 404 | p = 0 405 | while b: 406 | if b & 1: 407 | p ^= a 408 | a <<= 1 409 | if a & 0x100: 410 | a ^= 0x1b 411 | b >>= 1 412 | 413 | return p & 0xff 414 | 415 | # Precompute the multiplication tables for encryption 416 | gf_mul_by_2 = array('B', [galois_multiply(x, 2) for x in range(256)]) 417 | gf_mul_by_3 = array('B', [galois_multiply(x, 3) for x in range(256)]) 418 | # ... for decryption 419 | gf_mul_by_9 = array('B', [galois_multiply(x, 9) for x in range(256)]) 420 | gf_mul_by_11 = array('B', [galois_multiply(x, 11) for x in range(256)]) 421 | gf_mul_by_13 = array('B', [galois_multiply(x, 13) for x in range(256)]) 422 | gf_mul_by_14 = array('B', [galois_multiply(x, 14) for x in range(256)]) 423 | 424 | #### 425 | 426 | # The S-box is a 256-element array, that maps a single byte value to another 427 | # byte value. Since it's designed to be reversible, each value occurs only once 428 | # in the S-box 429 | # 430 | # More information: http://en.wikipedia.org/wiki/Rijndael_S-box 431 | 432 | aes_sbox = array('B', 433 | '637c777bf26b6fc53001672bfed7ab76' 434 | 'ca82c97dfa5947f0add4a2af9ca472c0' 435 | 'b7fd9326363ff7cc34a5e5f171d83115' 436 | '04c723c31896059a071280e2eb27b275' 437 | '09832c1a1b6e5aa0523bd6b329e32f84' 438 | '53d100ed20fcb15b6acbbe394a4c58cf' 439 | 'd0efaafb434d338545f9027f503c9fa8' 440 | '51a3408f929d38f5bcb6da2110fff3d2' 441 | 'cd0c13ec5f974417c4a77e3d645d1973' 442 | '60814fdc222a908846eeb814de5e0bdb' 443 | 'e0323a0a4906245cc2d3ac629195e479' 444 | 'e7c8376d8dd54ea96c56f4ea657aae08' 445 | 'ba78252e1ca6b4c6e8dd741f4bbd8b8a' 446 | '703eb5664803f60e613557b986c11d9e' 447 | 'e1f8981169d98e949b1e87e9ce5528df' 448 | '8ca1890dbfe6426841992d0fb054bb16'.decode('hex') 449 | ) 450 | 451 | # This is the inverse of the above. In other words: 452 | # aes_inv_sbox[aes_sbox[val]] == val 453 | 454 | aes_inv_sbox = array('B', 455 | '52096ad53036a538bf40a39e81f3d7fb' 456 | '7ce339829b2fff87348e4344c4dee9cb' 457 | '547b9432a6c2233dee4c950b42fac34e' 458 | '082ea16628d924b2765ba2496d8bd125' 459 | '72f8f66486689816d4a45ccc5d65b692' 460 | '6c704850fdedb9da5e154657a78d9d84' 461 | '90d8ab008cbcd30af7e45805b8b34506' 462 | 'd02c1e8fca3f0f02c1afbd0301138a6b' 463 | '3a9111414f67dcea97f2cfcef0b4e673' 464 | '96ac7422e7ad3585e2f937e81c75df6e' 465 | '47f11a711d29c5896fb7620eaa18be1b' 466 | 'fc563e4bc6d279209adbc0fe78cd5af4' 467 | '1fdda8338807c731b11210592780ec5f' 468 | '60517fa919b54a0d2de57a9f93c99cef' 469 | 'a0e03b4dae2af5b0c8ebbb3c83539961' 470 | '172b047eba77d626e169146355210c7d'.decode('hex') 471 | ) 472 | 473 | # The Rcon table is used in AES's key schedule (key expansion) 474 | # It's a pre-computed table of exponentation of 2 in AES's finite field 475 | # 476 | # More information: http://en.wikipedia.org/wiki/Rijndael_key_schedule 477 | 478 | aes_Rcon = array('B', 479 | '8d01020408102040801b366cd8ab4d9a' 480 | '2f5ebc63c697356ad4b37dfaefc59139' 481 | '72e4d3bd61c29f254a943366cc831d3a' 482 | '74e8cb8d01020408102040801b366cd8' 483 | 'ab4d9a2f5ebc63c697356ad4b37dfaef' 484 | 'c5913972e4d3bd61c29f254a943366cc' 485 | '831d3a74e8cb8d01020408102040801b' 486 | '366cd8ab4d9a2f5ebc63c697356ad4b3' 487 | '7dfaefc5913972e4d3bd61c29f254a94' 488 | '3366cc831d3a74e8cb8d010204081020' 489 | '40801b366cd8ab4d9a2f5ebc63c69735' 490 | '6ad4b37dfaefc5913972e4d3bd61c29f' 491 | '254a943366cc831d3a74e8cb8d010204' 492 | '08102040801b366cd8ab4d9a2f5ebc63' 493 | 'c697356ad4b37dfaefc5913972e4d3bd' 494 | '61c29f254a943366cc831d3a74e8cb'.decode('hex') 495 | ) --------------------------------------------------------------------------------