Ở đây khi ls ta thấy có một file tên là "-". Điều này làm cho khi ta chạy lệnh cat - bình thường sẽ không được vì dấu - thường dùng để xác định option.
Ở đây, mình có thể sử dụng "--" để chỉ định rằng các tham số sau đó không phải là tùy chọn. Nó sẽ hoạt động khi file có dạng "-abcxyz". Còn ở đây, mình sẽ dùng như sau:
Các bạn có thể cat từng file để kiếm password, hoặc sử dụng cat -- -file0* để cat tất cả các file. Tuy nhiên có vẻ hơi rối.
Dựa vào việc file chứa password sẽ là các kí tự human-readable, mình chỉ cần tìm ra file chứa ASCII. Ở đây, mình có thể sử dụng lệnh file để thực hiện
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
Nhận thấy file "-file07" là ASCII text, mình cat và lấy được password
Ở đây thì bài này chỉ có mỗi 1 file 1033 bytes nên mình không cần dựa vào các tiêu chí khác nữa. Tuy nhiên, nếu có nhiều file hiện ra thì mình sẽ làm như sau.
Thêm human-readable:
bandit5@bandit:~/inhere$ find . -size 1033c -exec file {} \; | grep "ASCII text"
./maybehere07/.file2: ASCII text, with very long lines (1000)
Note: "{}" sẽ được thay thế bằng tên từng file tìm bởi lệnh find, "\;"" đánh dấu kết thúc của mệnh đề -exec
Thêm not executable
bandit5@bandit:~/inhere$ find . -size 1033c -exec file {} \; ! -executable | grep "ASCII text"
./maybehere07/.file2: ASCII text, with very long lines (1000)
Các thông số trên có thể được xem thông qua lệnh ls -l. Ví dụ:
bandit6@bandit:/home$ ls -l
total 272
drwxr-xr-x 2 root root 4096 Oct 5 06:19 bandit0
Ở đây, root thứ nhất là user, root thứ hai là group, 4096 bytes là size.
Để tìm file có các tiêu chí trên, các bạn có thể dùng find kết hợp exec ls -l, tuy nhiên trong find đã có sẵn các tùy chọn về user và group nên mình sẽ dùng luôn
Ở đây, mình sẽ sử dụng grep để tìm các dấu "=" liền nhau, và sử dụng strings thay vì cat vì grep không dùng được nếu stdin có chứa dữ liệu không phải ASCII.
Đây có thể được gen ra bằng xxd. Mình sẽ sử dụng xxd -r để biến nó về dạng ban đầu.
bandit12@bandit:/tmp/trungpq$ xxd -r data.txt > data
bandit12@bandit:/tmp/trungpq$ file data
data: gzip compressed data, was "data2.bin", last modified: Thu Oct 5 06:19:20 2023, max compression, from Unix, original size modulo 2^32 573
Sau khi phục hồi, mình thu được một file gzip. Để giải nén, mình sử dụng lệnh gzip -d. Để làm được thì mình phải thêm đuôi .gz đã
bandit12@bandit:/tmp/trungpq$ mv data data.gz
bandit12@bandit:/tmp/trungpq$ gzip -d data.gz
bandit12@bandit:/tmp/trungpq$ ls
data
bandit12@bandit:/tmp/trungpq$ file data
data: bzip2 compressed data, block size = 900k
Sau khi giải nén mình thu được 1 file bzip2. Sử dụng bzip2 -d để giải nén
bandit12@bandit:/tmp/trungpq$ mv data data.bz2
bandit12@bandit:/tmp/trungpq$ bzip2 -d data.bz2
bandit12@bandit:/tmp/trungpq$ ls
data
bandit12@bandit:/tmp/trungpq$ file data
data: gzip compressed data, was "data4.bin", last modified: Thu Oct 5 06:19:20 2023, max compression, from Unix, original size modulo 2^32 20480
Tiếp tục thu được một file gzip. Làm tương tự
bandit12@bandit:/tmp/trungpq$ mv data data.gz
bandit12@bandit:/tmp/trungpq$ gzip -d data.gz
bandit12@bandit:/tmp/trungpq$ ls
data
bandit12@bandit:/tmp/trungpq$ file data
data: POSIX tar archive (GNU)
Lần này thì thu được một file tar. Sử dụng tar -xvf để giải nén nó:
bandit12@bandit:/tmp/trungpq$ mv data data.tar
bandit12@bandit:/tmp/trungpq$ tar -xvf data.tar
data5.bin
bandit12@bandit:/tmp/trungpq$ file data5.bin
data5.bin: POSIX tar archive (GNU)
Lặp lại quá trình trên vài lần, ta sẽ ra được password
bandit12@bandit:/tmp/trungpq$ tar -xvf data5.bin
data6.bin
bandit12@bandit:/tmp/trungpq$ file data6.bin
data6.bin: bzip2 compressed data, block size = 900k
bandit12@bandit:/tmp/trungpq$ tar -xvf data6.bin
data8.bin
bandit12@bandit:/tmp/trungpq$ file data8.bin
data8.bin: gzip compressed data, was "data9.bin", last modified: Thu Oct 5 06:19:20 2023, max compression, from Unix, original size modulo 2^32 49
bandit12@bandit:/tmp/trungpq$ mv data8.bin data8.gz
bandit12@bandit:/tmp/trungpq$ gzip -d data8.gz
bandit12@bandit:/tmp/trungpq$ ls
data5.bin data6.bin data8 data.tar
bandit12@bandit:/tmp/trungpq$ cat data8
The password is wbWdlBxEir4CaE8LaPhauuOo6pwRmrDw
bandit16@bandit:~$ nmap -sV -p 31000-32000 localhost
Starting Nmap 7.80 ( https://nmap.org ) at 2023-12-04 04:22 UTC
Nmap scan report for localhost (127.0.0.1)
Host is up (0.00010s latency).
Not shown: 996 closed ports
PORT STATE SERVICE VERSION
31046/tcp open echo
31518/tcp open ssl/echo
31691/tcp open echo
31790/tcp open ssl/unknown
31960/tcp open echo
1 service unrecognized despite returning data. If you know the service/version, please submit the following fingerprint at https://nmap.org/cgi-bin/submit.cgi?new-service :
SF-Port31790-TCP:V=7.80%T=SSL%I=7%D=12/4%Time=656D5423%P=x86_64-pc-linux-g
SF:nu%r(GenericLines,31,"Wrong!\x20Please\x20enter\x20the\x20correct\x20cu
SF:rrent\x20password\n")%r(GetRequest,31,"Wrong!\x20Please\x20enter\x20the
SF:\x20correct\x20current\x20password\n")%r(HTTPOptions,31,"Wrong!\x20Plea
SF:se\x20enter\x20the\x20correct\x20current\x20password\n")%r(RTSPRequest,
SF:31,"Wrong!\x20Please\x20enter\x20the\x20correct\x20current\x20password\
SF:n")%r(Help,31,"Wrong!\x20Please\x20enter\x20the\x20correct\x20current\x
SF:20password\n")%r(SSLSessionReq,31,"Wrong!\x20Please\x20enter\x20the\x20
SF:correct\x20current\x20password\n")%r(TerminalServerCookie,31,"Wrong!\x2
SF:0Please\x20enter\x20the\x20correct\x20current\x20password\n")%r(TLSSess
SF:ionReq,31,"Wrong!\x20Please\x20enter\x20the\x20correct\x20current\x20pa
SF:ssword\n")%r(Kerberos,31,"Wrong!\x20Please\x20enter\x20the\x20correct\x
SF:20current\x20password\n")%r(FourOhFourRequest,31,"Wrong!\x20Please\x20e
SF:nter\x20the\x20correct\x20current\x20password\n")%r(LPDString,31,"Wrong
SF:!\x20Please\x20enter\x20the\x20correct\x20current\x20password\n")%r(LDA
SF:PSearchReq,31,"Wrong!\x20Please\x20enter\x20the\x20correct\x20current\x
SF:20password\n")%r(SIPOptions,31,"Wrong!\x20Please\x20enter\x20the\x20cor
SF:rect\x20current\x20password\n");
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 98.34 seconds
Dựa vào kết quả nmap có thể nhận ra port mình cần là 31790. Kết nôi tới, mình ra được private ssh key của level tiếp theo
bandit16@bandit:~$ openssl s_client -connect localhost:31790
CONNECTED(00000003)
Can't use SSL_get_servername
depth=0 CN = localhost
verify error:num=18:self-signed certificate
verify return:1
depth=0 CN = localhost
verify error:num=10:certificate has expired
notAfter=Dec 3 06:50:34 2023 GMT
verify return:1
depth=0 CN = localhost
notAfter=Dec 3 06:50:34 2023 GMT
verify return:1
---
Certificate chain
0 s:CN = localhost
i:CN = localhost
a:PKEY: rsaEncryption, 2048 (bit); sigalg: RSA-SHA1
v:NotBefore: Dec 3 06:49:34 2023 GMT; NotAfter: Dec 3 06:50:34 2023 GMT
---
Server certificate
-----BEGIN CERTIFICATE-----
MIIDCzCCAfOgAwIBAgIEMeSI+jANBgkqhkiG9w0BAQUFADAUMRIwEAYDVQQDDAls
b2NhbGhvc3QwHhcNMjMxMjAzMDY0OTM0WhcNMjMxMjAzMDY1MDM0WjAUMRIwEAYD
VQQDDAlsb2NhbGhvc3QwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC9
4osQqA7RK75mD9eFboi2lArOz/JWq4YskGwdTqPtDl/BOYRaxHziLSY1jv0e1/j9
5e7BVeF8ds1ycGA+YFMXD/BTtZpprTqS+79bN1T+zbHOVoH4NvwG4q6lSzvM4CNW
eRko6lkoPtpKN4y7Ft8oMA6DVR06ld9C2BrEv9+UF9MAdRt5xvYXydk5GAJEdcyy
XnLD7dt+2PZJs2NLrPlVJnt3BBDPd4JSsTD6lm2cFF410xxLhqbmGvpcblG3HSRe
NxwBYdYx6Y2b2n7xNkwmTkMcwr49TTkvBBALWC6iJYQIS8LMLxq6C04/txr/ZkBZ
OpjLlfpKSkAv+NiFKP2/AgMBAAGjZTBjMBQGA1UdEQQNMAuCCWxvY2FsaG9zdDBL
BglghkgBhvhCAQ0EPhY8QXV0b21hdGljYWxseSBnZW5lcmF0ZWQgYnkgTmNhdC4g
U2VlIGh0dHBzOi8vbm1hcC5vcmcvbmNhdC8uMA0GCSqGSIb3DQEBBQUAA4IBAQBZ
WQzYWksvvHPwQfNclAgFNteiBQkrCqEcijkCv91Neabf/Z/y2WsZUre2IKX3tHm/
ghNsuS+PoS8safuR7quE8+jRjKvGh6aqtW9eCPkHUBc9Y9s/9+b+YJniNlHwashu
PmwqWGCrH7I4IsxkTgO3ZvP136tkkrdnCWlEhuqShpyWrp3ATYUSZS7Jv/NNc83R
5pYcfGtJIoE4PDc1yS0qfVVkgM///EAvY4UFBo/lQ1GMGe0qv5ZlJX9qCMpLKms9
5JkBFHPbxey0ZI1yP0LcDQqnpAZkacwRBr3Hrloo6uLkSzOPiBUN3/eoERiUx+7s
X6jUzug8v7AVfli/Jdkh
-----END CERTIFICATE-----
subject=CN = localhost
issuer=CN = localhost
---
No client certificate CA names sent
Peer signing digest: SHA256
Peer signature type: RSA-PSS
Server Temp Key: X25519, 253 bits
---
SSL handshake has read 1339 bytes and written 373 bytes
Verification error: certificate has expired
---
New, TLSv1.3, Cipher is TLS_AES_256_GCM_SHA384
Server public key is 2048 bit
Secure Renegotiation IS NOT supported
Compression: NONE
Expansion: NONE
No ALPN negotiated
Early data was not sent
Verify return code: 10 (certificate has expired)
---
---
Post-Handshake New Session Ticket arrived:
SSL-Session:
Protocol : TLSv1.3
Cipher : TLS_AES_256_GCM_SHA384
Session-ID: 056B81B396EE5171A2E5C48F222DE5E81EDEB4D87B9838BF0BC134F5FA9A749E
Session-ID-ctx:
Resumption PSK: 0528B3D8C9F1F6D2A934CEA0182E23BF4881D1F84D19F9D4A9F9B1DEA368F35F2A0640F5DFB2E913B6B8EF338F93565F
PSK identity: None
PSK identity hint: None
SRP username: None
TLS session ticket lifetime hint: 7200 (seconds)
TLS session ticket:
0000 - 50 21 ee 56 fb ef ef f3-18 f4 81 7b 6c cc d6 45 P!.V.......{l..E
0010 - 67 b1 0e 5e 30 c4 9a 68-d8 04 aa 94 62 f0 35 4a g..^0..h....b.5J
0020 - ab d4 ab ad ca e6 b8 88-f5 3e 00 52 a3 af ca 4a .........>.R...J
0030 - b2 e0 aa 34 32 ae 91 2f-ef d0 f8 9e 02 d2 9d 50 ...42../.......P
0040 - b9 c6 e0 0e ce c8 fb 62-a2 d2 8c e7 45 5b 4f 20 .......b....E[O
0050 - 49 aa 02 b7 a9 27 16 5d-2d df b4 d1 a1 5b a9 b7 I....'.]-....[..
0060 - fb 95 ef a9 40 69 8c f3-ce 76 0f 8e 83 ab 12 61 ....@i...v.....a
0070 - 30 88 dc 2e b3 49 a7 4c-63 64 3f 73 b2 a6 a3 78 0....I.Lcd?s...x
0080 - b1 80 50 71 a4 eb 21 f6-ca 10 3b 9b 3e 26 59 5c ..Pq..!...;.>&Y\
0090 - 34 22 27 2b e5 ba 3b 62-ce 13 11 b7 27 4e cf bb 4"'+..;b....'N..
00a0 - c5 29 3b 19 d4 a4 d9 4c-8a e6 f1 bc 15 ae 5c 84 .);....L......\.
00b0 - 9b 06 4c 12 4d 9d 68 b1-04 74 9e a9 ff c3 47 0c ..L.M.h..t....G.
00c0 - 69 9d 3c 7b 0a 86 bd d1-14 20 6b ce a2 62 7e f1 i.<{..... k..b~.
Start Time: 1701663430
Timeout : 7200 (sec)
Verify return code: 10 (certificate has expired)
Extended master secret: no
Max Early Data: 0
---
read R BLOCK
---
Post-Handshake New Session Ticket arrived:
SSL-Session:
Protocol : TLSv1.3
Cipher : TLS_AES_256_GCM_SHA384
Session-ID: 00A184027879E6EB9311FE56AB32D9D929B9D7FCA87D11BE95E4873CE517FB40
Session-ID-ctx:
Resumption PSK: 0B6A40FA38CC08F3DB5C2F96D79818CC9F7E553A611B314336844D726665BAECE061BD310340F43F4DE86E51470350B5
PSK identity: None
PSK identity hint: None
SRP username: None
TLS session ticket lifetime hint: 7200 (seconds)
TLS session ticket:
0000 - 50 21 ee 56 fb ef ef f3-18 f4 81 7b 6c cc d6 45 P!.V.......{l..E
0010 - 86 80 f8 a3 70 bf 75 33-eb e2 4b ac d8 b0 eb b8 ....p.u3..K.....
0020 - 44 3a d3 76 82 57 ab 3d-b8 5f 2e 9e 05 3c bb 63 D:.v.W.=._...<.c
0030 - 1a 45 af fe 0a 89 98 19-6b de ee eb 23 a9 4d f1 .E......k...#.M.
0040 - e2 a6 d4 69 11 28 35 57-de 39 19 80 f0 ac 22 ed ...i.(5W.9....".
0050 - f0 f4 2a ec d9 ad e9 5e-78 7f a0 8b 64 29 ce 0a ..*....^x...d)..
0060 - cf 7d 15 3a 0d 67 f9 ae-cc 2d 82 7b 66 7a 3d 4d .}.:.g...-.{fz=M
0070 - 29 c9 0a d6 f8 83 7d 3c-17 de b5 33 f2 2f 8d 1c ).....}<...3./..
0080 - eb ee 98 19 62 08 6e 20-79 d1 a1 65 be d1 a5 45 ....b.n y..e...E
0090 - f2 64 23 bc b0 06 43 df-e5 06 15 66 2e bc 7c a5 .d#...C....f..|.
00a0 - ed 41 9c 7c 87 87 d7 ac-a0 7a 7d d0 2e ea c3 c9 .A.|.....z}.....
00b0 - 0f e3 84 41 13 27 32 b8-92 a6 5c c0 a8 97 52 b1 ...A.'2...\...R.
00c0 - c8 31 9b 1d f2 1a 0f 93-c2 19 93 31 d5 87 65 f1 .1.........1..e.
Start Time: 1701663430
Timeout : 7200 (sec)
Verify return code: 10 (certificate has expired)
Extended master secret: no
Max Early Data: 0
---
read R BLOCK
JQttfApK4SeyHwDlI9SXGR50qclOAil1
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-----
closed
Do thư mục hiện tại không được phép ghi gì nên mình sẽ lưu private key này vào tmp và ssh tới level tiếp theo
bandit16@bandit:~$ vi /tmp/key.private
bandit16@bandit:~$ ssh -i /tmp/key.private bandit17@localhost
...
Permissions 0664 for '/tmp/key.private' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
Load key "/tmp/key.private": bad permissions
Lúc này sẽ xảy ra lỗi như vậy. Mình thử chmod 400 cho key.private và ssh thành công
Ở challenge này, khi ta ssh tới sẽ bị log out ra. Đề bài nói do file .bashrc đã được sửa đổi (.bashrc là tệp cấu hình cho môi trường dòng lệnh Bash của một người dùng trên hệ thống Linux hoặc Unix)
Để giải quyết vấn đề, ta có thể không sử dụng bash để ssh tới mà sử dụng một shell khác với tham số -t khi ssh. ssh bandit18@bandit.labs.overthewire.org -p 2220 -t "/bin/sh"
Này là minh họa cho setuid. Trong linux, nó cho phép một tệp thực thi chạy với quyền của người sở hữu (owner) của tệp thay vì với quyền của người dùng thực hiện tệp. Khi ls -l sẽ thấy có chữ "s"
File bandit20-do sẽ giúp chúng ta thực thi lệnh dưới quyền bandit20. Lấy password bằng cách sau:
File "suconnect" sẽ kết nối tới cổng người dùng nhập và lấy dữ liệu trả về. Nếu trùng với password của level trước thì sẽ trả về password của level sau
Vậy ta có thể tạo 1 server mà khi kết nối tới sẽ trả về password cũ. Các bạn có thể viết code hoặc sử dụng netcat như sau:
Tương tự level trước, ở đây mình có nội dung file "cronjob_bandit23.sh" như sau
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
Có thể thấy pass đc lưu vào file "/tmp/$mytarget" với mytarget=$(echo I am user $myname | md5sum | cut -d ' ' -f 1). Chúng ta hoàn toàn có thể tính được giá trị mytarget vì đã biết $myname là bandit23 bằng cách nhập vào terminal:
bandit22@bandit:/etc/cron.d$ echo I am user bandit23 | md5sum | cut -d ' ' -f 1
8ca319486bfbbc3663ea0fbe81326349
Cũng tương tự, đây là nội dung file "cronjob_bandit24.sh"
bandit23@bandit:/etc/cron.d$ cat /usr/bin/cronjob_bandit24.sh
#!/bin/bash
myname=$(whoami)
cd /var/spool/$myname/foo
echo "Executing and deleting all scripts in /var/spool/$myname/foo:"
for i in * .*;
do
if [ "$i" != "." -a "$i" != ".." ];
then
echo "Handling $i"
owner="$(stat --format "%U" ./$i)"
if [ "${owner}" = "bandit23" ]; then
timeout -s 9 60 ./$i
fi
rm -f ./$i
fi
done
Script này đơn thuần là kiểm tra tất cả các file trong /var/spool/bandit24/foo và xóa các file có owner là bandit23. Tuy nhiên, trước khi xóa, nó lại thực thi file đó. Vì vậy, ta có thể viết script để lấy pass của bandit24.
Đề bài yêu cầu kết nối tới cổng 30002. Chương trình sẽ bắt chúng ta nhập vào pass của bandit24 và 1 pincode gồm 4 chữ số. Ta có thể viết bashscript để thực hiện gen ra payload như sau
#!/bin/bash
for i in {0000..9999}
do
echo "VAfGXJ1PBSsPSnvsjI8p759leLZ9GGar $i"
done
Sau đó ta chạy lệnh:
bandit24@bandit:/tmp$ ./pass.sh | nc localhost 30002 | grep -v "Wrong"
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.
Correct!
The password of user bandit25 is p7TaowMYrmu23Ol8hiZh9UvD0O9hpx8d
Exiting.
Các bạn có thể viết code python pwntools nhưng nó sẽ rất lâu
Ta thấy nó thực hiện lệnh more để đọc file text.txt, khi đọc xong sẽ exit luôn. Điều thú vị ở lệnh more là nếu màn hình không đủ lớn để đọc hết 1 đoạn text thì nó sẽ cho mình hiển thị dần chứ không như lệnh cat. Trong lúc như vậy, ta có thể gọi ra shell để lấy được password.
Vậy đầu tiên là ta phải thu nhỏ màn hình terminal lại hết cỡ có thể, rồi sau đó ssh. Ta sẽ vào được more. Khi bạn đã không bị diss, hãy ấn nút V. Khi ấn V trong more, ta sẽ được nhảy sang vim
Khi này, ta có thể lấy pass bằng cách gõ lệnh sau trong vim
:e /etc/bandit_pass/bandit26
hoặc ta có thể làm như sau để lấy được shell của bandit26:
:set shell=/bin/bash
:shell
Từ 2 cách trên đều sẽ lấy được pass là c7GvcKlw9mC7aUQaPx7nwFstuAIBw1o1
Như đề bài chỉ, đầu tiên ta git clone repo qua cổng 2220
bandit27@bandit:/tmp$ git clone ssh://bandit27-git@localhost:2220/home/bandit27-git/repo
Cloning into 'repo'...
The authenticity of host '[localhost]:2220 ([127.0.0.1]:2220)' can't be established.
ED25519 key fingerprint is SHA256:C2ihUBV7ihnV1wUXRb4RrEcLfXC5CXlhmAAM/urerLY.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Could not create directory '/home/bandit27/.ssh' (Permission denied).
Failed to add the host to the list of known hosts (/home/bandit27/.ssh/known_hosts).
_ _ _ _
| |__ __ _ _ __ __| (_) |_
| '_ \ / _` | '_ \ / _` | | __|
| |_) | (_| | | | | (_| | | |_
|_.__/ \__,_|_| |_|\__,_|_|\__|
This is an OverTheWire game server.
More information on http://www.overthewire.org/wargames
bandit27-git@localhost's password:
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (3/3), done.
Mở repo và đọc file, ta ra password
bandit27@bandit:/tmp$ cd repo
bandit27@bandit:/tmp/repo$ ls
README
bandit27@bandit:/tmp/repo$ cat README
The password to the next level is: AVanL161y9rsbcJIsFHuw35rjaOM19nR