Pages

Tuesday, 14 January 2014

Attributes Of Servlets

An attribute in servlet is an object that can be set, get or removed from one of the following scopes:

request scope
session scope
application scope
The servlet programmer can pass information from one servlet to another using attributes. It is just like passing object from one class to another so that we can reuse the same object again and again.

Attribute specific methods of ServletRequest, HttpSession and ServletContext interface

There are following 4 attribute specific methods. They are as follows:
public void setAttribute(String name,Object object):sets the given object in the application scope.
public Object getAttribute(String name):Returns the attribute for the specified name.
public Enumeration getInitParameterNames():Returns the names of the context's initialization parameters as an Enumeration of String objects.
public void removeAttribute(String name):Removes the attribute with the given name from the servlet context.

Model View and Controller

MVC stands for Model View and Controller. It is a design pattern that separates the business logic, presentation logic and data.

Controller acts as an interface between View and Model. Controller intercepts all the incoming requests.

Model represents the state of the application i.e. data. It can also have business logic.

View represents the presentaion i.e. UI(User Interface).





Example of following MVC in JSP

In this example, we are using servlet as a controller, jsp as a view component, Java Bean class as a model.

In this example, we have created 5 pages:

index.jsp a page that gets input from the user.
ControllerServlet.java a servlet that acts as a controller.
login-success.jsp and login-error.jsp files acts as view components.
web.xml file for mapping the servlet.
File: index.jsp
<form action="ControllerServlet" method="post">  
Name:<input type="text" name="name"><br>  
Password:<input type="password" name="password"><br>  
<input type="submit" value="login">  
</form>  
File: ControllerServlet
package com.javatpoint;  
import java.io.IOException;  
import java.io.PrintWriter;  
import javax.servlet.RequestDispatcher;  
import javax.servlet.ServletException;  
import javax.servlet.http.HttpServlet;  
import javax.servlet.http.HttpServletRequest;  
import javax.servlet.http.HttpServletResponse;  
public class ControllerServlet extends HttpServlet {  
    protected void doPost(HttpServletRequest request, HttpServletResponse response)  
            throws ServletException, IOException {  
        response.setContentType("text/html");  
        PrintWriter out=response.getWriter();  
          
        String name=request.getParameter("name");  
        String password=request.getParameter("password");  
          
        LoginBean bean=new LoginBean();  
        bean.setName(name);  
        bean.setPassword(password);  
        request.setAttribute("bean",bean);  
          
        boolean status=bean.validate();  
          
        if(status){  
            RequestDispatcher rd=request.getRequestDispatcher("login-success.jsp");  
            rd.forward(request, response);  
        }  
        else{  
            RequestDispatcher rd=request.getRequestDispatcher("login-error.jsp");  
            rd.forward(request, response);  
        }  
      
    }  
  
    @Override  
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)  
            throws ServletException, IOException {  
        doPost(req, resp);  
    }  
}  
File: LoginBean.java
package com.javatpoint;  
public class LoginBean {  
private String name,password;  
  
public String getName() {  
    return name;  
}  
public void setName(String name) {  
    this.name = name;  
}  
public String getPassword() {  
    return password;  
}  
public void setPassword(String password) {  
    this.password = password;  
}  
public boolean validate(){  
    if(password.equals("admin")){  
        return true;  
    }  
    else{  
        return false;  
    }  
}  
}  
File: login-success.jsp
<%@page import="com.javatpoint.LoginBean"%>  
  
<p>You are successfully logged in!</p>  
<%  
LoginBean bean=(LoginBean)request.getAttribute("bean");  
out.print("Welcome, "+bean.getName());  
%>  
File: login-error.jsp
<p>Sorry! username or password error</p>  
<%@ include file="index.jsp" %>  
File: web.xml
<?xml version="1.0" encoding="UTF-8"?>  
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"   
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"   
id="WebApp_ID" version="3.0">  
    
  <servlet>  
  <servlet-name>s1</servlet-name>  
  <servlet-class>com.javatpoint.ControllerServlet</servlet-class>  
  </servlet>  
  <servlet-mapping>  
  <servlet-name>s1</servlet-name>  
  <url-pattern>/ControllerServlet</url-pattern>  
  </servlet-mapping>  
