OverTheWire-Bandit

OverTheWire-Bandit 1-27

官网:http://overthewire.org/wargames/bandit/

强盗战争是针对绝对的初学者。它将教授需要能够玩其他战争游戏的基础知识,通过这个游戏能学习到很多Linux的基础知识。和大多数其他游戏一样,这个游戏按层次组织。你从0级开始尝试“击败”或“完成”它。完成一个关卡会产生关于如何开始下一关的信息。本网站上的“Level ”页面包含有关如何从上一级开始X级的信息。

这个游戏有27关,对应27对账号密码组合。开始的时候送我们一个第一关的账号密码:「bandit0」-「bandit0」。
我们需要使用这个账号登陆服务器并找到「bandit1」的密码,然后使用得到的密码登陆「bandit1」,再找到「bandit2」的密码……

Level 0

这个级别的目标是让你使用SSH登录游戏。您需要连接的主机是 bandit.labs.overthewire.org,端口2220.用户名是bandit0,密码是bandit0。登录后,进入1级页面,了解如何击败1级。

我用的是XShell直接按提示输入账号密码,连接成功,进入下一级

Level 0 → Level 1

描述:下一级别的密码存储在位于主目录中的名为readme的文件 中。使用此密码使用SSH登录bandit1。只要你找到一个级别的密码,使用SSH(在端口2220)登录到该级别,并继续游戏。

过程:

1
2
3
4
bandit0@bandit:~$ ls
readme
bandit0@bandit:~$ cat readme
boJ9jbbUNNfktd78OOpsqOltutMc3MY1

ls命令列出当前目录下的文件,而用cat命令查看文件内容

密码:boJ9jbbUNNfktd78OOpsqOltutMc3MY1

Level 1 → Level 2

用账号:bandit1 ,密码:boJ9jbbUNNfktd78OOpsqOltutMc3MY1进入本关

描述:下一级的密码存储在一个名为- ,位于主目录中的文件中

过程:

1
2
3
4
bandit1@bandit:~$ ls
-
bandit1@bandit:~$ cat ./-
CV1DtqXWVFXTvM2F0k09SHz0YwRINYA9

文件名是:”-“,如果是其他名字直接 cat filename 就行了,如果是 “cat - “的话,就有一些小问题,因为 bash 中会用”-“来接受命令行参数,未避免冲突,我们使用”./“来表示当前目录,那”-“文件就表示为”./-“。

密码:CV1DtqXWVFXTvM2F0k09SHz0YwRINYA9

Level 2→ Level 3

用账号:bandit2 ,密码:CV1DtqXWVFXTvM2F0k09SHz0YwRINYA9进入本关

描述:下一级别的密码存储在位于主目录中的文件名为spaces in this filename

过程:

1
2
3
4
bandit2@bandit:~$ ls
spaces in this filename
bandit2@bandit:~$ cat spaces\ in\ this\ filename
UmHadQclWmgdLOKQ3YNgjWxGoRMb5luK

“ls”查看文件,注意spaces in this filename是一个文件,而不是四个,虽然文件名存在空格,但是Linux有自动补全的功能,输入”cat s”后,按一下Tab键就自动补全了

密码:UmHadQclWmgdLOKQ3YNgjWxGoRMb5luK

Level 3 → Level 4

用账号:bandit3 ,密码:UmHadQclWmgdLOKQ3YNgjWxGoRMb5luK进入本关

描述:下一级别的密码存储在inhere目录中的隐藏文件中 。

过程:

1
2
3
4
5
6
7
8
bandit3@bandit:~$ ls
inhere
bandit3@bandit:~$ cd inhere/
bandit3@bandit:~/inhere$ ls
bandit3@bandit:~/inhere$ ls -a
. .. .hidden
bandit3@bandit:~/inhere$ cat .hidden
pIwrPrtPN36QITSp3EQaw936yaFoFgAB

“ls -a”显示所有文件及目录 (ls内定将文件名或目录名称开头为”.”的视为隐藏档,不会列出),”.”开头的文件为隐藏文件,故”ls”没有列出

密码:pIwrPrtPN36QITSp3EQaw936yaFoFgAB

Level 4→ Level 5

用账号:bandit4 ,密码:pIwrPrtPN36QITSp3EQaw936yaFoFgAB进入本关

描述:下一级别的密码存储在inhere目录中唯一的人类可读文件中。提示:如果你的终端搞砸了,试试“重置”命令。

