def extract(inputf, outputf, password): # Process source image img = Image.open(inputf) (width, height) = img.size conv_image = img.convert("RGBA").getdata() # Extract LSBs v = [] for h in range(height): for w in range(width): (r, g, b, a) = conv_image.getpixel((w, h)) v.append(r & 1) #it will only append the lsb of each pixel v.append(g & 1) v.append(b & 1) data_out = bits_to_binary(v) # Decrypt cipher = AESCipher(password) data_dec = cipher.decrypt(data_out) # Write decrypted data out_f = open(outputf, "wb") out_f.write(data_dec) out_f.close() print ">> Data extracted from stego.png to %s." % outputf
def get(self): r = self.get_argument('r', '') if not r: self.write('参数错误') return openid = utils.decrypt(r) user_agent = self.request.headers.get('User-Agent', '') platform = utils.get_platform(user_agent) # 判断用户系统是否已知 user_info = users.get_info(openid) if not user_info['platform']: ip = self.request.remote_ip ip_address = IP.find(ip) users.set_ip(openid, ip, ip_address, platform) if user_info['status'] == -2: self.write("非法用户") return if platform == 2: url = urlparse.urljoin(constants.SITE_BASEURL, 'v1/applist/goandroid') self.redirect(url, False, 302) return aes = AESCipher() r = aes.encode(openid) url = 'http://w.ymapp.com/wx/ios/lists.html?r=%s' % r #url = 'http://au.youmi.net/wx/ios/lists.html?r=%s' % r self.redirect(url, False, 302)
def extract(in_file, out_file, password): # Process source image img = Image.open(in_file) (width, height) = img.size conv = img.convert("RGBA").getdata() print "[+] Image size: %dx%d pixels." % (width, height) # Extract LSBs v = [] for h in range(height): for w in range(width): (r, g, b, a) = conv.getpixel((w, h)) v.append(r & 1) v.append(g & 1) v.append(b & 1) data_out = assemble(v) # Decrypt characters = string.ascii_letters + string.digits for i in characters: for j in characters: for k in characters: for l in characters: password = i + j + k + l + "needmoneyandgirlfirend" cipher = AESCipher(password) data_dec = cipher.decrypt(data_out) if len(data_dec) > 0 and filter(data_dec): print password, data_dec # Write decrypted data print "[+] Written extracted data to %s." % out_file
def extract(in_file, out_file, password): # Process source image img = Image.open(in_file) (width, height) = img.size conv = img.convert("RGBA").getdata() print "[+] Image size: %dx%d pixels." % (width, height) # Extract LSBs v = [] for h in range(height): for w in range(width): (r, g, b, a) = conv.getpixel((w, h)) v.append(r & 1) v.append(g & 1) v.append(b & 1) data_out = assemble(v) # Decrypt cipher = AESCipher(password) data_dec = cipher.decrypt(data_out) # Write decrypted data out_f = open(out_file, "wb") out_f.write(data_dec) out_f.close() print "[+] Written extracted data to %s." % out_file
def decrypt_params(self, s): """ 解密参数 """ # 约定:首部填充21字节随机字符 s = base64.b64encode(base64.b64decode(s)[21:]) aes = AESCipher(self.config['crypt']['aeskey']) decrypt_data = aes.decrypt(s.replace(' ', '+')) return dict([(k, v[0]) for k, v in urlparse.parse_qs(decrypt_data).items()])
def postItem(username, password, subreddit, filename, KEYPASS): filepath = filename k = filename.rfind("/") filename = filename[k + 1:] loginMod(username, password, subreddit) cipher = AESCipher(KEYPASS) comment = cipher.encrypt_file(filepath) post_encryption(filename, comment) postMessage.SetLabel("Done") postMessage1.SetLabel("Done")
def postItem(username, password, subreddit, filename, KEYPASS): filepath = filename k = filename.rfind("/") filename = filename[k+1:] loginMod(username,password,subreddit) cipher = AESCipher(KEYPASS) comment = cipher.encrypt_file(filepath) post_encryption(filename, comment) postMessage.SetLabel("Done") postMessage1.SetLabel("Done")
def text_handler(self, msg): """ 文本回调 """ content = msg.get('Content', '') if 'iloveumlife' == content: aes = AESCipher(2) r = aes.encode(self.openid) url = 'http://w.ymapp.com/wx/aos/lists.html?r=%s' % r tt = '<a href="%s">传送门</a>' % url resp_content = self.parse_to_xml(msg, tt) else: resp_content = self.show_faq(msg) return resp_content
def embed(imgFile, payload, password): # Process source image img = Image.open(imgFile) (width, height) = img.size conv = img.convert("RGBA").getdata() print "[*] Input image size: %dx%d pixels." % (width, height) max_size = width * height * 3.0 / 8 / 1024 # max payload size print "[*] Usable payload size: %.2f KB." % (max_size) f = open(payload, "rb") data = f.read() f.close() print "[+] Payload size: %.3f KB " % (len(data) / 1024.0) # Encypt cipher = AESCipher(password) data_enc = cipher.encrypt(data) # Process data from payload file v = decompose(data_enc) # Add until multiple of 3 while (len(v) % 3): v.append(0) payload_size = len(v) / 8 / 1024.0 print "[+] Encrypted payload size: %.3f KB " % (payload_size) if (payload_size > max_size - 4): print "[-] Cannot embed. File too large" sys.exit() # Create output image steg_img = Image.new('RGBA', (width, height)) data_img = steg_img.getdata() idx = 0 for h in range(height): for w in range(width): (r, g, b, a) = conv.getpixel((w, h)) if idx < len(v): r = set_bit(r, 0, v[idx]) g = set_bit(g, 0, v[idx + 1]) b = set_bit(b, 0, v[idx + 2]) data_img.putpixel((w, h), (r, g, b, a)) idx = idx + 3 steg_img.save(imgFile + "-stego.png", "PNG") print "[+] %s embedded successfully!" % payload
def embed(imgFile, payload, password): # Process source image img = Image.open(imgFile) (width, height) = img.size conv = img.convert("RGBA").getdata() print "[*] Input image size: %dx%d pixels." % (width, height) max_size = width*height*3.0/8/1024 # max payload size print "[*] Usable payload size: %.2f KB." % (max_size) f = open(payload, "rb") data = f.read() f.close() print "[+] Payload size: %.3f KB " % (len(data)/1024.0) # Encypt cipher = AESCipher(password) data_enc = cipher.encrypt(data) # Process data from payload file v = decompose(data_enc) # Add until multiple of 3 while(len(v)%3): v.append(0) payload_size = len(v)/8/1024.0 print "[+] Encrypted payload size: %.3f KB " % (payload_size) if (payload_size > max_size - 4): print "[-] Cannot embed. File too large" sys.exit() # Create output image steg_img = Image.new('RGBA',(width, height)) data_img = steg_img.getdata() idx = 0 for h in range(height): for w in range(width): (r, g, b, a) = conv.getpixel((w, h)) if idx < len(v): r = set_bit(r, 0, v[idx]) g = set_bit(g, 0, v[idx+1]) b = set_bit(b, 0, v[idx+2]) data_img.putpixel((w,h), (r, g, b, a)) idx = idx + 3 steg_img.save(imgFile + "-stego.png", "PNG") print "[+] %s embedded successfully!" % payload
def get_config(): from crypt import AESCipher config_path = os.path.dirname(os.path.abspath(__file__)) config_file = os.path.join(config_path, 'config.json') with open(config_file, 'r') as f: config = json.load(f) crypt = AESCipher(config['CRYPT_KEY']) config_developer_key = crypt.decrypt(config['DEVELOPER_KEY']) config_login_user_name = crypt.decrypt(config['REMOT3_USER_NAME']) config_login_password = crypt.decrypt(config['REMOT3_PASSWORD']) return config_developer_key, config_login_user_name, config_login_password
def hide_text(sourceImg, secrettext, password): # Process source image img = Image.open(sourceImg) (width, height) = img.size conv_image = img.convert("RGBA").getdata() max_size = width * height * 3.0 / 8 / 1024 f = open(secrettext, "rb") data = f.read() f.close() cipher = AESCipher(password) data_enc = cipher.encrypt(data) # Process data from secrettext bitsoffile = binary_to_bits(data_enc) # Add until multiple of 3 while (len(bitsoffile) % 3): bitsoffile.append(0) secrettext_size = len(bitsoffile) / 8 / 1024.0 if (secrettext_size > max_size - 4): print "\n>>> Failed to hide the text, file is too large.\n" sys.exit() # Create output image steg_img = Image.new('RGBA', (width, height)) data_img = steg_img.getdata() v = 0 for h in range(height): for w in range(width): (r, g, b, a) = conv_image.getpixel((w, h)) if v < len(bitsoffile): r = set_bit(r, 0, bitsoffile[v]) g = set_bit(g, 0, bitsoffile[v + 1]) b = set_bit(b, 0, bitsoffile[v + 2]) data_img.putpixel((w, h), (r, g, b, a)) v = v + 3 steg_img.save("stego.png", "PNG") print "\n>> %s hidden successfully in the source file!\n" % secrettext
def embedRandom(imgFilePath, payloadFilePath, passwd, bitSelectionLimit): with Image.open(imgFilePath) as img: (width, height) = img.size imgData = img.convert("RGBA").getdata() print("[*] Input image size: {}x{} pixels.".format(width, height)) maxPayloadSize = width * height * 3 / 8 / 1024 print("[*] Usable payload size: {:.4f}KB.".format(maxPayloadSize)) with open(payloadFilePath, "rb") as payloadFile: payloadData = payloadFile.read() print("[*] Payload size: {:.4f}KB ".format(len(payloadData) / 1024)) # Encrypt payload data. payloadDataEnc = AESCipher(passwd).encrypt(payloadData) print("[*] Encrypted payload size: {:.4f}KB.".format( len(payloadDataEnc) / 1024)) # Payload data encrypted to list of bit triples. payloadDataEncBitTriples = list(grouper(decompose(payloadDataEnc), 3, 0)) payloadSize = len(payloadDataEncBitTriples) * 3 / 8 / 1024 if payloadSize > maxPayloadSize - 4: print("[!] Cannot embed. Payload file too large.") return # Create output stego-image. stegoImg = Image.new("RGBA", (width, height)) stegoImgData = stegoImg.getdata() # Copy the original img bytes. for h in range(height): for w in range(width): stegoImgData.putpixel((w, h), imgData.getpixel((w, h))) freePixels = [(w, h) for h in range(height) for w in range(width)] random.seed(hashlib.sha256(passwd.encode()).digest(), 2) for bitTriple in payloadDataEncBitTriples: pixel = rndPop(freePixels) r, g, b, a = stegoImgData.getpixel(pixel) r = set_bit(r, random.randrange(bitSelectionLimit + 1), bitTriple[0]) g = set_bit(g, random.randrange(bitSelectionLimit + 1), bitTriple[1]) b = set_bit(b, random.randrange(bitSelectionLimit + 1), bitTriple[2]) stegoImgData.putpixel(pixel, (r, g, b, a)) stegoImgFilePath = Path(imgFilePath) stegoImg.save( path.join(stegoImgFilePath.parent, stegoImgFilePath.stem + "-stego.png"), "PNG") print("[*] Payload file embedded successfully!")
def getItem(username, password, subreddit, filename, file_to_get, KEYPASS): filepath = filename #k = filename.rfind("/") #filename = filename[k+1:] #filepath = filepath[:k+1] #temp_fp = filepath #filepath = filepath + file_to_get loginMod(username, password, subreddit) cipher = AESCipher(KEYPASS) comment = get_decryption(file_to_get) """ if filename[-1] == ")": j = filename.rfind("(") - 1 n = len(filename) - j filepath = filepath[:-n] """ cipher.decrypt_file(comment, filepath) postMessage1.SetLabel("Done") postMessage.SetLabel("Done")
def getItem(username, password, subreddit, filename, file_to_get, KEYPASS): filepath = filename #k = filename.rfind("/") #filename = filename[k+1:] #filepath = filepath[:k+1] #temp_fp = filepath #filepath = filepath + file_to_get loginMod(username,password,subreddit) cipher=AESCipher(KEYPASS) comment = get_decryption(file_to_get) """ if filename[-1] == ")": j = filename.rfind("(") - 1 n = len(filename) - j filepath = filepath[:-n] """ cipher.decrypt_file(comment, filepath) postMessage1.SetLabel("Done") postMessage.SetLabel("Done")
def extractRandom(stegoImgFilePath, outputFilePath, passwd, bitSelectionLimit): # Process stego img file. with Image.open(stegoImgFilePath) as stegoImg: (width, height) = stegoImg.size stegoImgData = stegoImg.convert("RGBA").getdata() print("[*] Stego image size: {}x{} pixels.".format(width, height)) notCheckedPixels = [(w, h) for h in range(height) for w in range(width)] payloadDataEncBits = [] random.seed(hashlib.sha256(passwd.encode()).digest(), 2) # Retrieve payload size. for _ in range(11): payloadDataEncBits.extend( getHiddenBits(stegoImgData, rndPop(notCheckedPixels), bitSelectionLimit)) payloadSize = struct.unpack("i", bitLstToByteArray(payloadDataEncBits[:32]))[0] print("[*] Encrypted payload size: {:.4f}KB.".format(payloadSize / 1024)) for _ in range(int(math.ceil((payloadSize * 8 - 1) / 3))): payloadDataEncBits.extend( getHiddenBits(stegoImgData, rndPop(notCheckedPixels), bitSelectionLimit)) payloadDataEncBytes = assemble(payloadDataEncBits) # Decrypt payload data. payloadDataBytes = AESCipher(passwd).decrypt(payloadDataEncBytes) print("[*] Payload size: {:.4f}KB ".format(len(payloadDataBytes) / 1024)) # Write decrypted data. with open(outputFilePath, "wb") as outputFile: outputFile.write(payloadDataBytes) print("[*] Data extracted to {}.".format(outputFilePath))
from flask import Flask, jsonify, request from tinydb import Query, TinyDB from crypt import AESCipher, bcrypt_checkpw, bcrypt_encrypt import time from totp import Totp from expiringdict import ExpiringDict app = Flask(__name__) app.secret_key = '19#^f8kV8D55h!TXruYum%^VQh$zsCeQ' DB = TinyDB('./db.json') query = Query() passphrase = "6V5#645L5FJn#Zc9i^i$b^3*38dShnk$" aes = AESCipher(passphrase) CACHE = ExpiringDict(max_len=10000, max_age_seconds=60) def response(status, message, result=None): return jsonify({ "status": status, "message": message, "result": result }) def response_success(result=None): return response(2000, "success", result) @app.route('/api/create_seed', methods=['POST'])
def _encrypt_params(self, raw_params={}): aes = AESCipher(self.config['crypt']['aeskey']) s = [] for k in raw_params: s.append(k + '=' + str(raw_params[k])) return aes.encrypt('&'.join(s))
def encrypt(raw_str, platform=1): aes = AESCipher(platform) enc = urllib.quote(aes.encrypt(raw_str)) return enc
def decrypt(enc_str, platform=1): aes = AESCipher(platform) dec = aes.decrypt(urllib.unquote(enc_str)) return dec
os.environ['KIVY_GL_BACKEND'] = 'gl' # 日本語使用するためfont LabelBase.register(DEFAULT_FONT, r'./font/FONT') # ServletAPIbaseURL base_url = "http://FQCN/BusApplicationServerSide" # ユーザデータ保存用 user_file = os.getcwd()+ r'/savedata/userdata.txt' voice_file = os.getcwd()+ r'/Voicedata/voicedata.txt' pass_phrase = 'PASS PHRASE' cipher = AESCipher(pass_phrase) volume_data =os.getcwd() + r"/Voicedata/soundvolume.txt" if os.path.exists(volume_data) == False: fw = open(volume_data, 'w') fw.write('0') fw.close() # Main class MainScreen(Screen): def __init__(self, **kwargs): super().__init__(**kwargs) pygame.mixer.init() self.evt = None self.evt2 = None