赞
踩
目录
- # coding=utf-8
- from Crypto.Cipher import DES
-
- def decode_char(c):
- if c == 'a':
- r = '?'
- else:
- r = c
- return ord(r) - ord('!')
-
- def ascii_to_binary(s):
- assert len(s) == 24
- out = [0]*18
- i = 0
- j = 0
-
- for i in range(0, len(s), 4):
- y = decode_char(s[i + 0])
- y = (y << 6) & 0xffffff
- k = decode_char(s[i + 1])
-
- y = (y | k) & 0xffffff
- y = (y << 6) & 0xffffff
- k = decode_char(s[i + 2])
-
- y = (y | k) & 0xffffff
- y = (y << 6) & 0xffffff
- k = decode_char(s[i + 3])
- y = (y | k) & 0xffffff
-
- out[j+2] = chr(y & 0xff)
- out[j+1] = chr((y>>8) & 0xff)
- out[j+0] = chr((y>>16) & 0xff)
-
- j += 3
- return "".join(out)
-
- def decrypt_password(p):
- r = ascii_to_binary(p)
- r = r[:16]
- d = DES.new("\x01\x02\x03\x04\x05\x06\x07\x08", DES.MODE_ECB)
- r = d.decrypt(r)
- return r.rstrip("\x00")
-
- if __name__ == '__main__':
- miwen = "aK9Q4I)J'#[Q=^Q`MAF4<1!!" // 需要破解的密码
- print u'明文' + decrypt_password(miwen)

一般的ic卡喜欢将金额乘以一定数之后转为16进制,明文存储。然后这个数值常常是10或100。计算发现10000的16进制为2710(刚好是以小端方式存储的1027)。
20000的16进制为4E20,修改对应数值。(注意是小端存储)
重新上传文件,获得key。
- from base64 import *
- import re # 正则表达式模块
-
- def dfs(res, arr, pos): # 递归函数
- # ''.join(arr):将列表转换为字符串
- res.append(''.join(arr)) # append():将字符串加入列表中
- i = pos
- for i in range(i, len(arr)):
- if arr[i] <= 'Z' and arr[i] >= 'A':
- arr[i] = arr[i].lower() #转换为小写
- dfs(res, arr, i + 1)
- arr[i] = arr[i].upper() #转换为大写
-
- arr = list('AGV5IULSB3ZLVSE=') # 将字符串转换为列表,方便修改
- res = [] # 用来存放所有可能的序列
- dfs(res, arr, 0)
- # b64decode是base64模块提供的解码函数,返回值为bytes类型
- res_decode = map(b64decode, res) # map():将b64decode函数作用在res的每个元素上
-
- for i in res_decode:
- # re.findall():匹配正则表达式
- # repr():将bytes类型转换为字符串
- if re.findall(r'\\x', repr(i)): # 匹配\x,\x为十六进制转义字符,存在\x说明该字符不是能打印的二进制位
- continue
- else:
- print(i)

- <!--<?php
- header("Content-type:text/html;charset=utf-8");
- include "_flag.php";
- include "salt.php";
-
- $mysalt=SALT;
-
- if(isset($_GET['filepath'])&&!empty($_GET['filepath']) &&isset($_GET['sign']) &&!empty($_GET['sign'])){
- myreadfile($_GET['filepath'],$mysalt,$_GET['sign']);
- }
- else{
- //降低一点复杂度
- var_dump(strlen($mysalt));
- testsign("/etc/hosts",$mysalt);
- }
-
- function myhash($message,$mysalt){
- return md5($mysalt.$message);
- }
- function checksign($message,$mysalt,$sign){
- if($sign==myhash($message,$mysalt)){
- return True;
- }else{
- return False;
- }
- }
- function myreadfile($filepath,$mysalt,$sign){
- $res=checksign($filepath,$mysalt,$sign);
- if($res){
- echo getfile($filepath);
- }
- else{
- echo 'sign error!';
- }
- }
- function testsign($filepath,$mysalt){
- echo myhash($filepath,$mysalt);
- }
-
- echo "<!--".file_get_contents(__FILE__);

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。