2017-08-26 47 views
-2

我爲我的筆記本電腦製作了一個遠程管理工具,因此無論何時我都可以通過Web界面訪問它。當TaskManager或CMD終止應用程序時執行代碼

每當應用程序是通過任務管理器或CMD/Powershell的,打死我在想,如果我可以執行以下代碼:

 HttpWebRequest request = (HttpWebRequest)WebRequest.Create($"http://10.0.0.1/?p=Logout&HOSTNAME={HOSTNAME}&IP={IP}&USERNAME={USERNAME}&HASH={HASH}"); 
     request.AutomaticDecompression = DecompressionMethods.GZip; 
     using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()); 

(主機名,IP,用戶名和HASH是變量)

這將被執行,以便我的筆記本電腦從我的數據庫中註銷。

P.S我知道它很容易受到SQL注入攻擊,但稍後我會修復它。

回答

0

取決於你的應用程序被殺的方式,但你可以涵蓋很多。即時確定它適用於taskmanager,但TerminateProcess,當然在內核模式可能是一個痛苦,不是那樣,我會猜測。這裏有一個例子:

private delegate bool ConsoleEventDelegate(int eventType); 

public static Main(string[] args) 
{ 
      SetConsoleCtrlHandler(ConsoleEventCallback, true); 
      AppDomain.CurrentDomain.UnhandledException += Reset; 
      AppDomain.CurrentDomain.ProcessExit += Exit; 
      AppDomain.CurrentDomain.DomainUnload += Exit; 
} 

     private static void Exit(object sender, EventArgs e) 
     { 
      HttpWebRequest request = (HttpWebRequest)WebRequest.Create($"http://10.0.0.1/?p=Logout&HOSTNAME={HOSTNAME}&IP={IP}&USERNAME={USERNAME}&HASH={HASH}"); 
     request.AutomaticDecompression = DecompressionMethods.GZip; 
     using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()); 
     } 

     private static void Reset(object sender, UnhandledExceptionEventArgs e) 
     { 
      Exit(null, null); 
     } 

     private static bool ConsoleEventCallback(int eventType = 0) 
     { 
      Exit(null, null); 
      return false; 
     } 
相關問題