当前位置:网站首页>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]:~#
边栏推荐
- PHP8.2 version release administrator and release plan
- 每日面试题 2022/7/28
- Solve the problem of Zlibrary stuck/can't find the domain name/reached the limit, the latest address of Zlibrary
- When PHP initiates Alipay payment, the order information is garbled and solved
- Kali install IDEA
- 百度定位js API
- JS objects, functions and scopes
- [symfony/finder] The best file manipulation library
- 三元判断再三元判断
- ES6数组的扩展方法map、filter、reduce、fill和数组遍历for…in for…of arr.forEach
猜你喜欢
随机推荐
When PHP initiates Alipay payment, the order information is garbled and solved
(8) requests, os, sys, re, _thread
微信小程序开发视频加载:[渲染层网络层错误] Failed to load media
TCP通信程序
16. JS events, string and operator
IP access control: teach you how to implement an IP firewall with PHP
--fs module--
kali安装IDEA
正则笔记(1)- 正则表达式字符匹配攻略
[symfony/finder] The best file manipulation library
display,visibility,opacity
ES6介绍+定义变量+不同情况下箭头函数的this指向
JS对象, 函数和作用域
Multithreading (implementing multithreading, thread synchronization, producer and consumer)
TypeScript error error TS2469, error TS2731 solution
稳定好用的短连接生成平台,支持API批量生成
14. JS Statements and Comments, Variables and Data Types
ES6数组的扩展方法map、filter、reduce、fill和数组遍历for…in for…of arr.forEach
PHP Foundation March Press Announcement Released
PHP8.2的版本发布管理员和发布计划








