
關於ShellcodeTemplate
ShellcodeTemplate是一款易於修改的針對Windowsx64/x86的Shellcode模版工具,該工具基於TitanLdr開發,能夠幫助廣大研究人員將項目代碼編譯成一個PE可執行程序,並提取.text字段。
Shellcode百科
Shellcode是一段用於利用軟件漏洞而執行的代碼,實際上是十六進制形式的機器語言,大家知道機器語言是二進制的,CPU只認識二進制,因為要被直接注入到內存中,沒辦法編譯了,所以希望CPU可以執行,那就只能用機器代碼了,一般用匯編語言寫出程序,在從目標代碼中提取出來。
Shellcode可以按照攻擊者執行的位置分為本地Shellcode和遠程Shellcode。本地運行的Shellcode經常用於利用軟件漏洞提升權限,比如在Linux下由普通權限提升至root權限等。而遠程Shellcode指的是利用軟件漏洞獲得特定的Shellcode,再經由C或Python編寫遠程攻擊程序,進而取得對方電腦的root權限。
工具下載
廣大研究人員可以使用下列命令將該項目源碼克隆至本地:
git clone https://github.com/Cracked5pider/ShellcodeTemplate.git接下來,我們需要在makefile中修改項目名稱,將「ShellcodeTemplate」修改為你想要的名字,然後使用make來編譯項目源碼:make // to compile x64 and x86make x64 // to compile only x64make x86 // to compile only x86工具使用樣例
Shellocde的入口點如下所示,當然了,我們也可以根據自己的需要來進行修改。
首先,我們需要使用自定義的GetModuleHandle和GetProcAddress來初始化我們要用到的庫和函數:
SEC( text, B ) VOID Entry( VOID ){ INSTANCE Instance = { }; Instance.Modules.Kernel32 = TGetModuleHandle( HASH_KERNEL32 ); Instance.Modules.Ntdll = TGetModuleHandle( HASH_NTDLL ); if ( Instance.Modules.Kernel32 != NULL ) { // Load needed functions Instance.Win32.LoadLibraryA = TGetProcAddr( Instance.Modules.Kernel32, 0xb7072fdb ); // Load needed Libraries Instance.Modules.User*32 = Instance.Win32.LoadLibraryA( GET_SYMBOL( "User*32" ) ); if ( Instance.Modules.User*32 != NULL ) { Instance.Win32.MessageBoxA = TGetProcAddr( Instance.Modules.User*32, 0xb303ebb4 ); } } // ------ Code ------ Instance.Win32.MessageBoxA( NULL, GET_SYMBOL( "Hello World" ), GET_SYMBOL( "MessageBox Title" ), MB_OK );}值得注意的是,正如大家所看到的那樣,我們可以直接在我們的Shellcode中使用常規字符串,這是因為我們在鏈接的時候向我們的Shellcode中引入了.rdata字段,GET_SYMBOL將通過GetRIP()的偏移量獲取到函數或字符串的指針。
項目地址
https://github.com/Cracked5pider/ShellcodeTemplate
參考資料
https://twitter.com/ilove2pwn_
https://github.com/SecIdiot/TitanLdr