由rust编写的虚拟机pwn的变种,程序没有删符号表,希望能玩的开心。
主要思路来自于CVE
-
2021
-
29939
,一个发现在rust代码中的高危漏洞。由于 Size_hint 的错误实现所致。在文档中可以找对对应表述:
> `size_hint()`
is
primarily intended to be used
for
optimizations such as reserving space
for
the elements of the iterator, but must
not
be trusted to e.g., omit bounds checks
in
unsafe code. An incorrect implementation of `size_hint()` should
not
lead to memory safety violations.
由于 rust 向来以安全性著称,因此发生在rust中的漏洞就显得更加特殊一些,因此将该漏洞换了一种方式展现在题目里了。
通过逆向能够发现,程序会读取若干指令然后模拟执行,所以首先应该把握整个程序的大致意图。
然后是因为 rust 编写的缘故,运行时保护也比较多,对于各种非法操作都会很容易的导致panic,所以需要对整个程序的流程把握的比较明确。
然后发现程序使用StackVec来模拟虚拟机中的栈,逆向可知它们也都是建立在栈上而不是堆上的,且还通过length来指示栈当前内容的长度。
```c
vmvec::lib::StackVec<[u64_
64
]>
*
__cdecl vmvec::lib::StackVec$LT$A$GT$::new::h550b99ccd348adea(vmvec::lib::StackVec<[u64_
64
]>
*
retstr)
{
char v2[
512
];
/
/
[rsp
+
28h
] [rbp
-
600h
] BYREF
char src[
512
];
/
/
[rsp
+
228h
] [rbp
-
400h
] BYREF
char dest[
512
];
/
/
[rsp
+
428h
] [rbp
-
200h
] BYREF
memcpy(dest, src, sizeof(dest));
memcpy(v2, dest, sizeof(v2));
retstr
-
>length
=
0LL
;
memcpy(&retstr
-
>data, v2, sizeof(retstr
-
>data));
return
retstr;
}