« | August 2025 | » | 日 | 一 | 二 | 三 | 四 | 五 | 六 | | | | | | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | | | | | | | |
| 公告 |
戒除浮躁,读好书,交益友 |
Blog信息 |
blog名称:邢红瑞的blog 日志总数:523 评论数量:1142 留言数量:0 访问次数:9690957 建立时间:2004年12月20日 |

| |
从shellcode看编程的境界  原创空间, 软件技术, 电脑与网络
邢红瑞 发表于 2008/1/10 18:02:48 |
偶尔在群里说到了这个问题,起源是使用hibenrate的最高水平,hibernate的作用是实现数据CRUD,C 添加,R 获得,U 更新,D删除 。我个人的认为最高境界是Domain model,也就是让上层的开发者根部感觉不到数据库的存在,只关心对象之间的约束即可,其实这也应该是ORM的境界吧。还有一个实现网络的数据传输,实现目的就是数据准确 安全 高效的到达接收端,上层的程序不考虑底层的使用 socket写的,还是Ace ,ICE还是Corba或者RMI,这应该是做网络传输程序的最高境界。写程序的最高境界就是跨过语言和平台的界限,不考虑源码,也不考虑汇编指令,只考虑0和1的代码序列,当然这种代码序列是和平台cpu相关的。举一个简单的例子 调用windows api sleep,就是让程序睡觉,大家不必担心,特定os 特定sp的函数是一样的,因为微软编译的dll,经过rebase,而且建议大家不要rebase,所以这个地址是靠谱的。
#include "stdafx.h"#include "Windows.h"int main(int argc, char* argv[]){ Sleep(-1); return 0;}设个端点,F5运行,查看Alt+8汇编代码00401028 mov esi,esp0040102A push 0FFh0040102C call dword ptr [__imp__Sleep@4 (0042a14c)]ok,0FFh是压栈的数据,call 调用的函数的地址,这个地址不同操作系统 ,不同的SP版本是不同的,Sleep是Kernel32.dll的一个导出函数。我们先查看kernel32.dll的imagebase是 0x78c00000,建议使用depends.exe,使用dumpbin /all kernel32.dll >a.txt 也可以,主要是这个文件太大。查看Sleep的地址,使用dumpbin kernel32.dll /exports,是0x2442。地址就是0x7c800000+0x2442=0x7c802442写段程序
#include "stdafx.h"#include "Windows.h"int main(int argc, char* argv[]){ _asm{ push -1 mov eax ,0x7c802442 call eax } return 0;}
然后设个端点,F5运行,查看Alt+8汇编代码,选中 code byte10: push -100401028 6A FF push 0FFh11: mov eax ,0x7c8024420040102A B8 42 24 80 7C mov eax,7C802442h12: call eax0040102F FF D0 call eax
写段win32console程序,最好是空的,然后建立一个c文件,内容如下#include "Windows.h"void (*op)();int main(int argc, char* argv[]){ char code[]="\x6A\xFF\xB8\x42\x24\x80\x7C\xFF\xD0"; op=&code; op(); return 0;}如果连接时出现Winmain找不到,讲subsystem后的windows改为console,编译运行。打开depends,查看shellcode文件,发现使用两个dll kernel32.dll和nt.dll,但是没有引用其中的函数,从nt4开始,win32程序运行,需要kernel32.dll和nt.dll,如果你写汇编,不引用kernel的函数,程序跑不起来的。这种shellcode主要用于IDS检测,还好这个程序没有什么危害.查看函数地址最好的工具是Arwin,这里有源码,大家去编译吧,// arwin.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include <windows.h>#include <stdio.h>
/***************************************arwin - win32 address resolution programby steve hanna v.01 vividmachines.com shanna@uiuc.eduyou are free to modify this codebut please attribute me if youchange the code. bugfixes & additionsare welcome please email me!to compile:you will need a win32 compiler withthe win32 SDK
this program finds the absolute addressof a function in a specified DLL.happy shellcoding!***************************************/
int main(int argc, char** argv){ HMODULE hmod_libname; FARPROC fprc_func; printf("arwin - win32 address resolution program - by steve hanna - v.01\n"); if(argc < 3) { printf("%s <Library Name> <Function Name>\n",argv[0]); return 0; }
hmod_libname = LoadLibrary(argv[1]); if(hmod_libname == NULL) { printf("Error: could not load library!\n"); return 0; } fprc_func = GetProcAddress(hmod_libname,argv[2]); if(fprc_func == NULL) { printf("Error: could find the function in the library!\n"); return 0; } printf("%s is located at 0x%08x in %s\n",argv[2],(unsigned int)fprc_func,argv[1]);
}用法 arwin kernel32.dll Sleep |
|
|