{"id":369,"date":"2011-07-07T18:58:40","date_gmt":"2011-07-07T20:58:40","guid":{"rendered":"http:\/\/www.ragestorm.net\/blogs\/?p=369"},"modified":"2011-07-09T00:22:22","modified_gmt":"2011-07-09T02:22:22","slug":"finding-kernel32-base-address-shellcode","status":"publish","type":"post","link":"https:\/\/www.ragestorm.net\/blogs\/?p=369","title":{"rendered":"Finding Kernel32 Base Address Shellcode"},"content":{"rendered":"<p>Yet another one&#8230;<br \/>\nThis time, smaller, more correct, and still null-free.<br \/>\nI looked a bit at some shellcodes at exploit-db and googled too, to see whether anyone got a smaller way to no avail.<\/p>\n<p>I based my code on:<br \/>\n<a href=\"http:\/\/skypher.com\/index.php\/2009\/07\/22\/shellcode-finding-kernel32-in-windows-7\/\">http:\/\/skypher.com\/index.php\/2009\/07\/22\/shellcode-finding-kernel32-in-windows-7\/<\/a><br \/>\nAFAIK, who based his post on:<br \/>\n<a href=\"http:\/\/blog.harmonysecurity.com\/2009_06_01_archive.html\">http:\/\/blog.harmonysecurity.com\/2009_06_01_archive.html<\/a><\/p>\n<p>And this is my version:<\/p>\n<pre lang=\"asm\">\r\n00000000 (02) 6a30                     PUSH 0x30\r\n00000002 (01) 5e                       POP ESI\r\n; Use DB 0x64; LODSD\r\n00000003 (02) 64ad                     LODS EAX, [FS:ESI]\r\n00000005 (03) 8b700c                   MOV ESI, [EAX+0xc]\r\n00000008 (03) 8b761c                   MOV ESI, [ESI+0x1c]\r\n0000000b (03) 8b5608                   MOV EDX, [ESI+0x8]\r\n0000000e (04) 807e1c18                 CMP BYTE [ESI+0x1c], 0x18\r\n00000012 (02) 8b36                     MOV ESI, [ESI]\r\n00000014 (02) 75f5                     JNZ 0xb\r\n<\/pre>\n<p>The tricky part was how to read from FS:0x30, and the way I use is the smallest one, at least from what I checked.<br \/>\nAnother issue that was fixed is the check for kernel32.dll, usually the variation of this shellcode checks for a null byte, but it turned out to be bogous on W2k machines, so it was changed to check for a null word. Getting the shellcode by a byte or two longer.<\/p>\n<p>This way, it&#8217;s only 22 bytes, it doesn&#8217;t assume that kernel32.dll is the second\/third entry in the list, it actually loops till it finds the correct module length (len of &#8216;kernel32.dll&#8217; * 2 bytes). Also since kernelbase.dll can come first and that renders lots of implementations of this technique unusable.<br \/>\nAnd obviously the resulting base address of kernel32.dll is in EDX.<\/p>\n<p>Enjoy<\/p>\n<p>[Update July 9th:]<br \/>\nHere&#8217;s a link to an explanation about <a href=\"http:\/\/sandsprite.com\/CodeStuff\/Understanding_the_Peb_Loader_Data_List.html\">PEB\/LDR lists<\/a>.<br \/>\nSee first comment for a better version which is only 17 bytes.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Yet another one&#8230; This time, smaller, more correct, and still null-free. I looked a bit at some shellcodes at exploit-db and googled too, to see whether anyone got a smaller way to no avail. I based my code on: http:\/\/skypher.com\/index.php\/2009\/07\/22\/shellcode-finding-kernel32-in-windows-7\/ AFAIK, who based his post on: http:\/\/blog.harmonysecurity.com\/2009_06_01_archive.html And this is my version: 00000000 (02) 6a30 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","jetpack_publicize_message":""},"categories":[5,12,19,3,11,13,17,18,7],"tags":[],"jetpack_featured_media_url":"","jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/pbWKd-5X","_links":{"self":[{"href":"https:\/\/www.ragestorm.net\/blogs\/index.php?rest_route=\/wp\/v2\/posts\/369"}],"collection":[{"href":"https:\/\/www.ragestorm.net\/blogs\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ragestorm.net\/blogs\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ragestorm.net\/blogs\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ragestorm.net\/blogs\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=369"}],"version-history":[{"count":5,"href":"https:\/\/www.ragestorm.net\/blogs\/index.php?rest_route=\/wp\/v2\/posts\/369\/revisions"}],"predecessor-version":[{"id":372,"href":"https:\/\/www.ragestorm.net\/blogs\/index.php?rest_route=\/wp\/v2\/posts\/369\/revisions\/372"}],"wp:attachment":[{"href":"https:\/\/www.ragestorm.net\/blogs\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=369"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ragestorm.net\/blogs\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=369"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ragestorm.net\/blogs\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=369"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}