</web-app>  




JSP VS SERVLETS

Following Points are noted for Java Server Pages:-

1. JSP is a webpage scripting language that can generate dynamic content.
2. JSP run slower compared to Servlet as it takes compilation time to convert into Java Servlets.
3. It’s easier to code in JSP than in Java Servlets.
4. In MVC, jsp act as a view.
5. JSP are generally preferred when there is not much processing of data required.
6.The advantage of JSP programming over servlets is that we can build custom tags which can directly call Java beans.
7.We can achieve functionality of JSP at client side by running JavaScript at client side.


Following Points are noted for Java Servlets:-

1. Servlets are Java programs that are already compiled which also creates dynamic web content.
2. Servlets run faster compared to JSP.
3. Its little much code to write here.
4. In MVC, servlet act as a controller.
5. Servlets are best for use when there is more processing and manipulation involved.
6. There is no such custom tag facility in servlets.

7. There are no such methods for servlets.


Sunday, 6 October 2013

Scans and Counter Measures

Before Starting scanning and its methodology we must start with discussing types of scans.
First of all there are 3 types of scans possible based on their operation performed.
These are Port Scanning, Network Scanning and vulnerability scanning.
1.Port Scanning is used to determine open ports and services.
2.Network Scanning is used to locate working IP Addresses from a list and find out which are more      useful.
3.Vulnerability Scanning is for knowing the weaknesses in a network computers.

Know,Let us know about some popular services and ports used by them.FTP uses port no 21, Telnet uses port no 23, HTTP uses port 80, SMTP-25,POP3-110,HTTPS-443.

Scanning Methodology:-

1.Check for Live Systems.
we can check for live systems by performing Ping Sweep of IP Addresses.The systems responding to PING are active or live others might be Inactive or possibility of firewalls.

2.Check Open Ports.
3.Service Identification.
4.banner Grabbing or OS FingerPrinting.
5.Vulnerability Scanning.

NOTE:-
ICMP Scanning or Ping Sweep :-
Sending ICMP requests to all hosts on network to determine which are up and responding.It runs parallel on all systems because it can be run on all Systems simultaneously.

CounterMeasures to Port Scanning:-
Following steps could be followed:-
1.Implementation Of Intrusion Detection Systems or firewalls, should be followed.
2.After implementation of IDS or firewalls perform port scanning using tools such as Pinger, Friendly Pinger, WS_PING_PRO and many more so as to know whether firewall correctly works or not.
3.Check whether firewall able to detect probes set up by Port scanning tool.
It is to be noted that firewall must scan both data and packet not only TCP Header to determine whether traffic is allowed to pass through Firewall.
4.Network IDS should be used to hold on Operating System Detection Methods.
5.Onlu Needed Ports should be opened and rest closed.

Thursday, 26 September 2013

Introduction to FootPrinting

FootPrinting is the first step of Gathering Information about the systems of the organization we are trying to exploit.
Footprinting is a simple concept of revealing vulnerabilities in systems and the ease with which it can be exploited.
Purpose:-
Find ways to intrude into the systems and environments. It also includes creation of a map or BluePrint of Organization's Network.

A simple way for gathering information is GOOGLE the GURU.
So as to find out parameters , Some file types or some content in the URL.
Some Tools like samSpade, NSlookUp, WhoIs, DNSLookUp and many more are available.

DNS ENUMERATION:-
DNS or Domain Name Server is the process of locating all DNS servers and corresponding records.
Serching out for information about servers is made easy with help of various online available resources like

1.ARIN (American Registry for Internet Numbers)
Click here to view ARIN Website .
2.APNIC (Asia Pacific Network Information Centre)
Click Here to view APNIC Website .
3.LACNIC (Latin America And  Caribbean Network Information Centre)
Click Here to view LACNIC Website
4.RIPENCC for europe continent.
5.AFRINIC for africa continent.

DNS Record Types
1.A(Address):- Map Host Name to IP Address.
2.SDA(Start Of Authority):- Identify DNS Server responsible for Domain Information.
3.CNAME(Canonical Name):- Provide Additional Name of aliases for Address Records
4.MX(Mail Exchange):- Identify Mail Server For Domain.
5.SRV(Service):- Identify Services such as Directory Services.
6.PTR(Pointer):- Map IP Address To Host Names.
7.NS(Name Server):-Identify other Name services for Domain.


