Sunday, June 17, 2012

HTTP Response Headers for Mitigating Web Hacks

HTTP (Hyper Text Transfer Protocol) is an Application Protocol which has different headers for each Requests sent and Responses received based upon the content being exchanged between Web Server, Proxy Server, Cache Server, User-Agent etc.

HttpOnly
Example below shows the syntax used within the HTTP response header:
Set-Cookie: =[; =][; expires=][; domain=][; path=][; secure][; HttpOnly]

Majority of XSS attacks target theft of session id's, cookies etc. A server could help mitigate this issue by setting the HTTPOnly flag on a cookie it creates, indicating the cookie should not be accessible on the client.
 As a result, even if a cross-site scripting (XSS) flaw exists, and a user accidentally accesses a link that exploits this flaw, the browser (primarily Internet Explorer) will not reveal the cookie to a third party.



 If a browser that supports HttpOnly detects a cookie containing the HttpOnly flag, and client side script code attempts to read the cookie, the browser returns an empty string as the result. This causes the attack to fail by preventing the malicious (usually XSS) code from sending the data to an attacker's website.

X-Frame-Options
Used to prevent Clickjacking by not allowing page to be rendered in a frame. There are two possible values for X-Frame-Options
DENY
The page cannot be displayed in a frame, regardless of the site attempting to do so.
SAMEORIGIN
The page can only be displayed in a frame on the same origin as the page itself.



X-Content-Security-Policy
Example 1: Site wants all content to come from its own domain:
X-Content-Security-Policy: allow 'self'

Example 2: Auction site wants to allow images from anywhere, plugin content from a list of trusted media providers (including a content distribution network), and scripts only from its server hosting sanitized JavaScript:
X-Content-Security-Policy: allow 'self'; img-src *; \
                           object-src media1.com media2.com *.cdn.com; \
                           script-src trustedscripts.example.com

Example 3: Server administrators want to deny all third-party scripts for the site, and a given project group also wants to disallow media from other sites (header provided by sysadmins and header provided by project group are both present):
X-Content-Security-Policy: allow *; script-src 'self'
X-Content-Security-Policy: allow *; script-src 'self'; media-src 'self';

Example 4: Online payments site wants to ensure that all of the content in its pages is loaded over SSL to prevent attackers from eavesdropping on requests for insecure content:
X-Content-Security-Policy: allow https://*:443

Strict-Transport-Security (HSTS=HTTP Strict Transport Security)
The first time your site is accessed using HTTPS and it returns the Strict-Transport-Security header, the browser records this information, so that future attempts to load the site using HTTP will automatically use HTTPS instead.
Strict-Transport-Security: max-age=expireTime [; includeSubdomains]

expireTime
        The time, in seconds, that the browser should remember that this site is only to be accessed using HTTPS.
includeSubdomains (Optional)
        If this optional parameter is specified, this rule applies to all of the site's subdomains as well.

The HSTS policy helps protect website users against some passive (eavesdropping) and active network attacks. A man-in-the-middle attacker

X-XSS-Protection
This header is exclusive to Internet Explorer 8 which turns on cross site scripting protection(Off by default as it could potentially break some websites).

X-Download-Options
Stops the opening of the files directly from the domain. The browser removes the file opening control from the download box when it encounters a noopen parameter in the X-Download-Options as a part of the HTTP response.

X-Content-Type-Options
Used to prevent MIME based attacks which may lead to code execution.

unset Server
Don't give verbose information about type of Web Server running, its version, extra plugins loaded etc.

Packet Level View: SIP UAC REGISTERing with PBX Server

Lets get into the capture level details of SIP User Agent Client (UAC) registering with User Agent Server (UAS). Also see how subscribe and notify work.

Asterisk PBX (Private Branch eXchange) Server (UAS) 3.3.3.10
X-Lite Phone (UAC) 3.3.3.101

REGISTER
SIP registration is a method used by a SIP device (Softphone, Analog Phone with ATA, PBX Server etc) to inform its registrar (VoIP provider, PBX) where SIP device is located.
Initial REGISTER request may be plain without without Authentication details for registering contact information. If Client need to authenticate, PBX Server responds back with "401 Unauthorized". REGISTER requests should be challenged for Authentication. Once Registration is successful VoIP provider will know where to forward incoming calls. 





REGISTER requests add, remove and query bindings. A REGISTER request can add a new binding between an address-of-record and one or more contact addresses.  Registration on behalf of a particular address-of-record can be performed by a suitably authorized third party.  A client(Phone, UAC) can also remove previous bindings or query to determine which bindings are currently in place for an address-of-record.


Registrar 
A server that accepts REGISTER requests and places the information it receives in those requests into the location service for the domain it handles which registers one or more IP addresses to a certain SIP URI, indicated by the sip: scheme, although other protocol schemes are possible (such as tel:). More than one user agent can register at the same URI, with the result that all registered user agents will receive a call to the SIP URI.