过程:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
bandit4@bandit:~$ ls
inhere
bandit4@bandit:~$ cd inhere/
bandit4@bandit:~/inhere$ ls
-file00 -file02 -file04 -file06 -file08
-file01 -file03 -file05 -file07 -file09
bandit4@bandit:~/inhere$ file ./*
./-file00: data
./-file01: data
./-file02: data
./-file03: data
./-file04: data
./-file05: data
./-file06: data
./-file07: ASCII text
./-file08: data
./-file09: data
bandit4@bandit:~/inhere$ cat ./-file07
koReBOKuIDDepwhWk7jZC0RTdopnAYKh

inhere文件夹中存在10个文件,用Linux的”file”命令辨识文件类型,”*”是通配符,只有”-file07”文件类型不一样,八九不离十就是它了。

密码:koReBOKuIDDepwhWk7jZC0RTdopnAYKh

Level 5→ Level 6

用账号:bandit5,密码:koReBOKuIDDepwhWk7jZC0RTdopnAYKh进入本关

描述:下一级别的密码存储在inhere目录下的某个文件中,并具有以下所有属性:人类可读,大小为1033字节,不可执行

过程:

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
bandit5@bandit:~$ ls
inhere
bandit5@bandit:~$ cd inhere/
bandit5@bandit:~/inhere$ ls -l
total 80
drwxr-x--- 2 root bandit5 4096 Dec 28 14:34 maybehere00
drwxr-x--- 2 root bandit5 4096 Dec 28 14:34 maybehere01
drwxr-x--- 2 root bandit5 4096 Dec 28 14:34 maybehere02
drwxr-x--- 2 root bandit5 4096 Dec 28 14:34 maybehere03
drwxr-x--- 2 root bandit5 4096 Dec 28 14:34 maybehere04
drwxr-x--- 2 root bandit5 4096 Dec 28 14:34 maybehere05
drwxr-x--- 2 root bandit5 4096 Dec 28 14:34 maybehere06
drwxr-x--- 2 root bandit5 4096 Dec 28 14:34 maybehere07
drwxr-x--- 2 root bandit5 4096 Dec 28 14:34 maybehere08
drwxr-x--- 2 root bandit5 4096 Dec 28 14:34 maybehere09
drwxr-x--- 2 root bandit5 4096 Dec 28 14:34 maybehere10
drwxr-x--- 2 root bandit5 4096 Dec 28 14:34 maybehere11
drwxr-x--- 2 root bandit5 4096 Dec 28 14:34 maybehere12
drwxr-x--- 2 root bandit5 4096 Dec 28 14:34 maybehere13
drwxr-x--- 2 root bandit5 4096 Dec 28 14:34 maybehere14
drwxr-x--- 2 root bandit5 4096 Dec 28 14:34 maybehere15
drwxr-x--- 2 root bandit5 4096 Dec 28 14:34 maybehere16
drwxr-x--- 2 root bandit5 4096 Dec 28 14:34 maybehere17
drwxr-x--- 2 root bandit5 4096 Dec 28 14:34 maybehere18
drwxr-x--- 2 root bandit5 4096 Dec 28 14:34 maybehere19
bandit5@bandit:~/inhere$ find . -type f -size 1033c
./maybehere07/.file2
bandit5@bandit:~/inhere$ cat ./maybehere07/.file2
DXjZPULLxYr17uwoI01bNLQbtFemEgo7

“ls -l”除文件名称外,亦将文件型态、权限、拥有者、文件大小等资讯详细列出,发现有很多文件夹,”find . -type f -size 1033c”,”.”查找当前目录以及子目录,-type f指定文件类型为普通文件,-size 1033c指定文件大小为 1033 bytes

密码:DXjZPULLxYr17uwoI01bNLQbtFemEgo7

Level 6→ Level 7

用账号:bandit6,密码:DXjZPULLxYr17uwoI01bNLQbtFemEgo7进入本关

描述:下一级别的密码存储在服务器的某个位置,并具有以下所有属性:由用户bandit7拥有,由groupitit6拥有,大小为33个字节

过程:

1
2
3
4
bandit6@bandit:~$ find / -group bandit6 -user bandit7 -size 33c 2>/dev/null
/var/lib/dpkg/info/bandit7.password
bandit6@bandit:~$ cat /var/lib/dpkg/info/bandit7.password
HKBPTKQnIay4Fw76bEy8PVxKEDQRKTzs

“/“ linux 根目录,从最顶层开始查找,”2>/dev/null”中”2”表示错误输出,”>”是重定向符号表示把信息送到哪里,”/dev/null”是Linux黑洞.

密码:HKBPTKQnIay4Fw76bEy8PVxKEDQRKTzs

Level 7→ Level 8

用账号:bandit7,密码:HKBPTKQnIay4Fw76bEy8PVxKEDQRKTzs进入本关

描述:下一级的密码存储文件data.txt中, “millionth” 的下一个单词。

过程:

1
2
3
4
bandit7@bandit:~$ ls
data.txt
bandit7@bandit:~$ grep millionth data.txt
millionth cvX2JJa4CFALtqS87jk27qwqGhBM9plV

命令讲解”grep match_pattern file_name” ,在文件中搜索一个单词,命令会返回一个包含“match_pattern”的文本行

密码:cvX2JJa4CFALtqS87jk27qwqGhBM9plV

Level 8→ Level 9

用账号:bandit8,密码:cvX2JJa4CFALtqS87jk27qwqGhBM9plV进入本关

描述:下一级别的密码存储在文件data.txt中, 并且是仅出现一次的唯一文本行

过程:

1
2
3
4
bandit8@bandit:~$ ls
data.txt
bandit8@bandit:~$ sort data.txt | uniq -u
UsvVyFSfZZWbi6wgC7dAFyFuR6jQQUh

sort命令用于将文本文件内容加以排序,可针对文本文件的内容,以行为单位来排序。”uniq -u”是上下相邻两行对比得到是否为单一行。

密码:UsvVyFSfZZWbi6wgC7dAFyFuR6jQQUhR

Level 9→ Level 10

用账号:bandit9,密码:UsvVyFSfZZWbi6wgC7dAFyFuR6jQQUhR进入本关

描述:下一级别的密码存储在文件data.txt 中的少数人类可读字符串之一中,以几个’=’字符开始。

过程:

1
2
3
4
5
6
7
bandit9@bandit:~$ ls
data.txt
bandit9@bandit:~$ strings data.txt | grep ==
========== theP`
========== password
L========== isA
========== truKLdjsbJ5g7yyJ2X2R0o3a5HQJFuLk

strings是在文件中查找可打印字符串并输出长度为4个或更多的字符串,遇到换行或空字符结束,用 grep 命令筛选 含有”==”的字符串。

密码:truKLdjsbJ5g7yyJ2X2R0o3a5HQJFuLk

Level 10→ Level 11

用账号:bandit10,密码:truKLdjsbJ5g7yyJ2X2R0o3a5HQJFuLk进入本关

描述:下一级的密码存储在包含base64编码数据的文件data.txt

过程:

1
2
3
4
5
6
bandit10@bandit:~$ ls
data.txt
bandit10@bandit:~$ cat data.txt
VGhlIHBhc3N3b3JkIGlzIElGdWt3S0dzRlc4TU9xM0lSRnFyeEUxaHhUTkViVVBSCg==
bandit10@bandit:~$ base64 -d data.txt
The password is IFukwKGsFW8MOq3IRFqrxE1hxTNEbUPR

base64 编码了数据,解码就好了

密码:IFukwKGsFW8MOq3IRFqrxE1hxTNEbUPR

Level 11→ Level 12

用账号:bandit11,密码:IFukwKGsFW8MOq3IRFqrxE1hxTNEbUPR进入本关

描述:下一级的密码存储在文件data.txt中,其中所有小写(az)和大写(AZ)字母已被旋转了13个位置

过程:

1
2
3
4
5
6
bandit11@bandit:~$ ls
data.txt
bandit11@bandit:~$ cat data.txt
Gur cnffjbeq vf 5Gr8L4qetPEsPk8htqjhRK8XSP6x2RHh
bandit11@bandit:~$ cat data.txt | tr 'a-zA-Z' 'n-za-mN-ZA-M'
The password is 5Te8Y4drgCRfCx8ugdwuEX8KFC6k2EUu

tr 命令,参数为两个字符集,把第一个字符集中的字符替换为第二个字符集中的对应字符。题目中说旋转了13个位置,相当于26个字母前十三个和后十三个换了个位置。按照这样的对应关系,调整给出的字符集。

密码:5Te8Y4drgCRfCx8ugdwuEX8KFC6k2EUu

Level 12→ Level 13

用账号:bandit12,密码:5Te8Y4drgCRfCx8ugdwuEX8KFC6k2EUu进入本关

描述:下一级的密码存储在data.txt文件中,该文件是一个经过反复压缩的文件的十六进制转储文件。对于这个级别,可以在/ tmp下创建一个可以使用mkdir工作的目录。例如:mkdir / tmp / myname123。然后使用cp复制数据文件,并使用mv重命名它。

过程:

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
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
bandit12@bandit:~$ ls
data.txt
bandit12@bandit:~$ mkdir /tmp/Crayon123; cp data.txt /tmp/Crayon123/data_1; cd /tmp/Crayon123
bandit12@bandit:/tmp/Crayon123$ cat data_1 ;file data_1
00000000: 1f8b 0808 ecf2 445a 0203 6461 7461 322e ......DZ..data2.
00000010: 6269 6e00 0149 02b6 fd42 5a68 3931 4159 bin..I...BZh91AY
00000020: 2653 5930 3e1b 4000 0014 ffff dde3 2b6d &SY0>.@.......+m
00000030: afff dd1e dfd7 ffbf bdfb 3f67 bfff ffff ..........?g....
00000040: bde5 bfff aff7 bfdb e5ff ffef b001 39b0 ..............9.
00000050: 480d 3400 0068 0068 1a00 0000 01a3 4000 H.4..h.h......@.
00000060: 0001 a643 4d34 0000 d00d 0698 800d 1934 ...CM4.........4
00000070: d0c4 d034 1a36 a343 646a 1c9a 3206 9a00 ...4.6.Cdj..2...
00000080: 3406 8000 068d 064f 51a3 4000 000f 5000 4......OQ.@...P.
00000090: 6868 0034 d308 0da4 6990 1a03 4000 6869 hh.4....i...@.hi
000000a0: a0d0 00d3 2341 94d0 0006 8006 8034 1a34 ....#A.......4.4
000000b0: 00d0 d000 0310 d068 3400 001e 900d 1a19 .......h4.......
000000c0: 0062 68d3 4680 640f 48d0 d320 0068 621a .bh.F.d.H.. .hb.
000000d0: 0543 0116 180c 6232 a7d7 82c8 7bd4 2374 .C....b2....{.#t
000000e0: 1de5 e375 b7b9 0b78 2d37 bd61 5cdf 40da ...u...x-7.a\.@.
000000f0: b8e5 3258 213d e4bb ecb2 8d51 84f9 3bd0 ..2X!=.....Q..;.
00000100: b1c9 ef2a bcff 45cc 1f1c 0028 1cfe 8784 ...*..E....(....
00000110: 78a9 7611 0a81 c4d5 cb26 4b80 7888 c9bc x.v......&K.x...
00000120: 2b3e a351 59ae c1fd 36c8 286e d6c3 bb2b +>.QY...6.(n...+
00000130: b280 d19b 70b3 190a 0204 4603 9f79 e2b8 ....p.....F..y..
00000140: cf1b 8330 fcad 3780 86c2 5c3d 5bc9 4631 ...0..7...\=[.F1
00000150: 3718 5e2e a88c 34e6 8461 35ad c14f 6fd4 7.^...4..a5..Oo.
00000160: 31dd a5cc 5223 545e e01d ff23 cde3 22cc 1...R#T^...#..".
00000170: 22fa a62b e27a dfa5 d4f0 c326 28ef a4b3 "..+.z.....&(...
00000180: adc5 149c 1c27 dbc4 97b9 6342 487e bfe3 .....'....cBH~..
00000190: 02ee d63e 3379 8ebc d559 c670 7987 da1d ...>3y...Y.py...
000001a0: 4c4b 5ec4 9965 075b 9d0b 08ee df17 d07c LK^..e.[.......|
000001b0: ea9a 5fbf 43e7 d405 5239 1437 0c8a 34cd .._.C...R9.7..4.
000001c0: be6f a949 b061 68e8 6ba5 c9ba 4112 0819 .o.I.ah.k...A...
000001d0: 7cb9 a3c8 bff1 0895 1819 8f80 407e dc32 |...........@~.2
000001e0: 9269 ca68 3f58 bb30 cd9b fcd6 0006 1224 .i.h?X.0.......$
000001f0: 177b fe66 c676 01f0 a5bc 9131 6746 cc85 .{.f.v.....1gF..
00000200: 1a39 e46f 6b9a 7bd4 694b e999 c300 b57e .9.ok.{.iK.....~
00000210: 9b0a 1229 fac1 cc0c 24fb a905 a06a b8cf ...)....$....j..
00000220: cb56 2a73 6016 6950 8208 5785 af54 0d42 .V*s`.iP..W..T.B
00000230: 754e 5a48 8835 2b47 aa9b c45e 4ca8 a7a0 uNZH.5+G...^L...
00000240: 61dd e070 7717 9346 5f14 d808 8263 7746 a..pw..F_....cwF
00000250: 5100 3af8 fa20 ff8b b922 9c28 4818 1f0d Q.:.. ...".(H...
00000260: a000 e793 1e61 4902 0000 .....aI...
data_1: ASCII text
bandit12@bandit:/tmp/Crayon123$ xxd -r data_1 > data_2 ; file data_2
data_2: gzip compressed data, was "data2.bin", last modified: Thu Dec 28 13:34:36 2017, max compression, from Unix
bandit12@bandit:/tmp/Crayon123$ mv data_2 data_3.gz ;
bandit12@bandit:/tmp/Crayon123$ gzip -d data_3.gz ;
bandit12@bandit:/tmp/Crayon123$ ls
data_1 data_3
bandit12@bandit:/tmp/Crayon123$ file data_3
data_3: bzip2 compressed data, block size = 900k
bandit12@bandit:/tmp/Crayon123$ mv data_3 data_4.bz2 ; bzip2 -d data_4.bz2 ;
bandit12@bandit:/tmp/Crayon123$ ls
data_1 data_4
bandit12@bandit:/tmp/Crayon123$ file data_4
data_4: gzip compressed data, was "data4.bin", last modified: Thu Dec 28 13:34:36 2017, max compression, from Unix
bandit12@bandit:/tmp/Crayon123$ mv data_4 data_5.gz ; gzip -d data_5.gz
bandit12@bandit:/tmp/Crayon123$ ls
data_1 data_5
bandit12@bandit:/tmp/Crayon123$ file data_5
data_5: POSIX tar archive (GNU)
bandit12@bandit:/tmp/Crayon123$ mv data_5 data_6.tar ; tar -xvf data_6.tar
data5.bin
bandit12@bandit:/tmp/Crayon123$ ls
data5.bin data_1 data_6.tar
bandit12@bandit:/tmp/Crayon123$ file data5.bin
data5.bin: POSIX tar archive (GNU)
bandit12@bandit:/tmp/Crayon123$ mv data5.bin data_7.tar; tar -xvf data_7.tar
data6.bin
bandit12@bandit:/tmp/Crayon123$ file data6.bin
data6.bin: bzip2 compressed data, block size = 900k
bandit12@bandit:/tmp/Crayon123$ mv data6.bin data_8.bz2 ; bzip2 -d data_8.bz2
bandit12@bandit:/tmp/Crayon123$ ls
data_1 data_6.tar data_7.tar data_8
bandit12@bandit:/tmp/Crayon123$ file data_8
data_8: POSIX tar archive (GNU)
bandit12@bandit:/tmp/Crayon123$ mv data_8 data_9.tar ; tar -xvf data_9.tar
data8.bin
bandit12@bandit:/tmp/Crayon123$ ls
data8.bin data_1 data_6.tar data_7.tar data_9.tar
bandit12@bandit:/tmp/Crayon123$ file data8.bin
data8.bin: gzip compressed data, was "data9.bin", last modified: Thu Dec 28 13:34:36 2017, max compression, from Unix
bandit12@bandit:/tmp/Crayon123$ mv data8.bin data_10.gz ; gzip -d data_10.gz
bandit12@bandit:/tmp/Crayon123$ ls
data_1 data_10 data_6.tar data_7.tar data_9.tar
bandit12@bandit:/tmp/Crayon123$ file data_10
data_10: ASCII text
bandit12@bandit:/tmp/Crayon123$ cat data_10
The password is 8ZjyCRiBWFYkneahHwxCv3wb2a1ORpYL

其实这一题并不是很难,一步一步看解题过程就明白怎么回事了,文件最开始是16进制,用” xxd -r”将16进制文件转换为二进制文件,然后每一步都查看一次文件类型,并重命名为相应的文件类型,主要运用”bzip2 -d”,”gzip -d”,”tar -xvf”以及`这些解压方法。

密码:8ZjyCRiBWFYkneahHwxCv3wb2a1ORpYL

Level 13→ Level 14

用账号:bandit13,密码:8ZjyCRiBWFYkneahHwxCv3wb2a1ORpYL进入本关

描述:下一级的密码存储在 / etc / bandit_pass / bandit14中,只能由用户bandit14读取。对于这个级别,你不会得到下一个密码,但你得到一个私人SSH密钥,可以用来登录到下一个级别。 注意: localhost是指您正在使用的机器的主机名

过程:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
bandit13@bandit:~$ ls
sshkey.private
bandit13@bandit:~$ ssh -i sshkey.private bandit14@localhost
Could not create directory '/home/bandit13/.ssh'.
The authenticity of host 'localhost (127.0.0.1)' can't be established.
ECDSA key fingerprint is SHA256:98UL0ZWr85496EtCRkKlo20X3OPnyPSB5tB5RPbhczc.
Are you sure you want to continue connecting (yes/no)? yes
Failed to add the host to the list of known hosts (/home/bandit13/.ssh/known_hosts).
This is a OverTheWire game server. More information on http://www.overthewire.org/wargames

。。。。。。

bandit14@bandit:~$ cat /etc/bandit_pass/bandit14
4wcYUJFw0k0XLShlDzztnTBHiqxU3b3e

通过ssh命令,通过sshkey.private密钥连接进去,这里连接时不用指定端口(亲测),然后已经告诉你密码存在的位置,用cat查看

密码:4wcYUJFw0k0XLShlDzztnTBHiqxU3b3e

Level 14→ Level 15

用账号:bandit14,密码:4wcYUJFw0k0XLShlDzztnTBHiqxU3b3e进入本关

描述:可以通过将当前级别的密码提交到本地主机上的端口30000来检索下一级别的密码。

过程:

1
2
3
4
bandit14@bandit:~$ nc localhost 30000
4wcYUJFw0k0XLShlDzztnTBHiqxU3b3e
Correct!
BfMYroe26WYalil77FoDi9qh59eK5xNr

直接通过nc连接本地的30000端口,输入当前级别的密码后返回下一级密码。

密码:BfMYroe26WYalil77FoDi9qh59eK5xNr

Level 15→ Level 16

用账号:bandit15,密码:BfMYroe26WYalil77FoDi9qh59eK5xNr进入本关

描述:可以通过使用SSL加密将当前级别的密码提交到本地主机上的端口30001来检索下一级别的密码。

过程:

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
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
bandit15@bandit:~$ openssl s_client -connect localhost:30001 -ign_eof 
CONNECTED(00000003)
depth=0 CN = bandit
verify error:num=18:self signed certificate
verify return:1
depth=0 CN = bandit
verify return:1
---
Certificate chain
0 s:/CN=bandit
i:/CN=bandit
---
Server certificate
-----BEGIN CERTIFICATE-----
MIICsjCCAZqgAwIBAgIJAKZI1xYeoXFuMA0GCSqGSIb3DQEBCwUAMBExDzANBgNV
BAMMBmJhbmRpdDAeFw0xNzEyMjgxMzIzNDBaFw0yNzEyMjYxMzIzNDBaMBExDzAN
BgNVBAMMBmJhbmRpdDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAOcX
ruVcnQUBeHJeNpSYayQExCJmcHzSCktnOnF/H4efWzxvLRWt5z4gYaKvTC9ixLrb
K7a255GEaUbP/NVFpB/sn56uJc1ijz8u0hWQ3DwVe5ZrHUkNzAuvC2OeQgh2HanV
5LwB1nmRZn90PG1puKxktMjXsGY7f9Yvx1/yVnZqu2Ev2uDA0RXij/T+hEqgDMI7
y4ZFmuYD8z4b2kAUwj7RHh9LUKXKQlO+Pn8hchdR/4IK+Xc4+GFOin0XdQdUJaBD
8quOUma424ejF5aB6QCSE82MmHlLBO2tzC9yKv8L8w+fUeQFECH1WfPC56GcAq3U
IvgdjGrU/7EKN5XkONcCAwEAAaMNMAswCQYDVR0TBAIwADANBgkqhkiG9w0BAQsF
AAOCAQEAnrOty7WAOpDGhuu0V8FqPoKNwFrqGuQCTeqhQ9LP0bFNhuH34pZ0JFsH
L+Y/q4Um7+66mNJUFpMDykm51xLY2Y4oDNCzugy+fm5Q0EWKRwrq+hIM+5hs0RdC
nARP+719ddmUiXF7r7IVP2gK+xqpa8+YcYnLuoXEtpKkrrQCCUiqabltU5yRMR77
3wqB54txrB4IhwnXqpO23kTuRNrkG+JqDUkaVpvct+FAdT3PODMONP/oHII3SH9i
ar/rI9k+4hjlg4NqOoduxX9M+iLJ0Zgj6HAg3EQVn4NHsgmuTgmknbhqTU3o4IwB
XFnxdxVy0ImGYtvmnZDQCGivDok6jA==
-----END CERTIFICATE-----
subject=/CN=bandit
issuer=/CN=bandit
---
No client certificate CA names sent
---
SSL handshake has read 1015 bytes and written 631 bytes
---
New, TLSv1/SSLv3, Cipher is AES128-SHA
Server public key is 2048 bit
Secure Renegotiation IS supported
Compression: NONE
Expansion: NONE
No ALPN negotiated
SSL-Session:
Protocol : TLSv1
Cipher : AES128-SHA
Session-ID: 741E8F2AA4126571FCD3FD72409056D6C2BB4EBA4C96DAA7ECB1B923E0AA2142
Session-ID-ctx:
Master-Key: E404B34CD36A55A4AC779E1BEBBE03E160F4783C9DF59D9FE92D1E5F4287915E842262DBAF35246171BBF637330DDD6F
Key-Arg : None
PSK identity: None
PSK identity hint: None
SRP username: None
TLS session ticket lifetime hint: 7200 (seconds)
TLS session ticket:
0000 - 08 f0 15 a5 d6 6f a0 e8-06 d6 bb a4 0c 33 eb 04 .....o.......3..
0010 - bd 56 71 6b cb 4c fc f2-93 20 36 8b 57 85 3e 88 .Vqk.L... 6.W.>.
0020 - 26 35 ed d8 9d 5b 54 30-40 78 df 5d ef 0e 2b c1 &5...[T0@x.]..+.
0030 - c4 c8 55 4c 8f bf 7f 5d-4b 7c 14 6b 07 34 35 1d ..UL...]K|.k.45.
0040 - 62 8d 9d 8b 37 c6 be 1a-0c 81 59 13 68 e4 7a 4c b...7.....Y.h.zL
0050 - 20 e4 8c 1a 27 0c 0d a5-dd 5b 70 5b 27 76 e2 99 ...'....[p['v..
0060 - 58 3a dc e5 18 57 98 0b-e3 2f c3 4c c6 0f 97 2d X:...W.../.L...-
0070 - d6 7f 84 47 8b 88 17 b3-ec 27 b8 33 3e 1e 27 dd ...G.....'.3>.'.
0080 - 54 0d 24 63 18 f7 4c 5d-4e bf 06 2d 7c fb a1 a0 T.$c..L]N..-|...
0090 - f0 78 d9 33 06 5d bb a7-bb 7e ff 66 7e 4f 77 4b .x.3.]...~.f~OwK

Start Time: 1524472977
Timeout : 300 (sec)
Verify return code: 18 (self signed certificate)
---
BfMYroe26WYalil77FoDi9qh59eK5xNr
Correct!
cluFn7wTiGryunymYOu4RcffSxQluehd

closed

使用openssl命令连接成功后复制上本关的密码回车即可获得下一关的密码。

密码:cluFn7wTiGryunymYOu4RcffSxQluehd

Level 16→ Level 17

用账号:bandit16,密码:cluFn7wTiGryunymYOu4RcffSxQluehd进入本关

描述:可以通过将当前级别的密码提交给本地主机上的端口(范围在31000到32000)来检索下一级的凭证。首先找出哪些端口有一个服务器监听它们。然后找出哪些人说SSL和哪些不。只有一台服务器可以提供下一个凭证,其他人只需发送给您即可发送给它。

过程:

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
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
bandit16@bandit:~$ nmap -p 31000-32000 localhost

Starting Nmap 7.01 ( https://nmap.org ) at 2018-04-23 11:17 CEST
Nmap scan report for localhost (127.0.0.1)
Host is up (0.00019s latency).
Other addresses for localhost (not scanned): ::1
Not shown: 996 closed ports
PORT STATE SERVICE
31046/tcp open unknown
31518/tcp open unknown
31691/tcp open unknown
31790/tcp open unknown
31960/tcp open unknown

Nmap done: 1 IP address (1 host up) scanned in 0.07 seconds
bandit16@bandit:~$ echo "Hello World!" | nc localhost 31046
Hello World!
bandit16@bandit:~$ echo "Hello World!" | nc localhost 31518
bandit16@bandit:~$ echo "Hello World!" | nc localhost 31691
Hello World!
bandit16@bandit:~$ echo "Hello World!" | nc localhost 31790
bandit16@bandit:~$ echo "Hello World!" | nc localhost 31960
Hello World!
bandit16@bandit:~$ echo "Hello World" | openssl s_client -quiet -connect localhost:31518depth=0 CN = bandit
verify error:num=18:self signed certificate
verify return:1
depth=0 CN = bandit
verify return:1
Hello World
^C

bandit16@bandit:~$ openssl s_client -quiet -connect localhost:31790
depth=0 CN = bandit
verify error:num=18:self signed certificate
verify return:1
depth=0 CN = bandit
verify return:1
cluFn7wTiGryunymYOu4RcffSxQluehd
Correct!
-----BEGIN RSA PRIVATE KEY-----
MIIEogIBAAKCAQEAvmOkuifmMg6HL2YPIOjon6iWfbp7c3jx34YkYWqUH57SUdyJ
imZzeyGC0gtZPGujUSxiJSWI/oTqexh+cAMTSMlOJf7+BrJObArnxd9Y7YT2bRPQ
Ja6Lzb558YW3FZl87ORiO+rW4LCDCNd2lUvLE/GL2GWyuKN0K5iCd5TbtJzEkQTu
DSt2mcNn4rhAL+JFr56o4T6z8WWAW18BR6yGrMq7Q/kALHYW3OekePQAzL0VUYbW
JGTi65CxbCnzc/w4+mqQyvmzpWtMAzJTzAzQxNbkR2MBGySxDLrjg0LWN6sK7wNX
x0YVztz/zbIkPjfkU1jHS+9EbVNj+D1XFOJuaQIDAQABAoIBABagpxpM1aoLWfvD
KHcj10nqcoBc4oE11aFYQwik7xfW+24pRNuDE6SFthOar69jp5RlLwD1NhPx3iBl
J9nOM8OJ0VToum43UOS8YxF8WwhXriYGnc1sskbwpXOUDc9uX4+UESzH22P29ovd
d8WErY0gPxun8pbJLmxkAtWNhpMvfe0050vk9TL5wqbu9AlbssgTcCXkMQnPw9nC
YNN6DDP2lbcBrvgT9YCNL6C+ZKufD52yOQ9qOkwFTEQpjtF4uNtJom+asvlpmS8A
vLY9r60wYSvmZhNqBUrj7lyCtXMIu1kkd4w7F77k+DjHoAXyxcUp1DGL51sOmama
+TOWWgECgYEA8JtPxP0GRJ+IQkX262jM3dEIkza8ky5moIwUqYdsx0NxHgRRhORT
8c8hAuRBb2G82so8vUHk/fur85OEfc9TncnCY2crpoqsghifKLxrLgtT+qDpfZnx
SatLdt8GfQ85yA7hnWWJ2MxF3NaeSDm75Lsm+tBbAiyc9P2jGRNtMSkCgYEAypHd
HCctNi/FwjulhttFx/rHYKhLidZDFYeiE/v45bN4yFm8x7R/b0iE7KaszX+Exdvt
SghaTdcG0Knyw1bpJVyusavPzpaJMjdJ6tcFhVAbAjm7enCIvGCSx+X3l5SiWg0A
R57hJglezIiVjv3aGwHwvlZvtszK6zV6oXFAu0ECgYAbjo46T4hyP5tJi93V5HDi
Ttiek7xRVxUl+iU7rWkGAXFpMLFteQEsRr7PJ/lemmEY5eTDAFMLy9FL2m9oQWCg
R8VdwSk8r9FGLS+9aKcV5PI/WEKlwgXinB3OhYimtiG2Cg5JCqIZFHxD6MjEGOiu
L8ktHMPvodBwNsSBULpG0QKBgBAplTfC1HOnWiMGOU3KPwYWt0O6CdTkmJOmL8Ni
blh9elyZ9FsGxsgtRBXRsqXuz7wtsQAgLHxbdLq/ZJQ7YfzOKU4ZxEnabvXnvWkU
YOdjHdSOoKvDQNWu6ucyLRAWFuISeXw9a/9p7ftpxm0TSgyvmfLF2MIAEwyzRqaM
77pBAoGAMmjmIJdjp+Ez8duyn3ieo36yrttF5NSsJLAbxFpdlc1gvtGCWW+9Cq0b
dxviW8+TFVEBl1O4f7HVm6EpTscdDxU+bCXWkfjuRb7Dy9GOtt9JPsX8MBTakzh3
vBgsyi/sN3RqRBcGU40fOoZyfAMT8s1m/uYv52O6IgeuZ/ujbjY=
-----END RSA PRIVATE KEY-----

bandit16@bandit:~$ mkdir /tmp/crayonxin
bandit16@bandit:~$ cd /tmp/crayonxin
bandit16@bandit:/tmp/crayonxin$ echo "-----BEGIN RSA PRIVATE KEY-----
> MIIEogIBAAKCAQEAvmOkuifmMg6HL2YPIOjon6iWfbp7c3jx34YkYWqUH57SUdyJ
> imZzeyGC0gtZPGujUSxiJSWI/oTqexh+cAMTSMlOJf7+BrJObArnxd9Y7YT2bRPQ
> Ja6Lzb558YW3FZl87ORiO+rW4LCDCNd2lUvLE/GL2GWyuKN0K5iCd5TbtJzEkQTu
> DSt2mcNn4rhAL+JFr56o4T6z8WWAW18BR6yGrMq7Q/kALHYW3OekePQAzL0VUYbW
> JGTi65CxbCnzc/w4+mqQyvmzpWtMAzJTzAzQxNbkR2MBGySxDLrjg0LWN6sK7wNX
> x0YVztz/zbIkPjfkU1jHS+9EbVNj+D1XFOJuaQIDAQABAoIBABagpxpM1aoLWfvD
> KHcj10nqcoBc4oE11aFYQwik7xfW+24pRNuDE6SFthOar69jp5RlLwD1NhPx3iBl
> J9nOM8OJ0VToum43UOS8YxF8WwhXriYGnc1sskbwpXOUDc9uX4+UESzH22P29ovd
> d8WErY0gPxun8pbJLmxkAtWNhpMvfe0050vk9TL5wqbu9AlbssgTcCXkMQnPw9nC
> YNN6DDP2lbcBrvgT9YCNL6C+ZKufD52yOQ9qOkwFTEQpjtF4uNtJom+asvlpmS8A
> vLY9r60wYSvmZhNqBUrj7lyCtXMIu1kkd4w7F77k+DjHoAXyxcUp1DGL51sOmama
> +TOWWgECgYEA8JtPxP0GRJ+IQkX262jM3dEIkza8ky5moIwUqYdsx0NxHgRRhORT
> 8c8hAuRBb2G82so8vUHk/fur85OEfc9TncnCY2crpoqsghifKLxrLgtT+qDpfZnx
> SatLdt8GfQ85yA7hnWWJ2MxF3NaeSDm75Lsm+tBbAiyc9P2jGRNtMSkCgYEAypHd
> HCctNi/FwjulhttFx/rHYKhLidZDFYeiE/v45bN4yFm8x7R/b0iE7KaszX+Exdvt
> SghaTdcG0Knyw1bpJVyusavPzpaJMjdJ6tcFhVAbAjm7enCIvGCSx+X3l5SiWg0A
> R57hJglezIiVjv3aGwHwvlZvtszK6zV6oXFAu0ECgYAbjo46T4hyP5tJi93V5HDi
> Ttiek7xRVxUl+iU7rWkGAXFpMLFteQEsRr7PJ/lemmEY5eTDAFMLy9FL2m9oQWCg
> R8VdwSk8r9FGLS+9aKcV5PI/WEKlwgXinB3OhYimtiG2Cg5JCqIZFHxD6MjEGOiu
> L8ktHMPvodBwNsSBULpG0QKBgBAplTfC1HOnWiMGOU3KPwYWt0O6CdTkmJOmL8Ni
> blh9elyZ9FsGxsgtRBXRsqXuz7wtsQAgLHxbdLq/ZJQ7YfzOKU4ZxEnabvXnvWkU
> YOdjHdSOoKvDQNWu6ucyLRAWFuISeXw9a/9p7ftpxm0TSgyvmfLF2MIAEwyzRqaM
> 77pBAoGAMmjmIJdjp+Ez8duyn3ieo36yrttF5NSsJLAbxFpdlc1gvtGCWW+9Cq0b
> dxviW8+TFVEBl1O4f7HVm6EpTscdDxU+bCXWkfjuRb7Dy9GOtt9JPsX8MBTakzh3
> vBgsyi/sN3RqRBcGU40fOoZyfAMT8s1m/uYv52O6IgeuZ/ujbjY=
> -----END RSA PRIVATE KEY-----" > ssh.private

bandit16@bandit:/tmp/crayonxin$ chmod 600 ssh.private
bandit16@bandit:/tmp/crayonxin$ ssh -i ssh.private bandit17@localhost
Could not create directory '/home/bandit16/.ssh'.
The authenticity of host 'localhost (127.0.0.1)' can't be established.
ECDSA key fingerprint is SHA256:98UL0ZWr85496EtCRkKlo20X3OPnyPSB5tB5RPbhczc.
Are you sure you want to continue connecting (yes/no)? yes
Failed to add the host to the list of known hosts (/home/bandit16/.ssh/known_hosts).
。。。。。。

bandit17@bandit:~$ ls
passwords.new passwords.old

后来才知道密码位于/etc/bandit_pass/bandit17

密码:xLYVMN9WE5zQ5vHacb0sZEVqbrp7nBTn

Level 17→ Level 18

此题接着上一题的shell

描述:homedirectory中有2个文件:passwords.old和passwords.new。下一级别的密码位于 passwords.new中,是密码.old和passwords.new之间已更改的唯一行。

过程:

1
2
3
4
5
6
7
bandit17@bandit:~$ ls
passwords.new passwords.old
bandit17@bandit:~$ diff passwords.old passwords.new
42c42
< 6vcSC74ROI95NqkKaeEC2ABVMDX9TyUr
---
> kfBf3eYk5BPBRzwjqutbbfE887SVc5Yd

密码:kfBf3eYk5BPBRzwjqutbbfE887SVc5Yd

Level 18→ Level 19

用账号:bandit18,密码:kfBf3eYk5BPBRzwjqutbbfE887SVc5Yd进入本关

描述:下一级别的密码存储在家庭目录中的文件自述文件中。不幸的是, 当你使用SSH登录时,有人修改了.bashrc将你注销。

过程:

1
2
3
4
 Enjoy your stay!

Byebye !
Connection closing...Socket close.

刚刚连进去就断开了

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
bandit17@bandit:~$ ssh bandit18@localhost cat readme
The authenticity of host 'localhost (127.0.0.1)' can't be established.
ECDSA key fingerprint is SHA256:98UL0ZWr85496EtCRkKlo20X3OPnyPSB5tB5RPbhczc.
Are you sure you want to continue connecting (yes/no)? yes
Failed to add the host to the list of known hosts (/home/bandit17/.ssh/known_hosts).
This is a OverTheWire game server. More information on http://www.overthewire.org/wargames
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: UNPROTECTED PRIVATE KEY FILE! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0640 for '/home/bandit17/.ssh/id_rsa' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
Load key "/home/bandit17/.ssh/id_rsa": bad permissions
bandit18@localhost's password:
IueksS7Ubh8G3DCwVzrTd8rAVOwq3M5x

在进行ssh连接的时候就把参数带进去,在password: 后粘贴本关的密码后,就返回了下一关的密码。

密码:IueksS7Ubh8G3DCwVzrTd8rAVOwq3M5x

Level 19→ Level 20

用账号:bandit19,密码:IueksS7Ubh8G3DCwVzrTd8rAVOwq3M5x进入本关

描述:要访问下一级,您应该使用homeu目录中的setuid二进制文件。执行它没有参数找出如何使用它。使用setuid二进制文件后,可以在通常的地方(/ etc / bandit_pass)找到该级别的密码。

大致意思就是告诉你 Home 目录下有个文件,先不带参数执行一下,他会告诉你怎么用。

过程:

1
2
3
4
5
6
7
8
9
10
11
12
13
bandit19@bandit:~$ ls     
bandit20-do
bandit19@bandit:~$ ls -l bandit20-do
-rwsr-x--- 1 bandit20 bandit19 7408 Dec 28 14:34 bandit20-do
bandit19@bandit:~$ ./bandit20-do
Run a command as another user.
Example: ./bandit20-do id
bandit19@bandit:~$ ./bandit20-do id
uid=11019(bandit19) gid=11019(bandit19) euid=11020(bandit20) groups=11019(bandit19)
bandit19@bandit:~$ ./bandit20-do whoami
bandit20
bandit19@bandit:~$ ./bandit20-do cat /etc/bandit_pass/bandit20
GbKksEFF4yrVs6il55v6gwY5aVje5f0j

一步一步就知道这个文件的作用以及用法

密码:GbKksEFF4yrVs6il55v6gwY5aVje5f0j

Level 20→ Level 21

用账号:bandit20,密码:GbKksEFF4yrVs6il55v6gwY5aVje5f0j进入本关

描述:homedirectory中有一个setuid二进制文件,它执行以下操作:它在您指定为命令行参数的端口上连接到localhost。然后它从连接中读取一行文本,并将其与前一级别的密码(bandit20)进行比较。如果密码正确,它将传输下一级密码(bandit21)。

注意:尝试连接到您自己的网络守护程序,以查看它是否按照您的想法工作,这个程序会访问 localhost 的[你提供的端口号]来获取数据。这里我们需要处理两件事情:1.运行这个程序。2.创建一个监听事件并会回复这个程序当前关的密码。

过程:

首先使用nc 监听一个端口,并推送/etc/bandit_pass/bandit20文件内容,即bandit20的密码

1
2
3
4
5
6
bandit20@bandit:~$ ls
suconnect
bandit20@bandit:~$ ./suconnect
Usage: ./suconnect <portnumber>
This program will connect to the given port on localhost using TCP. If it receives the correct password from the other side, the next password is transmitted back.
bandit20@bandit:~$ nc -l -p 2333 < /etc/bandit_pass/bandit20

此时2333端口处于监听状态,再建立一个ssh连接

1
2
3
4
5
bandit20@bandit:~$ ls
suconnect
bandit20@bandit:~$ ./suconnect 2333
Read: GbKksEFF4yrVs6il55v6gwY5aVje5f0j
Password matches, sending next password

成功读取到文件以后,就把下一关的密码发送到监听端口

1
2
3
4
5
6
7
bandit20@bandit:~$ ls
suconnect
bandit20@bandit:~$ ./suconnect
Usage: ./suconnect <portnumber>
This program will connect to the given port on localhost using TCP. If it receives the correct password from the other side, the next password is transmitted back.
bandit20@bandit:~$ nc -l -p 2333 < /etc/bandit_pass/bandit20
gE269g2h3mw3pwgrj0Ha9Uoqen1c9DGr

成功获得密码 。

密码:gE269g2h3mw3pwgrj0Ha9Uoqen1c9DGr

Level 21→ Level 22

用账号:bandit21,密码:gE269g2h3mw3pwgrj0Ha9Uoqen1c9DGr进入本关

描述:一个程序从cron(基于时间的作业调度程序)定期自动运行 。查看/etc/cron.d/中的配置并查看正在执行的命令。

过程:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
bandit21@bandit:~$ cd /etc/cron.d/
bandit21@bandit:/etc/cron.d$ ls -al
total 28
drwxr-xr-x 2 root root 4096 Dec 28 14:34 .
drwxr-xr-x 100 root root 4096 Mar 12 09:51 ..
-rw-r--r-- 1 root root 102 Apr 5 2016 .placeholder
-rw-r--r-- 1 root root 120 Dec 28 14:34 cronjob_bandit22
-rw-r--r-- 1 root root 122 Dec 28 14:34 cronjob_bandit23
-rw-r--r-- 1 root root 120 Dec 28 14:34 cronjob_bandit24
-rw-r--r-- 1 root root 190 Oct 31 13:21 popularity-contest
bandit21@bandit:/etc/cron.d$ cat cronjob_bandit22
@reboot bandit22 /usr/bin/cronjob_bandit22.sh &> /dev/null
* * * * * bandit22 /usr/bin/cronjob_bandit22.sh &> /dev/null
bandit21@bandit:/etc/cron.d$ cat /usr/bin/cronjob_bandit22.sh
#!/bin/bash
chmod 644 /tmp/t7O6lds9S0RqQh9aMcz6ShpAoZKF7fgv
cat /etc/bandit_pass/bandit22 > /tmp/t7O6lds9S0RqQh9aMcz6ShpAoZKF7fgv
bandit21@bandit:/etc/cron.d$ cat /tmp/t7O6lds9S0RqQh9aMcz6ShpAoZKF7fgv
Yk7owGAcWjwMVRwrTesJEwB7WVOiILLI

cron指Linux系统下一个自动执行指定任务的程序(计划任务),” bandit22 /usr/bin/cronjob_bandit22.sh &> /dev/null” 中的”“表示每分钟执行一次这个脚本,再用cat查询该脚本的内容,不停把/etc/bandit_pass/bandit22文件内容(即下一关的密码)写入/tmp/t7O6lds9S0RqQh9aMcz6ShpAoZKF7fgv,并且更改了权限。

密码:Yk7owGAcWjwMVRwrTesJEwB7WVOiILLI

Level 22→ Level 23

用账号:bandit22,密码:Yk7owGAcWjwMVRwrTesJEwB7WVOiILLI进入本关

描述:一个程序从cron(基于时间的作业调度程序)定期自动运行 。查看/etc/cron.d/中的配置并查看正在执行的命令。

注意:查看其他人编写的shell脚本是非常有用的技巧。这个级别的脚本有意使其易于阅读。如果您在理解它的功能时遇到问题,请尝试执行它以查看它打印的调试信息。

过程:

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
bandit22@bandit:~$ cd /etc/cron.d
bandit22@bandit:/etc/cron.d$ ls -al
total 28
drwxr-xr-x 2 root root 4096 Dec 28 14:34 .
drwxr-xr-x 100 root root 4096 Mar 12 09:51 ..
-rw-r--r-- 1 root root 102 Apr 5 2016 .placeholder
-rw-r--r-- 1 root root 120 Dec 28 14:34 cronjob_bandit22
-rw-r--r-- 1 root root 122 Dec 28 14:34 cronjob_bandit23
-rw-r--r-- 1 root root 120 Dec 28 14:34 cronjob_bandit24
-rw-r--r-- 1 root root 190 Oct 31 13:21 popularity-contest
bandit22@bandit:/etc/cron.d$ cat -n cronjob_bandit23
1 @reboot bandit23 /usr/bin/cronjob_bandit23.sh &> /dev/null
2 * * * * * bandit23 /usr/bin/cronjob_bandit23.sh &> /dev/null
bandit22@bandit:/etc/cron.d$ cat /usr/bin/cronjob_bandit23.sh

# !/bin/bash

myname=$(whoami)
mytarget=$(echo I am user $myname | md5sum | cut -d ' ' -f 1)

echo "Copying passwordfile /etc/bandit_pass/$myname to /tmp/$mytarget"

cat /etc/bandit_pass/$myname > /tmp/$mytarget
bandit22@bandit:/etc/cron.d$ echo I am user bandit23 | md5sum | cut -d ' ' -f 1
8ca319486bfbbc3663ea0fbe81326349
bandit22@bandit:/etc/cron.d$ cat /tmp/8ca319486bfbbc3663ea0fbe81326349
jc1udXuA1tiHqjIsL8yaapX5XIAI6i0n

直接赋值执行。

密码:jc1udXuA1tiHqjIsL8yaapX5XIAI6i0n

Level 23→ Level 24

用账号:bandit23,密码:jc1udXuA1tiHqjIsL8yaapX5XIAI6i0n进入本关

描述:一个程序从cron(基于时间的作业调度程序)定期自动运行 。查看/etc/cron.d/中的配置并查看正在执行的命令。

注意:此级别要求您创建自己的第一个shell脚本。这是非常大的一步,当你击败这个级别时,你应该为自己感到自豪!

注2:请记住,你的shell脚本一旦被执行就被删除,所以你可能想保留一份副本……

过程:

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
35
36
37
38
39
40
41
42
43
44
45
46
47
bandit23@bandit:~$ cd /etc/cron.d
bandit23@bandit:/etc/cron.d$ ls
cronjob_bandit22 cronjob_bandit23 cronjob_bandit24 popularity-contest
bandit23@bandit:/etc/cron.d$ cat cronjob_bandit24
@reboot bandit24 /usr/bin/cronjob_bandit24.sh &> /dev/null
* * * * * bandit24 /usr/bin/cronjob_bandit24.sh &> /dev/null
bandit23@bandit:/etc/cron.d$ cat /usr/bin/cronjob_bandit24.sh
#!/bin/bash

myname=$(whoami)

cd /var/spool/$myname
echo "Executing and deleting all scripts in /var/spool/$myname:"
for i in * .*;
do
if [ "$i" != "." -a "$i" != ".." ];
then
echo "Handling $i"
timeout -s 9 60 ./$i
rm -f ./$i
fi
done

bandit23@bandit:/etc/cron.d$ mkdir /tmp/crayon
bandit23@bandit:/etc/cron.d$ cd /tmp/crayon
bandit23@bandit:/tmp/crayon$ vim bandit24.sh
bandit23@bandit:/tmp/crayon$ cat bandit24.sh
#!/bin/bash
cat /etc/bandit_pass/bandit24 >> /tmp/crayon/level24
bandit23@bandit:/tmp/crayon$ chmod 777 bandit24.sh
bandit23@bandit:/tmp/crayon$ cp bandit24.sh /var/spool/bandit24/
bandit23@bandit:/tmp/crayon$ chmod 777 /tmp/crayon
bandit23@bandit:/tmp/crayon$ ls /var/spool/bandit24/
ls: cannot open directory '/var/spool/bandit24/': Permission denied
bandit23@bandit:/tmp/crayon$ ls
bandit24.sh
bandit23@bandit:/tmp/crayon$ ls
bandit24.sh
bandit23@bandit:/tmp/crayon$ ls
bandit24.sh
bandit23@bandit:/tmp/crayon$ ls
bandit24.sh
# 等一会儿就有了
bandit23@bandit:/tmp/crayon$ ls
bandit24.sh level24
bandit23@bandit:/tmp/crayon$ cat level24
UoMYTrfrBFHyQXmg6gzctqAwOmw1IohZ

在/tmp/文件夹中创建一个目录。创建一个shell脚本将/etc/bandit_pass /bandit24复制到我们的/tmp/文件夹。将shell脚本复制到/var/spool/bandit24/。给shell脚本和/tmp/文件夹适当的权限。/usr/bin/cronjob_bandit24.sh这个shell的作用就是执行 /var/spool/bandit24 的脚本,60s 如果还没之行结束会强制kill掉,然后删除。所以我们写了一个把 /etc/bandit_pass/bandit24/ 输出到 /tmp/crayon的脚本到这个目录下,然后付了个权限。

密码:UoMYTrfrBFHyQXmg6gzctqAwOmw1IohZ

Level 24→ Level 25

用账号:bandit24,密码:UoMYTrfrBFHyQXmg6gzctqAwOmw1IohZ进入本关

描述:守护进程正在端口30002上侦听,并且如果给出bandit24的密码和一个秘密的数字4位pincode,它会给你bandit25的密码。没有办法检索pincode,除非通过所有10000个组合,称为暴力。

过程:

1
2
3
4
bandit24@bandit:~$ nc localhost 30002
I am the pincode checker for user bandit25. Please enter the password for user bandit24 and the secret pincode on a single line, separated by a space.
UoMYTrfrBFHyQXmg6gzctqAwOmw1IohZ 1234
Wrong! Please enter the correct pincode. Try again.

大概就是要写一个脚本了,10000种组合

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
bandit24@bandit:~$ clear
bandit24@bandit:~$ cd /tmp/crayon
bandit24@bandit:/tmp/crayon$ vim data.py
bandit24@bandit:/tmp/crayon$ cat data.py

# !/usr/bin/env python

f = open('crayon.txt','w')
passwd = "UoMYTrfrBFHyQXmg6gzctqAwOmw1IohZ"
for id in range(10000):
data =passwd + " " + str(id).zfill(4) + '\n'
f.write(data)
f.close()

bandit24@bandit:/tmp/crayon$ python data.py
bandit24@bandit:/tmp/crayon$ ls
bandit24.sh crayon.txt data.py level24
bandit24@bandit:/tmp/crayon$

生成一个名为crayon.txt的字典

1
2
3
UoMYTrfrBFHyQXmg6gzctqAwOmw1IohZ 0001
。。。。。。
UoMYTrfrBFHyQXmg6gzctqAwOmw1IohZ 9999
1
2
3
4
5
6
7
8
bandit24@bandit:/tmp/crayon$ nc localhost 30002 < /tmp/crayon/crayon.txt > /tmp/crayon/password.txt
bandit24@bandit:/tmp/crayon$ sort /tmp/crayon/password.txt | uniq -u

Correct!
Exiting.
I am the pincode checker for user bandit25. Please enter the password for user bandit24 and the secret pincode on a single line, separated by a space.
The password of user bandit25 is uNG9O58gUE7snukf3bvZ0rxhtnjzSGzG
bandit24@bandit:/tmp/crayon$

密码:uNG9O58gUE7snukf3bvZ0rxhtnjzSGzG

Level 25→ Level 26

用账号:bandit25,密码:uNG9O58gUE7snukf3bvZ0rxhtnjzSGzG进入本关

描述:从bandit25登录bandit26应该相当简单…用户bandit26的shell不是/ bin / bash,而是别的。了解它是什么,它是如何工作的以及如何摆脱它。

过程:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
bandit25@bandit:~$ ls
bandit26.sshkey
bandit25@bandit:~$ ssh bandit26@localhost -i bandit26.sshkey
Could not create directory '/home/bandit25/.ssh'.
The authenticity of host 'localhost (127.0.0.1)' can't be established.
ECDSA key fingerprint is SHA256:98UL0ZWr85496EtCRkKlo20X3OPnyPSB5tB5RPbhczc.
Are you sure you want to continue connecting (yes/no)? yes
。。。。。。
。。。。。。
_ _ _ _ ___ __
| | | (_) | |__ \ / /
| |__ __ _ _ __ __| |_| |_ ) / /_
| '_ \ / _` | '_ \ / _` | | __| / / '_ \
| |_) | (_| | | | | (_| | | |_ / /| (_) |
|_.__/ \__,_|_| |_|\__,_|_|\__|____\___/
Connection to localhost closed.
bandit25@bandit:~$

刚连上去就被关闭了。

1
2
3
4
5
6
7
8
9
10
bandit25@bandit:~$ cat /etc/passwd | grep bandit26
bandit26:x:11026:11026:bandit level 26:/home/bandit26:/usr/bin/showtext
bandit25@bandit:~$ cat /usr/bin/showtext

# !/bin/sh

export TERM=linux

more ~/text.txt
exit 0

more 命令是一次显示一屏文字,然后左下角会显示一个 more 和当前显示了百分之多少, 之前在其他登陆中不曾见过,想必就是 more 命令显示的 text.txt 的内容,因为行数足以一屏显示完,所以没有显示 more 就没有显示,我们的思路就在 more 的这个特点上。我们要让他卡在一屏读不完的位置,也就是让你的终端高度读不下6行(字符画高度), 这样我们可以在 more 的状态下通过一些特性执行命令找到我们下一关的密码

先把窗口缩到足够小,然后通过密钥连接

WGB1

WGB2

看到More后按V进入编辑模式

WGB3

然后使用命令 :ex! /etc/bandit_pass/bandit26 打开我们需要的密码文件

WGB4

WGB5

只想说长知识了,没想到还能这么玩

密码:5czgV9L3Xx8JPOyRbXh6lQbmIOWvPT6Z

Level 26 → Level 27

27级还不存在

gameover。。。。。。

有问题请留言