当前位置:网站首页>hackmyvm: again walkthrough
hackmyvm: again walkthrough
2022-08-02 03:25:00 【xdeclearn】
1. 命令执行获取shell
PORT STATE SERVICE
22/tcp open ssh
80/tcp open http
访问web,获得用户名和提示。
下载 upload.bck.
<?php
if (!isset($_FILES["myFile"])) {
die("There is no file to upload.");
}
$filepath = $_FILES['myFile']['tmp_name'];
$fileSize = filesize($filepath);
$fileinfo = finfo_open(FILEINFO_MIME_TYPE);
$filetype = finfo_file($fileinfo, $filepath);
if ($fileSize === 0) {
die("The file is empty.");
}
$allowedTypes = [
'image/jpeg' => 'jpg',
'text/plain' => 'txt'
];
if (!in_array($filetype, array_keys($allowedTypes))) {
echo $filetype;
die("File not allowed.");
}
$filename = basename($filepath);
$extension = $allowedTypes[$filetype];
$newFilepath = $_FILES['myFile']['name'];
if (!copy($filepath, $newFilepath)) {
die("Can't move file.");
}
$blacklistchars = '"%\'*|$;^`{}~\\#=&';
if (preg_match('/[' . $blacklistchars . ']/', $newFilepath)) {
echo ("No valid character detected");
exit();
}
if ($filetype === "image/jpeg"){
echo $newFilepath;
$myfile = fopen("outputimage.php", "w") or die("Unable to open file!");
$command = "base64 ".$newFilepath;
$output = shell_exec($command);
unlink($newFilepath);
echo "File uploaded";
$lol = '<img src="data:image/png;base64,'.$output.'" alt="Happy" />';
fwrite($myfile, $lol);
}
else{
$myfile2 = fopen("outputtext.txt", "w") or die("Unable to open file!");
$command = "cat ".$newFilepath;
$output = shell_exec($command);
unlink($newFilepath);
echo "File uploaded";
fwrite($myfile2, $output);
}
?>
利用过程分两步:
- 利用txt上传一段base64编码的php反弹shell。
base64 phpreverseshell.php > tmp.txt
通过上传页面上传txt。
- 利用上传
jpg图片利用base64 -d解码上传txt写入shell,并访问。
成功获取shell。
2. 提权
运行getcap查看特殊文件,发现php7.4具有cap_fowner权限。
修改/etc/passwd权限,将root:x:****改为root::****,成功切换至root。

[email protected]:/tmp$ su - root
su - root
[email protected]:~# ls -all
ls -all
total 28
drwx------ 3 root root 4096 Oct 12 17:36 .
drwxr-xr-x 18 root root 4096 Oct 11 07:33 ..
-rw------- 1 root root 155 Oct 12 17:36 .bash_history
-rw-r--r-- 1 root root 571 Apr 10 2021 .bashrc
drwxr-xr-x 3 root root 4096 Oct 11 07:38 .local
-rw-r--r-- 1 root root 161 Jul 9 2019 .profile
-rw------- 1 root root 25 Oct 11 07:41 r00t.txt
[email protected]:~#
边栏推荐
猜你喜欢
随机推荐
Solve the problem of Zlibrary stuck/can't find the domain name/reached the limit, the latest address of Zlibrary
三元判断再三元判断
[phpunit/php-timer] A timer for code execution time
IO stream, encoding table, character stream, character buffer stream
--fs module--
[league/flysystem]一个优雅且支持度非常高的文件操作接口
Xiaoyao multi-open emulator ADB driver connection
(6) 学生信息管理系统设计
一分种一起来了解Vite的基础
[symfony/finder] The best file manipulation library
SQL: DDL, DML, DQL, DCL corresponding introduction and demonstration
[phpunit/php-timer]一个用于代码执行时间的计时器
TypeScript error error TS2469, error TS2731 solution
IO流、 编码表、 字符流、 字符缓冲流
13. JS output content and syntax
New usage of string variable parsing in PHP8.2
[league/climate]一个功能健全的命令行功能操作库
3.PHP数据类型、常量、字符串和运算符
easyswoole uses redis to perform geoRadiusByMember Count invalid fix
百度定位js API






![[league/climate]一个功能健全的命令行功能操作库](/img/ce/39114b1c74af649223db97e5b0e29c.png)