Friday, 6 September 2013

Introduction To Network Mapping

Network Mapping In Simple terms means connecting Networks physically.Network mapping discovers all the devices on the network and their connectivity with that Network.

Let us Know Discuss about Network Mapping and actually ways of Network Mapping
1.Identify Live Hosts
2.Determine running Services
.TCP Port Scanning
.UDP Port Scanning
.Banner Grabbing
.ARP Discovery
3.Identify Perimeter Network (Router / Firewalls)‏
.Tracerouting
.Scan Default Firewall/Router Ports
.Perform FIN/ACK Scan
.Map Router / Firewall Rule-Base
4.Passive OS Guessing
5.Active OS Guessing
.TCP/IP Stack Fingerprinting
.HTTP Packet Analysis
.ICMP Packet Analysis
.Telnet Handshake Analysis
6.Host Enumeration
.Systems Enumeration

Identify Live Hosts:-
In this we discuss various tools which are used to detect Live Hosts Over the Network .
Here,Project Scope will restrict scan spectrum.
Tools Used for Identifying Live Hosts.
1.ping
2.nmap
3.hping
3.traceroute
4.tpctraceroute

ping as we all know is a pc network tool used to test whether a particular host is reachable across an IP network.

Nmap or Network Mapper is a security scanner tool used to discover Host and services on a computer network, thus creating a "map" of the network. To complete its goal, Nmap sends specially crafted packets to the target host and then analyzes the responses.
Some Of Features Of Nmap are:-
1.Host discovery - Identifying hosts on a network. For example, listing the hosts that respond to pings or have a particular port open.
2.Port scanning - Enumerating the open ports on target hosts.
3.Version detection - Interrogating network services on remote devices to determine application name and version number.
4.OS detection - Determining the operating system and hardware characteristics of network devices.
5.Scriptable interaction with the target - using Nmap Scripting Engine (NSE) and Lua programming language.(Lightweight Scripting Language written in ANSI C)
6.Nmap can provide further information on targets, including reverse DNS names, device types, and MAC addresses.
Typical uses of Nmap:
1.Auditing the security of a device by identifying the network connections which can be made to it.
2.Identifying open ports on a target host in preparation for auditing.
3.Network inventory, network mapping, maintenance and asset management.
4.Auditing the security of a network by identifying new servers.

hping is a free packet generator and analyzer for the TCP/IP protocol. Hping is one of the de facto tools for security auditing and testing of firewalls and networks, and was used to exploit the idle scan scanning technique, and now implemented in the Nmap Security Scanner. The Version hping3, is scriptable using the Tcl language and implements an engine for string based, human readable description of TCP/IP packets, so that the programmer can write scripts related to low level TCP/IP packet manipulation and analysis in very short time.
Like most tools used in computer security, hping is useful to both system administrators and hackers.




Thursday, 5 September 2013

Controls Assessment and Scheduling

Controls Assessment and Scheduling in Networks include steps or phases. Some of these are:-
1.Information Gathering.
2.Network Mapping.
3.Vulnerability Identification.
4.Penetration.
5.Gaining Access & Escalation
6.Enumerating Further.
7.Compromise Remote Users/Sites.
8.Maintaining Sites.
9.Covering Tracks.
We will Know discuss all of above One by One.

Information Gathering 

Following are the steps followed during Information Gathering Phase.
1.Locate the target Web presence.
2.Examine the target using search engines.
3.Search Web groups.
4.Search employee personal Web sites.
5.Search Security & Exchange Commission and finance sites.
6.Search uptime statistics sites.
7.Search system/network survey sites.
8.Search on P2P networks.
9.Search on Internet Relay Chat (IRC).
10.Search job databases.
11.Search newsgroups (NNTP).
12.Gain information from domain registrar.
13.Check for reverse DNS lookup presence.
14.Check more DNS information.
15.Check Spam database lookup.
16.Check to change WHOIS information.
Tools used for purpose of Information Gathering:
Firefox
Dogpile.com
Alexa.org
Archive.org