{"id":867,"date":"2014-08-27T21:15:32","date_gmt":"2014-08-27T21:15:32","guid":{"rendered":"http:\/\/www.gironsec.com\/blog\/?p=867"},"modified":"2014-08-27T21:15:53","modified_gmt":"2014-08-27T21:15:53","slug":"quicky-utility-plus-updates","status":"publish","type":"post","link":"https:\/\/www.gironsec.com\/blog\/2014\/08\/quicky-utility-plus-updates\/","title":{"rendered":"Quicky utility plus updates"},"content":{"rendered":"<p>It&#8217;s been a while, so its time to update the blog. <\/p>\n<p>Here&#8217;s a quick utility I wrote for finding hard coded addresses of functions within loaded modules.<br \/>\nWhat possible reason could there be for hard coding addresses? Shell code mostly. Even then, most decent shellcode will not bother hard coding any addresses as it makes the exploit unreliable on other OS&#8217;s.<\/p>\n<p>Example:<\/p>\n<p>Say I wanted to know the hard coded address of CsrGetProcessId for use within shell code or calling by address within asm. This little program will do this:<\/p>\n<p><a href=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2014\/08\/kon.png\"><img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2014\/08\/kon-300x169.png\" alt=\"kon\" width=\"300\" height=\"169\" class=\"alignnone size-medium wp-image-873\" srcset=\"https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2014\/08\/kon-300x169.png 300w, https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2014\/08\/kon-1024x578.png 1024w, https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2014\/08\/kon.png 1043w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/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: #557799\">#include &quot;stdafx.h&quot;<\/span>\r\n<span style=\"color: #557799\">#include &lt;Windows.h&gt;<\/span>\r\n\r\n<span style=\"color: #333399; font-weight: bold\">int<\/span> <span style=\"color: #0066BB; font-weight: bold\">main<\/span>(<span style=\"color: #333399; font-weight: bold\">int<\/span> argc, <span style=\"color: #333399; font-weight: bold\">char<\/span><span style=\"color: #333333\">*<\/span> argv[])\r\n{\r\n\t<span style=\"color: #008800; font-weight: bold\">if<\/span>(argc <span style=\"color: #333333\">&lt;<\/span> <span style=\"color: #0000DD; font-weight: bold\">2<\/span>)\r\n\t{\r\n\t\tprintf(<span style=\"background-color: #fff0f0\">&quot;Prints the hard coded addresses of functions for use with shellcode or whatever.<\/span><span style=\"color: #666666; font-weight: bold; background-color: #fff0f0\">\\r\\n<\/span><span style=\"background-color: #fff0f0\">&quot;<\/span>);\r\n\t\tprintf(<span style=\"background-color: #fff0f0\">&quot;Usage is %s dll function-name<\/span><span style=\"color: #666666; font-weight: bold; background-color: #fff0f0\">\\r\\n<\/span><span style=\"background-color: #fff0f0\">&quot;<\/span>,argv[<span style=\"color: #0000DD; font-weight: bold\">0<\/span>]);\r\n\t\t<span style=\"color: #008800; font-weight: bold\">return<\/span> <span style=\"color: #333333\">-<\/span><span style=\"color: #0000DD; font-weight: bold\">1<\/span>;\r\n\t}\r\n\t\r\n\tFARPROC ptr <span style=\"color: #333333\">=<\/span> GetProcAddress(GetModuleHandleA(argv[<span style=\"color: #0000DD; font-weight: bold\">1<\/span>]),argv[<span style=\"color: #0000DD; font-weight: bold\">2<\/span>]);\r\n    printf(<span style=\"background-color: #fff0f0\">&quot;The address 0x%8x is the hard coded address we use for function %s<\/span><span style=\"color: #666666; font-weight: bold; background-color: #fff0f0\">\\r\\n<\/span><span style=\"background-color: #fff0f0\">&quot;<\/span>,ptr,argv[<span style=\"color: #0000DD; font-weight: bold\">2<\/span>]); \r\n\t<span style=\"color: #008800; font-weight: bold\">return<\/span> <span style=\"color: #0000DD; font-weight: bold\">0<\/span>;\r\n}\r\n<\/pre>\n<\/div>\n<p>So using that,<\/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%\">\t<span style=\"color: #008800; font-weight: bold\">__asm<\/span>\r\n\t{\r\n\t\tmov eax,<span style=\"color: #005588; font-weight: bold\">0x7760cc92<\/span>\r\n\t\tcall eax\r\n\t\t; <span style=\"color: #333333\">^^<\/span> same as call CsrGetProcessId\r\n\t\tpush eax\r\n\t\tpush <span style=\"color: #0000DD; font-weight: bold\">0<\/span>\r\n\t\tpush <span style=\"color: #6600EE; font-weight: bold\">1f0ff<\/span>fh ;PROCESS_ALL_ACCESS <span style=\"color: #333333\">\/<\/span> <span style=\"color: #0000DD; font-weight: bold\">0<\/span>C3Ah\r\n                mov edx,<span style=\"color: #005588; font-weight: bold\">0x76a11952<\/span>\r\n\t\tcall edx;OpenProcess \r\n\t\ttest eax, eax\r\n\t\tjne admin_with_debug_priv\r\n\t\tret\r\n<span style=\"color: #997700; font-weight: bold\">admin_with_debug_priv:<\/span>\r\n\t\t_emit <span style=\"color: #005588; font-weight: bold\">0xEB<\/span>\r\n\t\t_emit <span style=\"color: #005588; font-weight: bold\">0xFE<\/span>\r\n\t}\r\n<\/pre>\n<\/div>\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: #888888\">\/\/ inliner.cpp : Defines the entry point for the console application.<\/span>\r\n<span style=\"color: #888888\">\/\/<\/span>\r\n\r\n<span style=\"color: #557799\">#include &quot;stdafx.h&quot;<\/span>\r\n<span style=\"color: #557799\">#include &lt;windows.h&gt;<\/span>\r\n<span style=\"color: #333399; font-weight: bold\">void<\/span> <span style=\"color: #0066BB; font-weight: bold\">BeingDbgd2<\/span>();\r\n<span style=\"color: #333399; font-weight: bold\">void<\/span> <span style=\"color: #0066BB; font-weight: bold\">BeingDbgd1<\/span>();\r\n\r\n<span style=\"color: #333399; font-weight: bold\">int<\/span> <span style=\"color: #0066BB; font-weight: bold\">_tmain<\/span>(<span style=\"color: #333399; font-weight: bold\">int<\/span> argc, _TCHAR<span style=\"color: #333333\">*<\/span> argv[])\r\n{\r\n\t<span style=\"color: #333399; font-weight: bold\">char<\/span> <span style=\"color: #333333\">*<\/span>what <span style=\"color: #333333\">=<\/span> <span style=\"background-color: #fff0f0\">&quot;CsrGetProcessId&quot;<\/span>;\r\n\tFARPROC ptr <span style=\"color: #333333\">=<\/span> GetProcAddress(GetModuleHandle(<span style=\"background-color: #fff0f0\">L&quot;ntdll.dll&quot;<\/span>),what);\r\n\tprintf(<span style=\"background-color: #fff0f0\">&quot;%p<\/span><span style=\"color: #666666; font-weight: bold; background-color: #fff0f0\">\\r\\n<\/span><span style=\"background-color: #fff0f0\">&quot;<\/span>, <span style=\"color: #333333\">&amp;<\/span>ptr);\r\n\tprintf(<span style=\"background-color: #fff0f0\">&quot;The address 0x%8x is the hard coded address we use for %s<\/span><span style=\"color: #666666; font-weight: bold; background-color: #fff0f0\">\\r\\n<\/span><span style=\"background-color: #fff0f0\">&quot;<\/span>,ptr,what); \r\n\tprintf(<span style=\"background-color: #fff0f0\">&quot;0x%8x<\/span><span style=\"color: #666666; font-weight: bold; background-color: #fff0f0\">\\r\\n<\/span><span style=\"background-color: #fff0f0\">&quot;<\/span>,<span style=\"color: #333333\">&amp;<\/span>ptr);\r\n\tsystem(<span style=\"background-color: #fff0f0\">&quot;pause&quot;<\/span>);\r\n\tBeingDbgd1();\r\n\tBeingDbgd2();\r\n\t<span style=\"color: #008800; font-weight: bold\">return<\/span> <span style=\"color: #0000DD; font-weight: bold\">0<\/span>;\r\n}\r\n\r\n<span style=\"color: #333399; font-weight: bold\">void<\/span> <span style=\"color: #0066BB; font-weight: bold\">BeingDbgd2<\/span>()\r\n{\r\n\t<span style=\"color: #008800; font-weight: bold\">__asm<\/span>\r\n\t{\r\n\t\tmov eax,<span style=\"color: #005588; font-weight: bold\">0x7760cc92<\/span>\r\n\t\tcall eax\r\n\t\t; <span style=\"color: #333333\">^^<\/span> same as call CsrGetProcessId\r\n\t\tpush eax\r\n\t\tpush <span style=\"color: #0000DD; font-weight: bold\">0<\/span>\r\n\t\tpush <span style=\"color: #0000DD; font-weight: bold\">0<\/span>C3Ah;PROCESS_ALL_ACCESS <span style=\"color: #333333\">\/<\/span> <span style=\"color: #6600EE; font-weight: bold\">1f0ff<\/span>fh \r\n\t\tcall OpenProcess\r\n\t\ttest eax, eax\r\n\t\tjne admin_with_debug_priv\r\n\t\tret\r\n<span style=\"color: #997700; font-weight: bold\">admin_with_debug_priv:<\/span>\r\n\t\t_emit <span style=\"color: #005588; font-weight: bold\">0xEB<\/span>\r\n\t\t_emit <span style=\"color: #005588; font-weight: bold\">0xFE<\/span>\r\n\t}\r\n}\r\n\r\n<span style=\"color: #333399; font-weight: bold\">void<\/span> <span style=\"color: #0066BB; font-weight: bold\">BeingDbgd1<\/span>()\r\n{\r\n\t<span style=\"color: #333399; font-weight: bold\">char<\/span> <span style=\"color: #333333\">*<\/span>fuckit <span style=\"color: #333333\">=<\/span> <span style=\"background-color: #fff0f0\">&quot;fuckthisshitforreal&quot;<\/span>;\r\n    <span style=\"color: #333399; font-weight: bold\">int<\/span> lol <span style=\"color: #333333\">=<\/span> <span style=\"color: #0000DD; font-weight: bold\">31<\/span>;\r\n    <span style=\"color: #008800; font-weight: bold\">__asm<\/span>{\r\n\t\txor eax,eax\r\n\t\t<span style=\"color: #333399; font-weight: bold\">int<\/span> <span style=\"color: #005588; font-weight: bold\">0x2d<\/span>\r\n\t\tinc eax\r\n\t\tje dbg\r\n\t\tret\r\n\t<span style=\"color: #997700; font-weight: bold\">dbg:<\/span>\r\n\t\t_emit <span style=\"color: #005588; font-weight: bold\">0xEB<\/span>\r\n\t\t_emit <span style=\"color: #005588; font-weight: bold\">0xFE<\/span>\r\n\t}\r\n\r\n\t<span style=\"color: #888888\">\/\/ awesome dont need to use _emit 0x2d<\/span>\r\n    printf(<span style=\"background-color: #fff0f0\">&quot;%d&quot;<\/span>,lol);\r\n\tprintf(<span style=\"background-color: #fff0f0\">&quot;%s&quot;<\/span>,fuckit);\r\n}\r\n<\/pre>\n<\/div>\n<p>Other than that, I was working through a variant of &#8216;torpig&#8217; which made some good use of anti-debugging features I don&#8217;t normally encounter such as process memory manipulation, section header adding, and anti-dumping. It doesn&#8217;t have to be dumped for me to see what&#8217;s going on, so I wasn&#8217;t too annoyed:<br \/>\n<a href=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2014\/08\/zomg.png\"><img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2014\/08\/zomg-300x173.png\" alt=\"zomg\" width=\"300\" height=\"173\" class=\"alignnone size-medium wp-image-877\" srcset=\"https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2014\/08\/zomg-300x173.png 300w, https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2014\/08\/zomg-1024x592.png 1024w, https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2014\/08\/zomg.png 1680w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>It&#8217;s been a while, so its time to update the blog. Here&#8217;s a quick utility I wrote for finding hard coded addresses of functions within loaded modules. What possible reason could there be for hard coding addresses? Shell code mostly. Even then, most decent shellcode will not bother hard coding any addresses as it makes [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/www.gironsec.com\/blog\/wp-json\/wp\/v2\/posts\/867"}],"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=867"}],"version-history":[{"count":5,"href":"https:\/\/www.gironsec.com\/blog\/wp-json\/wp\/v2\/posts\/867\/revisions"}],"predecessor-version":[{"id":878,"href":"https:\/\/www.gironsec.com\/blog\/wp-json\/wp\/v2\/posts\/867\/revisions\/878"}],"wp:attachment":[{"href":"https:\/\/www.gironsec.com\/blog\/wp-json\/wp\/v2\/media?parent=867"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gironsec.com\/blog\/wp-json\/wp\/v2\/categories?post=867"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gironsec.com\/blog\/wp-json\/wp\/v2\/tags?post=867"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}