{"id":668,"date":"2013-12-23T04:37:18","date_gmt":"2013-12-23T04:37:18","guid":{"rendered":"http:\/\/www.gironsec.com\/blog\/?p=668"},"modified":"2013-12-23T04:38:54","modified_gmt":"2013-12-23T04:38:54","slug":"other-antidebug-tricks","status":"publish","type":"post","link":"https:\/\/www.gironsec.com\/blog\/2013\/12\/other-antidebug-tricks\/","title":{"rendered":"Other AntiDebug tricks"},"content":{"rendered":"<p>I came across this <a href=\"https:\/\/code.google.com\/p\/corkami\/\">one individual&#8217;s page<\/a> whom is an avid reverse engineer with some great material.<\/p>\n<p>Check out his pdf <a href=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2013\/12\/cm.pdf\">cheat sheet<\/a> on anti-debugging. There were a few in there I didn&#8217;t know about like the &#8216;csr&#8217; trick which involves calling an undocumented &#8216;CsrGetProcessId&#8217; function within OpenProcess. CsrGetProcessId is a native API that returns the PID of csrss.exe. <\/p>\n<p>Evidently if you call OpenProcess and pass the ID returned by CsrGetProcessId(), no error will occur if the SeDebugPrivilege has been set with SetPrivilege() \/ AdjustTokenPrivileges(). How about some code with that shake?<br \/>\n<!-- 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 &lt;stdio.h&gt;<\/span>\r\n<span style=\"color: #557799\">#include &lt;windows.h&gt;<\/span>\r\n<span style=\"color: #008800; font-weight: bold\">typedef<\/span> <span style=\"color: #0066BB; font-weight: bold\">HANDLE<\/span> (<span style=\"color: #333333\">*<\/span>_CsrGetProcessId)();\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\">void<\/span>)\r\n{\r\nHMODULE nt<span style=\"color: #333333\">=<\/span>GetModuleHandle(<span style=\"background-color: #fff0f0\">&quot;ntdll.dll&quot;<\/span>);\r\n_CsrGetProcessId CsrGetProcessId<span style=\"color: #333333\">=<\/span>(_CsrGetProcessId)GetProcAddress(nt,<span style=\"background-color: #fff0f0\">&quot;CsrGetProcessId&quot;<\/span>);\r\nHANDLE proc <span style=\"color: #333333\">=<\/span> OpenProcess(PROCESS_ALL_ACCESS,FALSE,CsrGetProcessId());\r\n<span style=\"color: #008800; font-weight: bold\">if<\/span>(<span style=\"color: #333333\">!<\/span>proc)\r\n{\r\nprintf(<span style=\"background-color: #fff0f0\">&quot;debugger is present!&quot;<\/span>);\r\n}\r\n}\r\n<\/pre>\n<\/div>\n<p>The <a href=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2013\/12\/cm.pdf\">cheat sheet<\/a> has other stuff in it. Check it out some time. Better yet, check out the <a href=\"http:\/\/corkami.blogspot.com\">guy&#8217;s blog<\/a> instead.<\/p>\n<p>Happy cracking!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I came across this one individual&#8217;s page whom is an avid reverse engineer with some great material. Check out his pdf cheat sheet on anti-debugging. There were a few in there I didn&#8217;t know about like the &#8216;csr&#8217; trick which involves calling an undocumented &#8216;CsrGetProcessId&#8217; function within OpenProcess. CsrGetProcessId is a native API that returns [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[4,7],"tags":[82],"_links":{"self":[{"href":"https:\/\/www.gironsec.com\/blog\/wp-json\/wp\/v2\/posts\/668"}],"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=668"}],"version-history":[{"count":3,"href":"https:\/\/www.gironsec.com\/blog\/wp-json\/wp\/v2\/posts\/668\/revisions"}],"predecessor-version":[{"id":672,"href":"https:\/\/www.gironsec.com\/blog\/wp-json\/wp\/v2\/posts\/668\/revisions\/672"}],"wp:attachment":[{"href":"https:\/\/www.gironsec.com\/blog\/wp-json\/wp\/v2\/media?parent=668"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gironsec.com\/blog\/wp-json\/wp\/v2\/categories?post=668"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gironsec.com\/blog\/wp-json\/wp\/v2\/tags?post=668"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}