#everything is from here : https://www.youtube.com/watch?v=OQuRwpUTBpQ #i added comments so i can understand the code better import pefile #working with a pe file import re #regular expression search import struct #convert data to numbers import hashlib #sha1 hash import sys #arg def rc4crypt(data, key): #If the input is a string convert to byte arrays if type(data) == str: data = data.encode('utf-8') if type(key) == str: key = key.encode('utf-8') x = 0 box = list(range(256)) for i in range(256): x = (x + box[i] + key[i % len(key)]) % 256 box[i], box[x] = box[x], box[i] x = 0 y = 0 out = [] for c in data: x = (x + 1) % 256 y = (y + box[x]) % 256 box[x], box[y] = box[y], box[x] out.append(c ^ box[(box[x] + box[y]) % 256]) return bytes(out) if len(sys.argv) != 2 : print("Usage : python extract_config.py [sample.bin]") exit(0) sample_path = sys.argv[1] data = open(sample_path,"rb").read() pe = pefile.PE(data=data) """ 6A 08 push 8 ; dwDataLen 68 10 50 57 00 push offset pbData ; pbData 68 00 20 00 00 push 2000h ; pdwDataLen """ sig = rb"\x6A(.)\x68(....)\x68\x00\x20\x00\x00" #'.' is a wildcard, same as '?', '()' is for a capture group, so we can catch their values match = re.search(sig, data) if match == None : """ Signature got updated 6A 08 push 8 ; dwDataLen 68 10 40 00 10 push offset pbData ; pbData 56 push esi ; pdwDataLen """ sig = rb"\x6A(.)\x68(....)\x56" #'.' is a wildcard, same as '?', '()' is for a capture group, so we can catch their values match = re.search(sig, data) print("key length: %r" % match.group(1)) print("key address: %r" % match.group(2)) key_len = struct.unpack('b', match.group(1))[0] key_addr = struct.unpack('