SUBSCRIBE
The general concept of SUBSCRIBE is that entities in the network can subscribe (X-Lite softphone) 
to resource or call state for various resources or calls in the network, and those entities (or entities 
acting on their behalf) can send notifications (PBX, VoIP Service Provider) when those states change. 
If SUBSCRIBE needs Authentication Server responds back with "401 Unauthorized".


NOTIFY 
NOTIFY the subscriber of a new Event by returning current state information.
Typical flow of SUBSCRIBE and NOTIFY messages are given below
 (X-Lite Phone)     (Asterisk PBX Server)
   Subscriber          Notifier
       |-----SUBSCRIBE---->|     Request state subscription
       | <--------200---------- |     Acknowledge subscription
       |<------NOTIFY------- |     Return current state information
       |--------200----------->|
       |<------NOTIFY------- |     Return current state information
       |--------200----------->|
Subscriptions are expired and must be refreshed by subsequent SUBSCRIBE messages. 
To configure X-Lite Softphone and Asterisk PBX go through below link http://darshanams.blogspot.in/2012/06/softphone-registration-with-asterisk.html

Friday, June 15, 2012

REGISTERing Softphone and Analog Phone with Asterisk PBX

In this article we are going to look at configuring Asterisk PBX (Private Branch eXchange) with different Users/Extensions as well as REGISTERing X-Lite Softphone and Beetel M 71 Analog Phone with Asterisk Soft PBX.
Asterisk is installed on Ubuntu 12.04LTS, X-Lite Softphone on Windows XP SP3.

If Asterisk PBX is already running, stop asterisk service.
$sudo /etc/init.d/asterisk stop
 * Stopping Asterisk PBX: asterisk

Edit Asterisk PBX SIP Configuration file
$sudo vim /etc/asterisk/sip.conf

Add users as per requirement, see below snapshot   



Edit extensions.conf file, see below snapshot
$sudo vim /etc/asterisk/extensions.conf 

extern => 1003,n,Dial(SIP/1002,20,tr) is the config in above snapshot which says, "any call to extension 1003 will be forwarded to 1002".
Start Asterisk soft PBX as below
#sudo /etc/init.d/asterisk start
 * Starting Asterisk PBX: asterisk

After starting execute below command as root which will output Asterisk debug logs
#asterisk -vvr


When we start X-Lite Softphone and click Softphone -> Account Settings
below window should appear

Analog Phone is connected to ATA (Analog Telephone Adapter). ATA will have Phone Ports (RJ11) for connecting Analog Phones and Ethernet Ports (RJ45) for connecting to IP network.
Below snapshot shows Analog Telephone Adapter (ATA) connection setting.



REGISTERing my X-Lite Softphone with Asterisk PBX.


In the same way we should register Analog Phone(beetel M 71) with Asterisk PBX. Once the registration is done we can call from Analog Phone to Softphone or viceversa.

To get into details of how communication happens between Asterisk PBX and X-Lite Softphone by getting into each packet of the above capture see below post
http://darshanams.blogspot.in/2012/06/x-lite-client-registering-with-pbx.html

Thursday, May 31, 2012

Cain and Abel: Password Cracking

Cain and Abel is a Password recovery and Cracking tool using Dictionary, Bruteforce and Cryptanalysis on Windows Operating Systems.

Step 1: Open Cain and Abel, click on "Cracker". On the left column we can see different Cracking Techniques. Select the Cracker which you are interested in, here,  "LM & NTLM Hashes".


Step 2: After selecting "LM & NTLM Hashes", you can see + sign getting highlighted. Click on it. We can see different users present on this machine.




Step 3: Select the user for which you want to know/crack the password. We have different Password Cracking Techniques like Dictionary Attaks, Bruteforce Password guessing, Cryptanalysis Attacks etc. One you select the type of Cracking, go for "LM Hashes" or "NTLM Hashes"


Step 4: Below screenshot shows while cracking is going on.


Step 5: Screen shot showing the cracked password. Passwords are divided into two blocks of 7 characters each. On each block we calculate the LM Hash which is of 8 byte . "T" is the character present in password,  part of second block of hash. "IAMGREA" are characters present in password, part of first block of hash.


Step 6: Cracked Screen shot. Final. Enjoy !!!
Username: praveen
Password: iamgreat


Enjoy Cracking Passwords !
Strictly for educational purposes!!! Have Fun ;-)

The method described above is an offline cracking of passwords. You can crack  passwords online but chances of getting caught may be very high by Perimeter security devices(IDS, IPS, Web Gateways etc).

Read below article which explains how to build an open source IDS/IPS, Snort.
http://darshanams.blogspot.in/2012/05/installing-snort-from-source-as-ips.html

For sample Snort Rule/Signature structure
http://darshanams.blogspot.in/2012/07/bittorrent-useragents-and-detection.html

Wednesday, May 9, 2012

Installing SNORT as IPS, building from Source

