Ejemplo n.º 1
0
def analyze_url(url, time):
    m = re.fullmatch("https?://(.+)", url)
    if not m:
        url = "http://" + url
    if not validators.url(url):
        print("The target url is malformed:", url)
        return

    if results_coll.find_one({"url": url}):
        print("Already analyzed", url)
        return
    print("URL Target: " + colored(url, 'cyan') + " Visiting for " +
          colored(str(time), 'cyan') + " sec")
    os.makedirs(config['out'], exist_ok=True)
    wasm_save_dir = pathlib.Path(config["out"]) / "final"
    wasm_save_dir.mkdir(exist_ok=True)
    print("[S1] Website Analysis...")
    target = hash_string(url)
    wasm_dir = os.path.join(config['out'], target)
    cpu_stat_f = os.path.join(config['out'], target + ".txt")
    os.makedirs(wasm_dir, exist_ok=True)
    # ./chrome-build/chrome coinhive.com --no-sandbox --js-flags="--dump-wasm-module --dump-wasm-module-path=./data"
    command = config['chrome'] + ' ' + url + \
        ' --no-sandbox --headless --js-flags="--dump-wasm-module --dump-wasm-module-path=' + wasm_dir + '"'
    print(command)
    run.crawl(command, cpu_stat_f, url, time)
    wasm_files = []

    print("[S2] Looking for a wasm module...")
    for file in pathlib.Path(wasm_dir).iterdir():
        if file.name.endswith('.wasm'):
            wasm_files.append(file)
            break

    if not wasm_files:
        print("[S2] No Wasm module found... Moving to S4")
        print("[>] Hint: try to increase the timeout -tm [seconds]")
    else:
        print(
            "\033[0;31m[*] Wasm module(s) found: {}, count: {} \033[0m".format(
                [str(item) for item in wasm_files], len(wasm_files)))
        for f in wasm_files:
            shutil.copy(f, wasm_save_dir / f.name)
    results_coll.insert_one({"url": url, "count": len(wasm_files)})
    shutil.rmtree(wasm_dir)
    os.unlink(cpu_stat_f)
Ejemplo n.º 2
0
	if not os.path.exists(config['out']):
	    os.makedirs(config['out'])

	print "[S1] Website Analysis..."
	
	md5_target = md5.new(target).hexdigest()
	outwasm = os.path.join(config['out'], md5_target)
	cpu_stat_f = os.path.join(config['out'], md5_target + ".txt")

	if not os.path.exists(outwasm):
	    os.makedirs(outwasm)

	#./chrome-build/chrome coinhive.com --no-sandbox --js-flags="--dump-wasm-module --dump-wasm-module-path=./data"
	command = config['chrome'] + ' ' + target + \
		' --no-sandbox --remote-debugging-port=9222 --js-flags="--dump-wasm-module --dump-wasm-module-path=' + outwasm + '"'
	run.crawl(command, cpu_stat_f , target, time)

###############################################################################
#						Stage 2: Wasm analysis
###############################################################################
	wasm_f = ""
	stat_f = ""

	print "[S2] Looking for a wasm module..."
	for fname in os.listdir(outwasm):
		if fname.endswith('.wasm'):
			# do stuff on the file
			wasm_f = fname
			break

	if not wasm_f:
Ejemplo n.º 3
0
              colored(str(time), 'cyan') + " sec")
        ###############################################################################
        #						Stage 1: Website analysis
        ###############################################################################
        if not os.path.exists(config['out']):
            os.makedirs(config['out'])
        print("[S1] Website Analysis...")
        wasm_dir = os.path.join(config['out'], target)
        cpu_stat_f = os.path.join(config['out'], target + ".txt")
        os.makedirs(wasm_dir, exist_ok=True)
        # ./chrome-build/chrome coinhive.com --no-sandbox --js-flags="--dump-wasm-module --dump-wasm-module-path=./data"
        command = config['chrome'] + ' ' + url + \
            ' --no-sandbox --headless --js-flags="--dump-wasm-module --dump-wasm-module-path=' + wasm_dir + '"'
        # print cpu_stat_f
        print(command)
        run.crawl(command, cpu_stat_f, url, time)

        ###############################################################################
        #						Stage 2: Wasm analysis
        ###############################################################################
        wasm_files = []

        print("[S2] Looking for a wasm module...")
        for file in pathlib.Path(wasm_dir).iterdir():
            if file.name.endswith('.wasm'):
                wasm_files.append(file)
                break

        if not wasm_files:
            print("[S2] No Wasm module found... Moving to S4")
            print("[>] Hint: try to increase the timeout -tm [seconds]")