CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/tools/context/cpuid-key.c
Views: 11768
1
/*
2
* outputs a cpuid key for use in context keyed payload encoding.
3
*
4
* Author: Dimitris Glynos <dimitris at census-labs.com>
5
*/
6
7
8
#include <stdio.h>
9
10
int main()
11
{
12
unsigned long eax;
13
14
asm (
15
"xorl %%esi, %%esi;" /* esi is key store, zero it out */
16
"xorl %%edi, %%edi;" /* edi is loop iterator, ditto */
17
"cpuid_loop: movl %%edi, %%eax;" /* iterator is first arg
18
to cpuid */
19
"xorl %%ecx, %%ecx;" /* ecx is also used as arg to cpuid but
20
we'll use it always as zero */
21
"cpuid;"
22
"xorl %%eax, %%esi;"
23
"cmpl %%esi, %%eax;" /* first time round esi = eax */
24
/* not very safe heh? */
25
"jne not_first_time;"
26
"leal 0x1(%%eax, 1), %%edi;" /* first time round ... */
27
"not_first_time: xorl %%ebx, %%esi;"
28
"xorl %%ecx, %%esi;"
29
"xorl %%edx, %%esi;"
30
"subl $1, %%edi;"
31
"jne cpuid_loop;"
32
"movl %%esi, %%eax;"
33
: "=a" (eax)
34
);
35
36
printf("%#.8lx\n", eax);
37
return 0;
38
}
39
40