Install below libraries from source in given order by running commands "configure", "make" and "make install".
    pcre-8.30.zip
    libdnet-1.12.tgz
    libnetfilter_queue-1.0.1.tar
    libnfnetlink-1.0.0.tar
    libpcap-1.2.1.tar.gz
    daq-0.6.2.tar.gz
    snort-2.9.2.2.tar.gz
    snortrules-snapshot-2922.tar.gz
At the point of writing this article above tar/zip files were the latest available.

By default most of the packages install at /usr/local so forcing them to install in /usr. For example if you install libpcap-1.2.1 by just running ./configure and check the running version, it may show u as libpcap-0.9.4. To overcome the issue we are building with below argument
./configure –enable-ipv6 –prefix=/usr

--enable-ipv6              will enable sniffing IPv6 packets

When DAQ (Data Aquisition) module is successfully configured we get below output
DAQ Output after ./configure –enable-ipv6 --prefix=/etc

Build AFPacket DAQ module.. : yes
Build Dump DAQ module........ : yes
Build IPFW DAQ module......... : yes
Build IPQ DAQ module............ : no
Build NFQ DAQ module........... : yes
Build PCAP DAQ module......... : yes

IPQ is obsoleted so didn't install it


Snort Configuration Command
./configure --libdir=/usr/lib --includedir=/usr/include --enable-ipv6 --enable-gre --enable-targetbased –enable-ipfw –enable-dynamicplugin --enable-decoder-preprocessor-rules --enable-active-response --enable-normalizer --enable-reload --enable-react --enable-zlib

Fore developing preprocessor plugins you can add
--enable-debug
--enable-debug-msgs

Aditionally you might need dpx-1.4.tar.gz.

Errors seen while starting Snort:
For snort_dynamicrules not found error, create /usr/local/lib/snort_dynamicrules and copy .so files there,
For white_listing.rules, black_listing.rules files missing errors create those files and comment out reputation preprocessor from snort.conf.

#/home/praveen/snort-2.9.2.2#snort -V
,,_ -*> Snort! <*-
o" )~ Version 2.9.2.2 IPv6 GRE (Build 121)
'''' By Martin Roesch & The Snort Team: http://www.snort.org/snort/snort-team
Copyright (C) 1998-2012 Sourcefire, Inc., et al.
Using libpcap version 1.2.1
Using PCRE version: 8.30 2012-02-04
Using ZLIB version: 1.2.3
#/home/praveen/snort-2.9.2.2#

Starting snort with -Q option will make it run as IPS.


You can refer similar article from
http://techminded.net/blog/using-snort-as-service-ips.html

For Snort Preprocessors you can refer below link
http://darshanams.blogspot.in/2010/06/snort-preprocessors-and-alerts.html

For sending Snort alerts to Syslog server
http://darshanams.blogspot.in/2011/05/snort-logging-alerts-to-syslog-server.html

For detailed description of various concepts refer SnortTM Users Manual.
http://www.snort.org/assets/140/snort_manual_2_8_6.pdf

Thursday, May 3, 2012

Mac OS X Infector and Research Resources/Links

These are the links/resources collected by one of my friends Sandeep for his research purposes, shared with me. Most of it is worth the read. Hope this helps someone somewhere gain some knowledge........ !!!


HTE -- File manipulator
http://hte.sourceforge.net/

Mach-O filetype and infection methods
http://felinemenace.org/~nemo/slides/mach-o_infection.ppt

Same idea, different author
http://vx.netlux.org/lib/vrg01.html

Method Swizzling (you can remap the function name pointer to binary code mapping on OS-X)
http://www.cocoadev.com/index.pl?MethodSwizzling

Class Posing!
http://www.cocoadev.com/index.pl?ClassPosing
http://www.stepwise.com/Articles/Technical/PosersAndCategories/index.html

OS-X Tools:
otool -- Object File Displaying Tool http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/man1/otool.1.html

gdb -- GNU Debugger (part of GCC)
http://developer.apple.com/tools/gcc_overview.html

gas -- host spoofing manager
http://www.apple.com/downloads/macosx/development_tools/gasmask.html

libtool -- Create Libraries
http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/man1/libtool.1.html

file -- File Typer
http://linux.die.net/man/1/file

ktrace -- Kernel Trace Logging for a process
System Calls, Name Translations, Signal Processing, I/O

dtrace -- Debugger/Tracer in 10.5+
http://www.mactech.com/articles/mactech/Vol.23/23.11/ExploringLeopardwithDTrace/index.html

http://www.macosxhints.com/article.php?story=20071031121823710

kdump -- Kernel Dump Reader

class-dump -- Examines Objective-C Runtime data for MachO files.
http://codethecode.com/projects/class-dump/

Summary of other useful tools:
http://osxbook.com/book/bonus/ancient/whatismacosx/tools.html


Other interesting links are most welcome. I can update the post if there are any interesting links.