.NET 调用ShellExecute API执行系统命令

admin 2023年3月1日11:40:56评论24 views字数 729阅读2分25秒阅读模式

0x01 基本介绍

.NET调用Windows API执行系统命令,调用shell32.dll提供的ShellExecute 函数,ShellExecute函数用于启动一个程序或打开一个文件,并且可以指定程序窗口的外观和行为,c++原型定义如下

HINSTANCE ShellExecute(  HWND    hwnd,  LPCTSTR lpOperation,  LPCTSTR lpFile,  LPCTSTR lpParameters,  LPCTSTR lpDirectory,  INT     nShowCmd);

ShellExecute函数返回一个HINSTANCE类型的值,表示执行操作的句柄。如果操作成功,则返回值大于32,否则返回值小于等于32,.NET里需要导入 System.Runtime.InteropServices 命名空间,采用PInvoke加载Shell32

[DllImport("shell32.dll", SetLastError = true)]static extern IntPtr ShellExecute(IntPtr hwnd, string lpOperation, string lpFile, string lpParameters, string lpDirectory, int nShowCmd);

0x02 Webshell

需要导入 Import Namespace="System.Runtime.InteropServices",代码如下 

ShellExecute(IntPtr.Zero, "open", "calc.exe", null, null, 0);

章涉及的工具和PDF已打包发布在星球

.NET 调用ShellExecute API执行系统命令

原文始发于微信公众号(dotNet安全矩阵):.NET 调用ShellExecute API执行系统命令

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2023年3月1日11:40:56
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   .NET 调用ShellExecute API执行系统命令http://cn-sec.com/archives/1581550.html

发表评论

匿名网友 填写信息