Delphi 能不能从Ring 3进入Ring 0
我发现了一篇发表在1999.11.29 b13版的
《令win32应用程序跳入系统层》东南大学 卢威 luwei@126.com
是用vc++嵌汇编做的,
很接近了,可试试
BCB或DELPHI进入Ring0
东南大学卢威1999.12发表在<<计算机世界>>报上的一篇
<<WIN32跳入系统0层>>,原采用VC++编程,现改成C++Builder
供诸位参考,DELPHI类似;
void Ring0Proc() // 在Ring0中执行你自已的代码
{
// .......
asm mov eax,CR0; // 试验一下Ring3不能执行的特权指令
// .......
}
// =====================================================
void __declspec(naked) NewInt() //新中断
{
Ring0Proc();
asm iretd;
}
#define IntNo 9
DWORDLONG IDTR,SavedGate;
WORD OurGate[4]={0,0x0028,0xee00,0x0000};
void GotoRing0()
{
asm
{
mov eax,offset NewInt;
mov [OurGate],ax;
shr eax,16;
mov [OurGate+6],ax;
sidt fword ptr IDTR;
mov ebx,dword ptr [IDTR+2];
add ebx,IntNo*8;
mov edi,offset SavedGate;
mov esi,ebx;
movsd;
movsd;
mov edi,ebx;
mov esi,offset OurGate;
movsd;
movsd;
int IntNo;
mov edi,ebx; // 开始恢复原中断门
mov esi,offset SavedGate;
movsd;
movsd;
}
}
// ===================================================
void __fastcall TForm1::Button1Click(TObject *Sender)
{
GotoRing0();
}
***********************************************
编译是通过了,你自己调试一下吧。
lea esi, MyInt; 一句语法应该有逻辑错误,要在Debug中仔细看一下。
procedure MyInt;
asm
// 这里面的内容可要你自己写哦。
end;
const HookExceptionNumber = 3;
procedure GetRing0;
asm
// 连续压入8个字节作为缓冲区
push eax
push eax;
// 取得idt偏移,共6字节,含段选择子2字节,偏移4字节。
sidt [esp-02h]; // Get IDT Base Address
// 弹出4字节偏移
pop ebx;
// 每个中断门8字节,所以偏移是HookExceptionNumber*08h
// 另外的4字节是定位到中心,因为中断门的4字节偏移分开放在8字节的0、1、6、7中。
// 0、1存放偏移低16位,6、7存放高16位。2,3是段选择子。4、5是门属性。
add ebx, HookExceptionNumber*08h + 04h;
// 关中断,准备修改idt。
cli
// 取得中断门的4、5、6、7字节,其中6、7字节在ebp高16位
mov ebp, [ebx]; // Get Exception Base
// 取得中断门的0、1字节到bp(实际上是ebp的低16位)。
mov bp, [ebx-04h]; // Entry Point
// 这样就合成了完整的32位偏移。
// 取得自己中断函数入口地址,放入esi中。
lea esi, MyInt;
// 压入堆栈
push esi
// 填充入口低16位到中断门0、1字节。
mov [ebx-04h], si;
// 将高16位移动到低16位。
shr esi, 16; // Modify Exception
// 填充入口高16位到中断门6、7字节。
mov [ebx+02h], si; // Entry Point Address
// idt修改完毕。
// 调整堆栈
pop esi
// 此时堆栈比初始状态多压8字节。估计是在引发的中断中处理。
// ebp的初始中断入口估计也是在自己的中断函数中用于恢复现场。
// 后面的就是引发软中断,取得ring0权力。
// 不过说句老实话。CIH的创意是不错,不过CIH的汇编的水平其实很一般。
int HookExceptionNumber; // GenerateException
// ReadyRestoreSE:
sti
end;
----------------------------------
const IntNo=9;
var
IDTR,SavedGate:int64;
OurGate:array[0..3] of word=(0,$0028,$ee00,$0000);
procedure Ring0Proc; // 在Ring0中执行你自已的代码
begin
// .......
asm
mov eax,CR0; // 试验一下Ring3不能执行的特权指令
end;
end;
// =====================================================
procedure NewInt(); //新中断
begin
Ring0Proc();
asm
iretd;
end;
end;
procedure GotoRing0;
begin
asm
mov eax,offset NewInt;
mov word ptr[OurGate],ax;
shr eax,16;
mov word ptr[OurGate+6],ax;
sidt fword ptr IDTR;//在Delphi中应该改成:lea ebx, idtr; sidt [ebx]
mov ebx,dword ptr [IDTR+2];
add ebx,IntNo*8;
mov edi,offset SavedGate;
mov esi,ebx;
movsd;
movsd;
mov edi,ebx;
mov esi,offset OurGate;
movsd;
movsd;
int IntNo;
mov edi,ebx; // 开始恢复原中断门
mov esi,offset SavedGate;
movsd;
movsd;
end;
end;
// ===================================================
procedure TForm1.Button1Click(Sender: TObject);
begin
gotoring0;
end;
********************************
const IntNo=3;
//var
//IDTR,SavedGate:int64;
procedure Ring0Proc; // 在Ring0中执行你自已的代码
begin
// .......
// showmessage('kfsdj;fk');
asm
mov eax,CR0; // 试验一下Ring3不能执行的特权指令
end;
end;
// =====================================================
procedure NewInt(); //新中断
begin
Ring0Proc();
asm
iretd;
end;
end;
procedure GotoRing0;
begin
asm
mov edi,offset buf;
sidt [edi]; //Get IDT-->buf;
mov ebx,[edi+2] //求中断门基址
add ebx,IntNo*8;
mov esi,ebx;
push edi;
push esi;
movsd;
movsd;
cli;
mov eax,offset newint;
mov [ebx],ax;
shr eax,16;
mov [ebx+6],ax;
mov ax,0ee00h;
mov [ebx+4],ax;
int intno;
pop edi
pop esi;
movsd;
movsd;
sti;
end;
end;
http://blog.csdn.net/diligentcatrich/article/details/5493254
Delphi 能不能从Ring 3进入Ring 0的更多相关文章
- delphi vlc 安装bug 处理编译错误"0" is an invalid value for the "DebugInformation" parameter of the "DCC"
处理编译错误"0" is an invalid value for the "DebugInformation" parameter of the "DCC" [摘要:http://blog.csdn ...
- 问题-[Delphi]用LoadLibrary加载DLL时返回0的错误
问题现象:用LoadLibrary加载DLL一直返回0句柄,无法进行下一步操作,但同样的代码可以访问到别的DLL.问题处理:1.你加载的路径是不对的,一定要看好路径.2.你是在虚拟机中操作的DLL,因 ...
- Delphi中,FALSE 和 nil ,true 和 nil,0的区别
True和False是布尔型(Boolean)的值,就是"是"或"否"的意思.nil就是空,一般用于指针或对象变量,指对针或对象对象一般初始化为nil或者释放后 ...
- uva 524 prime ring problem——yhx
Prime Ring Problem A ring is composed of n (even number) circles as shown in diagram. Put natural ...
- Lockless Ring Buffer Design
https://www.kernel.org/doc/Documentation/trace/ring-buffer-design.txt Lockless Ring Buffer Design == ...
- OpenStack_Swift源代码分析——创建Ring及加入�设备源代码算法具体分析
1 创建Ring 代码具体分析 在OpenStack_Swift--Ring组织架构中我们具体分析了Ring的具体工作过程,以下就Ring中添加�设备,删除设备,已经又一次平衡的实现过程作具体的介绍. ...
- OpenStack_Swift源代码分析——Ring基本原理及一致性Hash算法
1.Ring的基本概念 Ring是swfit中最重要的组件.用于记录存储对象与物理位置之间的映射关系,当用户须要对Account.Container.Object操作时,就须要查询相应的Ring文件( ...
- UVa 524 Prime Ring Problem(DFS , 回溯)
题意 把1到n这n个数以1为首位围成一圈 输出全部满足随意相邻两数之和均为素数的全部排列 直接枚举排列看是否符合肯定会超时的 n最大为16 利用回溯法 边生成边推断 就要快非常多了 #inc ...
- Segment,Path,Ring和Polyline对象
Segment几何对象 Segment对象是一个有起点和终点的“线“,也就是说Segement只有两个点,至于两点之间的线是直的,还是曲的,需要其余的参数定义.所以Segment是由起点,终点和参 ...
随机推荐
- ZOJ 3326 An Awful Problem 模拟
只有在 Month 和 Day 都为素数的时候才能得到糖 那就模拟一遍时间即可. //#pragma comment(linker, "/STACK:16777216") //fo ...
- Net FLow Template
EK Template : bool bfs(int src, int des){ memset(pre, -, sizeof(pre)); while(!que.empty()) que.pop( ...
- springMVC中得到request对象,session对象
RequestAttributes ra = RequestContextHolder.getRequestAttributes(); HttpServletRequest request = ((S ...
- Regionals 2012, Asia - Jakarta 解题报告
啥都不会做了.. 做题慢死 A.Grandpa's Walk 签到题. 直接DFS就行. 注意先判断这个点可以作为一个路径的起点不. 然后再DFS. 否则处理起来略麻烦 #include <io ...
- quartz群调查调度机制和源代码分析
pageId=85056282#quartz集群调度机制调研及源代码分析-quartz2.2.1集群调度机制调研及源代码分析" style="color:rgb(59,115,17 ...
- 再造 “手机QQ” 侧滑菜单(三)——视图联动
代码示例:https://github.com/johnlui/SwiftSideslipLikeQQ 本 文中,我们将一起使用 UINavigationController 来管理主视图,并实现点击 ...
- 网页制作之JavaScript部分 1 - 语法(复制教材内容)
一.简介 1.JavaScript它是个什么东西? 它是个脚本语言,需要有宿主文件,他的宿主文件是html文件. 2.它与Java有什么关系? 没有什么直接联系,java是Sun公司(已经没有了,被O ...
- BZOJ 3685: 普通van Emde Boas树( 线段树 )
建颗权值线段树就行了...连离散化都不用... 没加读入优化就TLE, 加了就A掉了...而且还快了接近1/4.... ---------------------------------------- ...
- java--实例成员 & 静态成员
class run{ static String str1 = "静态变量"; String str2 = "非静态变量"; public static voi ...
- ubuntu 12.04 安装sublime2
add-apt-repository ppa:webupd8team/sublime-text-2 apt-get update apt-get install sublime-text 安装控制器: ...